Merge branch 'targetAdjustment' into master

This commit is contained in:
Evan Kranzler 2019-01-12 14:42:58 -05:00 committed by GitHub
commit 3483b3a181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
154 changed files with 3062 additions and 2964 deletions

View file

@ -1,7 +1,5 @@
package mage;
import java.io.Serializable;
import java.util.UUID;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
@ -10,6 +8,9 @@ import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import org.apache.log4j.Logger;
import java.io.Serializable;
import java.util.UUID;
/**
* A object reference that takes zone changes into account.
*
@ -145,4 +146,8 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
}
return null;
}
public boolean zoneCounterIsCurrent(Game game) {
return game.getState().getZoneChangeCounter(sourceId) == zoneChangeCounter;
}
}

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
@ -526,4 +519,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.Mana;
import mage.abilities.costs.*;
@ -37,6 +33,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
*/
@ -71,6 +72,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();
@ -1223,4 +1225,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

@ -1,6 +1,5 @@
package mage.abilities.effects.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
@ -12,8 +11,9 @@ import mage.target.targetpointer.FirstTargetPointer;
import mage.target.targetpointer.SecondTargetPointer;
import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DestroyTargetEffect extends OneShotEffect {
@ -26,14 +26,18 @@ public class DestroyTargetEffect extends OneShotEffect {
}
public DestroyTargetEffect(String ruleText) {
this(false);
staticText = ruleText;
this(ruleText, false);
}
public DestroyTargetEffect(boolean noRegen) {
this(noRegen, false);
}
public DestroyTargetEffect(String ruleText, boolean noRegen) {
this(noRegen, false);
staticText = ruleText;
}
public DestroyTargetEffect(boolean noRegen, boolean multitargetHandling) {
super(Outcome.DestroyPermanent);
this.noRegen = noRegen;

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);
@ -360,9 +362,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
public List<Mana> getMana() {
List<Mana> mana = new ArrayList<>();
for (ActivatedManaAbilityImpl ability : this.abilities.getActivatedManaAbilities(Zone.BATTLEFIELD)) {
for (Mana netMana : ability.getNetMana(null)) {
mana.add(netMana);
}
mana.addAll(ability.getNetMana(null));
}
return mana;
}

View file

@ -5,6 +5,7 @@ import mage.MageObject;
import mage.ObjectColor;
import mage.abilities.*;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostAdjuster;
import mage.abilities.costs.Costs;
import mage.abilities.costs.CostsImpl;
import mage.abilities.costs.mana.ManaCost;
@ -52,6 +53,7 @@ public class StackAbility extends StackObjImpl implements Ability {
private String name;
private String expansionSetCode;
private TargetAdjuster targetAdjuster = null;
private CostAdjuster costAdjuster = null;
public StackAbility(Ability ability, UUID controllerId) {
this.ability = ability;
@ -627,4 +629,21 @@ public class StackAbility extends StackObjImpl 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

@ -1,15 +1,17 @@
package mage.watchers.common;
import mage.MageObjectReference;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import mage.MageObjectReference;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.Watcher;
/**
* @author magenoxx_at_gmail.com
@ -47,6 +49,15 @@ public class AttackedThisTurnWatcher extends Watcher {
return this.attackedThisTurnCreaturesCounts;
}
public boolean checkIfAttacked(Permanent permanent, Game game) {
for (MageObjectReference mor : attackedThisTurnCreatures) {
if (mor.refersTo(permanent, game)) {
return true;
}
}
return false;
}
@Override
public AttackedThisTurnWatcher copy() {
return new AttackedThisTurnWatcher(this);

View file

@ -1,17 +1,17 @@
package mage.watchers.common;
import java.util.HashSet;
import java.util.Set;
import mage.MageObjectReference;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author Quercitron
*/
public class BlockedThisTurnWatcher extends Watcher {
@ -44,6 +44,15 @@ public class BlockedThisTurnWatcher extends Watcher {
return this.blockedThisTurnCreatures;
}
public boolean checkIfBlocked(Permanent permanent, Game game) {
for (MageObjectReference mor : blockedThisTurnCreatures) {
if (mor.refersTo(permanent, game)) {
return true;
}
}
return false;
}
@Override
public void reset() {
super.reset();