Implemented Capricopian

This commit is contained in:
Evan Kranzler 2020-04-21 17:34:18 -04:00
parent 332da23746
commit fde0873895
3 changed files with 184 additions and 76 deletions

View file

@ -1,6 +1,5 @@
package mage.abilities;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.condition.Condition;
@ -12,11 +11,7 @@ import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects;
import mage.abilities.mana.ManaOptions;
import mage.cards.Card;
import mage.constants.AbilityType;
import mage.constants.AsThoughEffectType;
import mage.constants.TargetController;
import mage.constants.TimingRule;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.command.Commander;
import mage.game.command.Emblem;
@ -24,8 +19,9 @@ import mage.game.command.Plane;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class ActivatedAbilityImpl extends AbilityImpl implements ActivatedAbility {
@ -148,6 +144,34 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
@Override
public abstract ActivatedAbilityImpl copy();
protected boolean checkTargetController(UUID playerId, Game game) {
switch (mayActivate) {
case ANY:
return true;
case ACTIVE:
return game.getActivePlayerId() == playerId;
case NOT_YOU:
return !controlsAbility(playerId, game);
case TEAM:
return !game.getPlayer(controllerId).hasOpponent(playerId, game);
case OPPONENT:
return game.getPlayer(controllerId).hasOpponent(playerId, game);
case OWNER:
Permanent permanent = game.getPermanent(getSourceId());
return permanent != null && permanent.isOwnedBy(playerId);
case YOU:
return controlsAbility(playerId, game);
case CONTROLLER_ATTACHED_TO:
Permanent enchantment = game.getPermanent(getSourceId());
if (enchantment == null || enchantment.getAttachedTo() == null) {
return false;
}
Permanent enchanted = game.getPermanent(enchantment.getAttachedTo());
return enchanted != null && enchanted.isControlledBy(playerId);
}
return true;
}
@Override
public ActivationStatus canActivate(UUID playerId, Game game) {
//20091005 - 602.2
@ -156,49 +180,8 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
|| condition.apply(game, this)))) {
return ActivationStatus.getFalse();
}
switch (mayActivate) {
case ANY:
break;
case ACTIVE:
if (game.getActivePlayerId() != playerId) {
return ActivationStatus.getFalse();
}
break;
case NOT_YOU:
if (controlsAbility(playerId, game)) {
return ActivationStatus.getFalse();
}
break;
case TEAM:
if (game.getPlayer(controllerId).hasOpponent(playerId, game)) {
return ActivationStatus.getFalse();
}
break;
case OPPONENT:
if (!game.getPlayer(controllerId).hasOpponent(playerId, game)) {
return ActivationStatus.getFalse();
}
break;
case OWNER:
Permanent permanent = game.getPermanent(getSourceId());
if (!permanent.isOwnedBy(playerId)) {
return ActivationStatus.getFalse();
}
break;
case YOU:
if (!controlsAbility(playerId, game)) {
return ActivationStatus.getFalse();
}
break;
case CONTROLLER_ATTACHED_TO:
Permanent enchantment = game.getPermanent(getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
Permanent enchanted = game.getPermanent(enchantment.getAttachedTo());
if (enchanted != null && enchanted.isControlledBy(playerId)) {
break;
}
}
return ActivationStatus.getFalse();
if (!this.checkTargetController(playerId, game)) {
return ActivationStatus.getFalse();
}
//20091005 - 602.5d/602.5e
MageObjectReference permittingObject = game.getContinuousEffects()
@ -227,17 +210,16 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
protected boolean controlsAbility(UUID playerId, Game game) {
if (this.controllerId != null && this.controllerId.equals(playerId)) {
return true;
} else {
MageObject mageObject = game.getObject(this.sourceId);
if (mageObject instanceof Emblem) {
return ((Emblem) mageObject).isControlledBy(playerId);
} else if (mageObject instanceof Plane) {
return ((Plane) mageObject).isControlledBy(playerId);
} else if (mageObject instanceof Commander) {
return ((Commander) mageObject).isControlledBy(playerId);
} else if (game.getState().getZone(this.sourceId) != Zone.BATTLEFIELD) {
return ((Card) mageObject).isOwnedBy(playerId);
}
}
MageObject mageObject = game.getObject(this.sourceId);
if (mageObject instanceof Emblem) {
return ((Emblem) mageObject).isControlledBy(playerId);
} else if (mageObject instanceof Plane) {
return ((Plane) mageObject).isControlledBy(playerId);
} else if (mageObject instanceof Commander) {
return ((Commander) mageObject).isControlledBy(playerId);
} else if (game.getState().getZone(this.sourceId) != Zone.BATTLEFIELD) {
return ((Card) mageObject).isOwnedBy(playerId);
}
return false;
}
@ -271,22 +253,20 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
@Override
public boolean activate(Game game, boolean noMana) {
if (hasMoreActivationsThisTurn(game)) {
if (super.activate(game, noMana)) {
ActivationInfo activationInfo = getActivationInfo(game);
if (activationInfo == null) {
activationInfo = new ActivationInfo(game.getTurnNum(), 1);
} else if (activationInfo.turnNum != game.getTurnNum()) {
activationInfo.turnNum = game.getTurnNum();
activationInfo.activationCounter = 1;
} else {
activationInfo.activationCounter++;
}
setActivationInfo(activationInfo, game);
return true;
}
if (!hasMoreActivationsThisTurn(game) || !super.activate(game, noMana)) {
return false;
}
return false;
ActivationInfo activationInfo = getActivationInfo(game);
if (activationInfo == null) {
activationInfo = new ActivationInfo(game.getTurnNum(), 1);
} else if (activationInfo.turnNum != game.getTurnNum()) {
activationInfo.turnNum = game.getTurnNum();
activationInfo.activationCounter = 1;
} else {
activationInfo.activationCounter++;
}
setActivationInfo(activationInfo, game);
return true;
}
@Override