net.sf.magicproject.stack
Class StackManager

java.lang.Object
  extended by net.sf.magicproject.stack.StackManager
All Implemented Interfaces:
StackContext

public final class StackManager
extends java.lang.Object
implements StackContext

Represents all methods to cast a spell/ability. Manage the succession of actions of a ability.

Since:
0.12 enable to abort mana pay of a spell/ability
0.13 ability will be differenced from other spell, copy is highlifghted to green
0.24 save and restore choice list of opponent too
0.30 an option "auto play single "YOU MUST" ability is suported
0.30 if two players declines to response to a spell, we resolve stack
0.31 an option "skip all even opponent's spell" is suported
0.52 "hop" instruction supported, you we can now implement the instruction "if then else"
0.52 private values added, used as registers for each spell.
0.72 requesting 'refresh' for cards have been implemented.
0.80 looping actions supported
0.85 Game restart after a game lost is supported
0.85 Mana pay can be aborted.
0.86 Cost are initialized and can be canceled/replayed.
Author:
Fabrice Daugan

Field Summary
static long abilityID
          Ability ID
static ActionManager actionManager
          The current action manager.
static boolean canBeAborted
          Indicates if the current spell can be aborted or not
static java.lang.String CANCEL_TXT
          The cancel text
static java.util.Stack<net.sf.magicproject.stack.StackManager.StackElement> CONTEXTES
          contains all contexts
static Ability currentAbility
          the current ability in the stack
static java.lang.String DECLINE_TXT
          The decline text
static int idActivePlayer
          Identifiant of active player
static int idCurrentPlayer
          Current player
static int idHandedPlayer
          Identifiant of player having hand (not allways active player)
static IntegerList intList
          The current integer list.
static MMiniPipe noReplayToken
          The object used to exclusively manage player events.
static int oldIdHandedPlayer
          Identifiant of last player having hand (not allways active player).
static Player[] PLAYERS
          players of the play
static int previousPlace
          Is the previous place of current spell.
static int[] registers
          private registers for each spell/ability
static java.util.List<IntegerList> SAVED_INT_LISTS
          All saved integer list.
static java.util.List<java.util.List<Targetable>> SAVED_TARGET_LISTS
          Represents the target list saved during this turn.
static Player spellController
          the player controlling the current spell
static TargetManager targetOptions
          the target option associated to the current spell
static AbstractCard tokenCard
          card representing card in stack
static TriggeredCard triggered
          Current spell is a triggered ability if not null
static java.lang.String TT_CANCEL
          The cancel tooltip text
static java.lang.String TT_DECLINE
          Decline tooltip text
static int zoneAbortion
          represents the place where aborted spells would be placed
 
Method Summary
 void abortion(AbstractCard card, Ability source)
          Remove the specified card from the stack.
static Player activePlayer()
          return the active player
static void cancel()
          Cancel the current spell or ability.
static boolean currentIsYou()
          Indicates if the current player is you.
static Player currentPlayer()
          return the current player
static void disableAbort()
          disable abort action
static void enableAbort()
          enable abort action
 void finishSpell()
          This method finish the current spell.
 ContextEventListener getAbilityContext()
          Return the current context.
static Ability getAbilityOf(MCard card)
          The ability corresponding to the specified card
 Ability getAbortingAbility()
          Return the ability causing the abortion of this ability.
 ActionManager getActionManager()
          Return the action manager of this context.
static ActionManager getActionManager(AbstractCard card)
          Return the action context corresponding to the specified card.
 java.util.List<AdditionalCost> getAdditionalCost()
          Returns the current additional costs.
 MAction[] getAdditionalCost(Ability ability)
          Returns the additional cost can be applied to the given ability.
static StackContext getContextOf(AbstractCard card)
          Return the context associated to the given card.
static java.lang.String getHtmlManaCost(MCard card)
          Return HTML representation of total mana cost of the specified card.
static java.lang.String getHtmlManaPaid(MCard card)
          Return HTML representation of total mana paid for the specified card.
static StackManager getInstance()
          Return the unique instance of this class.
static int getManaPaid(MCard card, int color)
          Return mana paid for the specified card and specified color.
static MCard getRealSource(MCard owner)
          Return the real card of the current ability.
static Targetable getSaved(Ability ability)
          Return the targetable saved into the specified ability
 MCard getSourceCard()
          Return the card source of the current capcity/spell in the stack
static Player getSpellController()
          Return the player controlling the current spell
 TargetedList getTargetedList()
          Return the target option of the current spell. this target option is owned by the current spell.
static java.util.List<Targetable> getTargetListAccess()
          Return the target list.
static int getTotalManaCost(AbstractCard card)
          Return total mana cost of the specified card.
static int getTotalManaPaid(MCard card)
          Return total mana paid for the specified card.
 void init(java.io.InputStream inputFile, int firstPlayer)
          Read from the specified stream the initial registers of players.
static boolean isEmpty()
          tell if it stills yet any abilities in the stack
static boolean isPlaying(ReplacementAbility ability)
          Indicates if the specified replacement ability has already been used to replace the main action.
static boolean isTargetMode()
          Indicates the current action is waiting for a target.
static boolean isYou(Player player)
          Indicates if the specified player is you
static void newSpell(Ability ability, boolean advancedMode)
          Add a spell/activated ability to the stack
static boolean newSpell(TriggeredCard triggered)
          Add a triggered ability to the stack.
static Player nonActivePlayer()
          return the non-active player
static void postLoseGame(int idPlayer)
          Add the "lose status" to specified player
static void postRefreshAbilities(MCard card)
          Post a request to refresh the abilities of a card.
static void postRefreshColor(MCard card)
          Post a request to refresh the colors of a card.
static void postRefreshController(MCard card)
          Post a request to refresh the conntroller of a card.
static void postRefreshIdCard(MCard card)
          Post a request to refresh the card types of a card.
static void postRefreshProperties(MCard card, int property)
          Post a request to refresh a property of a card.
static void postRefreshRegisters(MCard card, int index)
          Post a request to refresh a register of a card.
static boolean processRefreshRequests()
          For each cards having posted a refresh request, process to the refreshing
static void reset()
          Reset completely the stack
static void resolveStack()
          Resolve the stack
An ability is splited into 4 parts : paying part (cost) raise event "casting", stack waiting triggered abilities and active player gets priority effect part (effects) restore context, stack waiting triggered abilities and active player gets priority
 void setTargetedList(TargetedList savedTargeted)
          Set a new targeted list.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spellController

public static Player spellController
the player controlling the current spell


targetOptions

public static TargetManager targetOptions
the target option associated to the current spell


intList

public static IntegerList intList
The current integer list. This list is private to each ability.


registers

public static int[] registers
private registers for each spell/ability


tokenCard

public static AbstractCard tokenCard
card representing card in stack


triggered

public static TriggeredCard triggered
Current spell is a triggered ability if not null


currentAbility

public static Ability currentAbility
the current ability in the stack


previousPlace

public static int previousPlace
Is the previous place of current spell. So means something only when user can abort, and only if the card representing this spell is not tokenized. If is -1, abort spell cause the current spell in stack to be removed (not moved to an existing zone)


canBeAborted

public static boolean canBeAborted
Indicates if the current spell can be aborted or not


abilityID

public static long abilityID
Ability ID


actionManager

public static volatile ActionManager actionManager
The current action manager.


oldIdHandedPlayer

public static volatile int oldIdHandedPlayer
Identifiant of last player having hand (not allways active player). This id is set just before idHandedPlayer is set to -1


idActivePlayer

public static volatile int idActivePlayer
Identifiant of active player


idCurrentPlayer

public static volatile int idCurrentPlayer
Current player


idHandedPlayer

public static volatile int idHandedPlayer
Identifiant of player having hand (not allways active player)


PLAYERS

public static final Player[] PLAYERS
players of the play


noReplayToken

public static MMiniPipe noReplayToken
The object used to exclusively manage player events.


zoneAbortion

public static int zoneAbortion
represents the place where aborted spells would be placed


CONTEXTES

public static final java.util.Stack<net.sf.magicproject.stack.StackManager.StackElement> CONTEXTES
contains all contexts


SAVED_TARGET_LISTS

public static final java.util.List<java.util.List<Targetable>> SAVED_TARGET_LISTS
Represents the target list saved during this turn. This list is automatically reseted at the beginning of a turn, and before any triggered or activated abilities can be played.


SAVED_INT_LISTS

public static final java.util.List<IntegerList> SAVED_INT_LISTS
All saved integer list.


TT_DECLINE

public static final java.lang.String TT_DECLINE
Decline tooltip text


TT_CANCEL

public static final java.lang.String TT_CANCEL
The cancel tooltip text


CANCEL_TXT

public static final java.lang.String CANCEL_TXT
The cancel text


DECLINE_TXT

public static final java.lang.String DECLINE_TXT
The decline text

Method Detail

reset

public static void reset()
Reset completely the stack


init

public void init(java.io.InputStream inputFile,
                 int firstPlayer)
          throws java.io.IOException
Read from the specified stream the initial registers of players.

Parameters:
inputFile - is the file containing the stack definition.
firstPlayer - the player's id starting the game.
Throws:
java.io.IOException - if error occurred during the reading process from the specified input stream

newSpell

public static void newSpell(Ability ability,
                            boolean advancedMode)
Add a spell/activated ability to the stack

Parameters:
ability - is the ability played
advancedMode - if true, this ability would be added with advanced mode option.
Since:
0.13 ability will be differenced from other spell, copy is highlighted to green, 0.85 advanced mode supported

newSpell

public static boolean newSpell(TriggeredCard triggered)
Add a triggered ability to the stack. If this ability is an hidden one, the stack is resolved immediatly and then another triggered card can be added. Otherwise, this triggered ability is added to the stack and the 'wait triggered buffer choice' process is reloaded until no more triggered ability can be added to the stack.

Parameters:
triggered - is the triggered ability to add to t he stack
Returns:
true if the stack can be resolved after this call.
Since:
0.60

getAdditionalCost

public java.util.List<AdditionalCost> getAdditionalCost()
Returns the current additional costs.

Returns:
the current additional costs.

getAdditionalCost

public MAction[] getAdditionalCost(Ability ability)
Returns the additional cost can be applied to the given ability.

Parameters:
ability - the ability to test.
Returns:
the additional cost can be applied to the given ability.

resolveStack

public static void resolveStack()
Resolve the stack


cancel

public static void cancel()
Cancel the current spell or ability. A cancelled ability is removed from the stack. A cancelled spell is returned from the stack to it's previous zone. A cancelled triggered ability, if hidden, is stopped immediatly and the stack resolution continues. A cancelled triggered ability that is not hidden is simply restarted : it is neither removed from the stack neither replaced in the TBZ.

Since:
0.86, 0.90 The spell is only cancelled if the current ability is in "cost part".

finishSpell

public void finishSpell()
This method finish the current spell. Remove it from the stack and restore the last context of stack.


enableAbort

public static void enableAbort()
enable abort action

Since:
0.12 enable to abort mana pay of a spell/ability

disableAbort

public static void disableAbort()
disable abort action

Since:
0.12 enable to abort mana pay of a spell/ability

isEmpty

public static boolean isEmpty()
tell if it stills yet any abilities in the stack

Returns:
true if it stills yet any abilities in the stack

getSourceCard

public MCard getSourceCard()
Description copied from interface: StackContext
Return the card source of the current capcity/spell in the stack

Specified by:
getSourceCard in interface StackContext
Returns:
the card source of the current capcity/spell in the stack

abortion

public void abortion(AbstractCard card,
                     Ability source)
Description copied from interface: StackContext
Remove the specified card from the stack. If it's a spell, it goes to the abortion place, otherwise it would be simply removed. After calling this method, caller should call the normal 'resolveStack' method.

Specified by:
abortion in interface StackContext
Parameters:
card - the card to make abort.
source - the ability source.

getTargetListAccess

public static java.util.List<Targetable> getTargetListAccess()
Return the target list.

Returns:
the target list.

currentPlayer

public static Player currentPlayer()
return the current player

Returns:
the current player

activePlayer

public static Player activePlayer()
return the active player

Returns:
the active player

nonActivePlayer

public static Player nonActivePlayer()
return the non-active player

Returns:
the non-active player

currentIsYou

public static boolean currentIsYou()
Indicates if the current player is you. Current player is the player'turn.

Returns:
true if the current player is you

isYou

public static boolean isYou(Player player)
Indicates if the specified player is you

Parameters:
player - the player to test
Returns:
true if the specified player is you

isPlaying

public static boolean isPlaying(ReplacementAbility ability)
Indicates if the specified replacement ability has already been used to replace the main action. This function verify this ability is not in the stack between the top and the last non-replacement ability.

Parameters:
ability - the replacement ability to search
Returns:
true if the specified replacement ability has already been used to replace the main action.

getAbilityOf

public static Ability getAbilityOf(MCard card)
The ability corresponding to the specified card

Parameters:
card - the card linked to the searched ability
Returns:
the ability corresponding to the specified card

getActionManager

public static ActionManager getActionManager(AbstractCard card)
Return the action context corresponding to the specified card. If the given card is not found in the context, an exception is thrown.

Parameters:
card - the card linked to the searched ability
Returns:
the action context corresponding to the specified card

getActionManager

public ActionManager getActionManager()
Description copied from interface: StackContext
Return the action manager of this context.

Specified by:
getActionManager in interface StackContext
Returns:
the action manager of this context.

getContextOf

public static StackContext getContextOf(AbstractCard card)
Return the context associated to the given card. Return null if the given card the current spell instance. If the given card is not found in the context, an exception is thrown.

Parameters:
card - the card linked to the searched ability
Returns:
the context corresponding to the specified card.

getRealSource

public static MCard getRealSource(MCard owner)
Return the real card of the current ability. In fact, this method return the card owning the last non-replacement ability.
TODO is the given card is the card owning the current ability, in this case the parameter is obselete.

Parameters:
owner - the card owning the action requesting the real card.
Returns:
the real card of the current ability.

getSpellController

public static Player getSpellController()
Return the player controlling the current spell

Returns:
the player controlling the current spell

processRefreshRequests

public static boolean processRefreshRequests()
For each cards having posted a refresh request, process to the refreshing

Returns:
true if there was one or several posted request.

postLoseGame

public static void postLoseGame(int idPlayer)
Add the "lose status" to specified player

Parameters:
idPlayer - the loosing player.
Since:
0.85

postRefreshIdCard

public static void postRefreshIdCard(MCard card)
Post a request to refresh the card types of a card. A card can be refreshed only once for the card types.

Parameters:
card - the card to refresh.

postRefreshAbilities

public static void postRefreshAbilities(MCard card)
Post a request to refresh the abilities of a card. A card can be refreshed only once for the abilities.

Parameters:
card - the card to refresh.

postRefreshColor

public static void postRefreshColor(MCard card)
Post a request to refresh the colors of a card. A card can be refreshed only once for the colors.

Parameters:
card - the card to refresh.

postRefreshProperties

public static void postRefreshProperties(MCard card,
                                         int property)
Post a request to refresh a property of a card. A card can be refreshed only once for a same register.

Parameters:
card - the card to refresh.
property - the property to refresh.

postRefreshRegisters

public static void postRefreshRegisters(MCard card,
                                        int index)
Post a request to refresh a register of a card. A card can be refreshed only once for a same register.

Parameters:
card - the card to refresh.
index - the register index to refresh.

postRefreshController

public static void postRefreshController(MCard card)
Post a request to refresh the conntroller of a card. A card can be refreshed only once for the abilities.

Parameters:
card - the card to refresh.

getSaved

public static Targetable getSaved(Ability ability)
Return the targetable saved into the specified ability

Parameters:
ability - the ability containing the saved component
Returns:
the targetable saved into the specified ability

isTargetMode

public static boolean isTargetMode()
Indicates the current action is waiting for a target.

Returns:
true if the current action is waiting for a target.

getAbilityContext

public ContextEventListener getAbilityContext()
Return the current context. Null if current ability is not a triggered one.

Specified by:
getAbilityContext in interface StackContext
Returns:
the current context. Null if current ability is not a triggered one.

getTargetedList

public TargetedList getTargetedList()
Description copied from interface: StackContext
Return the target option of the current spell. this target option is owned by the current spell. May be reseted, changed by the spell itself.

Specified by:
getTargetedList in interface StackContext
Returns:
the targeted list of this context.

setTargetedList

public void setTargetedList(TargetedList savedTargeted)
Set a new targeted list.

Parameters:
savedTargeted - the new targeted list.

getInstance

public static StackManager getInstance()
Return the unique instance of this class.

Returns:
the unique instance of this class.

getHtmlManaPaid

public static java.lang.String getHtmlManaPaid(MCard card)
Return HTML representation of total mana paid for the specified card.

Parameters:
card - the card associated to a spell in the stack
Returns:
HTML representation of total mana paid for the specified card.

getHtmlManaCost

public static java.lang.String getHtmlManaCost(MCard card)
Return HTML representation of total mana cost of the specified card.

Parameters:
card - the card associated to a spell in the stack
Returns:
HTML representation of total mana cost of the specified card.

getTotalManaCost

public static int getTotalManaCost(AbstractCard card)
Return total mana cost of the specified card.

Parameters:
card - the card associated to a spell in the stack
Returns:
total mana cost of the specified card.

getTotalManaPaid

public static int getTotalManaPaid(MCard card)
Return total mana paid for the specified card.

Parameters:
card - the card associated to a spell in the stack
Returns:
total mana paid for the specified card.

getManaPaid

public static int getManaPaid(MCard card,
                              int color)
Return mana paid for the specified card and specified color.

Parameters:
card - the card associated to a spell in the stack
color - the color of mana paid.
Returns:
mana paid for the specified card and specified color.

getAbortingAbility

public Ability getAbortingAbility()
Description copied from interface: StackContext
Return the ability causing the abortion of this ability.

Specified by:
getAbortingAbility in interface StackContext
Returns:
the ability causing the abortion of this ability.


Copyright © 2003-2007 Magic-Project. All Rights Reserved.