mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
Reworking "as long as you control this" effects (WIP) (#8620)
* added WhileControlled duration, removed SourceOnBattlefieldControlUnchangedCondition * refactored effects which keep things tapped * a few additional missed cards * refactored cards which check for being controlled and tapped * [NEO] Implemented Kyodai, Soul of Kamigawa
This commit is contained in:
parent
0ca75806fe
commit
d030848552
36 changed files with 495 additions and 1239 deletions
|
|
@ -1,43 +0,0 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.LostControlWatcher;
|
||||
|
||||
/**
|
||||
* This condition checks if ever since first call of the apply method the
|
||||
* controller of the source has changed
|
||||
*
|
||||
* Monitoring the LOST_CONTROL event has the advantage that also all layered
|
||||
* effects can correctly check for controller change because comparing old and
|
||||
* new controller during their apply time does not take into account layered
|
||||
* change control effects that will be applied later.
|
||||
*
|
||||
* This condition needs the LostControlWatcher, so be sure to add it to the card
|
||||
* that uses the condition.
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class SourceOnBattlefieldControlUnchangedCondition implements Condition {
|
||||
|
||||
private Long checkingSince;
|
||||
private int startingZoneChangeCounter;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (checkingSince == null) {
|
||||
checkingSince = System.currentTimeMillis() - 1;
|
||||
startingZoneChangeCounter = game.getState().getZoneChangeCounter(source.getSourceId());
|
||||
}
|
||||
if (game.getState().getZoneChangeCounter(source.getSourceId()) > startingZoneChangeCounter) {
|
||||
return false;
|
||||
}
|
||||
LostControlWatcher watcher = game.getState().getWatcher(LostControlWatcher.class);
|
||||
if (watcher != null) {
|
||||
return checkingSince > watcher.getOrderOfLastLostControl(source.getSourceId());
|
||||
}
|
||||
throw new UnsupportedOperationException("LostControlWatcher not found!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -104,8 +104,13 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
|
|||
if (!conditionState && effect.getDuration() == Duration.OneUse) {
|
||||
used = true;
|
||||
}
|
||||
if (!conditionState && effect.getDuration() == Duration.Custom) {
|
||||
this.discard();
|
||||
switch (effect.getDuration()) {
|
||||
case OneUse:
|
||||
used = true;
|
||||
break;
|
||||
case Custom:
|
||||
case WhileControlled:
|
||||
this.discard();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -123,11 +128,13 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
|
|||
otherwiseEffect.setTargetPointer(this.targetPointer);
|
||||
return otherwiseEffect.apply(game, source);
|
||||
}
|
||||
if (effect.getDuration() == Duration.OneUse) {
|
||||
used = true;
|
||||
}
|
||||
if (effect.getDuration() == Duration.Custom) {
|
||||
this.discard();
|
||||
switch (effect.getDuration()) {
|
||||
case OneUse:
|
||||
used = true;
|
||||
break;
|
||||
case Custom:
|
||||
case WhileControlled:
|
||||
this.discard();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -176,7 +183,8 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
|
|||
|
||||
/**
|
||||
* Return all effects list, for tests only
|
||||
* @return
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<ContinuousEffect> getAllEffects() {
|
||||
List<ContinuousEffect> res = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -177,6 +177,7 @@ public class ContinuousEffects implements Serializable {
|
|||
for (ContinuousEffect effect : layeredEffects) {
|
||||
switch (effect.getDuration()) {
|
||||
case WhileOnBattlefield:
|
||||
case WhileControlled:
|
||||
case WhileOnStack:
|
||||
case WhileInGraveyard:
|
||||
Set<Ability> abilities = layeredEffects.getAbility(effect.getId());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package mage.abilities.effects;
|
||||
|
||||
import java.util.*;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.MageSingleton;
|
||||
|
|
@ -8,9 +7,12 @@ import mage.cards.Card;
|
|||
import mage.constants.Duration;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -145,6 +147,12 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
|
|||
}
|
||||
break;
|
||||
case Custom:
|
||||
case UntilYourNextTurn:
|
||||
case UntilEndOfYourNextTurn:
|
||||
// until your turn effects continue until real turn reached, their used it's own inactive method
|
||||
// 514.2 Second, the following actions happen simultaneously: all damage marked on permanents
|
||||
// (including phased-out permanents) is removed and all "until end of turn" and "this turn" effects end.
|
||||
// This turn-based action doesn’t use the stack.
|
||||
// custom effects must process it's own inactive method (override)
|
||||
// custom effects may not end, if the source permanent of the effect has left the game
|
||||
// 800.4a (only any effects which give that player control of any objects or players end)
|
||||
|
|
@ -156,18 +164,14 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
|
|||
// end of turn discards on cleanup steps
|
||||
// 514.2
|
||||
break;
|
||||
case UntilYourNextTurn:
|
||||
case UntilEndOfYourNextTurn:
|
||||
// until your turn effects continue until real turn reached, their used it's own inactive method
|
||||
// 514.2 Second, the following actions happen simultaneously: all damage marked on permanents
|
||||
// (including phased-out permanents) is removed and all "until end of turn" and "this turn" effects end.
|
||||
// This turn-based action doesn’t use the stack.
|
||||
if (effect.isInactive(ability, game)) {
|
||||
case UntilSourceLeavesBattlefield:
|
||||
if (hasOwnerLeftGame || game.getState().getZone(ability.getSourceId()) != Zone.BATTLEFIELD) {
|
||||
it.remove();
|
||||
}
|
||||
break;
|
||||
case UntilSourceLeavesBattlefield:
|
||||
if (hasOwnerLeftGame || Zone.BATTLEFIELD != game.getState().getZone(ability.getSourceId())) {
|
||||
case WhileControlled:
|
||||
Permanent permanent = ability.getSourcePermanentIfItStillExists(game);
|
||||
if (hasOwnerLeftGame || permanent == null || !permanent.isControlledBy(ability.getControllerId())) {
|
||||
it.remove();
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
||||
|
|
@ -12,18 +10,27 @@ import mage.game.Game;
|
|||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DontUntapInControllersUntapStepTargetEffect extends ContinuousRuleModifyingEffectImpl {
|
||||
|
||||
private final String targetName;
|
||||
|
||||
public DontUntapInControllersUntapStepTargetEffect(Duration duration) {
|
||||
this(duration, "That creature");
|
||||
}
|
||||
|
||||
public DontUntapInControllersUntapStepTargetEffect(Duration duration, String targetName) {
|
||||
super(duration, Outcome.Detriment);
|
||||
this.targetName = targetName;
|
||||
}
|
||||
|
||||
public DontUntapInControllersUntapStepTargetEffect(final DontUntapInControllersUntapStepTargetEffect effect) {
|
||||
super(effect);
|
||||
this.targetName = effect.targetName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -36,16 +43,6 @@ public class DontUntapInControllersUntapStepTargetEffect extends ContinuousRuleM
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoMessage(Ability source, GameEvent event, Game game) {
|
||||
MageObject mageObject = game.getObject(source.getSourceId());
|
||||
Permanent permanentToUntap = game.getPermanent((event.getTargetId()));
|
||||
if (permanentToUntap != null && mageObject != null) {
|
||||
return permanentToUntap.getIdName() + " doesn't untap (" + mageObject.getIdName() + ')';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.UNTAP;
|
||||
|
|
@ -53,14 +50,16 @@ public class DontUntapInControllersUntapStepTargetEffect extends ContinuousRuleM
|
|||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (game.getTurn().getStepType() == PhaseStep.UNTAP) {
|
||||
for (UUID targetId : targetPointer.getTargets(game, source)) {
|
||||
if (event.getTargetId().equals(targetId)) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent != null && game.isActivePlayer(permanent.getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (game.getTurn().getStepType() != PhaseStep.UNTAP) {
|
||||
return false;
|
||||
}
|
||||
for (UUID targetId : targetPointer.getTargets(game, source)) {
|
||||
if (!event.getTargetId().equals(targetId)) {
|
||||
continue;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent != null && game.isActivePlayer(permanent.getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -68,11 +67,11 @@ public class DontUntapInControllersUntapStepTargetEffect extends ContinuousRuleM
|
|||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
return "target " + mode.getTargets().get(0).getTargetName()
|
||||
+ " doesn't untap during its controller's untap step" + (getDuration().toString().isEmpty() ? "" : " " + getDuration());
|
||||
return targetName + " doesn't untap during its controller's untap step"
|
||||
+ (getDuration().toString().isEmpty() ? "" : " ") + getDuration();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ public enum Duration {
|
|||
OneUse("", true, true),
|
||||
EndOfGame("for the rest of the game", false, false),
|
||||
WhileOnBattlefield("", false, false),
|
||||
WhileControlled("for as long as you control {this}", true, false),
|
||||
WhileOnStack("", false, true),
|
||||
WhileInGraveyard("", false, false),
|
||||
EndOfTurn("until end of turn", true, true),
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class LostControlWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Long> lastLostControl = new HashMap<>();
|
||||
|
||||
public LostControlWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.LOST_CONTROL) {
|
||||
lastLostControl.put(event.getTargetId(), System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
lastLostControl.clear();
|
||||
}
|
||||
|
||||
public long getOrderOfLastLostControl(UUID sourceId) {
|
||||
return lastLostControl.getOrDefault(sourceId, new Long(0));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue