add custom canPlay method for MagicPermanentActivation to perform more complex checking such as permanent that needs to tap but already tapped to pay for mana cost

master
melvin 2013-10-31 14:35:15 +08:00
parent c07e0a62a9
commit d4c3095d12
1 changed files with 29 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import magic.model.MagicChangeCardDefinition;
import magic.model.MagicGame; import magic.model.MagicGame;
import magic.model.MagicPayedCost; import magic.model.MagicPayedCost;
import magic.model.MagicPermanent; import magic.model.MagicPermanent;
import magic.model.MagicPlayer;
import magic.model.MagicSource; import magic.model.MagicSource;
import magic.model.MagicCopyable; import magic.model.MagicCopyable;
import magic.model.MagicCopyMap; import magic.model.MagicCopyMap;
@ -58,6 +59,34 @@ public abstract class MagicPermanentActivation extends MagicActivation<MagicPerm
); );
} }
@Override
public final boolean canPlay(final MagicGame game, final MagicPlayer player, final MagicPermanent source, final boolean useHints) {
final boolean superCanPlay = super.canPlay(game, player, source, useHints);
// More complex check that first executes events without choice, then check conditions of the others
if (superCanPlay && source.producesMana()) {
game.record();
for (final MagicEvent event : getCostEvent(source)) {
if (event.hasChoice() == false) {
game.executeEvent(event, MagicEvent.NO_CHOICE_RESULTS);
}
}
for (final MagicEvent event : getCostEvent(source)) {
if (event.hasChoice() == true) {
for (final MagicCondition condition : event.getConditions()) {
if (!condition.accept(source)) {
game.restore();
return false;
}
}
}
}
game.restore();
}
return superCanPlay;
}
@Override @Override
public MagicCopyable copy(final MagicCopyMap copyMap) { public MagicCopyable copy(final MagicCopyMap copyMap) {
return this; return this;