mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Fix Dead-Iron Sledge (Issue #6445)
This commit is contained in:
parent
25886e4c1e
commit
06f770b9cd
1 changed files with 26 additions and 47 deletions
|
@ -2,14 +2,12 @@
|
||||||
package mage.cards.d;
|
package mage.cards.d;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.TriggeredAbility;
|
|
||||||
import mage.abilities.TriggeredAbilityImpl;
|
import mage.abilities.TriggeredAbilityImpl;
|
||||||
import mage.abilities.costs.mana.GenericManaCost;
|
import mage.abilities.costs.mana.GenericManaCost;
|
||||||
|
import mage.abilities.effects.Effect;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.keyword.EquipAbility;
|
import mage.abilities.keyword.EquipAbility;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
|
@ -19,14 +17,13 @@ import mage.constants.Outcome;
|
||||||
import mage.constants.SubType;
|
import mage.constants.SubType;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.combat.CombatGroup;
|
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.target.targetpointer.FixedTargets;
|
import mage.target.targetpointer.FixedTargets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jerekwilson
|
* @author jerekwilson, ciaccona007
|
||||||
*/
|
*/
|
||||||
public final class DeadIronSledge extends CardImpl {
|
public final class DeadIronSledge extends CardImpl {
|
||||||
|
|
||||||
|
@ -35,7 +32,7 @@ public final class DeadIronSledge extends CardImpl {
|
||||||
this.subtype.add(SubType.EQUIPMENT);
|
this.subtype.add(SubType.EQUIPMENT);
|
||||||
|
|
||||||
// Whenever equipped creature blocks or becomes blocked by a creature, destroy both creatures.
|
// Whenever equipped creature blocks or becomes blocked by a creature, destroy both creatures.
|
||||||
this.addAbility(new DeadIronSledgeTriggeredAbility());
|
this.addAbility(new DeadIronSledgeTriggeredAbility(new DeadIronSledgeDestroyEffect(), false));
|
||||||
|
|
||||||
// Equip {2}
|
// Equip {2}
|
||||||
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(2)));
|
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(2)));
|
||||||
|
@ -54,70 +51,52 @@ public final class DeadIronSledge extends CardImpl {
|
||||||
|
|
||||||
class DeadIronSledgeTriggeredAbility extends TriggeredAbilityImpl {
|
class DeadIronSledgeTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
|
|
||||||
private Set<UUID> possibleTargets = new HashSet<>();
|
public DeadIronSledgeTriggeredAbility(Effect effect, boolean optional) {
|
||||||
|
super(Zone.BATTLEFIELD, effect, optional);
|
||||||
DeadIronSledgeTriggeredAbility() {
|
|
||||||
super(Zone.BATTLEFIELD, new DeadIronSledgeDestroyEffect(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeadIronSledgeTriggeredAbility(final DeadIronSledgeTriggeredAbility ability) {
|
public DeadIronSledgeTriggeredAbility(final DeadIronSledgeTriggeredAbility ability) {
|
||||||
super(ability);
|
super(ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkEventType(GameEvent event, Game game) {
|
public boolean checkEventType(GameEvent event, Game game) {
|
||||||
return event.getType() == GameEvent.EventType.DECLARED_BLOCKERS;
|
return event.getType() == GameEvent.EventType.BLOCKER_DECLARED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
List<Permanent> targetPermanents = new ArrayList<>();
|
Permanent equipment = game.getPermanent(sourceId);
|
||||||
Permanent equipment = game.getPermanentOrLKIBattlefield((this.getSourceId()));
|
|
||||||
if (equipment != null && equipment.getAttachedTo() != null) {
|
if (equipment != null && equipment.getAttachedTo() != null) {
|
||||||
Permanent equippedPermanent = game.getPermanentOrLKIBattlefield((equipment.getAttachedTo()));
|
Permanent equipped = game.getPermanent(equipment.getAttachedTo());
|
||||||
if (equippedPermanent != null) {
|
if (equipped.getId().equals(event.getTargetId()) || equipped.getId().equals(event.getSourceId())) {
|
||||||
possibleTargets.clear();
|
List<Permanent> targets = new ArrayList<>();
|
||||||
if (equippedPermanent.isBlocked(game)) {
|
|
||||||
possibleTargets.add(equippedPermanent.getId()); //add equipped creature to target list
|
|
||||||
}
|
|
||||||
if (equippedPermanent.isAttacking()) {
|
|
||||||
for (CombatGroup group : game.getCombat().getGroups()) {
|
|
||||||
if (group.getAttackers().contains(equippedPermanent.getId())) {
|
|
||||||
possibleTargets.addAll(group.getBlockers());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (equippedPermanent.getBlocking() > 0) {
|
|
||||||
for (CombatGroup group : game.getCombat().getGroups()) {
|
|
||||||
if (group.getBlockers().contains(equippedPermanent.getId())) {
|
|
||||||
possibleTargets.addAll(group.getAttackers());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!possibleTargets.isEmpty()) {
|
|
||||||
this.getTargets().clear();
|
|
||||||
|
|
||||||
for (UUID creatureId : possibleTargets) {
|
Permanent blocker = game.getPermanent(event.getSourceId());
|
||||||
Permanent target = game.getPermanentOrLKIBattlefield(creatureId);
|
if (blocker != null) {
|
||||||
targetPermanents.add(target);
|
targets.add(blocker);
|
||||||
}
|
|
||||||
|
|
||||||
this.getEffects().get(0).setTargetPointer(new FixedTargets(targetPermanents, game));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Permanent blocked = game.getPermanent(event.getTargetId());
|
||||||
|
if (blocked != null) {
|
||||||
|
targets.add(blocked);
|
||||||
|
}
|
||||||
|
this.getEffects().get(0).setTargetPointer(new FixedTargets(targets, game));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TriggeredAbility copy() {
|
public String getRule() {
|
||||||
return new DeadIronSledgeTriggeredAbility(this);
|
return "Whenever equipped creature blocks or becomes blocked by a creature, " + super.getRule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRule() {
|
public DeadIronSledgeTriggeredAbility copy() {
|
||||||
return "Whenever equipped creature blocks or becomes blocked by a creature, destroy both creatures.";
|
return new DeadIronSledgeTriggeredAbility(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue