updated implementation of Adapt

This commit is contained in:
Evan Kranzler 2019-01-03 16:20:36 -05:00
parent 618300cdc3
commit 965fa971a3
6 changed files with 50 additions and 26 deletions

View file

@ -5,6 +5,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
@ -40,8 +41,15 @@ public class AdaptEffect extends OneShotEffect {
if (permanent == null) {
return false;
}
if (permanent.getCounters(game).getCount(CounterType.P1P1) == 0) {
permanent.addCounters(CounterType.P1P1.createInstance(adaptNumber), source, game);
GameEvent event = new GameEvent(
GameEvent.EventType.ADAPT, source.getSourceId(), source.getSourceId(),
source.getControllerId(), adaptNumber, false
);
if (game.replaceEvent(event)) {
return false;
}
if (permanent.getCounters(game).getCount(CounterType.P1P1) == 0 || event.getFlag()) {
permanent.addCounters(CounterType.P1P1.createInstance(event.getAmount()), source, game);
}
return true;
}

View file

@ -0,0 +1,27 @@
package mage.abilities.keyword;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.keyword.AdaptEffect;
import mage.constants.Zone;
/**
* @author TheElk801
*/
public class AdaptAbility extends ActivatedAbilityImpl {
public AdaptAbility(int adaptNumber, String manaCost) {
super(Zone.BATTLEFIELD, new AdaptEffect(adaptNumber), new ManaCostsImpl(manaCost));
}
public AdaptAbility(final AdaptAbility ability) {
super(ability);
}
@Override
public AdaptAbility copy() {
return new AdaptAbility(this);
}
}

View file

@ -1,14 +1,14 @@
package mage.game.events;
import mage.MageObjectReference;
import mage.constants.Zone;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageObjectReference;
import mage.constants.Zone;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GameEvent implements Serializable {
@ -232,6 +232,7 @@ public class GameEvent implements Serializable {
FLIP, FLIPPED,
UNFLIP, UNFLIPPED,
TRANSFORM, TRANSFORMED,
ADAPT,
BECOMES_MONSTROUS,
BECOMES_EXERTED,
/* BECOMES_EXERTED
@ -383,12 +384,12 @@ public class GameEvent implements Serializable {
}
private GameEvent(EventType type, UUID customEventType,
UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) {
UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) {
this(type, customEventType, targetId, sourceId, playerId, amount, flag, null);
}
private GameEvent(EventType type, UUID customEventType,
UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag, MageObjectReference reference) {
UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag, MageObjectReference reference) {
this.type = type;
this.customEventType = customEventType;
this.targetId = targetId;
@ -466,7 +467,7 @@ public class GameEvent implements Serializable {
/**
* used to store which replacement effects were already applied to an event
* or or any modified events that may replace it
*
* <p>
* 614.5. A replacement effect doesn't invoke itself repeatedly; it gets
* only one opportunity to affect an event or any modified events that may
* replace it. Example: A player controls two permanents, each with an