forked from External/mage
* Commander - Fixed cost reduction for casting commander.
This commit is contained in:
parent
0b6f338b2c
commit
0697801cdc
5 changed files with 95 additions and 80 deletions
|
|
@ -29,29 +29,24 @@ package mage.abilities.common;
|
|||
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbilityImpl;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import mage.constants.TimingRule;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.command.Commander;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Plopman
|
||||
*/
|
||||
public class CastCommanderAbility extends ActivatedAbilityImpl<CastCommanderAbility> {
|
||||
public class CastCommanderAbility extends SpellAbility {
|
||||
|
||||
public CastCommanderAbility(Card card) {
|
||||
super(Zone.COMMAND, new CastCommanderEffect(), card.getManaCost());
|
||||
super(card.getManaCost(), card.getName(), Zone.COMMAND, SpellAbilityType.BASE);
|
||||
this.timing = TimingRule.SORCERY;
|
||||
this.usesStack = false;
|
||||
this.usesStack = true;
|
||||
this.controllerId = card.getOwnerId();
|
||||
this.sourceId = card.getId();
|
||||
}
|
||||
|
|
@ -60,6 +55,26 @@ public class CastCommanderAbility extends ActivatedAbilityImpl<CastCommanderAbil
|
|||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(Game game, boolean noMana) {
|
||||
if (super.activate(game, noMana)) {
|
||||
// save amount of times commander was cast
|
||||
Integer castCount = (Integer)game.getState().getValue(sourceId + "_castCount");
|
||||
if(castCount != null){
|
||||
castCount++;
|
||||
game.getState().setValue(sourceId + "_castCount", castCount);
|
||||
}
|
||||
else {
|
||||
castCount = 1;
|
||||
game.getState().setValue(sourceId + "_castCount", castCount);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public CastCommanderAbility copy() {
|
||||
return new CastCommanderAbility(this);
|
||||
|
|
@ -67,52 +82,52 @@ public class CastCommanderAbility extends ActivatedAbilityImpl<CastCommanderAbil
|
|||
|
||||
}
|
||||
|
||||
class CastCommanderEffect extends OneShotEffect<CastCommanderEffect> {
|
||||
|
||||
public CastCommanderEffect() {
|
||||
super(Outcome.Benefit);
|
||||
staticText = "cast commander";
|
||||
}
|
||||
|
||||
public CastCommanderEffect(final CastCommanderEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastCommanderEffect copy() {
|
||||
return new CastCommanderEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
MageObject object = game.getObject(source.getSourceId());
|
||||
if (object != null && object instanceof Commander) {
|
||||
Commander commander = (Commander)object;
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
SpellAbility spellAbility = commander.getCard().getSpellAbility();
|
||||
|
||||
spellAbility.clear();
|
||||
int amount = source.getManaCostsToPay().getX();
|
||||
spellAbility.getManaCostsToPay().setX(amount);
|
||||
for (Target target : spellAbility.getTargets()) {
|
||||
target.setRequired(true);
|
||||
}
|
||||
if(controller.cast(spellAbility, game, true)){
|
||||
Integer castCount = (Integer)game.getState().getValue(commander.getId() + "_castCount");
|
||||
if(castCount != null){
|
||||
castCount++;
|
||||
game.getState().setValue(commander.getId() + "_castCount", castCount);
|
||||
}
|
||||
else {
|
||||
castCount = 1;
|
||||
game.getState().setValue(commander.getId() + "_castCount", castCount);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//class CastCommanderEffect extends OneShotEffect<CastCommanderEffect> {
|
||||
//
|
||||
// public CastCommanderEffect() {
|
||||
// super(Outcome.Benefit);
|
||||
// staticText = "cast commander";
|
||||
// }
|
||||
//
|
||||
// public CastCommanderEffect(final CastCommanderEffect effect) {
|
||||
// super(effect);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public CastCommanderEffect copy() {
|
||||
// return new CastCommanderEffect(this);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean apply(Game game, Ability source) {
|
||||
// MageObject object = game.getObject(source.getSourceId());
|
||||
// if (object != null && object instanceof Commander) {
|
||||
// Commander commander = (Commander)object;
|
||||
// Player controller = game.getPlayer(source.getControllerId());
|
||||
// if (controller != null) {
|
||||
// SpellAbility spellAbility = commander.getCard().getSpellAbility();
|
||||
//
|
||||
// spellAbility.clear();
|
||||
// int amount = source.getManaCostsToPay().getX();
|
||||
// spellAbility.getManaCostsToPay().setX(amount);
|
||||
// for (Target target : spellAbility.getTargets()) {
|
||||
// target.setRequired(true);
|
||||
// }
|
||||
// if(controller.cast(spellAbility, game, true)){
|
||||
// Integer castCount = (Integer)game.getState().getValue(commander.getId() + "_castCount");
|
||||
// if(castCount != null){
|
||||
// castCount++;
|
||||
// game.getState().setValue(commander.getId() + "_castCount", castCount);
|
||||
// }
|
||||
// else {
|
||||
// castCount = 1;
|
||||
// game.getState().setValue(commander.getId() + "_castCount", castCount);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
Loading…
Add table
Add a link
Reference in a new issue