mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
Test and fix for triggered abilities of double faced cards
This commit is contained in:
parent
17dbe0ae57
commit
f641ffe77b
2 changed files with 64 additions and 16 deletions
|
@ -6,7 +6,7 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
* @author BetaSteward, noxx
|
||||
*/
|
||||
public class HuntmasterOfTheFellsTest extends CardTestPlayerBase {
|
||||
|
||||
|
@ -28,5 +28,31 @@ public class HuntmasterOfTheFellsTest extends CardTestPlayerBase {
|
|||
assertPermanentCount(playerA, "Ravager of the Fells", 1);
|
||||
assertPermanentCount(playerB, "Ornithopter", 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests first trigger happens both on enter battlefield and transform events
|
||||
*/
|
||||
@Test
|
||||
public void testCard2() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 3);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain");
|
||||
addCard(Constants.Zone.HAND, playerA, "Huntmaster of the Fells");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Ornithopter");
|
||||
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Mountain", 2);
|
||||
addCard(Constants.Zone.HAND, playerB, "Lightning Bolt", 2);
|
||||
|
||||
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Huntmaster of the Fells");
|
||||
castSpell(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA);
|
||||
castSpell(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA);
|
||||
setStopAt(4, Constants.PhaseStep.DRAW);
|
||||
execute();
|
||||
|
||||
assertLife(playerA, 18); // -6 damage, +4 life
|
||||
assertLife(playerB, 18);
|
||||
assertPermanentCount(playerA, "Wolf", 2);
|
||||
assertPermanentCount(playerA, "Ravager of the Fells", 0); // transformed back
|
||||
assertPermanentCount(playerA, "Huntmaster of the Fells", 1);
|
||||
assertPermanentCount(playerB, "Ornithopter", 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import mage.MageObject;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -54,26 +55,47 @@ public class TriggeredAbilities extends HashMap<UUID, TriggeredAbility> {
|
|||
public void checkTriggers(GameEvent event, Game game) {
|
||||
for (TriggeredAbility ability: this.values()) {
|
||||
if (ability.isInUseableZone(game, true)) {
|
||||
MageObject object = game.getPermanent(ability.getSourceId());
|
||||
if (object == null) {
|
||||
object = game.getLastKnownInformation(ability.getSourceId(), event.getZone());
|
||||
if (object == null) {
|
||||
object = game.getObject(ability.getSourceId());
|
||||
}
|
||||
}
|
||||
if (object != null && object.getAbilities().contains(ability)) {
|
||||
if (object instanceof Permanent) {
|
||||
ability.setControllerId(((Permanent) object).getControllerId());
|
||||
}
|
||||
if (ability.checkTrigger(event, game)) {
|
||||
UUID controllerId = ability.getControllerId();
|
||||
ability.trigger(game, controllerId);
|
||||
MageObject object = getMageObject(event, game, ability);
|
||||
if (object != null) {
|
||||
if (checkAbilityStillExists(ability, object)) {
|
||||
if (object instanceof Permanent) {
|
||||
ability.setControllerId(((Permanent) object).getControllerId());
|
||||
}
|
||||
if (ability.checkTrigger(event, game)) {
|
||||
UUID controllerId = ability.getControllerId();
|
||||
ability.trigger(game, controllerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAbilityStillExists(TriggeredAbility ability, MageObject object) {
|
||||
boolean exists = true;
|
||||
if (!object.getAbilities().contains(ability)) {
|
||||
exists = false;
|
||||
if (object instanceof PermanentCard) {
|
||||
PermanentCard permanent = (PermanentCard)object;
|
||||
if (permanent.canTransform()) {
|
||||
exists = permanent.getCard().getAbilities().contains(ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
private MageObject getMageObject(GameEvent event, Game game, TriggeredAbility ability) {
|
||||
MageObject object = game.getPermanent(ability.getSourceId());
|
||||
if (object == null) {
|
||||
object = game.getLastKnownInformation(ability.getSourceId(), event.getZone());
|
||||
if (object == null) {
|
||||
object = game.getObject(ability.getSourceId());
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
public void add(TriggeredAbility ability) {
|
||||
this.put(ability.getId(), ability);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue