mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
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:
@@ -426,7 +426,5 @@ public abstract class GameEntity extends MyObservable {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public GameState getGame() {
|
||||
return null;
|
||||
}
|
||||
public abstract GameState getGame();
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ public class PlayEffect extends SpellAbilityEffect {
|
||||
boolean noManaCost = sa.hasParam("WithoutManaCost");
|
||||
if (controller.isHuman()) {
|
||||
SpellAbility newSA = noManaCost ? tgtSA.copyWithNoManaCost() : tgtSA;
|
||||
((HumanPlayer)activator).playSpellAbility(newSA);
|
||||
HumanPlayer.playSpellAbility(activator, newSA);
|
||||
} else {
|
||||
if (tgtSA instanceof Spell) { // Isn't it ALWAYS a spell?
|
||||
Spell spell = (Spell) tgtSA;
|
||||
|
||||
@@ -86,7 +86,7 @@ public class InputPassPriority extends InputBase {
|
||||
Runnable execAbility = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((HumanPlayer)player).playSpellAbility(card, ab);
|
||||
HumanPlayer.playSpellAbility(player, card, ab);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
Runnable proc = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((HumanPlayer)chosen.getActivatingPlayer()).playSpellAbility(chosen);
|
||||
HumanPlayer.playSpellAbility(chosen.getActivatingPlayer(), chosen);
|
||||
onManaAbilityPlayed(chosen);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -53,13 +53,13 @@ public class HumanPlayer extends Player {
|
||||
* @param card
|
||||
* @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)
|
||||
this.playLand(c);
|
||||
p.playLand(c);
|
||||
else {
|
||||
this.playSpellAbility(ab);
|
||||
HumanPlayer.playSpellAbility(p, ab);
|
||||
}
|
||||
game.getPhaseHandler().setPriority(this);
|
||||
p.getGame().getPhaseHandler().setPriority(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,9 +76,9 @@ public class HumanPlayer extends Player {
|
||||
* @param sa
|
||||
* 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);
|
||||
sa.setActivatingPlayer(this);
|
||||
sa.setActivatingPlayer(p);
|
||||
|
||||
final Card source = sa.getSourceCard();
|
||||
|
||||
@@ -88,7 +88,7 @@ public class HumanPlayer extends Player {
|
||||
CharmEffect.makeChoices(sa);
|
||||
}
|
||||
|
||||
sa = chooseOptionalAdditionalCosts(sa);
|
||||
sa = chooseOptionalAdditionalCosts(p, sa);
|
||||
|
||||
if (sa == null) {
|
||||
return;
|
||||
@@ -116,15 +116,53 @@ public class HumanPlayer extends Player {
|
||||
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
|
||||
req.fillRequirements(false, false, false);
|
||||
} else {
|
||||
if (payManaCostIfNeeded(sa)) {
|
||||
if (payManaCostIfNeeded(p, sa)) {
|
||||
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>
|
||||
* playSpellAbility_NoStack.
|
||||
@@ -146,52 +184,13 @@ public class HumanPlayer extends Player {
|
||||
|
||||
req.fillRequirements(useOldTargets, false, true);
|
||||
} else {
|
||||
if (payManaCostIfNeeded(sa)) {
|
||||
if (payManaCostIfNeeded(this, sa)) {
|
||||
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) {
|
||||
final List<SpellAbility> choices = c.getBasicSpells();
|
||||
// TODO add Buyback, Kicker, ... , spells here
|
||||
|
||||
@@ -373,14 +373,14 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
@Override
|
||||
public void playMiracle(SpellAbility miracle, Card card) {
|
||||
if (GuiDialog.confirm(card, card + " - Drawn. Play for Miracle Cost?")) {
|
||||
player.playSpellAbility(miracle);
|
||||
HumanPlayer.playSpellAbility(player, miracle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playMadness(SpellAbility madness) {
|
||||
if (GuiDialog.confirm(madness.getSourceCard(), madness.getSourceCard() + " - Discarded. Pay Madness Cost?")) {
|
||||
player.playSpellAbility(madness);
|
||||
HumanPlayer.playSpellAbility(player, madness);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1062,7 +1062,7 @@ public class MagicStack extends MyObservable {
|
||||
for (int i = size - 1; i >= 0; i--) {
|
||||
SpellAbility next = orderedSAs.get(i);
|
||||
if (next.isTrigger()) {
|
||||
((HumanPlayer)activePlayer).playSpellAbility(next);
|
||||
HumanPlayer.playSpellAbility(activePlayer, next);
|
||||
} else {
|
||||
this.add(next);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class CField implements ICDoc {
|
||||
final SpellAbility ab = CField.this.playerViewer.getController().getAbilityToPlay(game.getAbilitesOfCard(c, CField.this.playerViewer));
|
||||
if ( null != ab) {
|
||||
FThreads.invokeInNewThread(new Runnable(){ @Override public void run(){
|
||||
CField.this.playerViewer.playSpellAbility(c, ab);
|
||||
HumanPlayer.playSpellAbility(CField.this.playerViewer, c, ab);
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user