mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 05:09:16 -08:00
* Reworked Perisist and Undying to not use replacement effects to add the needed counters.
This commit is contained in:
parent
e2625fd60e
commit
b40c8535e9
9 changed files with 218 additions and 195 deletions
|
|
@ -1,50 +1,45 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.DiesTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.abilities.effects.common.ReturnSourceFromGraveyardToBattlefieldEffect;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.counters.CounterType;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.EntersTheBattlefieldEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
|
||||
|
||||
public class PersistAbility extends DiesTriggeredAbility {
|
||||
|
||||
public PersistAbility() {
|
||||
|
|
@ -73,7 +68,6 @@ public class PersistAbility extends DiesTriggeredAbility {
|
|||
if (permanent.getCounters().getCount(CounterType.M1M1) == 0) {
|
||||
FixedTarget fixedTarget = new FixedTarget(permanent.getId());
|
||||
fixedTarget.init(game, this);
|
||||
game.getState().setValue("persist" + getSourceId().toString(), fixedTarget);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -104,58 +98,9 @@ class PersistEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
game.addEffect(new PersistReplacementEffect(), source);
|
||||
Counters countersToAdd = new Counters();
|
||||
countersToAdd.addCounter(CounterType.M1M1.createInstance());
|
||||
game.setEnterWithCounters(source.getSourceId(), countersToAdd);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class PersistReplacementEffect extends ReplacementEffectImpl {
|
||||
|
||||
PersistReplacementEffect() {
|
||||
super(Duration.Custom, Outcome.UnboostCreature, false);
|
||||
selfScope = true;
|
||||
staticText = "return it to the battlefield under its owner's control with a -1/-1 counter on it";
|
||||
}
|
||||
|
||||
PersistReplacementEffect(final PersistReplacementEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistReplacementEffect copy() {
|
||||
return new PersistReplacementEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (permanent != null) {
|
||||
permanent.addCounters(CounterType.M1M1.createInstance(), game);
|
||||
}
|
||||
discard();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getTargetId().equals(source.getSourceId())) {
|
||||
Object fixedTarget = game.getState().getValue("persist" + source.getSourceId().toString());
|
||||
if (fixedTarget instanceof FixedTarget && ((FixedTarget) fixedTarget).getTarget().equals(source.getSourceId()) &&
|
||||
((FixedTarget) fixedTarget).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(source.getSourceId())) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.DiesTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.abilities.effects.common.ReturnSourceFromGraveyardToBattlefieldEffect;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
|
@ -19,7 +16,7 @@ import mage.game.permanent.Permanent;
|
|||
* @author Loki
|
||||
*/
|
||||
public class UndyingAbility extends DiesTriggeredAbility {
|
||||
|
||||
|
||||
public UndyingAbility() {
|
||||
super(new UndyingEffect());
|
||||
this.addEffect(new ReturnSourceFromGraveyardToBattlefieldEffect(false, true));
|
||||
|
|
@ -39,7 +36,6 @@ public class UndyingAbility extends DiesTriggeredAbility {
|
|||
if (super.checkTrigger(event, game)) {
|
||||
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
|
||||
if (!permanent.getCounters().containsKey(CounterType.P1P1) || permanent.getCounters().getCount(CounterType.P1P1) == 0) {
|
||||
game.getState().setValue("undying" + getSourceId(),permanent.getId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,58 +66,9 @@ class UndyingEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
game.addEffect(new UndyingReplacementEffect(), source);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class UndyingReplacementEffect extends ReplacementEffectImpl {
|
||||
|
||||
UndyingReplacementEffect() {
|
||||
super(Duration.OneUse, Outcome.BoostCreature, false);
|
||||
selfScope = true;
|
||||
staticText = "return it to the battlefield under its owner's control with a +1/+1 counter on it";
|
||||
}
|
||||
|
||||
UndyingReplacementEffect(final UndyingReplacementEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UndyingReplacementEffect copy() {
|
||||
return new UndyingReplacementEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (permanent != null) {
|
||||
game.getState().setValue("undying" + source.getSourceId(), null);
|
||||
permanent.addCounters(CounterType.P1P1.createInstance(), game);
|
||||
}
|
||||
used = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getTargetId().equals(source.getSourceId())) {
|
||||
// Check if undying condition is true
|
||||
UUID targetId = (UUID) game.getState().getValue("undying" + source.getSourceId());
|
||||
if (targetId != null && targetId.equals(source.getSourceId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return false;
|
||||
Counters countersToAdd = new Counters();
|
||||
countersToAdd.addCounter(CounterType.P1P1.createInstance());
|
||||
game.setEnterWithCounters(source.getSourceId(), countersToAdd);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -602,6 +602,8 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
PermanentCard permanent = new PermanentCard(this, event.getPlayerId(), game);
|
||||
// make sure the controller of all continuous effects of this card are switched to the current controller
|
||||
game.getContinuousEffects().setController(objectId, event.getPlayerId());
|
||||
// check if there are counters to add to the permanent (e.g. from non replacement effects like Persist)
|
||||
checkForCountersToAdd(permanent, game);
|
||||
game.addPermanent(permanent);
|
||||
setZone(Zone.BATTLEFIELD, game);
|
||||
game.setScopeRelevant(true);
|
||||
|
|
@ -621,6 +623,16 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void checkForCountersToAdd(PermanentCard permanent, Game game) {
|
||||
Counters countersToAdd = game.getEnterWithCounters(permanent.getId());
|
||||
if (countersToAdd != null) {
|
||||
for (Counter counter : countersToAdd.values()) {
|
||||
permanent.addCounters(counter, game);
|
||||
}
|
||||
game.setEnterWithCounters(permanent.getId(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFaceDown(boolean value, Game game) {
|
||||
game.getState().getCardState(objectId).setFaceDown(value);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ import mage.constants.MultiplayerAttackOption;
|
|||
import mage.constants.PlayerAction;
|
||||
import mage.constants.RangeOfInfluence;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.combat.Combat;
|
||||
import mage.game.command.Commander;
|
||||
import mage.game.command.Emblem;
|
||||
|
|
@ -436,4 +437,8 @@ public interface Game extends MageItem, Serializable {
|
|||
void rollbackTurns(int turnsToRollback);
|
||||
|
||||
boolean executingRollback();
|
||||
|
||||
void setEnterWithCounters(UUID sourceId, Counters counters);
|
||||
|
||||
Counters getEnterWithCounters(UUID sourceId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ import mage.constants.PlayerAction;
|
|||
import mage.constants.RangeOfInfluence;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.counters.Counters;
|
||||
import mage.filter.Filter;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
|
|
@ -207,6 +208,9 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
private final int startLife;
|
||||
protected PlayerList playerList;
|
||||
|
||||
// used to set the counters a permanent adds the battlefield (if no replacement effect is used e.g. Persist)
|
||||
protected Map<UUID, Counters> enterWithCounters = new HashMap<>();
|
||||
|
||||
public GameImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.range = range;
|
||||
|
|
@ -246,6 +250,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
this.priorityTime = game.priorityTime;
|
||||
this.saveGame = game.saveGame;
|
||||
this.startLife = game.startLife;
|
||||
this.enterWithCounters.putAll(game.enterWithCounters);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -2665,4 +2670,20 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
return executingRollback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnterWithCounters(UUID sourceId, Counters counters) {
|
||||
if (counters == null) {
|
||||
if (enterWithCounters.containsKey(sourceId)) {
|
||||
enterWithCounters.remove(sourceId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
enterWithCounters.put(sourceId, counters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Counters getEnterWithCounters(UUID sourceId) {
|
||||
return enterWithCounters.get(sourceId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue