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 0000000000..a977004e62 Binary files /dev/null and b/Mage.Client/src/main/resources/hint/restrict.png differ 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) {