Added static and colored hints for cards

This commit is contained in:
Oleg Agafonov 2019-02-04 18:48:45 +04:00
parent fce93c66e1
commit 13ed3c6dbd
7 changed files with 120 additions and 10 deletions

View file

@ -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<Hint> getHints();
Ability addHint(Hint hint);
}

View file

@ -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<Hint> 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<Ability> 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<Hint> getHints() {
return this.hints;
}
@Override
public Ability addHint(Hint hint) {
this.hints.add(hint);
return this;
}
}

View file

@ -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();
}

View file

@ -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("<font color=%s>%s</font>", 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);
}
}

View file

@ -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<String> 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:

View file

@ -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<String> getRules(Game game) {
try {
List<String> 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;

View file

@ -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<Hint> getHints() {
return this.ability.getHints();
}
@Override
public Ability addHint(Hint hint) {
// only abilities supports addhint
return null;
}
}