HumanPlayer - changed 1st portion of methods invoking abilities from GUI into static methods (to move them later to a different place later)

This commit is contained in:
Maxmtg
2013-05-12 03:40:10 +00:00
parent 4ed58e2a4d
commit 72b2344cc9
8 changed files with 57 additions and 60 deletions

View File

@@ -426,7 +426,5 @@ public abstract class GameEntity extends MyObservable {
return this.name; return this.name;
} }
public GameState getGame() { public abstract GameState getGame();
return null;
}
} }

View File

@@ -245,7 +245,7 @@ public class PlayEffect extends SpellAbilityEffect {
boolean noManaCost = sa.hasParam("WithoutManaCost"); boolean noManaCost = sa.hasParam("WithoutManaCost");
if (controller.isHuman()) { if (controller.isHuman()) {
SpellAbility newSA = noManaCost ? tgtSA.copyWithNoManaCost() : tgtSA; SpellAbility newSA = noManaCost ? tgtSA.copyWithNoManaCost() : tgtSA;
((HumanPlayer)activator).playSpellAbility(newSA); HumanPlayer.playSpellAbility(activator, newSA);
} else { } else {
if (tgtSA instanceof Spell) { // Isn't it ALWAYS a spell? if (tgtSA instanceof Spell) { // Isn't it ALWAYS a spell?
Spell spell = (Spell) tgtSA; Spell spell = (Spell) tgtSA;

View File

@@ -86,7 +86,7 @@ public class InputPassPriority extends InputBase {
Runnable execAbility = new Runnable() { Runnable execAbility = new Runnable() {
@Override @Override
public void run() { public void run() {
((HumanPlayer)player).playSpellAbility(card, ab); HumanPlayer.playSpellAbility(player, card, ab);
} }
}; };

View File

@@ -292,7 +292,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
Runnable proc = new Runnable() { Runnable proc = new Runnable() {
@Override @Override
public void run() { public void run() {
((HumanPlayer)chosen.getActivatingPlayer()).playSpellAbility(chosen); HumanPlayer.playSpellAbility(chosen.getActivatingPlayer(), chosen);
onManaAbilityPlayed(chosen); onManaAbilityPlayed(chosen);
} }
}; };

View File

@@ -53,13 +53,13 @@ public class HumanPlayer extends Player {
* @param card * @param card
* @param ab * @param ab
*/ */
public void playSpellAbility(Card c, SpellAbility ab) { public static void playSpellAbility(Player p, Card c, SpellAbility ab) {
if (ab == Ability.PLAY_LAND_SURROGATE) if (ab == Ability.PLAY_LAND_SURROGATE)
this.playLand(c); p.playLand(c);
else { else {
this.playSpellAbility(ab); HumanPlayer.playSpellAbility(p, ab);
} }
game.getPhaseHandler().setPriority(this); p.getGame().getPhaseHandler().setPriority(p);
} }
@Override @Override
@@ -76,9 +76,9 @@ public class HumanPlayer extends Player {
* @param sa * @param sa
* a {@link forge.card.spellability.SpellAbility} object. * a {@link forge.card.spellability.SpellAbility} object.
*/ */
public final void playSpellAbility(SpellAbility sa) { public final static void playSpellAbility(Player p, SpellAbility sa) {
FThreads.assertExecutedByEdt(false); FThreads.assertExecutedByEdt(false);
sa.setActivatingPlayer(this); sa.setActivatingPlayer(p);
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
@@ -88,7 +88,7 @@ public class HumanPlayer extends Player {
CharmEffect.makeChoices(sa); CharmEffect.makeChoices(sa);
} }
sa = chooseOptionalAdditionalCosts(sa); sa = chooseOptionalAdditionalCosts(p, sa);
if (sa == null) { if (sa == null) {
return; return;
@@ -116,15 +116,53 @@ public class HumanPlayer extends Player {
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment); final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
req.fillRequirements(false, false, false); req.fillRequirements(false, false, false);
} else { } else {
if (payManaCostIfNeeded(sa)) { if (payManaCostIfNeeded(p, sa)) {
if (sa.isSpell() && !source.isCopiedSpell()) { if (sa.isSpell() && !source.isCopiedSpell()) {
sa.setSourceCard(game.getAction().moveToStack(source)); sa.setSourceCard(p.getGame().getAction().moveToStack(source));
} }
game.getStack().add(sa); p.getGame().getStack().add(sa);
} }
} }
} }
/**
* choose optional additional costs. For HUMAN only
* @param activator
*
* @param original
* the original sa
* @return an ArrayList<SpellAbility>.
*/
private static SpellAbility chooseOptionalAdditionalCosts(Player p, final SpellAbility original) {
//final HashMap<String, SpellAbility> map = new HashMap<String, SpellAbility>();
final List<SpellAbility> abilities = GameActionUtil.getOptionalCosts(original);
if (!original.isSpell()) {
return original;
}
return p.getController().getAbilityToPlay(abilities);
}
private static boolean payManaCostIfNeeded(final Player p, final SpellAbility sa) {
final ManaCostBeingPaid manaCost;
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
manaCost = new ManaCostBeingPaid(ManaCost.ZERO);
} else {
manaCost = new ManaCostBeingPaid(sa.getPayCosts().getTotalMana());
manaCost.applySpellCostChange(sa);
}
boolean isPaid = manaCost.isPaid();
if( !isPaid ) {
InputPayManaBase inputPay = new InputPayManaSimple(p.getGame(), sa, manaCost);
FThreads.setInputAndWait(inputPay);
isPaid = inputPay.isPaid();
}
return isPaid;
}
/** /**
* <p> * <p>
* playSpellAbility_NoStack. * playSpellAbility_NoStack.
@@ -146,52 +184,13 @@ public class HumanPlayer extends Player {
req.fillRequirements(useOldTargets, false, true); req.fillRequirements(useOldTargets, false, true);
} else { } else {
if (payManaCostIfNeeded(sa)) { if (payManaCostIfNeeded(this, sa)) {
AbilityUtils.resolve(sa, false); AbilityUtils.resolve(sa, false);
} }
} }
} }
private boolean payManaCostIfNeeded(final SpellAbility sa) {
final ManaCostBeingPaid manaCost;
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
manaCost = new ManaCostBeingPaid(ManaCost.ZERO);
} else {
manaCost = new ManaCostBeingPaid(sa.getPayCosts().getTotalMana());
manaCost.applySpellCostChange(sa);
}
boolean isPaid = manaCost.isPaid();
if( !isPaid ) {
InputPayManaBase inputPay = new InputPayManaSimple(game, sa, manaCost);
FThreads.setInputAndWait(inputPay);
isPaid = inputPay.isPaid();
}
return isPaid;
}
/**
* choose optional additional costs. For HUMAN only
* @param activator
*
* @param original
* the original sa
* @return an ArrayList<SpellAbility>.
*/
public SpellAbility chooseOptionalAdditionalCosts(final SpellAbility original) {
//final HashMap<String, SpellAbility> map = new HashMap<String, SpellAbility>();
final List<SpellAbility> abilities = GameActionUtil.getOptionalCosts(original);
if (!original.isSpell()) {
return original;
}
return getController().getAbilityToPlay(abilities);
}
public final void playCardWithoutManaCost(final Card c) { public final void playCardWithoutManaCost(final Card c) {
final List<SpellAbility> choices = c.getBasicSpells(); final List<SpellAbility> choices = c.getBasicSpells();
// TODO add Buyback, Kicker, ... , spells here // TODO add Buyback, Kicker, ... , spells here

View File

@@ -373,14 +373,14 @@ public class PlayerControllerHuman extends PlayerController {
@Override @Override
public void playMiracle(SpellAbility miracle, Card card) { public void playMiracle(SpellAbility miracle, Card card) {
if (GuiDialog.confirm(card, card + " - Drawn. Play for Miracle Cost?")) { if (GuiDialog.confirm(card, card + " - Drawn. Play for Miracle Cost?")) {
player.playSpellAbility(miracle); HumanPlayer.playSpellAbility(player, miracle);
} }
} }
@Override @Override
public void playMadness(SpellAbility madness) { public void playMadness(SpellAbility madness) {
if (GuiDialog.confirm(madness.getSourceCard(), madness.getSourceCard() + " - Discarded. Pay Madness Cost?")) { if (GuiDialog.confirm(madness.getSourceCard(), madness.getSourceCard() + " - Discarded. Pay Madness Cost?")) {
player.playSpellAbility(madness); HumanPlayer.playSpellAbility(player, madness);
} }
} }

View File

@@ -1062,7 +1062,7 @@ public class MagicStack extends MyObservable {
for (int i = size - 1; i >= 0; i--) { for (int i = size - 1; i >= 0; i--) {
SpellAbility next = orderedSAs.get(i); SpellAbility next = orderedSAs.get(i);
if (next.isTrigger()) { if (next.isTrigger()) {
((HumanPlayer)activePlayer).playSpellAbility(next); HumanPlayer.playSpellAbility(activePlayer, next);
} else { } else {
this.add(next); this.add(next);
} }

View File

@@ -150,7 +150,7 @@ public class CField implements ICDoc {
final SpellAbility ab = CField.this.playerViewer.getController().getAbilityToPlay(game.getAbilitesOfCard(c, CField.this.playerViewer)); final SpellAbility ab = CField.this.playerViewer.getController().getAbilityToPlay(game.getAbilitesOfCard(c, CField.this.playerViewer));
if ( null != ab) { if ( null != ab) {
FThreads.invokeInNewThread(new Runnable(){ @Override public void run(){ FThreads.invokeInNewThread(new Runnable(){ @Override public void run(){
CField.this.playerViewer.playSpellAbility(c, ab); HumanPlayer.playSpellAbility(CField.this.playerViewer, c, ab);
}}); }});
} }
} }