Added possibility that opponent can activate activateted ability to activatedAbility. Minor changes.

This commit is contained in:
LevelX2 2013-01-31 21:56:11 +01:00
parent 90e4c74a4d
commit eff6ea131f
4 changed files with 22 additions and 5 deletions

View file

@ -196,6 +196,7 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
// 20121001 - 601.2b // 20121001 - 601.2b
// If the spell has a variable cost that will be paid as it's being cast (such as an {X} in // If the spell has a variable cost that will be paid as it's being cast (such as an {X} in
// its mana cost; see rule 107.3), the player announces the value of that variable. // its mana cost; see rule 107.3), the player announces the value of that variable.
// TODO: Handle announcing other variable costs here like: RemoveVariableCountersSourceCost
if (game.getPlayer(this.controllerId).isHuman()) { if (game.getPlayer(this.controllerId).isHuman()) {
// AI can't handle this yet. Uses old way of playXMana // AI can't handle this yet. Uses old way of playXMana
VariableManaCost manaX = null; VariableManaCost manaX = null;
@ -276,7 +277,11 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
} }
//20100716 - 601.2g //20100716 - 601.2g
if (!costs.pay(this, game, sourceId, controllerId, noMana)) { UUID activatorId = controllerId;
if (this instanceof ActivatedAbilityImpl) {
activatorId = ((ActivatedAbilityImpl)this).getActivatorId();
}
if (!costs.pay(this, game, sourceId, activatorId, noMana)) {
logger.debug("activate failed - non mana costs"); logger.debug("activate failed - non mana costs");
return false; return false;
} }

View file

@ -54,6 +54,8 @@ import mage.target.Target;
public abstract class ActivatedAbilityImpl<T extends ActivatedAbilityImpl<T>> extends AbilityImpl<T> implements ActivatedAbility { public abstract class ActivatedAbilityImpl<T extends ActivatedAbilityImpl<T>> extends AbilityImpl<T> implements ActivatedAbility {
protected TimingRule timing = TimingRule.INSTANT; protected TimingRule timing = TimingRule.INSTANT;
protected boolean onlyOpponentCanActivate = false;
protected UUID activatorId;
protected ActivatedAbilityImpl(AbilityType abilityType, Zone zone) { protected ActivatedAbilityImpl(AbilityType abilityType, Zone zone) {
super(abilityType, zone); super(abilityType, zone);
@ -62,6 +64,8 @@ public abstract class ActivatedAbilityImpl<T extends ActivatedAbilityImpl<T>> ex
public ActivatedAbilityImpl(ActivatedAbilityImpl ability) { public ActivatedAbilityImpl(ActivatedAbilityImpl ability) {
super(ability); super(ability);
timing = ability.timing; timing = ability.timing;
onlyOpponentCanActivate = ability.onlyOpponentCanActivate;
activatorId = ability.activatorId;
} }
public ActivatedAbilityImpl(Zone zone) { public ActivatedAbilityImpl(Zone zone) {
@ -152,12 +156,14 @@ public abstract class ActivatedAbilityImpl<T extends ActivatedAbilityImpl<T>> ex
@Override @Override
public boolean canActivate(UUID playerId, Game game) { public boolean canActivate(UUID playerId, Game game) {
//20091005 - 602.2 //20091005 - 602.2
if (!controlsAbility(playerId, game)) { if ((!onlyOpponentCanActivate && !controlsAbility(playerId, game)) ||
(onlyOpponentCanActivate && !game.getOpponents(controllerId).contains(playerId))) {
return false; return false;
} }
//20091005 - 602.5d/602.5e //20091005 - 602.5d/602.5e
if (timing == TimingRule.INSTANT || game.canPlaySorcery(playerId)) { if (timing == TimingRule.INSTANT || game.canPlaySorcery(playerId)) {
if (costs.canPay(sourceId, controllerId, game) && canChooseTarget(game)) { if (costs.canPay(sourceId, controllerId, game) && canChooseTarget(game)) {
this.activatorId = playerId;
return true; return true;
} }
} }
@ -230,4 +236,12 @@ public abstract class ActivatedAbilityImpl<T extends ActivatedAbilityImpl<T>> ex
} }
return sb.toString(); return sb.toString();
} }
public void setOnlyOpponentCanActivate(boolean onlyOpponentCanActivate) {
this.onlyOpponentCanActivate = onlyOpponentCanActivate;
}
public UUID getActivatorId() {
return this.activatorId;
}
} }

View file

@ -51,7 +51,6 @@ import mage.target.TargetPermanent;
public class RemoveCounterCost extends CostImpl<RemoveCounterCost> { public class RemoveCounterCost extends CostImpl<RemoveCounterCost> {
private TargetPermanent target; private TargetPermanent target;
private int amount;
private String name; private String name;
private CounterType counterTypeToRemove; private CounterType counterTypeToRemove;
@ -68,7 +67,6 @@ public class RemoveCounterCost extends CostImpl<RemoveCounterCost> {
public RemoveCounterCost(final RemoveCounterCost cost) { public RemoveCounterCost(final RemoveCounterCost cost) {
super(cost); super(cost);
this.target = cost.target.copy(); this.target = cost.target.copy();
this.amount = cost.amount;
this.name = cost.name; this.name = cost.name;
} }

View file

@ -12,7 +12,7 @@ import mage.game.permanent.Permanent;
public class ControlEnchantedEffect extends ContinuousEffectImpl<ControlEnchantedEffect> { public class ControlEnchantedEffect extends ContinuousEffectImpl<ControlEnchantedEffect> {
public ControlEnchantedEffect() { public ControlEnchantedEffect() {
super(Constants.Duration.WhileOnBattlefield, Constants.Outcome.Detriment); super(Constants.Duration.WhileOnBattlefield, Constants.Outcome.GainControl);
staticText = "You control enchanted creature"; staticText = "You control enchanted creature";
} }