refactor: improved some error messages/tests

This commit is contained in:
Oleg Agafonov 2023-06-16 07:32:21 +04:00
parent 7f8526192f
commit f0da749e0a
3 changed files with 11 additions and 7 deletions

View file

@ -5,10 +5,7 @@ import mage.MageObject;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.LegendarySpellAbility;
import mage.abilities.common.SagaAbility;
import mage.abilities.common.WerewolfBackTriggeredAbility;
import mage.abilities.common.WerewolfFrontTriggeredAbility;
import mage.abilities.common.*;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.FightTargetsEffect;
import mage.abilities.effects.common.counter.ProliferateEffect;
@ -1734,6 +1731,11 @@ public class VerifyCardDataTest {
fail(card, "abilities", "the back face of a double-faced card should be nightCard = true");
}
// special check: siege ability must be used in double faced cards only
if (card.getAbilities().containsClass(SiegeAbility.class) && card.getSecondCardFace() == null) {
fail(card, "abilities", "miss second side settings in card with siege ability");
}
// special check: legendary spells need to have legendary spell ability
if (card.isLegendary() && !card.isPermanent() && !card.getAbilities().containsClass(LegendarySpellAbility.class)) {
fail(card, "abilities", "legendary nonpermanent cards need to have LegendarySpellAbility");

View file

@ -64,10 +64,12 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
if (event == null || !game.getContinuousEffects().preventedByRuleModification(event, ability, game, false)) {
if (object != null) {
boolean controllerSet = false;
if (ability.getZone() != Zone.COMMAND && event != null
if (ability.getZone() != Zone.COMMAND
&& event != null
&& event.getTargetId() != null
&& ability.isLeavesTheBattlefieldTrigger()
&& game.getLKI().get(Zone.BATTLEFIELD) != null && game.getLKI().get(Zone.BATTLEFIELD).containsKey(ability.getSourceId())) {
&& game.getLKI().get(Zone.BATTLEFIELD) != null
&& game.getLKI().get(Zone.BATTLEFIELD).containsKey(ability.getSourceId())) {
// need to check if object was face down for dies and destroy events because the ability triggers in the new zone, zone counter -1 is used
Permanent permanent = (Permanent) game.getLastKnownInformation(ability.getSourceId(), Zone.BATTLEFIELD, ability.getSourceObjectZoneChangeCounter() - 1);
if (permanent != null) {

View file

@ -637,7 +637,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
public SpellAbility getSecondFaceSpellAbility() {
Card secondFace = getSecondCardFace();
if (secondFace == null || secondFace.getClass().equals(getClass())) {
throw new IllegalArgumentException("Wrong code usage. getSecondFaceSpellAbility can only be used for double faced card (main side).");
throw new IllegalArgumentException("Wrong code usage: getSecondFaceSpellAbility can only be used for double faced card (main side), broken card: " + this.getName());
}
return secondFace.getSpellAbility();
}