From 1b32793388f3b8ca98c70917167032ecc40f04e0 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 8 Feb 2019 03:08:28 +0400 Subject: [PATCH] Added restrict effect hints to permanents; --- .../org/mage/card/arcane/ManaSymbols.java | 3 + .../src/main/resources/hint/restrict.png | Bin 0 -> 4562 bytes .../java/mage/abilities/hint/HintUtils.java | 4 ++ Mage/src/main/java/mage/cards/CardImpl.java | 24 +++++-- .../mage/game/permanent/PermanentImpl.java | 65 +++++++++++++++-- .../main/java/mage/players/PlayerImpl.java | 67 +++++++++--------- Mage/src/main/java/mage/util/GameLog.java | 6 +- 7 files changed, 120 insertions(+), 49 deletions(-) create mode 100644 Mage.Client/src/main/resources/hint/restrict.png diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java b/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java index 4f6ce2069b..6f9af45363 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java @@ -775,6 +775,9 @@ public final class ManaSymbols { if (replaced.contains(HintUtils.HINT_ICON_BAD)) { replaced = replaced.replace(HintUtils.HINT_ICON_BAD, GuiDisplayUtil.getHintIconHtml("bad", symbolSize) + " "); } + if (replaced.contains(HintUtils.HINT_ICON_RESTRICT)) { + replaced = replaced.replace(HintUtils.HINT_ICON_RESTRICT, GuiDisplayUtil.getHintIconHtml("restrict", symbolSize) + " "); + } // ignored data restore replaced = replaced diff --git a/Mage.Client/src/main/resources/hint/restrict.png b/Mage.Client/src/main/resources/hint/restrict.png new file mode 100644 index 0000000000000000000000000000000000000000..a977004e624db7e658e9b30ab37749fc8a84dccb GIT binary patch literal 4562 zcmV;@5iRbCP){23ma;R zDKW7bf}IA&IF!ZKTOlKeq0xXdEuo?~W$I~@5FnIG8? zXAt(IWLyfsJnuvyFEEjFAhJkvC%p1;09yg97jivRpVQ9H-$W6I3*$xrOeT+GJl;-` z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STiYaj_~9vt$LE5aBjgMNra@#XfTC@lRb?cl9WmF^o52xmZ8xO`JO8@`>07*qoM6N<$g1u66LI3~& literal 0 HcmV?d00001 diff --git a/Mage/src/main/java/mage/abilities/hint/HintUtils.java b/Mage/src/main/java/mage/abilities/hint/HintUtils.java index 554d599c61..796c1e591c 100644 --- a/Mage/src/main/java/mage/abilities/hint/HintUtils.java +++ b/Mage/src/main/java/mage/abilities/hint/HintUtils.java @@ -7,9 +7,13 @@ import java.awt.*; */ public class HintUtils { + public static final boolean ABILITY_HINTS_ENABLE = true; + public static final boolean RESTRICT_HINTS_ENABLE = true; + // icons changes to real files on client side (see mana icons replacement) public static final String HINT_ICON_GOOD = "ICON_GOOD"; public static final String HINT_ICON_BAD = "ICON_BAD"; + public static final String HINT_ICON_RESTRICT = "ICON_RESTRICT"; public static String prepareText(String text, Color color) { return prepareText(text, color, null); diff --git a/Mage/src/main/java/mage/cards/CardImpl.java b/Mage/src/main/java/mage/cards/CardImpl.java index db47e6de17..e5e292a30c 100644 --- a/Mage/src/main/java/mage/cards/CardImpl.java +++ b/Mage/src/main/java/mage/cards/CardImpl.java @@ -6,6 +6,7 @@ import mage.Mana; import mage.ObjectColor; import mage.abilities.*; import mage.abilities.hint.Hint; +import mage.abilities.hint.HintUtils; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.repository.PluginClassloaderRegistery; import mage.constants.*; @@ -254,15 +255,26 @@ 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, ability); - if (s != null && !s.isEmpty()) { - rules.add(s); + + // ability hints + List abilityHints = new ArrayList<>(); + if (HintUtils.ABILITY_HINTS_ENABLE) { + for (Ability ability : abilities) { + for (Hint hint : ability.getHints()) { + String s = hint.getText(game, ability); + if (s != null && !s.isEmpty()) { + abilityHints.add(s); + } } } } + + // restrict hints only for permanents, not cards + + // total hints + if (!abilityHints.isEmpty()) { + rules.addAll(abilityHints); + } } return rules; } catch (Exception e) { diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index c36a2f7f18..fe92f6e6e8 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -9,6 +9,7 @@ import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.Effect; import mage.abilities.effects.RestrictionEffect; import mage.abilities.hint.Hint; +import mage.abilities.hint.HintUtils; import mage.abilities.keyword.*; import mage.abilities.text.TextPart; import mage.cards.Card; @@ -245,22 +246,74 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { } } - // extra hints - for (Ability ability : abilities) { - for (Hint hint : ability.getHints()) { - String s = hint.getText(game, ability); - if (s != null && !s.isEmpty()) { - rules.add(s); + // ability hints + List abilityHints = new ArrayList<>(); + if (HintUtils.ABILITY_HINTS_ENABLE) { + for (Ability ability : abilities) { + for (Hint hint : ability.getHints()) { + String s = hint.getText(game, ability); + if (s != null && !s.isEmpty()) { + abilityHints.add(s); + } } } } + // restrict hints + List restrictHints = new ArrayList<>(); + if (HintUtils.RESTRICT_HINTS_ENABLE) { + for (Map.Entry> entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) { + for (Ability ability : entry.getValue()) { + if (!entry.getKey().applies(this, ability, game)) { + continue; + } + + if (!entry.getKey().canAttack(game) || !entry.getKey().canAttack(this, null, ability, game)) { + restrictHints.add(HintUtils.prepareText("Can't attack" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT)); + } + + if (!entry.getKey().canBlock(null, this, ability, game)) { + restrictHints.add(HintUtils.prepareText("Can't block" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT)); + } + + if (!entry.getKey().canBeUntapped(this, ability, game)) { + restrictHints.add(HintUtils.prepareText("Can't untapped" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT)); + } + + if (!entry.getKey().canUseActivatedAbilities(this, ability, game)) { + restrictHints.add(HintUtils.prepareText("Can't use activated abilities" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT)); + } + + if (!entry.getKey().canTransform(this, ability, game)) { + restrictHints.add(HintUtils.prepareText("Can't transform" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT)); + } + } + } + restrictHints.sort(String::compareTo); + } + + // total hints + if (!abilityHints.isEmpty() || !restrictHints.isEmpty()) { + rules.addAll(abilityHints); + rules.addAll(restrictHints); + } + return rules; } catch (Exception e) { return rulesError; } } + private String addSourceObjectName(Game game, Ability ability) { + if (ability != null) { + MageObject object = game.getObject(ability.getSourceId()); + if (object != null) { + return " (" + object.getIdName() + ")"; + } + } + return ""; + } + @Override public Abilities getAbilities() { return abilities; diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index ffd9d3e95c..29a9cac92a 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -1,9 +1,5 @@ package mage.players; -import java.io.Serializable; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.Map.Entry; import mage.ConditionalMana; import mage.MageObject; import mage.MageObjectReference; @@ -69,6 +65,11 @@ import mage.util.GameLog; import mage.util.RandomUtil; import org.apache.log4j.Logger; +import java.io.Serializable; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.Map.Entry; + public abstract class PlayerImpl implements Player, Serializable { private static final Logger logger = Logger.getLogger(PlayerImpl.class); @@ -1422,10 +1423,10 @@ public abstract class PlayerImpl implements Player, Serializable { != null // if anyone sees an issue with this code, please report it. Worked in my testing. || game.getContinuousEffects().asThough(object.getId(), - AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, - ability, - this.getId(), - game) + AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, + ability, + this.getId(), + game) != null) { if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) { @@ -2527,7 +2528,7 @@ public abstract class PlayerImpl implements Player, Serializable { for (Card card : library.getCards(game)) { for (Ability ability : card.getAbilities()) { if (ability.getClass() == WhileSearchingPlayFromLibraryAbility.class) { - libraryCastableCardTracker.put(card.getId(), card.getName() + " [" + card.getId().toString().substring(0, 3) + "]"); + libraryCastableCardTracker.put(card.getId(), card.getIdName()); } } } @@ -2636,7 +2637,7 @@ public abstract class PlayerImpl implements Player, Serializable { /** * @param game * @param appliedEffects - * @param numSides Number of sides the dice has + * @param numSides Number of sides the dice has * @return the number that the player rolled */ @Override @@ -2670,10 +2671,10 @@ public abstract class PlayerImpl implements Player, Serializable { /** * @param game * @param appliedEffects - * @param numberChaosSides The number of chaos sides the planar die - * currently has (normally 1 but can be 5) + * @param numberChaosSides The number of chaos sides the planar die + * currently has (normally 1 but can be 5) * @param numberPlanarSides The number of chaos sides the planar die - * currently has (normally 1) + * currently has (normally 1) * @return the outcome that the player rolled. Either ChaosRoll, PlanarRoll * or NilRoll */ @@ -2830,7 +2831,7 @@ public abstract class PlayerImpl implements Player, Serializable { /** * @param ability - * @param available if null, it won't be checked if enough mana is available + * @param available if null, it won't be checked if enough mana is available * @param sourceObject * @param game * @return @@ -3380,7 +3381,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean canPaySacrificeCost(Permanent permanent, UUID sourceId, - UUID controllerId, Game game + UUID controllerId, Game game ) { return sacrificeCostFilter == null || !sacrificeCostFilter.match(permanent, sourceId, controllerId, game); } @@ -3528,8 +3529,8 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCards(Card card, Zone toZone, - Ability source, Game game, - boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects + Ability source, Game game, + boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects ) { Set cardList = new HashSet<>(); if (card != null) { @@ -3540,22 +3541,22 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCards(Cards cards, Zone toZone, - Ability source, Game game + Ability source, Game game ) { return moveCards(cards.getCards(game), toZone, source, game); } @Override public boolean moveCards(Set cards, Zone toZone, - Ability source, Game game + Ability source, Game game ) { return moveCards(cards, toZone, source, game, false, false, false, null); } @Override public boolean moveCards(Set cards, Zone toZone, - Ability source, Game game, - boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects + Ability source, Game game, + boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects ) { if (cards.isEmpty()) { return true; @@ -3641,8 +3642,8 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCardsToExile(Card card, Ability source, - Game game, boolean withName, UUID exileId, - String exileZoneName + Game game, boolean withName, UUID exileId, + String exileZoneName ) { Set cards = new HashSet<>(); cards.add(card); @@ -3651,8 +3652,8 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCardsToExile(Set cards, Ability source, - Game game, boolean withName, UUID exileId, - String exileZoneName + Game game, boolean withName, UUID exileId, + String exileZoneName ) { if (cards.isEmpty()) { return true; @@ -3667,14 +3668,14 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCardToHandWithInfo(Card card, UUID sourceId, - Game game + Game game ) { return this.moveCardToHandWithInfo(card, sourceId, game, true); } @Override public boolean moveCardToHandWithInfo(Card card, UUID sourceId, - Game game, boolean withName + Game game, boolean withName ) { boolean result = false; Zone fromZone = game.getState().getZone(card.getId()); @@ -3699,7 +3700,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public Set moveCardsToGraveyardWithInfo(Set allCards, Ability source, - Game game, Zone fromZone + Game game, Zone fromZone ) { UUID sourceId = source == null ? null : source.getSourceId(); Set movedCards = new LinkedHashSet<>(); @@ -3707,7 +3708,7 @@ public abstract class PlayerImpl implements Player, Serializable { // identify cards from one owner Cards cards = new CardsImpl(); UUID ownerId = null; - for (Iterator it = allCards.iterator(); it.hasNext();) { + for (Iterator it = allCards.iterator(); it.hasNext(); ) { Card card = it.next(); if (cards.isEmpty()) { ownerId = card.getOwnerId(); @@ -3768,7 +3769,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCardToGraveyardWithInfo(Card card, UUID sourceId, - Game game, Zone fromZone + Game game, Zone fromZone ) { if (card == null) { return false; @@ -3797,8 +3798,8 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCardToLibraryWithInfo(Card card, UUID sourceId, - Game game, Zone fromZone, - boolean toTop, boolean withName + Game game, Zone fromZone, + boolean toTop, boolean withName ) { if (card == null) { return false; @@ -3832,7 +3833,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCardToExileWithInfo(Card card, UUID exileId, String exileName, UUID sourceId, - Game game, Zone fromZone, boolean withName) { + Game game, Zone fromZone, boolean withName) { if (card == null) { return false; } diff --git a/Mage/src/main/java/mage/util/GameLog.java b/Mage/src/main/java/mage/util/GameLog.java index a97c1d8988..93c2646088 100644 --- a/Mage/src/main/java/mage/util/GameLog.java +++ b/Mage/src/main/java/mage/util/GameLog.java @@ -1,11 +1,9 @@ - package mage.util; import mage.MageObject; import mage.ObjectColor; /** - * * @author LevelX2 */ public final class GameLog { @@ -40,11 +38,11 @@ public final class GameLog { } public static String getColoredObjectIdName(MageObject mageObject) { - return "" + mageObject.getName() + " [" + mageObject.getId().toString().substring(0, 3) + "]"; + return "" + mageObject.getIdName() + ""; } public static String getColoredObjectIdNameForTooltip(MageObject mageObject) { - return "" + mageObject.getName() + " [" + mageObject.getId().toString().substring(0, 3) + "]"; + return "" + mageObject.getIdName() + ""; } public static String getNeutralColoredText(String text) {