use of mage.abilities.effects.Effect in project mage by magefree.
the class PopulateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return true;
}
player.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent tokenToCopy = game.getPermanent(target.getFirstTarget());
if (tokenToCopy == null) {
return true;
}
game.informPlayers("Token selected for populate: " + tokenToCopy.getLogName());
Effect effect = new CreateTokenCopyTargetEffect(null, null, false, 1, tappedAndAttacking, tappedAndAttacking);
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
return effect.apply(game, source);
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class ReplicateCopyEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.sourceId)) {
StackObject spell = game.getStack().getStackObject(this.sourceId);
if (spell instanceof Spell) {
Card card = ((Spell) spell).getCard();
if (card != null) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof ReplicateAbility) {
if (ability.isActivated()) {
for (Effect effect : this.getEffects()) {
effect.setValue("ReplicateSpell", spell);
effect.setValue("ReplicateCount", ((ReplicateAbility) ability).getActivateCount());
}
return true;
}
}
}
}
}
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class AllianceOfArmsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int xSum = 0;
xSum += ManaUtil.playerPaysXGenericMana(false, "Alliance of Arms", controller, source, game);
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (!Objects.equals(playerId, controller.getId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
xSum += ManaUtil.playerPaysXGenericMana(false, "Alliance of Arms", player, source, game);
}
}
}
if (xSum > 0) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Effect effect = new CreateTokenTargetEffect(new SoldierToken(), xSum);
effect.setTargetPointer(new FixedTarget(playerId));
effect.apply(game, source);
}
}
// prevent undo
controller.resetStoredBookmark(game);
return true;
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class BalduvianWarlordUnblockEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getTargets().getFirstTarget());
if (controller != null && permanent != null) {
// Remove target creature from combat
Effect effect = new RemoveFromCombatTargetEffect();
effect.apply(game, source);
// Make blocked creatures unblocked
BlockedByOnlyOneCreatureThisCombatWatcher watcher = game.getState().getWatcher(BlockedByOnlyOneCreatureThisCombatWatcher.class);
if (watcher != null) {
Set<CombatGroup> combatGroups = watcher.getBlockedOnlyByCreature(permanent.getId());
if (combatGroups != null) {
for (CombatGroup combatGroup : combatGroups) {
if (combatGroup != null) {
combatGroup.setBlocked(false, game);
}
}
}
}
// Choose new creature to block
if (permanent.isCreature(game)) {
// according to the following mail response from MTG Rules Management about False Orders:
// "if Player A attacks Players B and C, Player B's creatures cannot block creatures attacking Player C"
// therefore we need to single out creatures attacking the target blocker's controller (disappointing, I know)
List<Permanent> list = new ArrayList<>();
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (combatGroup.getDefendingPlayerId().equals(permanent.getControllerId())) {
for (UUID attackingCreatureId : combatGroup.getAttackers()) {
Permanent targetsControllerAttacker = game.getPermanent(attackingCreatureId);
list.add(targetsControllerAttacker);
}
}
}
Player targetsController = game.getPlayer(permanent.getControllerId());
if (targetsController != null) {
FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
filter.add(new PermanentInListPredicate(list));
TargetAttackingCreature target = new TargetAttackingCreature(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
controller.chooseTarget(outcome, target, source, game);
}
} else {
return true;
}
Permanent chosenPermanent = game.getPermanent(target.getFirstTarget());
if (chosenPermanent != null && chosenPermanent.isCreature(game)) {
CombatGroup chosenGroup = game.getCombat().findGroup(chosenPermanent.getId());
if (chosenGroup != null) {
// Relevant ruling for Balduvian Warlord:
// 7/15/2006 If an attacking creature has an ability that triggers “When this creature becomes blocked,”
// it triggers when a creature blocks it due to the Warlord's ability only if it was unblocked at that point.
boolean notYetBlocked = chosenGroup.getBlockers().isEmpty();
chosenGroup.addBlockerToGroup(permanent.getId(), controller.getId(), game);
// 702.21h
game.getCombat().addBlockingGroup(permanent.getId(), chosenPermanent.getId(), controller.getId(), game);
if (notYetBlocked) {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, chosenPermanent.getId(), source, null));
Set<MageObjectReference> morSet = new HashSet<>();
morSet.add(new MageObjectReference(chosenPermanent, game));
for (UUID bandedId : chosenPermanent.getBandedCards()) {
CombatGroup bandedGroup = game.getCombat().findGroup(bandedId);
if (bandedGroup != null && chosenGroup.getBlockers().size() == 1) {
morSet.add(new MageObjectReference(bandedId, game));
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, bandedId, source, null));
}
}
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));
}
game.fireEvent(new BlockerDeclaredEvent(chosenPermanent.getId(), permanent.getId(), permanent.getControllerId()));
}
// a new blockingGroup is formed, so it's necessary to find it again
CombatGroup blockGroup = findBlockingGroup(permanent, game);
if (blockGroup != null) {
blockGroup.pickAttackerOrder(permanent.getControllerId(), game);
}
}
}
return true;
}
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class CemeteryGatekeeperTriggeredAbility method checkInterveningIfClause.
@Override
public boolean checkInterveningIfClause(Game game) {
Effect effect = getEffects().get(0);
UUID targetId = (UUID) effect.getValue("targetId");
GameEvent.EventType eventType = (GameEvent.EventType) effect.getValue("eventType");
UUID exileId = (UUID) effect.getValue("exileId");
if (targetId != null && eventType != null && exileId != null) {
if (eventType == GameEvent.EventType.LAND_PLAYED) {
Permanent permanent = game.getPermanent(targetId);
return permanent != null && checkCardTypes(permanent.getCardType(game), exileId, game);
} else if (eventType == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getSpellOrLKIStack(targetId);
return spell != null && checkCardTypes(spell.getCardType(game), exileId, game);
}
}
return false;
}
Aggregations