mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
revamped how conditional and limited-use activated abilities are implemented
This commit is contained in:
parent
650f184ee6
commit
9b25dd0e39
6 changed files with 55 additions and 93 deletions
|
@ -37,6 +37,8 @@ import mage.abilities.costs.mana.ManaCostsImpl;
|
|||
import mage.abilities.effects.AsThoughEffectImpl;
|
||||
import mage.abilities.effects.AsThoughManaEffect;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.AsThoughEffectType;
|
||||
|
@ -89,14 +91,14 @@ public class QuicksilverElemental extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class QuicksilverElementalEffect extends ContinuousEffectImpl {
|
||||
class QuicksilverElementalEffect extends OneShotEffect {
|
||||
|
||||
public QuicksilverElementalEffect() {
|
||||
super(Duration.EndOfTurn, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
||||
QuicksilverElementalEffect() {
|
||||
super(Outcome.Benefit);
|
||||
staticText = "{this} gains all activated abilities of target creature until end of turn";
|
||||
}
|
||||
|
||||
public QuicksilverElementalEffect(final QuicksilverElementalEffect effect) {
|
||||
QuicksilverElementalEffect(final QuicksilverElementalEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
|
@ -112,13 +114,46 @@ class QuicksilverElementalEffect extends ContinuousEffectImpl {
|
|||
|
||||
if (permanent != null && creature != null) {
|
||||
for (ActivatedAbility ability : creature.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
|
||||
permanent.addAbility(ability, source.getSourceId(), game);
|
||||
Ability newAbility = ability.copy();
|
||||
newAbility.newOriginalId();
|
||||
game.addEffect(new GainAbilitySourceEffect(newAbility, Duration.EndOfTurn), source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//class QuicksilverElementalEffect extends ContinuousEffectImpl {
|
||||
//
|
||||
// public QuicksilverElementalEffect() {
|
||||
// super(Duration.EndOfTurn, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
||||
// staticText = "{this} gains all activated abilities of target creature until end of turn";
|
||||
// }
|
||||
//
|
||||
// public QuicksilverElementalEffect(final QuicksilverElementalEffect effect) {
|
||||
// super(effect);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public QuicksilverElementalEffect copy() {
|
||||
// return new QuicksilverElementalEffect(this);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean apply(Game game, Ability source) {
|
||||
// Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
// Permanent creature = game.getPermanent(source.getTargets().getFirstTarget());
|
||||
//
|
||||
// if (permanent != null && creature != null) {
|
||||
// for (ActivatedAbility ability : creature.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
|
||||
// permanent.addAbility(ability, source.getSourceId(), game);
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
|
||||
class QuickSilverElementalBlueManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
|
||||
|
||||
public QuickSilverElementalBlueManaEffect() {
|
||||
|
|
|
@ -275,7 +275,7 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
|
|||
return checkPlayableMode;
|
||||
}
|
||||
|
||||
private boolean hasMoreActivationsThisTurn(Game game) {
|
||||
protected boolean hasMoreActivationsThisTurn(Game game) {
|
||||
ActivationInfo activationInfo = getActivationInfo(game);
|
||||
return activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < maxActivationsPerTurn;
|
||||
}
|
||||
|
@ -305,8 +305,8 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
|
|||
}
|
||||
|
||||
private ActivationInfo getActivationInfo(Game game) {
|
||||
Integer turnNum = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game));
|
||||
Integer activationCount = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsCount", sourceId, game));
|
||||
Integer turnNum = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsTurn" + originalId, sourceId, game));
|
||||
Integer activationCount = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsCount" + originalId, sourceId, game));
|
||||
if (turnNum == null || activationCount == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
|
|||
}
|
||||
|
||||
private void setActivationInfo(ActivationInfo activationInfo, Game game) {
|
||||
game.getState().setValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game), activationInfo.turnNum);
|
||||
game.getState().setValue(CardUtil.getCardZoneString("activationsCount", sourceId, game), activationInfo.activationCounter);
|
||||
game.getState().setValue(CardUtil.getCardZoneString("activationsTurn" + originalId, sourceId, game), activationInfo.turnNum);
|
||||
game.getState().setValue(CardUtil.getCardZoneString("activationsCount" + originalId, sourceId, game), activationInfo.activationCounter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
package mage.abilities.decorator;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.ActivatedAbilityImpl;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.Cost;
|
||||
|
@ -24,7 +23,6 @@ public class ConditionalActivatedAbility extends ActivatedAbilityImpl {
|
|||
|
||||
private static final Effects emptyEffects = new Effects();
|
||||
|
||||
private final Condition condition;
|
||||
private String ruleText = null;
|
||||
|
||||
public ConditionalActivatedAbility(Zone zone, Effect effect, Cost cost, Condition condition) {
|
||||
|
@ -64,14 +62,6 @@ public class ConditionalActivatedAbility extends ActivatedAbilityImpl {
|
|||
return super.getEffects(game, effectType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canActivate(UUID playerId, Game game) {
|
||||
if (!condition.apply(game, this)) {
|
||||
return false;
|
||||
}
|
||||
return super.canActivate(playerId, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConditionalActivatedAbility copy() {
|
||||
return new ConditionalActivatedAbility(this);
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.abilities.mana;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.effects.common.AddConditionalColorlessManaEffect;
|
||||
|
@ -37,8 +36,6 @@ import mage.game.Game;
|
|||
|
||||
public class ActivateIfConditionManaAbility extends ActivatedManaAbilityImpl {
|
||||
|
||||
private final Condition condition;
|
||||
|
||||
public ActivateIfConditionManaAbility(Zone zone, BasicManaEffect effect, Cost cost, Condition condition) {
|
||||
super(zone, effect, cost);
|
||||
this.netMana.add(effect.getMana());
|
||||
|
@ -56,20 +53,9 @@ public class ActivateIfConditionManaAbility extends ActivatedManaAbilityImpl {
|
|||
this.condition = ability.condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canActivate(UUID playerId, Game game) {
|
||||
if (condition.apply(game, this)) {
|
||||
return super.canActivate(playerId, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(Game game, boolean noMana) {
|
||||
if (canActivate(this.controllerId, game)) {
|
||||
return super.activate(game, noMana);
|
||||
}
|
||||
return false;
|
||||
return super.activate(game, noMana);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
* 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.mana;
|
||||
|
||||
import mage.Mana;
|
||||
|
@ -34,9 +33,6 @@ import mage.abilities.effects.common.AddManaOfAnyColorEffect;
|
|||
import mage.abilities.effects.common.BasicManaEffect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -44,60 +40,26 @@ import java.util.UUID;
|
|||
*/
|
||||
public class ActivateOncePerTurnManaAbility extends ActivatedManaAbilityImpl {
|
||||
|
||||
static class ActivationInfo {
|
||||
|
||||
public int turnNum;
|
||||
public int activationCounter;
|
||||
|
||||
public ActivationInfo(int turnNum, int activationCounter) {
|
||||
this.turnNum = turnNum;
|
||||
this.activationCounter = activationCounter;
|
||||
}
|
||||
}
|
||||
|
||||
public ActivateOncePerTurnManaAbility(Zone zone, BasicManaEffect effect, Cost cost) {
|
||||
super(zone, effect, cost);
|
||||
this.netMana.add(effect.getMana());
|
||||
this.maxActivationsPerTurn = 1;
|
||||
}
|
||||
|
||||
public ActivateOncePerTurnManaAbility(Zone zone, AddManaOfAnyColorEffect effect, Cost cost) {
|
||||
super(zone, effect, cost);
|
||||
this.netMana.add(new Mana(0,0,0,0,0,0,effect.getAmount(), 0));
|
||||
this.netMana.add(new Mana(0, 0, 0, 0, 0, 0, effect.getAmount(), 0));
|
||||
this.maxActivationsPerTurn = 1;
|
||||
}
|
||||
|
||||
public ActivateOncePerTurnManaAbility(ActivateOncePerTurnManaAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canActivate(UUID playerId, Game game) {
|
||||
if (super.canActivate(playerId, game)) {
|
||||
ActivationInfo activationInfo = getActivationInfo(game);
|
||||
if (activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(Game game, boolean noMana) {
|
||||
if (canActivate(this.controllerId, 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;
|
||||
}
|
||||
return super.activate(game, noMana);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -112,18 +74,4 @@ public class ActivateOncePerTurnManaAbility extends ActivatedManaAbilityImpl {
|
|||
return new ActivateOncePerTurnManaAbility(this);
|
||||
}
|
||||
|
||||
private ActivationInfo getActivationInfo(Game game) {
|
||||
Integer turnNum = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game));
|
||||
Integer activationCount = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsCount", sourceId, game));
|
||||
if (turnNum == null || activationCount == null) {
|
||||
return null;
|
||||
}
|
||||
return new ActivationInfo(turnNum, activationCount);
|
||||
}
|
||||
|
||||
private void setActivationInfo(ActivationInfo activationInfo, Game game) {
|
||||
game.getState().setValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game), activationInfo.turnNum);
|
||||
game.getState().setValue(CardUtil.getCardZoneString("activationsCount", sourceId, game), activationInfo.activationCounter);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,10 +69,13 @@ public abstract class ActivatedManaAbilityImpl extends ActivatedAbilityImpl impl
|
|||
|
||||
@Override
|
||||
public boolean canActivate(UUID playerId, Game game) {
|
||||
if (!super.hasMoreActivationsThisTurn(game) || !(condition == null || condition.apply(game, this))) {
|
||||
return false;
|
||||
}
|
||||
if (!controlsAbility(playerId, game)) {
|
||||
return false;
|
||||
}
|
||||
if (timing == TimingRule.SORCERY
|
||||
if (timing == TimingRule.SORCERY
|
||||
&& !game.canPlaySorcery(playerId)
|
||||
&& !game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.ACTIVATE_AS_INSTANT, this, controllerId, game)) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue