mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Ability refactor: source improves, deprecated code removed;
This commit is contained in:
parent
8af43dc13a
commit
eea808d2d6
27 changed files with 37 additions and 39 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue