mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
Improved ability outcome processing;
This commit is contained in:
parent
ab10ee10c9
commit
89394ffe0a
20 changed files with 227 additions and 100 deletions
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
package mage.abilities;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.abilities.common.ZoneChangeTriggeredAbility;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.keyword.ProtectionAbility;
|
||||
|
|
@ -13,6 +10,9 @@ import mage.game.Game;
|
|||
import mage.util.ThreadLocalStringBuilder;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -220,7 +220,7 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
|
|||
|
||||
@Override
|
||||
public boolean contains(T ability) {
|
||||
for (Iterator<T> iterator = this.iterator(); iterator.hasNext();) { // simple loop can cause java.util.ConcurrentModificationException
|
||||
for (Iterator<T> iterator = this.iterator(); iterator.hasNext(); ) { // simple loop can cause java.util.ConcurrentModificationException
|
||||
T test = iterator.next();
|
||||
// Checking also by getRule() without other restrictions is a problem when a triggered ability will be copied to a permanent that had the same ability
|
||||
// already before the copy. Because then it keeps the triggered ability twice and it triggers twice.
|
||||
|
|
@ -273,7 +273,7 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
|
|||
|
||||
@Override
|
||||
public int getOutcomeTotal() {
|
||||
return stream().mapToInt(ability -> ability.getEffects().getOutcomeTotal()).sum();
|
||||
return stream().mapToInt(ability -> ability.getEffects().getOutcomeScore(ability)).sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
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;
|
||||
|
|
@ -12,10 +9,7 @@ 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;
|
||||
import mage.constants.Zone;
|
||||
import mage.constants.*;
|
||||
import mage.game.Controllable;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
|
@ -26,6 +20,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.
|
||||
|
|
@ -46,10 +44,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();
|
||||
|
||||
|
|
@ -58,10 +54,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();
|
||||
|
||||
|
|
@ -267,16 +261,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,8 +283,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)
|
||||
|
|
@ -526,4 +518,8 @@ public interface Ability extends Controllable, Serializable {
|
|||
List<Hint> getHints();
|
||||
|
||||
Ability addHint(Hint hint);
|
||||
|
||||
Ability addCustomOutcome(Outcome customOutcome);
|
||||
|
||||
Outcome getCustomOutcome();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.abilities.costs.*;
|
||||
import mage.abilities.costs.common.PayLifeCost;
|
||||
|
|
@ -33,6 +29,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
|
||||
*/
|
||||
|
|
@ -68,6 +69,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
protected TargetAdjuster targetAdjuster = null;
|
||||
protected CostAdjuster costAdjuster = null;
|
||||
protected List<Hint> hints = new ArrayList<>();
|
||||
protected Outcome customOutcome = null; // uses for AI decisions instead effects
|
||||
|
||||
public AbilityImpl(AbilityType abilityType, Zone zone) {
|
||||
this.id = UUID.randomUUID();
|
||||
|
|
@ -117,6 +119,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
for (Hint hint : ability.getHints()) {
|
||||
this.hints.add(hint.copy());
|
||||
}
|
||||
this.customOutcome = ability.customOutcome;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -321,7 +324,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
sourceObject.adjustTargets(this, game);
|
||||
}
|
||||
if (!getTargets().isEmpty()) {
|
||||
Outcome outcome = getEffects().isEmpty() ? Outcome.Detriment : getEffects().get(0).getOutcome();
|
||||
Outcome outcome = getEffects().getOutcome(this);
|
||||
// only activated abilities can be canceled by user (not triggered)
|
||||
if (!getTargets().chooseTargets(outcome, this.controllerId, this, noMana, game, this instanceof ActivatedAbility)) {
|
||||
// was canceled during targer selection
|
||||
|
|
@ -948,10 +951,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
}
|
||||
return ((Permanent) object).isPhasedIn();
|
||||
} else if (object instanceof Card) {
|
||||
if (!((Card) object).getAbilities(game).contains(this)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return ((Card) object).getAbilities(game).contains(this);
|
||||
} else if (!object.getAbilities().contains(this)) { // not sure which object it can still be
|
||||
// check if it's an ability that is temporary gained to a card
|
||||
Abilities<Ability> otherAbilities = game.getState().getAllOtherAbilities(this.getSourceId());
|
||||
|
|
@ -1250,4 +1250,15 @@ public abstract class AbilityImpl implements Ability {
|
|||
this.hints.add(hint);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ability addCustomOutcome(Outcome customOutcome) {
|
||||
this.customOutcome = customOutcome;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Outcome getCustomOutcome() {
|
||||
return this.customOutcome;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package mage.abilities;
|
|||
import mage.MageObject;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.AbilityType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
|
@ -61,7 +60,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|
|||
MageObject object = game.getObject(getSourceId());
|
||||
Player player = game.getPlayer(this.getControllerId());
|
||||
if (player != null && object != null) {
|
||||
if (!player.chooseUse(getEffects().isEmpty() ? Outcome.Detriment : getEffects().get(0).getOutcome(), this.getRule(object.getLogName()), this, game)) {
|
||||
if (!player.chooseUse(getEffects().getOutcome(this), this.getRule(object.getLogName()), this, game)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package mage.abilities.effects;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.constants.Outcome;
|
||||
import mage.target.targetpointer.TargetPointer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -99,7 +97,11 @@ public class Effects extends ArrayList<Effect> {
|
|||
return sbText.toString();
|
||||
}
|
||||
|
||||
public boolean hasOutcome(Outcome outcome) {
|
||||
public boolean hasOutcome(Ability source, Outcome outcome) {
|
||||
Outcome realOutcome = (source == null ? null : source.getCustomOutcome());
|
||||
if (realOutcome != null) {
|
||||
return realOutcome == outcome;
|
||||
}
|
||||
for (Effect effect : this) {
|
||||
if (effect.getOutcome() == outcome) {
|
||||
return true;
|
||||
|
|
@ -108,18 +110,40 @@ public class Effects extends ArrayList<Effect> {
|
|||
return false;
|
||||
}
|
||||
|
||||
public List<Outcome> getOutcomes() {
|
||||
Set<Outcome> outcomes = new HashSet<>();
|
||||
for (Effect effect : this) {
|
||||
outcomes.add(effect.getOutcome());
|
||||
}
|
||||
return new ArrayList<>(outcomes);
|
||||
/**
|
||||
* @param source source ability for effects
|
||||
* @return real outcome of ability
|
||||
*/
|
||||
public Outcome getOutcome(Ability source) {
|
||||
return getOutcome(source, Outcome.Detriment);
|
||||
}
|
||||
|
||||
public int getOutcomeTotal() {
|
||||
public Outcome getOutcome(Ability source, Outcome defaultOutcome) {
|
||||
Outcome realOutcome = (source == null ? null : source.getCustomOutcome());
|
||||
if (realOutcome != null) {
|
||||
return realOutcome;
|
||||
}
|
||||
|
||||
if (!this.isEmpty()) {
|
||||
return this.get(0).getOutcome();
|
||||
}
|
||||
|
||||
return defaultOutcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param source source ability for effects
|
||||
* @return total score of outcome effects (plus/minus)
|
||||
*/
|
||||
public int getOutcomeScore(Ability source) {
|
||||
int total = 0;
|
||||
for (Effect effect : this) {
|
||||
if (effect.getOutcome().isGood()) {
|
||||
// custom ability outcome must "rewrite" effect's outcome (it uses for AI desisions and card score... hmm, getOutcomeTotal used on 28.01.2020)
|
||||
Outcome realOutcome = (source == null ? null : source.getCustomOutcome());
|
||||
if (realOutcome == null) {
|
||||
realOutcome = effect.getOutcome();
|
||||
}
|
||||
if (realOutcome.isGood()) {
|
||||
total++;
|
||||
} else {
|
||||
total--;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.MageObject;
|
||||
|
|
@ -103,11 +102,11 @@ public class CopyPermanentEffect extends OneShotEffect {
|
|||
// attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
|
||||
for (Ability ability : bluePrintPermanent.getAbilities()) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
auraOutcome = ability.getEffects().getOutcome(ability);
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
if (effect instanceof AttachEffect) {
|
||||
if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
|
||||
auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
|
||||
auraOutcome = effect.getOutcome();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -118,12 +117,9 @@ public class CopyPermanentEffect extends OneShotEffect {
|
|||
if (auraTarget == null) {
|
||||
for (Ability ability : bluePrintPermanent.getAbilities()) {
|
||||
if (ability instanceof EnchantAbility) {
|
||||
auraOutcome = ability.getEffects().getOutcome(ability);
|
||||
if (ability.getTargets().size() > 0) { // Animate Dead don't have targets
|
||||
auraTarget = ability.getTargets().get(0);
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
// first outcome
|
||||
auraOutcome = effect.getOutcome();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -6,11 +5,9 @@ import mage.abilities.DelayedTriggeredAbility;
|
|||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CreateDelayedTriggeredAbilityEffect extends OneShotEffect {
|
||||
|
|
@ -28,7 +25,7 @@ public class CreateDelayedTriggeredAbilityEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
public CreateDelayedTriggeredAbilityEffect(DelayedTriggeredAbility ability, boolean copyTargets, boolean initAbility) {
|
||||
super(ability.getEffects().isEmpty() ? Outcome.Detriment : ability.getEffects().get(0).getOutcome());
|
||||
super(ability.getEffects().getOutcome(ability));
|
||||
this.ability = ability;
|
||||
this.copyTargets = copyTargets;
|
||||
this.initAbility = initAbility;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,12 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.SpecialAction;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CreateSpecialActionEffect extends OneShotEffect {
|
||||
|
|
@ -17,7 +14,7 @@ public class CreateSpecialActionEffect extends OneShotEffect {
|
|||
protected SpecialAction action;
|
||||
|
||||
public CreateSpecialActionEffect(SpecialAction action) {
|
||||
super(action.getEffects().isEmpty() ? Outcome.Detriment : action.getEffects().get(0).getOutcome());
|
||||
super(action.getEffects().getOutcome(action));
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class DoIfCostPaid extends OneShotEffect {
|
|||
}
|
||||
message = CardUtil.replaceSourceName(message, mageObject.getLogName());
|
||||
boolean result = true;
|
||||
Outcome payOutcome = executingEffects.size() > 0 ? executingEffects.get(0).getOutcome() : this.outcome;
|
||||
Outcome payOutcome = executingEffects.getOutcome(source, this.outcome);
|
||||
if (cost.canPay(source, source.getSourceId(), player.getId(), game)
|
||||
&& (!optional || player.chooseUse(payOutcome, message, source, game))) {
|
||||
cost.clearPaid();
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
|
|||
}
|
||||
|
||||
public GainAbilityTargetEffect(Ability ability, Duration duration, String rule, boolean onCard, Layer layer, SubLayer subLayer) {
|
||||
super(duration, layer, subLayer,
|
||||
!ability.getEffects().isEmpty() ? ability.getEffects().get(0).getOutcome() : Outcome.AddAbility);
|
||||
super(duration, layer, subLayer, ability.getEffects().getOutcome(ability, Outcome.AddAbility));
|
||||
this.ability = ability;
|
||||
staticText = rule;
|
||||
this.onCard = onCard;
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ public final class RateCard {
|
|||
}
|
||||
|
||||
private static int isEffectRemoval(Card card, Ability ability, Effect effect) {
|
||||
// it's effect relates score, do not use custom outcome from ability
|
||||
if (effect.getOutcome() == Outcome.Removal) {
|
||||
// found removal
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
package mage.game.stack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.ObjectColor;
|
||||
|
|
@ -34,6 +30,11 @@ import mage.util.GameLog;
|
|||
import mage.util.SubTypeList;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
|
@ -578,7 +579,7 @@ public class StackAbility extends StackObjImpl implements Ability {
|
|||
game.getStack().push(newStackAbility);
|
||||
if (chooseNewTargets && !newAbility.getTargets().isEmpty()) {
|
||||
Player controller = game.getPlayer(newControllerId);
|
||||
Outcome outcome = newAbility.getEffects().isEmpty() ? Outcome.Detriment : newAbility.getEffects().get(0).getOutcome();
|
||||
Outcome outcome = newAbility.getEffects().getOutcome(newAbility);
|
||||
if (controller.chooseUse(outcome, "Choose new targets?", source, game)) {
|
||||
newAbility.getTargets().clearChosen();
|
||||
newAbility.getTargets().chooseTargets(outcome, newControllerId, newAbility, false, game, false);
|
||||
|
|
@ -648,7 +649,16 @@ public class StackAbility extends StackObjImpl implements Ability {
|
|||
|
||||
@Override
|
||||
public Ability addHint(Hint hint) {
|
||||
// only abilities supports addhint
|
||||
return null;
|
||||
throw new IllegalArgumentException("Stack ability is not supports hint adding");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ability addCustomOutcome(Outcome customOutcome) {
|
||||
throw new IllegalArgumentException("Stack ability is not supports custom outcome adding");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Outcome getCustomOutcome() {
|
||||
return this.ability.getCustomOutcome();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ public abstract class StackObjImpl implements StackObject {
|
|||
targetAmount = " (amount: " + target.getTargetAmount(targetId) + ")";
|
||||
}
|
||||
// change the target?
|
||||
Outcome outcome = mode.getEffects().isEmpty() ? Outcome.Detriment : mode.getEffects().get(0).getOutcome();
|
||||
Outcome outcome = mode.getEffects().getOutcome(ability);
|
||||
|
||||
if (targetNames != null
|
||||
&& (forceChange || targetController.chooseUse(outcome, "Change this target: " + targetNames + targetAmount + '?', ability, game))) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue