From 2f8ac764176af8b2be681a9ba10a8e0420b041d9 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 17 Mar 2014 08:37:54 +0100 Subject: [PATCH] * Game log - triggered abilities are now logged as they go to stack. Some minor formatting. --- .../mage/sets/fifthedition/Brainstorm.java | 10 +- .../mage/sets/innistrad/SnapcasterMage.java | 8 +- .../src/mage/sets/zendikar/SpellPierce.java | 2 + Mage/src/mage/abilities/Ability.java | 9 + Mage/src/mage/abilities/AbilityImpl.java | 134 +++++++++- Mage/src/mage/abilities/ActivatedAbility.java | 2 - .../mage/abilities/ActivatedAbilityImpl.java | 252 +++++++++--------- Mage/src/mage/abilities/PlayLandAbility.java | 4 +- Mage/src/mage/abilities/SpecialAction.java | 1 + Mage/src/mage/abilities/SpellAbility.java | 4 +- .../mage/abilities/TriggeredAbilityImpl.java | 24 +- Mage/src/mage/game/GameState.java | 2 +- Mage/src/mage/game/stack/Spell.java | 10 +- Mage/src/mage/game/stack/StackAbility.java | 5 + Mage/src/mage/players/PlayerImpl.java | 54 ++-- 15 files changed, 338 insertions(+), 183 deletions(-) diff --git a/Mage.Sets/src/mage/sets/fifthedition/Brainstorm.java b/Mage.Sets/src/mage/sets/fifthedition/Brainstorm.java index 38b3730aea..cae1984e9b 100644 --- a/Mage.Sets/src/mage/sets/fifthedition/Brainstorm.java +++ b/Mage.Sets/src/mage/sets/fifthedition/Brainstorm.java @@ -28,14 +28,14 @@ package mage.sets.fifthedition; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInHand; @@ -101,7 +101,7 @@ class BrainstormEffect extends OneShotEffect { Card card = player.getHand().get(target.getFirstTarget(), game); if (card != null) { player.getHand().remove(card); - card.moveToZone(Zone.LIBRARY, source.getId(), game, true); + card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true); } return true; } diff --git a/Mage.Sets/src/mage/sets/innistrad/SnapcasterMage.java b/Mage.Sets/src/mage/sets/innistrad/SnapcasterMage.java index f6fe533496..2aa5d7149c 100644 --- a/Mage.Sets/src/mage/sets/innistrad/SnapcasterMage.java +++ b/Mage.Sets/src/mage/sets/innistrad/SnapcasterMage.java @@ -29,7 +29,6 @@ package mage.sets.innistrad; import java.util.UUID; import mage.MageInt; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.ContinuousEffectImpl; @@ -48,6 +47,7 @@ import mage.filter.FilterCard; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.CardTypePredicate; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.target.common.TargetCardInYourGraveyard; /** @@ -112,9 +112,9 @@ class SnapcasterMageEffect extends ContinuousEffectImpl { @Override public void init(Ability source, Game game) { Card card = game.getCard(targetPointer.getFirst(game, source)); - MageObject sourceObject = game.getObject(source.getSourceId()); - if (card != null && sourceObject != null) { - game.informPlayers(new StringBuilder(sourceObject.getName()).append(" gives flashback to ").append(card.getName()).toString()); + Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); + if (card != null && sourcePermanent != null) { + game.informPlayers(new StringBuilder(sourcePermanent.getName()).append(" gives flashback to ").append(card.getName()).toString()); } } diff --git a/Mage.Sets/src/mage/sets/zendikar/SpellPierce.java b/Mage.Sets/src/mage/sets/zendikar/SpellPierce.java index 3005a15362..890b21b032 100644 --- a/Mage.Sets/src/mage/sets/zendikar/SpellPierce.java +++ b/Mage.Sets/src/mage/sets/zendikar/SpellPierce.java @@ -36,6 +36,7 @@ import mage.abilities.effects.common.CounterUnlessPaysEffect; import mage.cards.CardImpl; import mage.filter.FilterSpell; import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.AnotherCardPredicate; import mage.filter.predicate.mageobject.CardTypePredicate; import mage.target.TargetSpell; @@ -49,6 +50,7 @@ public class SpellPierce extends CardImpl { static { filter.add(Predicates.not(new CardTypePredicate(CardType.CREATURE))); + filter.add(new AnotherCardPredicate()); } public SpellPierce(UUID ownerId) { diff --git a/Mage/src/mage/abilities/Ability.java b/Mage/src/mage/abilities/Ability.java index 7789f04208..e17880624c 100644 --- a/Mage/src/mage/abilities/Ability.java +++ b/Mage/src/mage/abilities/Ability.java @@ -419,5 +419,14 @@ public interface Ability extends Controllable, Serializable { * @param abilityWord */ void setAbilityWord(AbilityWord abilityWord); + + /** + * Creates the message about the ability casting/triggering/activating to post in the game log + * before the ability resolves. + * + * @param game + * @return + */ + String getGameLogMessage(Game game); } diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index b4146984f3..5909baac94 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -57,10 +57,13 @@ import mage.constants.AbilityType; import mage.constants.AbilityWord; import mage.constants.EffectType; import mage.constants.Outcome; +import mage.constants.SpellAbilityType; import mage.constants.Zone; import mage.game.Game; import mage.game.command.Emblem; import mage.game.permanent.PermanentCard; +import mage.game.stack.Spell; +import mage.game.stack.StackAbility; import mage.players.Player; import mage.target.Target; import mage.target.Targets; @@ -750,7 +753,134 @@ public abstract class AbilityImpl> implements Ability { public void setAbilityWord(AbilityWord abilityWord) { this.abilityWord = abilityWord; } - - + + @Override + public String getGameLogMessage(Game game) { + if (game.isSimulation()) { + return ""; + } + MageObject object = game.getObject(this.sourceId); + return new StringBuilder(" activates: ") + .append(object != null ? this.formatRule(modes.getText(), object.getName()) :modes.getText()) + .append(" from ") + .append(getMessageText(game)).toString(); + } + + protected String getMessageText(Game game) { + StringBuilder sb = new StringBuilder(); + MageObject object = game.getObject(this.sourceId); + if (object == null) { + object = game.getLastKnownInformation(this.sourceId, Zone.BATTLEFIELD); + } + if (object != null) { + if (object instanceof StackAbility) { + Card card = game.getCard(((StackAbility) object).getSourceId()); + if (card != null) { + sb.append(card.getName()); + } else { + sb.append(object.getName()); + } + } else { + if (object instanceof Spell) { + Spell spell = (Spell) object; + String castText = spell.getSpellAbility().toString(); + sb.append((castText.startsWith("Cast ") ? castText.substring(5):castText)); + if (spell.getFromZone() == Zone.GRAVEYARD) { + sb.append(" from graveyard"); + } + sb.append(getOptionalTextSuffix(game, spell)); + } else { + sb.append(object.getName()); + } + } + } else { + sb.append("unknown"); + } + if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) { + if (((Spell) object).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) { + Spell spell = (Spell) object; + int i = 0; + for (SpellAbility spellAbility : spell.getSpellAbilities()) { + i++; + String half; + if (i == 1) { + half = " left"; + } else { + half = " right"; + } + if (spellAbility.getTargets().size() > 0) { + sb.append(half).append(" half targeting "); + for (Target target: spellAbility.getTargets()) { + sb.append(target.getTargetedName(game)); + } + } + } + } else { + Spell spell = (Spell) object; + int i = 0; + for (SpellAbility spellAbility : spell.getSpellAbilities()) { + i++; + if ( i > 1) { + sb.append(" splicing "); + if (spellAbility.name.length() > 5 && spellAbility.name.startsWith("Cast ")) { + sb.append(spellAbility.name.substring(5)); + } else { + sb.append(spellAbility.name); + } + } + appendTargetDescriptionForLog(sb, spellAbility.getTargets(), game); + } + } + } else if (object instanceof Spell && ((Spell) object).getSpellAbility().getModes().size() > 1) { + Modes spellModes = ((Spell) object).getSpellAbility().getModes(); + int item = 0; + for (Mode mode : spellModes.values()) { + item++; + if (spellModes.getSelectedModes().contains(mode.getId())) { + spellModes.setMode(mode); + sb.append(" (mode ").append(item).append(")"); + appendTargetDescriptionForLog(sb, getTargets(), game); + } + } + } else { + appendTargetDescriptionForLog(sb, getTargets(), game); + } + for (Choice choice :this.getChoices()) { + sb.append(" - ").append(choice.getMessage()).append(": ").append(choice.getChoice()); + } + return sb.toString(); + } + + protected void appendTargetDescriptionForLog(StringBuilder sb, Targets targets, Game game) { + if (targets.size() > 0) { + String usedVerb = null; + for (Target target : targets) { + if (!target.isNotTarget()) { + if (usedVerb == null || usedVerb.equals(" choosing ")) { + usedVerb = " targeting "; + sb.append(usedVerb); + } + } else if (target.isNotTarget() && (usedVerb == null || usedVerb.equals(" targeting "))) { + usedVerb = " choosing "; + sb.append(usedVerb); + } + sb.append(target.getTargetedName(game)); + } + } + } + + private String getOptionalTextSuffix(Game game, Spell spell) { + StringBuilder sb = new StringBuilder(); + for (Ability ability : (Abilities) spell.getAbilities()) { + if (ability instanceof OptionalAdditionalSourceCosts) { + sb.append(((OptionalAdditionalSourceCosts) ability).getCastMessageSuffix()); + } + if (ability instanceof AlternativeSourceCosts) { + sb.append(((AlternativeSourceCosts) ability).getCastMessageSuffix()); + } + } + return sb.toString(); + } + } diff --git a/Mage/src/mage/abilities/ActivatedAbility.java b/Mage/src/mage/abilities/ActivatedAbility.java index 24b6773f15..84e0150c70 100644 --- a/Mage/src/mage/abilities/ActivatedAbility.java +++ b/Mage/src/mage/abilities/ActivatedAbility.java @@ -38,6 +38,4 @@ import mage.game.Game; public interface ActivatedAbility extends Ability { boolean canActivate(UUID playerId, Game game); - String getActivatedMessage(Game game); - } diff --git a/Mage/src/mage/abilities/ActivatedAbilityImpl.java b/Mage/src/mage/abilities/ActivatedAbilityImpl.java index 10e37e0e02..93185bb4df 100644 --- a/Mage/src/mage/abilities/ActivatedAbilityImpl.java +++ b/Mage/src/mage/abilities/ActivatedAbilityImpl.java @@ -50,7 +50,6 @@ import mage.game.Game; import mage.game.stack.Spell; import mage.game.stack.StackAbility; import mage.target.Target; -import mage.target.Targets; /** @@ -208,133 +207,134 @@ public abstract class ActivatedAbilityImpl> ex return false; } - @Override - public String getActivatedMessage(Game game) { - if (game.isSimulation()) { - return ""; - } - MageObject object = game.getObject(this.sourceId); - return new StringBuilder(" activates: ") - .append(object != null ? this.formatRule(modes.getText(), object.getName()) :modes.getText()) - .append(" from ") - .append(getMessageText(game)).toString(); - } +// @Override +// public String getGameLogMessage(Game game) { +// if (game.isSimulation()) { +// return ""; +// } +// MageObject object = game.getObject(this.sourceId); +// return new StringBuilder(" activates: ") +// .append(object != null ? this.formatRule(modes.getText(), object.getName()) :modes.getText()) +// .append(" from ") +// .append(getMessageText(game)).toString(); +// } +// +// @Override +// protected String getMessageText(Game game) { +// StringBuilder sb = new StringBuilder(); +// MageObject object = game.getObject(this.sourceId); +// if (object == null) { +// object = game.getLastKnownInformation(this.sourceId, Zone.BATTLEFIELD); +// } +// if (object != null) { +// if (object instanceof StackAbility) { +// Card card = game.getCard(((StackAbility) object).getSourceId()); +// if (card != null) { +// sb.append(card.getName()); +// } else { +// sb.append(object.getName()); +// } +// } else { +// if (object instanceof Spell) { +// Spell spell = (Spell) object; +// String castText = spell.getSpellAbility().toString(); +// sb.append((castText.startsWith("Cast ") ? castText.substring(5):castText)); +// if (spell.getFromZone() == Zone.GRAVEYARD) { +// sb.append(" from graveyard"); +// } +// sb.append(getOptionalTextSuffix(game, spell)); +// } else { +// sb.append(object.getName()); +// } +// } +// } else { +// sb.append("unknown"); +// } +// if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) { +// if (((Spell) object).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) { +// Spell spell = (Spell) object; +// int i = 0; +// for (SpellAbility spellAbility : spell.getSpellAbilities()) { +// i++; +// String half; +// if (i == 1) { +// half = " left"; +// } else { +// half = " right"; +// } +// if (spellAbility.getTargets().size() > 0) { +// sb.append(half).append(" half targeting "); +// for (Target target: spellAbility.getTargets()) { +// sb.append(target.getTargetedName(game)); +// } +// } +// } +// } else { +// Spell spell = (Spell) object; +// int i = 0; +// for (SpellAbility spellAbility : spell.getSpellAbilities()) { +// i++; +// if ( i > 1) { +// sb.append(" splicing "); +// if (spellAbility.name.length() > 5 && spellAbility.name.startsWith("Cast ")) { +// sb.append(spellAbility.name.substring(5)); +// } else { +// sb.append(spellAbility.name); +// } +// } +// appendTargetDescriptionForLog(sb, spellAbility.getTargets(), game); +// } +// } +// } else if (object instanceof Spell && ((Spell) object).getSpellAbility().getModes().size() > 1) { +// Modes spellModes = ((Spell) object).getSpellAbility().getModes(); +// int item = 0; +// for (Mode mode : spellModes.values()) { +// item++; +// if (spellModes.getSelectedModes().contains(mode.getId())) { +// spellModes.setMode(mode); +// sb.append(" (mode ").append(item).append(")"); +// appendTargetDescriptionForLog(sb, getTargets(), game); +// } +// } +// } else { +// appendTargetDescriptionForLog(sb, getTargets(), game); +// } +// for (Choice choice :this.getChoices()) { +// sb.append(" - ").append(choice.getMessage()).append(": ").append(choice.getChoice()); +// } +// return sb.toString(); +// } - protected String getMessageText(Game game) { - StringBuilder sb = new StringBuilder(); - MageObject object = game.getObject(this.sourceId); - if (object == null) { - object = game.getLastKnownInformation(this.sourceId, Zone.BATTLEFIELD); - } - if (object != null) { - if (object instanceof StackAbility) { - Card card = game.getCard(((StackAbility) object).getSourceId()); - if (card != null) { - sb.append(card.getName()); - } else { - sb.append(object.getName()); - } - } else { - if (object instanceof Spell) { - Spell spell = (Spell) object; - String castText = spell.getSpellAbility().toString(); - sb.append((castText.startsWith("Cast ") ? castText.substring(5):castText)); - if (spell.getFromZone() == Zone.GRAVEYARD) { - sb.append(" from graveyard"); - } - sb.append(getOptionalTextSuffix(game, spell)); - } else { - sb.append(object.getName()); - } - } - } else { - sb.append("unknown"); - } - if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) { - if (((Spell) object).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) { - Spell spell = (Spell) object; - int i = 0; - for (SpellAbility spellAbility : spell.getSpellAbilities()) { - i++; - String half; - if (i == 1) { - half = " left"; - } else { - half = " right"; - } - if (spellAbility.getTargets().size() > 0) { - sb.append(half).append(" half targeting "); - for (Target target: spellAbility.getTargets()) { - sb.append(target.getTargetedName(game)); - } - } - } - } else { - Spell spell = (Spell) object; - int i = 0; - for (SpellAbility spellAbility : spell.getSpellAbilities()) { - i++; - if ( i > 1) { - sb.append(" splicing "); - if (spellAbility.name.length() > 5 && spellAbility.name.startsWith("Cast ")) { - sb.append(spellAbility.name.substring(5)); - } else { - sb.append(spellAbility.name); - } - } - appendTargetDescriptionForLog(sb, spellAbility.getTargets(), game); - } - } - } else if (object instanceof Spell && ((Spell) object).getSpellAbility().getModes().size() > 1) { - Modes spellModes = ((Spell) object).getSpellAbility().getModes(); - int item = 0; - for (Mode mode : spellModes.values()) { - item++; - if (spellModes.getSelectedModes().contains(mode.getId())) { - spellModes.setMode(mode); - sb.append(" (mode ").append(item).append(")"); - appendTargetDescriptionForLog(sb, getTargets(), game); - } - } - } else { - appendTargetDescriptionForLog(sb, getTargets(), game); - } - for (Choice choice :this.getChoices()) { - sb.append(" - ").append(choice.getMessage()).append(": ").append(choice.getChoice()); - } - return sb.toString(); - } - - private void appendTargetDescriptionForLog(StringBuilder sb, Targets targets, Game game) { - if (targets.size() > 0) { - String usedVerb = null; - for (Target target: targets) { - if (!target.isNotTarget()) { - if (usedVerb == null || usedVerb.equals(" choosing ")) { - usedVerb = " targeting "; - sb.append(usedVerb); - } - } else if (target.isNotTarget() && (usedVerb == null || usedVerb.equals(" targeting "))) { - usedVerb = " choosing "; - sb.append(usedVerb); - } - sb.append(target.getTargetedName(game)); - } - } - } +// private void appendTargetDescriptionForLog(StringBuilder sb, Targets targets, Game game) { +// if (targets.size() > 0) { +// String usedVerb = null; +// for (Target target: targets) { +// if (!target.isNotTarget()) { +// if (usedVerb == null || usedVerb.equals(" choosing ")) { +// usedVerb = " targeting "; +// sb.append(usedVerb); +// } +// } else if (target.isNotTarget() && (usedVerb == null || usedVerb.equals(" targeting "))) { +// usedVerb = " choosing "; +// sb.append(usedVerb); +// } +// sb.append(target.getTargetedName(game)); +// } +// } +// } - private String getOptionalTextSuffix(Game game, Spell spell) { - StringBuilder sb = new StringBuilder(); - for (Ability ability : (Abilities) spell.getAbilities()) { - if (ability instanceof OptionalAdditionalSourceCosts) { - sb.append(((OptionalAdditionalSourceCosts) ability).getCastMessageSuffix()); - } - if (ability instanceof AlternativeSourceCosts) { - sb.append(((AlternativeSourceCosts) ability).getCastMessageSuffix()); - } - } - return sb.toString(); - } +// private String getOptionalTextSuffix(Game game, Spell spell) { +// StringBuilder sb = new StringBuilder(); +// for (Ability ability : (Abilities) spell.getAbilities()) { +// if (ability instanceof OptionalAdditionalSourceCosts) { +// sb.append(((OptionalAdditionalSourceCosts) ability).getCastMessageSuffix()); +// } +// if (ability instanceof AlternativeSourceCosts) { +// sb.append(((AlternativeSourceCosts) ability).getCastMessageSuffix()); +// } +// } +// return sb.toString(); +// } public void setMayActivate(TargetController mayActivate) { this.mayActivate = mayActivate; diff --git a/Mage/src/mage/abilities/PlayLandAbility.java b/Mage/src/mage/abilities/PlayLandAbility.java index 69edc07450..61ebf7a540 100644 --- a/Mage/src/mage/abilities/PlayLandAbility.java +++ b/Mage/src/mage/abilities/PlayLandAbility.java @@ -62,8 +62,8 @@ public class PlayLandAbility extends ActivatedAbilityImpl { } @Override - public String getActivatedMessage(Game game) { - return " plays " + getMessageText(game); + public String getGameLogMessage(Game game) { + return new StringBuilder(" plays ").append(getMessageText(game)).toString(); } @Override diff --git a/Mage/src/mage/abilities/SpecialAction.java b/Mage/src/mage/abilities/SpecialAction.java index 77c7761100..cdfd568e68 100644 --- a/Mage/src/mage/abilities/SpecialAction.java +++ b/Mage/src/mage/abilities/SpecialAction.java @@ -34,6 +34,7 @@ import mage.constants.Zone; /** * * @author BetaSteward_at_googlemail.com + * @param */ public abstract class SpecialAction> extends ActivatedAbilityImpl { diff --git a/Mage/src/mage/abilities/SpellAbility.java b/Mage/src/mage/abilities/SpellAbility.java index 10860e61dc..b2f1ae3a79 100644 --- a/Mage/src/mage/abilities/SpellAbility.java +++ b/Mage/src/mage/abilities/SpellAbility.java @@ -114,8 +114,8 @@ public class SpellAbility extends ActivatedAbilityImpl { } @Override - public String getActivatedMessage(Game game) { - return " casts " + getMessageText(game); + public String getGameLogMessage(Game game) { + return new StringBuilder(" casts ").append(getMessageText(game)).toString(); } @Override diff --git a/Mage/src/mage/abilities/TriggeredAbilityImpl.java b/Mage/src/mage/abilities/TriggeredAbilityImpl.java index 2a59cf28cb..022d1be403 100644 --- a/Mage/src/mage/abilities/TriggeredAbilityImpl.java +++ b/Mage/src/mage/abilities/TriggeredAbilityImpl.java @@ -29,10 +29,10 @@ package mage.abilities; import java.util.UUID; -import mage.constants.AbilityType; -import mage.constants.Zone; import mage.MageObject; import mage.abilities.effects.Effect; +import mage.constants.AbilityType; +import mage.constants.Zone; import mage.game.Game; import mage.players.Player; @@ -95,19 +95,23 @@ public abstract class TriggeredAbilityImpl> ex } //20091005 - 603.4 if (checkInterveningIfClause(game)) { - // log resolve of triggered ability - if (object != null && object.getName() != null) { - if (this.getRuleVisible()) { - game.informPlayers(new StringBuilder(object.getName()).append(" triggered ability resolves: ").append(this.getRule(object.getName())).toString()); - } - } else { - game.informPlayers(new StringBuilder("Ability triggered: ").append(this.getRule()).toString()); - } return super.resolve(game); } return false; } + @Override + public String getGameLogMessage(Game game) { + MageObject object = game.getObject(sourceId); + StringBuilder sb = new StringBuilder(); + if (object != null) { + sb.append(object.getName()).append(" - ability triggered: ").append(this.getRule(object.getName())); + } else { + sb.append("Ability triggered: ").append(this.getRule()); + } + return sb.toString(); + } + @Override public String getRule() { String superRule = super.getRule(true); diff --git a/Mage/src/mage/game/GameState.java b/Mage/src/mage/game/GameState.java index f1367b83bb..918bd00062 100644 --- a/Mage/src/mage/game/GameState.java +++ b/Mage/src/mage/game/GameState.java @@ -588,7 +588,7 @@ public class GameState implements Serializable, Copyable { } public List getTriggered(UUID controllerId) { - List triggereds = new ArrayList(); + List triggereds = new ArrayList<>(); for (TriggeredAbility ability: triggered) { if (ability.getControllerId().equals(controllerId)) { triggereds.add(ability); diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index 6d90954cf6..cb31bd8c88 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -69,8 +69,8 @@ import mage.watchers.Watcher; */ public class Spell> implements StackObject, Card { - private final List spellCards = new ArrayList(); - private final List spellAbilities = new ArrayList(); + private final List spellCards = new ArrayList<>(); + private final List spellAbilities = new ArrayList<>(); private final Card card; private final SpellAbility ability; @@ -144,7 +144,7 @@ public class Spell> implements StackObject, Card { } public String getActivatedMessage(Game game) { - return ability.getActivatedMessage(game); + return ability.getGameLogMessage(game); } @Override @@ -463,7 +463,7 @@ public class Spell> implements StackObject, Card { @Override public List getCardType() { if (this.getSpellAbility() instanceof BestowAbility) { - List cardTypes = new ArrayList(); + List cardTypes = new ArrayList<>(); cardTypes.addAll(card.getCardType()); cardTypes.remove(CardType.CREATURE); return cardTypes; @@ -474,7 +474,7 @@ public class Spell> implements StackObject, Card { @Override public List getSubtype() { if (this.getSpellAbility() instanceof BestowAbility) { - List subtypes = new ArrayList(); + List subtypes = new ArrayList<>(); subtypes.addAll(card.getSubtype()); subtypes.add("Aura"); return subtypes; diff --git a/Mage/src/mage/game/stack/StackAbility.java b/Mage/src/mage/game/stack/StackAbility.java index 749c4ddfa7..774802ca19 100644 --- a/Mage/src/mage/game/stack/StackAbility.java +++ b/Mage/src/mage/game/stack/StackAbility.java @@ -399,6 +399,11 @@ public class StackAbility implements StackObject, Ability { public void setAbilityWord(AbilityWord abilityWord) { throw new UnsupportedOperationException("Not supported."); } + + @Override + public String getGameLogMessage(Game game) { + throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates. + } } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 97db95c684..a70e7541a9 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -161,7 +161,7 @@ public abstract class PlayerImpl> implements Player, Ser protected boolean quit; protected RangeOfInfluence range; - protected Set inRange = new HashSet(); + protected Set inRange = new HashSet<>(); protected boolean isTestMode = false; protected boolean canGainLife = true; protected boolean canLoseLife = true; @@ -169,8 +169,8 @@ public abstract class PlayerImpl> implements Player, Ser protected boolean canPaySacrificeCost = true; protected boolean isGameUnderControl = true; protected UUID turnController; - protected Set playersUnderYourControl = new HashSet(); - protected List attachments = new ArrayList(); + protected Set playersUnderYourControl = new HashSet<>(); + protected List attachments = new ArrayList<>(); protected boolean topCardRevealed = false; @@ -715,7 +715,7 @@ public abstract class PlayerImpl> implements Player, Ser GameEvent event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId); event.setZone(fromZone); game.fireEvent(event); - game.fireInformEvent(new StringBuilder(name).append(spell.getActivatedMessage(game)).toString()); + game.informPlayers(new StringBuilder(name).append(spell.getActivatedMessage(game)).toString()); game.removeBookmark(bookmark); resetStoredBookmark(game); return true; @@ -778,7 +778,7 @@ public abstract class PlayerImpl> implements Player, Ser game.getStack().push(new StackAbility(ability, playerId)); if (ability.activate(game, false)) { game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY, ability.getId(), ability.getSourceId(), playerId)); - game.fireInformEvent(name + ability.getActivatedMessage(game)); + game.informPlayers(new StringBuilder(name).append(ability.getGameLogMessage(game)).toString()); game.removeBookmark(bookmark); resetStoredBookmark(game); return true; @@ -804,7 +804,7 @@ public abstract class PlayerImpl> implements Player, Ser int bookmark = game.bookmarkState(); if (action.activate(game, false)) { game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY, action.getSourceId(), action.getId(), playerId)); - game.fireInformEvent(name + action.getActivatedMessage(game)); + game.informPlayers(new StringBuilder(name).append(action.getGameLogMessage(game)).toString()); if (action.resolve(game)) { game.removeBookmark(bookmark); resetStoredBookmark(game); @@ -866,23 +866,29 @@ public abstract class PlayerImpl> implements Player, Ser //20091005 - 603.3c, 603.3d int bookmark = game.bookmarkState(); //FIXME: remove try\catch once we find out the reason for NPE on server - TriggeredAbility ability = null; - try { - ability = source.copy(); - } catch (NullPointerException npe) { - log.fatal("NPE for source=" + source); - log.fatal("NPE for source=" + source.getRule()); - throw npe; - } + TriggeredAbility ability = source.copy(); +// try { +// ability = source.copy(); +// } catch (NullPointerException npe) { +// log.fatal("NPE for source=" + source); +// log.fatal("NPE for source=" + source.getRule()); +// throw npe; +// } if (ability != null && ability.canChooseTarget(game)) { if (ability.isUsesStack()) { game.getStack().push(new StackAbility(ability, playerId)); if (ability.activate(game, false)) { + if (ability.getRuleVisible()) { + game.informPlayers(ability.getGameLogMessage(game)); + } game.removeBookmark(bookmark); return true; } } else { if (ability.activate(game, false)) { + if (ability.getRuleVisible()) { + game.informPlayers(ability.getGameLogMessage(game)); + } ability.resolve(game); game.removeBookmark(bookmark); return true; @@ -894,7 +900,7 @@ public abstract class PlayerImpl> implements Player, Ser } protected LinkedHashMap getSpellAbilities(MageObject object, Zone zone, Game game) { - LinkedHashMap useable = new LinkedHashMap(); + LinkedHashMap useable = new LinkedHashMap<>(); for (Ability ability: object.getAbilities()) { if (ability instanceof SpellAbility) { if (((SpellAbility) ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) { @@ -976,7 +982,7 @@ public abstract class PlayerImpl> implements Player, Ser } protected LinkedHashMap getUseableManaAbilities(MageObject object, Zone zone, Game game) { - LinkedHashMap useable = new LinkedHashMap(); + LinkedHashMap useable = new LinkedHashMap<>(); for (ManaAbility ability: object.getAbilities().getManaAbilities(zone)) { if (ability.canActivate(playerId, game)) { useable.put(ability.getId(), ability); @@ -1044,14 +1050,14 @@ public abstract class PlayerImpl> implements Player, Ser @Override public void untap(Game game) { // create list of all "notMoreThan" effects to track which one are consumed - HashMap>, Integer> notMoreThanEffectsUsage = new HashMap>, Integer>(); + HashMap>, Integer> notMoreThanEffectsUsage = new HashMap<>(); for (Entry> restrictionEffect: game.getContinuousEffects().getApplicableRestrictionUntapNotMoreThanEffects(this, game).entrySet()) { notMoreThanEffectsUsage.put(restrictionEffect, new Integer(restrictionEffect.getKey().getNumber())); } if (!notMoreThanEffectsUsage.isEmpty()) { // create list of all permanents that can be untapped generally - List canBeUntapped = new ArrayList(); + List canBeUntapped = new ArrayList<>(); for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) { boolean untap = true; for (RestrictionEffect effect: game.getContinuousEffects().getApplicableRestrictionEffects(permanent, game).keySet()) { @@ -1062,7 +1068,7 @@ public abstract class PlayerImpl> implements Player, Ser } } // selected permanents to untap - List selectedToUntap = new ArrayList(); + List selectedToUntap = new ArrayList<>(); // player can cancel the seletion of an effect to use a prefered order of restriction effects boolean playerCanceledSelection; @@ -1173,7 +1179,7 @@ public abstract class PlayerImpl> implements Player, Ser } private List getPermanentsThatCanBeUntapped(Game game, List canBeUntapped, RestrictionUntapNotMoreThanEffect handledEffect, HashMap>, Integer> notMoreThanEffectsUsage) { - List leftForUntap = new ArrayList(); + List leftForUntap = new ArrayList<>(); // select permanents that can still be untapped for (Permanent permanent: canBeUntapped) { if (handledEffect.getFilter().match(permanent, game)) { // matches the restricted permanents of handled entry @@ -1698,7 +1704,7 @@ public abstract class PlayerImpl> implements Player, Ser // returns only mana producers that don't require mana payment protected List getAvailableManaProducers(Game game) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) { boolean canAdd = false; for (ManaAbility ability: permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) { @@ -1719,7 +1725,7 @@ public abstract class PlayerImpl> implements Player, Ser // returns only mana producers that require mana payment protected List getAvailableManaProducersWithCost(Game game) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) { for (ManaAbility ability: permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) { if (ability.canActivate(playerId, game) && !ability.getManaCosts().isEmpty()) { @@ -1822,7 +1828,7 @@ public abstract class PlayerImpl> implements Player, Ser } } // eliminate duplicate activated abilities - Map playableActivated = new HashMap(); + Map playableActivated = new HashMap<>(); for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) { for (ActivatedAbility ability: permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) { if (!playableActivated.containsKey(ability.toString())) { @@ -1859,7 +1865,7 @@ public abstract class PlayerImpl> implements Player, Ser */ @Override public List getPlayableOptions(Ability ability, Game game) { - List options = new ArrayList(); + List options = new ArrayList<>(); if (ability.isModal()) { addModeOptions(options, ability, game);