added cost adjustment framework

This commit is contained in:
Evan Kranzler 2018-09-30 20:12:07 -04:00
parent 57470be67f
commit 9d9c7b0242
4 changed files with 66 additions and 34 deletions

View file

@ -1,10 +1,8 @@
package mage.abilities;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostAdjuster;
import mage.abilities.costs.Costs;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
@ -24,6 +22,10 @@ import mage.target.Targets;
import mage.target.targetadjustment.TargetAdjuster;
import mage.watchers.Watcher;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
/**
* Practically everything in the game is started from an Ability. This interface
* describes what an Ability is composed of at the highest level.
@ -44,10 +46,8 @@ public interface Ability extends Controllable, Serializable {
*
* @see mage.players.PlayerImpl#playAbility(mage.abilities.ActivatedAbility,
* mage.game.Game)
* @see
* mage.game.GameImpl#addTriggeredAbility(mage.abilities.TriggeredAbility)
* @see
* mage.game.GameImpl#addDelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility)
* @see mage.game.GameImpl#addTriggeredAbility(mage.abilities.TriggeredAbility)
* @see mage.game.GameImpl#addDelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility)
*/
void newId();
@ -56,10 +56,8 @@ public interface Ability extends Controllable, Serializable {
*
* @see mage.players.PlayerImpl#playAbility(mage.abilities.ActivatedAbility,
* mage.game.Game)
* @see
* mage.game.GameImpl#addTriggeredAbility(mage.abilities.TriggeredAbility)
* @see
* mage.game.GameImpl#addDelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility)
* @see mage.game.GameImpl#addTriggeredAbility(mage.abilities.TriggeredAbility)
* @see mage.game.GameImpl#addDelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility)
*/
void newOriginalId();
@ -143,7 +141,7 @@ public interface Ability extends Controllable, Serializable {
/**
* TODO Method is unused, keep it around?
*
* <p>
* Gets all costs that are optional to this ability. These costs can be paid
* in addition to other costs to have other effects put into place.
*
@ -208,7 +206,6 @@ public interface Ability extends Controllable, Serializable {
*
* @return The {@link java.util.UUID} of the first target within the targets
* list.
*
* @see mage.target.Target
*/
UUID getFirstTarget();
@ -266,17 +263,15 @@ public interface Ability extends Controllable, Serializable {
/**
* Activates this ability prompting the controller to pay any mandatory
*
* @param game A reference the {@link Game} for which this ability should be
* activated within.
* @param game A reference the {@link Game} for which this ability should be
* activated within.
* @param noMana Whether or not {@link ManaCosts} have to be paid.
* @return True if this ability was successfully activated.
*
* @see mage.players.PlayerImpl#cast(mage.abilities.SpellAbility,
* mage.game.Game, boolean)
* @see mage.players.PlayerImpl#playAbility(mage.abilities.ActivatedAbility,
* mage.game.Game)
* @see
* mage.players.PlayerImpl#triggerAbility(mage.abilities.TriggeredAbility,
* @see mage.players.PlayerImpl#triggerAbility(mage.abilities.TriggeredAbility,
* mage.game.Game)
*/
boolean activate(Game game, boolean noMana);
@ -290,9 +285,7 @@ public interface Ability extends Controllable, Serializable {
*
* @param game The {@link Game} for which this ability resolves within.
* @return Whether or not this ability successfully resolved.
*
* @see
* mage.players.PlayerImpl#playManaAbility(mage.abilities.mana.ManaAbility,
* @see mage.players.PlayerImpl#playManaAbility(mage.abilities.mana.ManaAbility,
* mage.game.Game)
* @see mage.players.PlayerImpl#specialAction(mage.abilities.SpecialAction,
* mage.game.Game)
@ -380,7 +373,7 @@ public interface Ability extends Controllable, Serializable {
/**
* Sets the value for the ruleAtTheTop attribute
*
* <p>
* true = show the rule at the top position of the rules
*
* @param ruleAtTheTop
@ -398,7 +391,7 @@ public interface Ability extends Controllable, Serializable {
/**
* Sets the value for the worksFaceDown flag
*
* <p>
* true = the ability works also if the object is face down
*
* @param worksFaceDown
@ -414,7 +407,7 @@ public interface Ability extends Controllable, Serializable {
/**
* Sets the value for the ruleVisible attribute
*
* <p>
* true = rule will be shown for the card / permanent false = rule won't be
* shown
*
@ -432,7 +425,7 @@ public interface Ability extends Controllable, Serializable {
/**
* Sets the value for the additional costs rule attribute
*
* <p>
* true = rule will be shown for the card / permanent false = rule won't be
* shown
*
@ -451,7 +444,7 @@ public interface Ability extends Controllable, Serializable {
* Sets the ability word for the given ability. An ability word is a word
* that, in essence, groups, and reminds players of, cards that have a
* common functionality and does not imply any particular rules.
*
* <p>
* --- Not usable yet for rule text generation of triggered abilities ---
*
* @param abilityWord
@ -531,4 +524,10 @@ public interface Ability extends Controllable, Serializable {
TargetAdjuster getTargetAdjuster();
void adjustTargets(Game game);
void setCostAdjuster(CostAdjuster costAdjuster);
CostAdjuster getCostAdjuster();
void adjustCosts(Game game);
}

View file

@ -1,9 +1,5 @@
package mage.abilities;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.Mana;
@ -15,8 +11,8 @@ import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.mana.DynamicManaEffect;
import mage.abilities.effects.common.ManaEffect;
import mage.abilities.effects.mana.DynamicManaEffect;
import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.cards.Card;
import mage.cards.SplitCard;
@ -38,6 +34,11 @@ import mage.util.ThreadLocalStringBuilder;
import mage.watchers.Watcher;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -73,6 +74,7 @@ public abstract class AbilityImpl implements Ability {
protected List<Ability> subAbilities = null;
protected boolean canFizzle = true;
protected TargetAdjuster targetAdjuster = null;
protected CostAdjuster costAdjuster = null;
public AbilityImpl(AbilityType abilityType, Zone zone) {
this.id = UUID.randomUUID();
@ -1240,4 +1242,21 @@ public abstract class AbilityImpl implements Ability {
targetAdjuster.adjustTargets(this, game);
}
}
@Override
public void setCostAdjuster(CostAdjuster costAdjuster) {
this.costAdjuster = costAdjuster;
}
@Override
public CostAdjuster getCostAdjuster() {
return costAdjuster;
}
@Override
public void adjustCosts(Game game) {
if (costAdjuster != null) {
costAdjuster.adjustCosts(this, game);
}
}
}

View file

@ -0,0 +1,12 @@
package mage.abilities.costs;
import mage.abilities.Ability;
import mage.game.Game;
/**
* @author TheElk801
*/
public interface CostAdjuster {
void adjustCosts(Ability ability, Game game);
}

View file

@ -327,9 +327,11 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
return spellAbility;
}
// @Override
// public void adjustCosts(Ability ability, Game game) {
// }
@Override
public void adjustCosts(Ability ability, Game game) {
ability.adjustCosts(game);
}
@Override
public void adjustTargets(Ability ability, Game game) {
ability.adjustTargets(game);