From 13ed3c6dbd04158108b6ceb7b42f9437aab4aa7b Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Mon, 4 Feb 2019 18:48:45 +0400 Subject: [PATCH] Added static and colored hints for cards --- .../src/main/java/mage/abilities/Ability.java | 5 +++ .../main/java/mage/abilities/AbilityImpl.java | 22 ++++++++-- .../main/java/mage/abilities/hint/Hint.java | 16 ++++++++ .../java/mage/abilities/hint/StaticHint.java | 40 +++++++++++++++++++ Mage/src/main/java/mage/cards/CardImpl.java | 13 +++++- .../mage/game/permanent/PermanentImpl.java | 22 +++++++--- .../java/mage/game/stack/StackAbility.java | 12 ++++++ 7 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/hint/Hint.java create mode 100644 Mage/src/main/java/mage/abilities/hint/StaticHint.java diff --git a/Mage/src/main/java/mage/abilities/Ability.java b/Mage/src/main/java/mage/abilities/Ability.java index e28354a1ba..386f8d56c7 100644 --- a/Mage/src/main/java/mage/abilities/Ability.java +++ b/Mage/src/main/java/mage/abilities/Ability.java @@ -8,6 +8,7 @@ import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCosts; import mage.abilities.effects.Effect; import mage.abilities.effects.Effects; +import mage.abilities.hint.Hint; import mage.constants.AbilityType; import mage.constants.AbilityWord; import mage.constants.EffectType; @@ -525,4 +526,8 @@ public interface Ability extends Controllable, Serializable { CostAdjuster getCostAdjuster(); void adjustCosts(Game game); + + List getHints(); + + Ability addHint(Hint hint); } diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index 7a3053a126..b652c76fe7 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -12,6 +12,7 @@ import mage.abilities.effects.Effects; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.mana.DynamicManaEffect; +import mage.abilities.hint.Hint; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.Card; import mage.cards.SplitCard; @@ -73,6 +74,7 @@ public abstract class AbilityImpl implements Ability { protected boolean canFizzle = true; protected TargetAdjuster targetAdjuster = null; protected CostAdjuster costAdjuster = null; + protected List hints = new ArrayList<>(); public AbilityImpl(AbilityType abilityType, Zone zone) { this.id = UUID.randomUUID(); @@ -120,6 +122,9 @@ public abstract class AbilityImpl implements Ability { this.canFizzle = ability.canFizzle; this.targetAdjuster = ability.targetAdjuster; this.costAdjuster = ability.costAdjuster; + for (Hint hint : ability.getHints()) { + this.hints.add(hint.copy()); + } } @Override @@ -256,7 +261,7 @@ public abstract class AbilityImpl implements Ability { } } if (modes.getAdditionalCost() != null) { - ((OptionalAdditionalModeSourceCosts) modes.getAdditionalCost()).addOptionalAdditionalModeCosts(this, game); + modes.getAdditionalCost().addOptionalAdditionalModeCosts(this, game); } // 20130201 - 601.2b // If the spell has alternative or additional costs that will be paid as it's being cast such @@ -952,9 +957,7 @@ public abstract class AbilityImpl implements Ability { } else if (!object.getAbilities().contains(this)) { // check if it's an ability that is temporary gained to a card Abilities otherAbilities = game.getState().getAllOtherAbilities(this.getSourceId()); - if (otherAbilities == null || !otherAbilities.contains(this)) { - return false; - } + return otherAbilities != null && otherAbilities.contains(this); } } return true; @@ -1243,4 +1246,15 @@ public abstract class AbilityImpl implements Ability { costAdjuster.adjustCosts(this, game); } } + + @Override + public List getHints() { + return this.hints; + } + + @Override + public Ability addHint(Hint hint) { + this.hints.add(hint); + return this; + } } diff --git a/Mage/src/main/java/mage/abilities/hint/Hint.java b/Mage/src/main/java/mage/abilities/hint/Hint.java new file mode 100644 index 0000000000..9d5963c144 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/hint/Hint.java @@ -0,0 +1,16 @@ +package mage.abilities.hint; + +import mage.game.Game; + +import java.io.Serializable; +import java.util.UUID; + +/** + * @author JayDi85 + */ +public interface Hint extends Serializable { + + String getText(Game game, UUID sourceId); + + Hint copy(); +} \ No newline at end of file diff --git a/Mage/src/main/java/mage/abilities/hint/StaticHint.java b/Mage/src/main/java/mage/abilities/hint/StaticHint.java new file mode 100644 index 0000000000..e5e16d0a1a --- /dev/null +++ b/Mage/src/main/java/mage/abilities/hint/StaticHint.java @@ -0,0 +1,40 @@ +package mage.abilities.hint; + +import mage.game.Game; + +import java.awt.*; +import java.util.UUID; + +/** + * @author JayDi85 + */ +public class StaticHint implements Hint { + + private String text; + + public StaticHint(String text) { + this(text, null); + } + + public StaticHint(String text, Color color) { + if (color != null) { + String hex = String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getGreen()); + this.text = String.format("%s", hex, text); + } else { + this.text = text; + } + } + + public String getText(Game game, UUID sourceId) { + return text; + } + + private StaticHint(final StaticHint hint) { + this.text = hint.text; + } + + @Override + public Hint copy() { + return new StaticHint(this); + } +} diff --git a/Mage/src/main/java/mage/cards/CardImpl.java b/Mage/src/main/java/mage/cards/CardImpl.java index 9a473048df..94076fff79 100644 --- a/Mage/src/main/java/mage/cards/CardImpl.java +++ b/Mage/src/main/java/mage/cards/CardImpl.java @@ -5,6 +5,7 @@ import mage.MageObjectImpl; import mage.Mana; import mage.ObjectColor; import mage.abilities.*; +import mage.abilities.hint.Hint; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.repository.PluginClassloaderRegistery; import mage.constants.*; @@ -243,6 +244,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card { try { List rules = getRules(); if (game != null) { + // debug state CardState cardState = game.getState().getCardState(objectId); if (cardState != null) { for (String data : cardState.getInfo().values()) { @@ -252,6 +254,15 @@ public abstract class CardImpl extends MageObjectImpl implements Card { rules.add(ability.getRule()); } } + // extra hints + for (Ability ability : abilities) { + for (Hint hint : ability.getHints()) { + String s = hint.getText(game, objectId); + if (s != null && !s.isEmpty()) { + rules.add(s); + } + } + } } return rules; } catch (Exception e) { @@ -486,7 +497,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card { } } if (lkiObject != null) { - removed = game.getState().getCommand().remove((CommandObject) lkiObject); + removed = game.getState().getCommand().remove(lkiObject); } break; case OUTSIDE: diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index 0b646f11dc..19d5a624d0 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -8,6 +8,7 @@ import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.Effect; import mage.abilities.effects.RestrictionEffect; +import mage.abilities.hint.Hint; import mage.abilities.keyword.*; import mage.abilities.text.TextPart; import mage.cards.Card; @@ -236,11 +237,24 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { public List getRules(Game game) { try { List rules = getRules(); + + // info if (info != null) { for (String data : info.values()) { rules.add(data); } } + + // extra hints + for (Ability ability : abilities) { + for (Hint hint : ability.getHints()) { + String s = hint.getText(game, objectId); + if (s != null && !s.isEmpty()) { + rules.add(s); + } + } + } + return rules; } catch (Exception e) { return rulesError; @@ -477,7 +491,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { public boolean phaseIn(Game game, boolean onlyDirect) { if (!phasedIn) { if (!replaceEvent(EventType.PHASE_IN, game) - && ((onlyDirect && !indirectPhase) || (!onlyDirect))) { + && (!onlyDirect || !indirectPhase)) { this.phasedIn = true; this.indirectPhase = false; if (!game.isSimulation()) { @@ -768,7 +782,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { sourceControllerId = ((Card) source).getOwnerId(); } else if (source instanceof CommandObject) { sourceControllerId = ((CommandObject) source).getControllerId(); - sourceAbilities = ((CommandObject) source).getAbilities(); + sourceAbilities = source.getAbilities(); } else { source = null; } @@ -969,9 +983,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { } // needed to get the correct possible targets if target rule modification effects are active // e.g. Fiendslayer Paladin tried to target with Ultimate Price - if (game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(EventType.TARGET, this.getId(), source.getId(), sourceControllerId), null, game, true)) { - return false; - } + return !game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(EventType.TARGET, this.getId(), source.getId(), sourceControllerId), null, game, true); } return true; diff --git a/Mage/src/main/java/mage/game/stack/StackAbility.java b/Mage/src/main/java/mage/game/stack/StackAbility.java index 6d1afef06c..909cfb5845 100644 --- a/Mage/src/main/java/mage/game/stack/StackAbility.java +++ b/Mage/src/main/java/mage/game/stack/StackAbility.java @@ -13,6 +13,7 @@ import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.Effects; +import mage.abilities.hint.Hint; import mage.abilities.text.TextPart; import mage.cards.Card; import mage.cards.FrameStyle; @@ -647,4 +648,15 @@ public class StackAbility extends StackObjImpl implements Ability { costAdjuster.adjustCosts(this, game); } } + + @Override + public List getHints() { + return this.ability.getHints(); + } + + @Override + public Ability addHint(Hint hint) { + // only abilities supports addhint + return null; + } }