net.sf.magicproject.action
Class PayMana

java.lang.Object
  extended by net.sf.magicproject.action.MAction
      extended by net.sf.magicproject.action.UserAction
          extended by net.sf.magicproject.action.PayMana
All Implemented Interfaces:
ChoosenAction, InitAction, Replayable, RollBackAction, Waiting, WaitingAbility, WaitingMana

public class PayMana
extends UserAction
implements ChoosenAction, InitAction, WaitingMana, WaitingAbility, RollBackAction

Used to pay mana, remove directly mana from the mana pool

Since:
0.54, 0.70 'auto use colored mana as colorless mana' AI has been upgraded to manage case where only one colored mana can be used as colorless mana, 0.71 'auto use colored mana as colorless mana' AI has been upgraded to prevent the opponent to be informed you are using this option., 0.85 Mana pay can be aborted.
Author:
Fabrice Daugan
See Also:
Actiontype.PAY_MANA

Field Summary
 TestOn controller
          The player paying this mana
static int thresholdColored
          The maximum number of mana symbols displayed in context menu.
static boolean useMana
          If true, mana operation are nor ignored.
 
Method Summary
 java.util.List<Ability> abilitiesOf(MCard card)
          Return activated abilities of the specified card.
 java.util.List<Ability> advancedAbilitiesOf(MCard card)
          Return activated advanced abilities of the specified card.
 boolean choose(ActionContextWrapper actionContext, ContextEventListener context, Ability ability)
          No generated event.
 boolean clickOn(Ability ability)
          Called to specify the triggered card chosen for the current action by the handed player
static void clickOn(java.io.InputStream input)
          This method is invoked when opponent has clicked on manas. this call should be done from the net.sf.magicproject.network listener
 boolean clickOn(Mana mana)
          Called to specify the mana component chosen for the current action by the handed player
 void disactivate(ActionContextWrapper actionContext, ContextEventListener context, Ability ability)
          No generated event.
 void finished()
          Called when this action is finished (aborted or completed).
 Actiontype getIdAction()
          Return the index of this action.
 boolean init(ActionContextWrapper actionContext, ContextEventListener context, Ability ability)
          No generated event.
 int[] manaNeeded(Ability ability, ContextEventListener context)
          Return the amount of mana needed (constant part only) to play this ability As default, we return an empty number for all manas.
 boolean manualSkip()
          Called by the handed player when he/she wants to skip/abort this action.
 boolean replay(ActionContextWrapper actionContext, ContextEventListener context, Ability ability)
          Generate event associated to this action.
 void rollback(ActionContextWrapper actionContext, ContextEventListener context, Ability ability)
          No generated event.
 boolean succeedClickOn(Ability ability)
          This function should be called by the 'clickOn' caller in case of the specified ability has been handled during the checking validity of this click in the clickOn(Ability) function.
 boolean succeedClickOn(Mana mana)
          This function should be called by the 'clickOn' caller in case of the specified card has been handled during the checking validity of this click in the clickOn(Mana) function.
 java.lang.String toHtmlString(Ability ability, ContextEventListener context)
          Return the HTML code representing this action.
 java.lang.String toHtmlString(Ability ability, ContextEventListener context, ActionContextWrapper actionContext)
          Return the HTML code representing this action.
static java.lang.String toHtmlString(int[] manaPool)
          Return Html string corresponding to the given mana pool.
 java.lang.String toString(Ability ability)
          String representation of this action.
 
Methods inherited from class net.sf.magicproject.action.UserAction
getActionName, toHtmlString
 
Methods inherited from class net.sf.magicproject.action.MAction
equal, parseTest, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

controller

public TestOn controller
The player paying this mana


useMana

public static boolean useMana
If true, mana operation are nor ignored.


thresholdColored

public static int thresholdColored
The maximum number of mana symbols displayed in context menu.

Method Detail

getIdAction

public Actiontype getIdAction()
Description copied from class: MAction
Return the index of this action. As default, this is a zero id

Specified by:
getIdAction in class UserAction
Returns:
the index of this action.
See Also:
Actiontype

manaNeeded

public int[] manaNeeded(Ability ability,
                        ContextEventListener context)
Description copied from class: MAction
Return the amount of mana needed (constant part only) to play this ability As default, we return an empty number for all manas.

Overrides:
manaNeeded in class UserAction
Parameters:
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
context - the context of playing ability.
Returns:
array of mana needed to play this ability

init

public boolean init(ActionContextWrapper actionContext,
                    ContextEventListener context,
                    Ability ability)
Description copied from interface: InitAction
No generated event. Let the active player playing this action.
Generally, this method is used to initialize the context of this action such as required mana, or fixing some values.
Be aware this method can be called several times if there it is in a loop (hop usage), so manage this case to prevent a reset of context each time this method is called during the initialization phase.

Specified by:
init in interface InitAction
Parameters:
actionContext - the context containing data saved by this action during the 'choose" proceess.
context - is the context attached to this action.
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
Returns:
true if the stack can be resolved just after this call.

disactivate

public void disactivate(ActionContextWrapper actionContext,
                        ContextEventListener context,
                        Ability ability)
No generated event. Unset this action as current one.

Specified by:
disactivate in interface ChoosenAction
Parameters:
actionContext - the context containing data saved by this action during the 'choose" proceess.
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
context - is the context attached to this action.

rollback

public void rollback(ActionContextWrapper actionContext,
                     ContextEventListener context,
                     Ability ability)
No generated event. Rollback an action.

Specified by:
rollback in interface RollBackAction
Parameters:
actionContext - the context containing data saved by this action during the 'choose" proceess.
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
context - is the context attached to this action.

finished

public void finished()
Called when this action is finished (aborted or completed). No stack operation should be done here.
For this action, all mana are dishilighted.

Specified by:
finished in interface Waiting
Specified by:
finished in interface WaitingAbility
Specified by:
finished in interface WaitingMana

choose

public boolean choose(ActionContextWrapper actionContext,
                      ContextEventListener context,
                      Ability ability)
Description copied from interface: ChoosenAction
No generated event. Let the active player playing this action.

Specified by:
choose in interface ChoosenAction
Parameters:
actionContext - the context containing data saved by this action during the 'choose" proceess.
context - is the context attached to this action.
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
Returns:
true if the stack can be resolved just after this call.

replay

public boolean replay(ActionContextWrapper actionContext,
                      ContextEventListener context,
                      Ability ability)
Description copied from interface: ChoosenAction
Generate event associated to this action. Only one or several events are generated and may be collected by event listeners. Then play this action

Specified by:
replay in interface ChoosenAction
Specified by:
replay in interface InitAction
Specified by:
replay in interface Replayable
Parameters:
actionContext - the context containing data saved by this action during the 'choose" proceess.
context - is the context attached to this action.
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
Returns:
true if the stack can be resolved just after this call.

manualSkip

public boolean manualSkip()
Description copied from interface: Waiting
Called by the handed player when he/she wants to skip/abort this action. No stack operation should be done here.

Specified by:
manualSkip in interface Waiting
Specified by:
manualSkip in interface WaitingAbility
Specified by:
manualSkip in interface WaitingMana
Returns:
true if this action allow the skip/cancel.

clickOn

public boolean clickOn(Mana mana)
Description copied from interface: WaitingMana
Called to specify the mana component chosen for the current action by the handed player

Specified by:
clickOn in interface WaitingMana
Parameters:
mana - the clicked mana component by the handed player for the current action
Returns:
true if this click has been managed. Return false if this click has been ignored

succeedClickOn

public boolean succeedClickOn(Mana mana)
Description copied from interface: WaitingMana
This function should be called by the 'clickOn' caller in case of the specified card has been handled during the checking validity of this click in the clickOn(Mana) function.

Specified by:
succeedClickOn in interface WaitingMana
Parameters:
mana - the mana that was clicked and successfuly handled by the clickOn(Card) function.
Returns:
true if this action is completed

clickOn

public static void clickOn(java.io.InputStream input)
                    throws java.io.IOException
This method is invoked when opponent has clicked on manas. this call should be done from the net.sf.magicproject.network listener

Parameters:
input - input stream of our net.sf.magicproject.network connection
Throws:
java.io.IOException - if error occurred when reading the message

toHtmlString

public java.lang.String toHtmlString(Ability ability,
                                     ContextEventListener context,
                                     ActionContextWrapper actionContext)
Description copied from interface: ChoosenAction
Return the HTML code representing this action. If this action is named, it's name will be returned. If not, if existing, the picture associated to this action is returned. Otherwise, built-in action's text will be returned.

Specified by:
toHtmlString in interface ChoosenAction
Parameters:
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
context - is the context attached to this action.
actionContext - the context of this action.
Returns:
the HTML code representing this action. If this action is named, it's name will be returned. If not, if existing, the picture associated to this action is returned. Otherwise, built-in action's text will be returned.

toHtmlString

public java.lang.String toHtmlString(Ability ability,
                                     ContextEventListener context)
Description copied from class: MAction
Return the HTML code representing this action. If no picture is associated to this action, only text will be returned.

Overrides:
toHtmlString in class UserAction
Parameters:
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
context - is the context attached to this action.
Returns:
the HTML code representing this action. If no picture is associated to this action, only text will be returned.
See Also:
MAction.toString(Ability), MAction.toHtmlString(Ability, int, ContextEventListener)

toString

public java.lang.String toString(Ability ability)
Description copied from class: MAction
String representation of this action.

Specified by:
toString in class UserAction
Parameters:
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
Returns:
action name.
See Also:
Object.toString()

clickOn

public boolean clickOn(Ability ability)
Description copied from interface: WaitingAbility
Called to specify the triggered card chosen for the current action by the handed player

Specified by:
clickOn in interface WaitingAbility
Parameters:
ability - the clicked card by the handed player for the current action
Returns:
true if this click has been managed. Return false if this click has been ignored

abilitiesOf

public java.util.List<Ability> abilitiesOf(MCard card)
Description copied from interface: WaitingAbility
Return activated abilities of the specified card.

Specified by:
abilitiesOf in interface WaitingAbility
Parameters:
card - the requesting card the abilities will be listed from.
Returns:
activated abilities of the specified card.

advancedAbilitiesOf

public java.util.List<Ability> advancedAbilitiesOf(MCard card)
Description copied from interface: WaitingAbility
Return activated advanced abilities of the specified card.

Specified by:
advancedAbilitiesOf in interface WaitingAbility
Parameters:
card - the requesting card the abilities will be listed from.
Returns:
activated advanced abilities of the specified card.

succeedClickOn

public boolean succeedClickOn(Ability ability)
Description copied from interface: WaitingAbility
This function should be called by the 'clickOn' caller in case of the specified ability has been handled during the checking validity of this click in the clickOn(Ability) function.

Specified by:
succeedClickOn in interface WaitingAbility
Parameters:
ability - the ability that was clicked and successfuly handled by the clickOn(Ability) function.
Returns:
true if this action is completed
See Also:
WaitingAbility.clickOn(Ability)

toHtmlString

public static java.lang.String toHtmlString(int[] manaPool)
Return Html string corresponding to the given mana pool. Colors with no mana in the mana pool are ignored. If a color appear more than THRESHOLD_COLORED, the {color} x {amount} will be used. If the given code is empty the {0} value will be returned.

Parameters:
manaPool - the amount of mana to pay
Returns:
Html string corresponding to the given mana pool.


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