HumanPlayer: all specific methods converted to static, preparing to delete the enclosing class.

This commit is contained in:
Maxmtg
2013-05-12 18:00:16 +00:00
parent 158cc0c895
commit 5ba925c156
8 changed files with 67 additions and 63 deletions

View File

@@ -240,7 +240,7 @@ public class ReplacementHandler {
Player player = replacementEffect.getHostCard().getController();
//player.getController().playNoStack()
if (player.isHuman()) {
((HumanPlayer)player).playSpellAbilityNoStack(effectSA);
HumanPlayer.playSpellAbilityNoStack(player, effectSA);
} else {
ComputerUtil.playNoStack((AIPlayer) player, effectSA, game);
}

View File

@@ -430,7 +430,7 @@ public class TriggerHandler {
if (regtrig.isStatic()) {
if (wrapperAbility.getActivatingPlayer().isHuman()) {
((HumanPlayer)wrapperAbility.getActivatingPlayer()).playSpellAbilityNoStack(wrapperAbility);
HumanPlayer.playSpellAbilityNoStack(wrapperAbility.getActivatingPlayer(), wrapperAbility);
} else {
wrapperAbility.doTrigger(isMandatory, (AIPlayer)wrapperAbility.getActivatingPlayer());
ComputerUtil.playNoStack((AIPlayer)wrapperAbility.getActivatingPlayer(), wrapperAbility, game);

View File

@@ -365,7 +365,7 @@ public class WrappedAbility extends Ability implements ISpellAbility {
return;
if (getActivatingPlayer().isHuman()) {
((HumanPlayer)getActivatingPlayer()).playSpellAbilityNoStack(sa, true);
HumanPlayer.playSpellAbilityNoStack(getActivatingPlayer(), sa, true);
} else {
// commented out because i don't think this should be called
// again here

View File

@@ -1435,7 +1435,7 @@ public class GameAction {
if (GuiDialog.confirm(c, "Use " + c +"'s ability?")) {
// If we ever let the AI memorize cards in the players
// hand, this would be a place to do so.
((HumanPlayer)p).playSpellAbilityNoStack(effect);
HumanPlayer.playSpellAbilityNoStack(p, effect);
}
}
}

View File

@@ -282,7 +282,7 @@ public final class GameActionUtil {
if (p.isHuman()) {
if (GuiDialog.confirm(rippledCards[i], "Cast " + rippledCards[i].getName() + "?")) {
((HumanPlayer)p).playCardWithoutManaCost(rippledCards[i]);
HumanPlayer.playCardWithoutPayingManaCost(((HumanPlayer)p), rippledCards[i]);
revealed.remove(rippledCards[i]);
}
} else {

View File

@@ -154,6 +154,58 @@ public class HumanPlayer extends Player {
return isPaid;
}
/**
* TODO: Write javadoc for this method.
* @param humanPlayer
* @param c
*/
public static final void playCardWithoutPayingManaCost(Player player, Card c) {
final List<SpellAbility> choices = c.getBasicSpells();
// TODO add Buyback, Kicker, ... , spells here
SpellAbility sa = player.getController().getAbilityToPlay(choices);
if (sa != null) {
sa.setActivatingPlayer(player);
playSaWithoutPayingManaCost(player, sa);
}
}
/**
* <p>
* playSpellAbilityForFree.
* </p>
*
* @param sa
* a {@link forge.card.spellability.SpellAbility} object.
*/
public static final void playSaWithoutPayingManaCost(final Player player, final SpellAbility sa) {
FThreads.assertExecutedByEdt(false);
final Card source = sa.getSourceCard();
source.setSplitStateToPlayAbility(sa);
if (sa.getPayCosts() != null) {
if (sa.getApi() == ApiType.Charm && !sa.isWrapper()) {
CharmEffect.makeChoices(sa);
}
final CostPayment payment = new CostPayment(sa.getPayCosts(), sa);
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
req.fillRequirements(false, true, false);
} else {
if (sa.isSpell()) {
final Card c = sa.getSourceCard();
if (!c.isCopiedSpell()) {
sa.setSourceCard(player.getGame().getAction().moveToStack(c));
}
}
boolean x = sa.getSourceCard().getManaCost().getShardCount(ManaCostShard.X) > 0;
player.getGame().getStack().add(sa, x);
}
}
/**
* <p>
* playSpellAbility_NoStack.
@@ -164,71 +216,23 @@ public class HumanPlayer extends Player {
* @param skipTargeting
* a boolean.
*/
public final void playSpellAbilityNoStack( final SpellAbility sa) {
playSpellAbilityNoStack(sa, false);
public final static void playSpellAbilityNoStack(final Player player, final SpellAbility sa) {
playSpellAbilityNoStack(player, sa, false);
}
public final void playSpellAbilityNoStack(final SpellAbility sa, boolean useOldTargets) {
sa.setActivatingPlayer(this);
public final static void playSpellAbilityNoStack(final Player player, final SpellAbility sa, boolean useOldTargets) {
sa.setActivatingPlayer(player);
if (sa.getPayCosts() != null) {
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, new CostPayment(sa.getPayCosts(), sa));
req.fillRequirements(useOldTargets, false, true);
} else {
if (payManaCostIfNeeded(this, sa)) {
if (payManaCostIfNeeded(player, sa)) {
AbilityUtils.resolve(sa, false);
}
}
}
public final void playCardWithoutManaCost(final Card c) {
final List<SpellAbility> choices = c.getBasicSpells();
// TODO add Buyback, Kicker, ... , spells here
SpellAbility sa = controller.getAbilityToPlay(choices);
if (sa == null) {
return;
}
sa.setActivatingPlayer(this);
this.playSpellAbilityWithoutPayingManaCost(sa);
}
/**
* <p>
* playSpellAbilityForFree.
* </p>
*
* @param sa
* a {@link forge.card.spellability.SpellAbility} object.
*/
public final void playSpellAbilityWithoutPayingManaCost(final SpellAbility sa) {
FThreads.assertExecutedByEdt(false);
final Card source = sa.getSourceCard();
source.setSplitStateToPlayAbility(sa);
if (sa.getPayCosts() != null) {
if (sa.getApi() == ApiType.Charm && !sa.isWrapper()) {
CharmEffect.makeChoices(sa);
}
final CostPayment payment = new CostPayment(sa.getPayCosts(), sa);
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
req.fillRequirements(false, true, false);
} else {
if (sa.isSpell()) {
final Card c = sa.getSourceCard();
if (!c.isCopiedSpell()) {
sa.setSourceCard(game.getAction().moveToStack(c));
}
}
boolean x = sa.getSourceCard().getManaCost().getShardCount(ManaCostShard.X) > 0;
game.getStack().add(sa, x);
}
}
} // end HumanPlayer class

View File

@@ -106,7 +106,7 @@ public class PlayerControllerHuman extends PlayerController {
*/
public void playFromSuspend(Card c) {
c.setSuspendCast(true);
player.playCardWithoutManaCost(c);
HumanPlayer.playCardWithoutPayingManaCost(player, c);
}
/* (non-Javadoc)
@@ -124,7 +124,7 @@ public class PlayerControllerHuman extends PlayerController {
boolean result = GuiDialog.confirm(cascadedCard, question.toString());
if ( result )
player.playCardWithoutManaCost(cascadedCard);
HumanPlayer.playCardWithoutPayingManaCost(player, cascadedCard);
return result;
}
@@ -133,7 +133,7 @@ public class PlayerControllerHuman extends PlayerController {
*/
@Override
public void playSpellAbilityForFree(SpellAbility copySA) {
player.playSpellAbilityWithoutPayingManaCost(copySA);
HumanPlayer.playSaWithoutPayingManaCost(player, copySA);
}
/**

View File

@@ -637,7 +637,7 @@ public final class GuiDisplayUtil {
game.getAction().moveToHand(forgeCard); // this is really needed (for rollbacks at least)
// Human player is choosing targets for an ability controlled by chosen player.
sa.setActivatingPlayer(p);
Singletons.getControl().getPlayer().playSpellAbilityWithoutPayingManaCost(sa);
HumanPlayer.playSaWithoutPayingManaCost(Singletons.getControl().getPlayer(), sa);
}
});
}