mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00: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
|
@ -1267,7 +1267,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
//play a land that will allow us to play an unplayable
|
||||
for (Mana mana : unplayable.keySet()) {
|
||||
for (Card card : lands) {
|
||||
for (ActivatedManaAbilityImpl ability : card.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD)) {
|
||||
for (ActivatedManaAbilityImpl ability : card.getAbilities(game).getActivatedManaAbilities(Zone.BATTLEFIELD)) {
|
||||
for (Mana netMana : ability.getNetMana(game)) {
|
||||
if (netMana.enough(mana)) {
|
||||
this.playLand(card, game, false);
|
||||
|
@ -1281,7 +1281,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
//play a land that will get us closer to playing an unplayable
|
||||
for (Mana mana : unplayable.keySet()) {
|
||||
for (Card card : lands) {
|
||||
for (ActivatedManaAbilityImpl ability : card.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD)) {
|
||||
for (ActivatedManaAbilityImpl ability : card.getAbilities(game).getActivatedManaAbilities(Zone.BATTLEFIELD)) {
|
||||
for (Mana netMana : ability.getNetMana(game)) {
|
||||
if (mana.contains(netMana)) {
|
||||
this.playLand(card, game, false);
|
||||
|
@ -1362,7 +1362,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
for (Card card : graveyard.getCards(game)) {
|
||||
for (ActivatedAbility ability : card.getAbilities().getActivatedAbilities(Zone.GRAVEYARD)) {
|
||||
for (ActivatedAbility ability : card.getAbilities(game).getActivatedAbilities(Zone.GRAVEYARD)) {
|
||||
if (ability.canActivate(playerId, game).canActivate()) {
|
||||
ManaOptions abilityOptions = ability.getManaCosts().getOptions();
|
||||
if (abilityOptions.isEmpty()) {
|
||||
|
|
|
@ -225,9 +225,7 @@ class AnimateDeadChangeAbilityEffect extends ContinuousEffectImpl implements Sou
|
|||
abilityToRemove = ability;
|
||||
}
|
||||
}
|
||||
if (abilityToRemove != null) {
|
||||
permanent.getAbilities().remove(abilityToRemove);
|
||||
}
|
||||
permanent.removeAbility(abilityToRemove, source.getSourceId(), game);
|
||||
permanent.addAbility(newAbility, source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ class ArtisanOfFormsApplyToPermanent extends ApplyToPermanent {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Permanent permanent, Ability source, UUID copyToObjectId) {
|
||||
permanent.addAbility(ArtisanOfForms.createAbility(), game);
|
||||
permanent.addAbility(ArtisanOfForms.createAbility(), source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,8 +122,8 @@ class BludgeonBrawlGainAbilityEffect extends ContinuousEffectImpl {
|
|||
Permanent permanent = game.getPermanent(permanentId);
|
||||
if (permanent != null) {
|
||||
int convertedManaCost = permanent.getConvertedManaCost();
|
||||
permanent.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(convertedManaCost)), game);
|
||||
permanent.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(convertedManaCost, 0)), game);
|
||||
permanent.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(convertedManaCost)), source.getSourceId(), game);
|
||||
permanent.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(convertedManaCost, 0)), source.getSourceId(), game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -56,8 +56,8 @@ class DacksDuplicateApplyToPermanent extends ApplyToPermanent {
|
|||
* 29/05/2014 The ability of Dack's Duplicate doesn't target the
|
||||
* creature.
|
||||
*/
|
||||
permanent.addAbility(new DethroneAbility(), game);
|
||||
permanent.addAbility(HasteAbility.getInstance(), game);
|
||||
permanent.addAbility(new DethroneAbility(), source.getSourceId(), game);
|
||||
permanent.addAbility(HasteAbility.getInstance(), source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class EvilTwinApplyToPermanent extends ApplyToPermanent {
|
|||
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DestroyTargetEffect(), new ManaCostsImpl("{U}{B}"));
|
||||
ability.addCost(new TapSourceCost());
|
||||
ability.addTarget(new TargetCreaturePermanent(filter));
|
||||
permanent.addAbility(ability, game);
|
||||
permanent.addAbility(ability, source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class GargoyleSentinelEffect extends ContinuousEffectImpl {
|
|||
switch (layer) {
|
||||
case AbilityAddingRemovingEffects_6:
|
||||
if (sublayer == SubLayer.NA) {
|
||||
permanent.getAbilities().removeIf(entry -> entry.getId().equals(DefenderAbility.getInstance().getId()));
|
||||
permanent.removeAbility(DefenderAbility.getInstance(), source.getSourceId(), game);
|
||||
permanent.getAbilities().add(FlyingAbility.getInstance());
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -100,7 +100,7 @@ class GravityWellEffect extends ContinuousEffectImpl {
|
|||
switch (layer) {
|
||||
case AbilityAddingRemovingEffects_6:
|
||||
if (sublayer == SubLayer.NA) {
|
||||
permanent.getAbilities().removeIf(entry -> entry.getId().equals(FlyingAbility.getInstance().getId()));
|
||||
permanent.removeAbility(FlyingAbility.getInstance(), source.getSourceId(), game);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ class HisokasGuardGainAbilityTargetEffect extends ContinuousEffectImpl {
|
|||
if (hisokasGuard != null && !hisokasGuard.getConnectedCards("HisokasGuard").isEmpty()) {
|
||||
Permanent guardedCreature = game.getPermanent(hisokasGuard.getConnectedCards("HisokasGuard").get(0));
|
||||
if (guardedCreature != null && hisokasGuard.isTapped()) {
|
||||
guardedCreature.addAbility(ability, game);
|
||||
guardedCreature.addAbility(ability, source.getSourceId(), game);
|
||||
return true;
|
||||
} else {
|
||||
// if guard isn't tapped, the effect is no more valid
|
||||
|
|
|
@ -72,7 +72,7 @@ class ProteanThaumaturgeApplyToPermanent extends ApplyToPermanent {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Permanent permanent, Ability source, UUID copyToObjectId) {
|
||||
permanent.addAbility(ProteanThaumaturge.createAbility(), game);
|
||||
permanent.addAbility(ProteanThaumaturge.createAbility(), source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class SakashimaTheImpostorApplier extends ApplyToPermanent {
|
|||
permanent.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD,
|
||||
new CreateDelayedTriggeredAbilityEffect(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnToHandSourceEffect(true)), false),
|
||||
new ManaCostsImpl("{2}{U}{U}")
|
||||
), game);
|
||||
), source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ public final class UncheckedGrowth extends CardImpl {
|
|||
for (UUID permanentId : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(permanentId);
|
||||
if (permanent != null && permanent.hasSubtype(SubType.SPIRIT, game)) {
|
||||
permanent.addAbility(TrampleAbility.getInstance(), game);
|
||||
permanent.addAbility(TrampleAbility.getInstance(), source.getSourceId(), game);
|
||||
affectedTargets++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ class UnstableShapeshifterEffect extends OneShotEffect {
|
|||
if (targetCreature != null && permanent != null) {
|
||||
Permanent blueprintPermanent = game.copyPermanent(Duration.Custom, targetCreature, permanent.getId(), source, new EmptyApplyToPermanent());
|
||||
blueprintPermanent.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD,
|
||||
new UnstableShapeshifterEffect(), filterAnotherCreature, false, SetTargetPointer.PERMANENT, ""), game);
|
||||
new UnstableShapeshifterEffect(), filterAnotherCreature, false, SetTargetPointer.PERMANENT, ""), source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -86,7 +86,7 @@ class VraskaTheUnseenGainAbilityEffect extends ContinuousEffectImpl {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
permanent.addAbility(ability, game);
|
||||
permanent.addAbility(ability, source.getSourceId(), game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -40,7 +40,7 @@ public class SerializationTest extends CardTestPlayerBase {
|
|||
currentGame.addPermanent(permanent);
|
||||
|
||||
// mark damage from infected ability
|
||||
permanent.addAbility(InfectAbility.getInstance(), currentGame);
|
||||
permanent.addAbility(InfectAbility.getInstance(), null, currentGame);
|
||||
permanent.markDamage(1, permanent.getId(), currentGame, false, false);
|
||||
|
||||
// test compress (it uses default java serialization)
|
||||
|
|
|
@ -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…
Reference in a new issue