use of mage.game.combat.CombatGroup in project mage by magefree.
the class SorrowsPathSwitchBlockersEffect method reassignBlocker.
private void reassignBlocker(Permanent blocker, Set<Permanent> attackers, Game game) {
for (Permanent attacker : attackers) {
CombatGroup group = game.getCombat().findGroup(attacker.getId());
if (group != null) {
group.addBlockerToGroup(blocker.getId(), blocker.getControllerId(), game);
game.getCombat().addBlockingGroup(blocker.getId(), attacker.getId(), blocker.getControllerId(), game);
// TODO: find an alternate event solution for multi-blockers (as per issue #4285), this will work fine for single blocker creatures though
game.fireEvent(new BlockerDeclaredEvent(attacker.getId(), blocker.getId(), blocker.getControllerId()));
group.pickBlockerOrder(attacker.getControllerId(), game);
}
}
// a new blockingGroup is formed, so it's necessary to find it again
CombatGroup blockGroup = findBlockingGroup(blocker, game);
if (blockGroup != null) {
blockGroup.pickAttackerOrder(blocker.getControllerId(), game);
}
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class TheWretchedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent theWretched = source.getSourcePermanentIfItStillExists(game);
if (theWretched == null || theWretched.isRemovedFromCombat() || !theWretched.isAttacking() || !source.isControlledBy(theWretched.getControllerId())) {
return false;
}
// Check if control of source has changed since ability triggered????? (does it work is it neccessary???)
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (!combatGroup.getAttackers().contains(source.getSourceId())) {
continue;
}
for (UUID creatureId : combatGroup.getBlockers()) {
Permanent blocker = game.getPermanent(creatureId);
if (blocker == null || blocker.getBlocking() <= 0) {
continue;
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.WhileControlled, source.getControllerId());
effect.setTargetPointer(new FixedTarget(blocker.getId(), game));
game.addEffect(effect, source);
}
}
return true;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class TrialEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null && creature != null) {
Set<Card> toHand = new HashSet<>();
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (combatGroup.getBlockers().contains(creature.getId())) {
for (UUID attackerId : combatGroup.getAttackers()) {
Permanent attacker = game.getPermanent(attackerId);
if (attacker != null) {
toHand.add(attacker);
}
}
} else if (combatGroup.getAttackers().contains(creature.getId())) {
for (UUID blockerId : combatGroup.getBlockers()) {
Permanent blocker = game.getPermanent(blockerId);
if (blocker != null) {
toHand.add(blocker);
}
}
}
}
controller.moveCards(toHand, Zone.HAND, source, game);
return true;
}
return false;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class BecomeBlockedTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Set<MageObjectReference> morSet = new HashSet<>();
for (UUID targetId : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent == null) {
continue;
}
CombatGroup combatGroup = game.getCombat().findGroup(permanent.getId());
if (combatGroup == null) {
continue;
}
boolean alreadyBlocked = combatGroup.getBlocked();
combatGroup.setBlocked(true, game);
if (alreadyBlocked) {
continue;
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, permanent.getId(), source, null));
morSet.add(new MageObjectReference(permanent, game));
}
String key = UUID.randomUUID().toString();
game.getState().setValue("becameBlocked_" + key, morSet);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BATCH_BLOCK_NONCOMBAT, source.getSourceId(), source, source.getControllerId(), key, 0));
return true;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class CombatSimulator method load.
public static CombatSimulator load(Game game) {
CombatSimulator simCombat = new CombatSimulator();
for (CombatGroup group : game.getCombat().getGroups()) {
simCombat.groups.add(new CombatGroupSimulator(group.getDefenderId(), group.getAttackers(), group.getBlockers(), game));
}
for (UUID defenderId : game.getCombat().getDefenders()) {
simCombat.defenders.add(defenderId);
Player player = game.getPlayer(defenderId);
if (player != null) {
simCombat.playersLife.put(defenderId, player.getLife());
} else {
Permanent permanent = game.getPermanent(defenderId);
simCombat.planeswalkerLoyalty.put(defenderId, permanent.getCounters(game).getCount(CounterType.LOYALTY));
}
}
return simCombat;
}
Aggregations