mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 22:42:03 -08:00
* 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
|
|
@ -609,7 +609,7 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
|
|||
@Override
|
||||
public boolean isInUseableZone(Game game, MageObject source, boolean checkLKI) {
|
||||
|
||||
// emblem are always actual
|
||||
// emblem are always actual (also true for a commander? LevelX)
|
||||
if (zone.equals(Zone.COMMAND)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
// }
|
||||
//}
|
||||
|
|
@ -52,11 +52,12 @@ import mage.players.Player;
|
|||
*/
|
||||
public class CommanderReplacementEffect extends ReplacementEffectImpl<CommanderReplacementEffect> {
|
||||
|
||||
private UUID commander;
|
||||
public CommanderReplacementEffect(UUID commander) {
|
||||
private UUID commanderId;
|
||||
|
||||
public CommanderReplacementEffect(UUID commanderId) {
|
||||
super(Duration.WhileOnBattlefield, Outcome.Benefit);
|
||||
staticText = "If a commander would be put into its owner’s graveyard from anywhere, that player may put it into the command zone instead. If a commander would be put into the exile zone from anywhere, its owner may put it into the command zone instead.";
|
||||
this.commander = commander;
|
||||
this.commanderId = commanderId;
|
||||
this.duration = Duration.EndOfGame;
|
||||
}
|
||||
|
||||
|
|
@ -80,17 +81,16 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl<CommanderR
|
|||
Permanent permanent = ((ZoneChangeEvent)event).getTarget();
|
||||
if (permanent != null) {
|
||||
Player player = game.getPlayer(permanent.getOwnerId());
|
||||
if(player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){
|
||||
return permanent.moveToZone(Zone.COMMAND, source.getId(), game, false);
|
||||
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){
|
||||
return permanent.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Card card = game.getCard(event.getTargetId());
|
||||
if (card != null) {
|
||||
Player player = game.getPlayer(card.getOwnerId());
|
||||
if(player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){
|
||||
return card.moveToZone(Zone.COMMAND, source.getId(), game, false);
|
||||
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){
|
||||
return card.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl<CommanderR
|
|||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && (((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD || ((ZoneChangeEvent)event).getToZone() == Zone.EXILED)) {
|
||||
if(commander != null && commander.equals(event.getTargetId())){
|
||||
if(commanderId != null && commanderId.equals(event.getTargetId())){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,16 +48,16 @@ import mage.game.Game;
|
|||
* */
|
||||
public class CommanderCostModification extends CostModificationEffectImpl<CommanderCostModification> {
|
||||
|
||||
private UUID commander;
|
||||
private UUID commanderId;
|
||||
|
||||
public CommanderCostModification(UUID commander) {
|
||||
public CommanderCostModification(UUID commanderId) {
|
||||
super(Duration.Custom, Outcome.Neutral, CostModificationType.INCREASE_COST);
|
||||
this.commander = commander;
|
||||
this.commanderId = commanderId;
|
||||
}
|
||||
|
||||
public CommanderCostModification(final CommanderCostModification effect) {
|
||||
super(effect);
|
||||
this.commander = effect.commander;
|
||||
this.commanderId = effect.commanderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -65,10 +65,10 @@ public class CommanderCostModification extends CostModificationEffectImpl<Comman
|
|||
|
||||
Mana mana = abilityToModify.getManaCostsToPay().getMana();
|
||||
|
||||
Integer castCount = (Integer)game.getState().getValue(commander + "_castCount");
|
||||
Integer castCount = (Integer)game.getState().getValue(commanderId + "_castCount");
|
||||
if(castCount == null){
|
||||
castCount = 0;
|
||||
game.getState().setValue(commander + "_castCount", castCount);
|
||||
game.getState().setValue(commanderId + "_castCount", castCount);
|
||||
}
|
||||
|
||||
int newCount = mana.getColorless() + 2*castCount;
|
||||
|
|
@ -80,7 +80,7 @@ public class CommanderCostModification extends CostModificationEffectImpl<Comman
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (abilityToModify instanceof CastCommanderAbility && abilityToModify.getSourceId().equals(commander)) {
|
||||
if (abilityToModify instanceof CastCommanderAbility && abilityToModify.getSourceId().equals(commanderId)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue