Ability refactor: source improves, deprecated code removed;

This commit is contained in:
Oleg Agafonov 2020-05-28 22:38:31 +04:00
parent 8af43dc13a
commit eea808d2d6
27 changed files with 37 additions and 39 deletions

View file

@ -17,7 +17,7 @@ public enum BuybackCondition implements Condition {
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card != null) {
return card.getAbilities().stream()
return card.getAbilities(game).stream()
.filter(a -> a instanceof BuybackAbility)
.anyMatch(a -> ((BuybackAbility) a).isBuybackActivated(game));
}

View file

@ -19,9 +19,9 @@ public enum DashedCondition implements Condition {
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card != null) {
return card.getAbilities().stream()
return card.getAbilities(game).stream()
.filter(a -> a instanceof DashAbility)
.anyMatch(d -> ((DashAbility)d).isActivated(source, game));
.anyMatch(d -> ((DashAbility) d).isActivated(source, game));
}
return false;

View file

@ -22,7 +22,7 @@ public enum EvokedCondition implements Condition {
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card != null) {
return card.getAbilities().stream()
return card.getAbilities(game).stream()
.filter(ab -> ab instanceof EvokeAbility)
.anyMatch(evoke -> ((EvokeAbility) evoke).isActivated(source, game));
}

View file

@ -41,7 +41,7 @@ public class CopyTokenEffect extends ContinuousEffectImpl {
}
permanent.getAbilities().clear();
for (Ability ability : token.getAbilities()) {
permanent.addAbility(ability, game);
permanent.addAbility(ability, source.getSourceId(), game);
}
permanent.getPower().setValue(token.getPower().getValue());
permanent.getToughness().setValue(token.getToughness().getValue());

View file

@ -38,7 +38,7 @@ public class GainProtectionFromTypeTargetEffect extends GainAbilityTargetEffect
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(source.getFirstTarget());
if (creature != null) {
creature.addAbility(ability, game);
creature.addAbility(ability, source.getSourceId(), game);
return true;
}
return false;

View file

@ -38,7 +38,7 @@ public class TransformAbility extends SimpleStaticAbility {
return "";
}
public static void transform(Permanent permanent, Card sourceCard, Game game) {
public static void transform(Permanent permanent, Card sourceCard, Game game, Ability source) {
if (sourceCard == null) {
return;
@ -63,7 +63,7 @@ public class TransformAbility extends SimpleStaticAbility {
permanent.setExpansionSetCode(sourceCard.getExpansionSetCode());
permanent.getAbilities().clear();
for (Ability ability : sourceCard.getAbilities()) {
permanent.addAbility(ability, game);
permanent.addAbility(ability, source == null ? null : source.getSourceId(), game, false);
}
permanent.getPower().modifyBaseValue(sourceCard.getPower().getValue());
permanent.getToughness().modifyBaseValue(sourceCard.getToughness().getValue());
@ -105,7 +105,7 @@ class TransformEffect extends ContinuousEffectImpl {
return false;
}
TransformAbility.transform(permanent, card, game);
TransformAbility.transform(permanent, card, game, source);
return true;

View file

@ -1647,7 +1647,7 @@ public abstract class GameImpl implements Game, Serializable {
}
newBluePrint.assignNewId();
if (copyFromPermanent.isTransformed()) {
TransformAbility.transform(newBluePrint, newBluePrint.getSecondCardFace(), this);
TransformAbility.transform(newBluePrint, newBluePrint.getSecondCardFace(), this, source);
}
}
if (applier != null) {

View file

@ -327,16 +327,16 @@ public class Battlefield implements Serializable {
}
}
public List<Permanent> getPhasedIn(UUID controllerId) {
public List<Permanent> getPhasedIn(Game game, UUID controllerId) {
return field.values()
.stream()
.filter(perm -> perm.getAbilities().containsKey(PhasingAbility.getInstance().getId())
.filter(perm -> perm.hasAbility(PhasingAbility.getInstance(), game)
&& perm.isPhasedIn()
&& perm.isControlledBy(controllerId))
.collect(Collectors.toList());
}
public List<Permanent> getPhasedOut(UUID controllerId) {
public List<Permanent> getPhasedOut(Game game, UUID controllerId) {
return field.values()
.stream()
.filter(perm -> !perm.isPhasedIn() && perm.isControlledBy(controllerId))

View file

@ -53,7 +53,7 @@ public class PermanentCard extends PermanentImpl {
if (game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId()) != null) {
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId(), null);
setTransformed(true);
TransformAbility.transform(this, getSecondCardFace(), game);
TransformAbility.transform(this, getSecondCardFace(), game, null);
}
}
}

View file

@ -59,7 +59,7 @@ public class PermanentToken extends PermanentImpl {
} else {
// first time -> create ContinuousEffects only once
for (Ability ability : token.getAbilities()) {
this.addAbility(ability, game);
this.addAbility(ability, null, game);
}
}
this.abilities.setControllerId(this.controllerId);

View file

@ -1759,8 +1759,8 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public void phasing(Game game) {
//20091005 - 502.1
List<Permanent> phasedOut = game.getBattlefield().getPhasedOut(playerId);
for (Permanent permanent : game.getBattlefield().getPhasedIn(playerId)) {
List<Permanent> phasedOut = game.getBattlefield().getPhasedOut(game, playerId);
for (Permanent permanent : game.getBattlefield().getPhasedIn(game, playerId)) {
// 502.15i When a permanent phases out, any local enchantments or Equipment
// attached to that permanent phase out at the same time. This alternate way of
// phasing out is known as phasing out "indirectly." An enchantment or Equipment

View file

@ -21,7 +21,7 @@ public class AbilityApplier extends ApplyToPermanent {
@Override
public boolean apply(Game game, Permanent permanent, Ability source, UUID copyToObjectId) {
permanent.addAbility(ability, game);
permanent.addAbility(ability, source.getSourceId(), game);
return true;
}