net.sf.magicproject.action.target
Class ChoosenTarget

java.lang.Object
  extended by net.sf.magicproject.action.MAction
      extended by net.sf.magicproject.action.UserAction
          extended by net.sf.magicproject.action.Target
              extended by net.sf.magicproject.action.target.ChoosenTarget
All Implemented Interfaces:
ChoosenAction, Replayable, RollBackAction, StandardAction, Waiting, WaitingCard, WaitingPlayer
Direct Known Subclasses:
RealTarget, SilentTarget

public abstract class ChoosenTarget
extends Target
implements WaitingPlayer, WaitingCard, ChoosenAction

Add to the target list card(s) or player(s) following the specified mode and the specified type. If mode is 'choose' or 'opponentchoose', then a 'targeted' event is raised when the choice is made. In case of 'all', 'random', 'myself' or any target known with acces register, no event is generated. The friendly test, and the type are necessary only for the modes 'random', 'all', 'choose' and 'opponentchoose' to list the valids targets. The target list is used by the most actions.
For example, if the next action 'damage', all cards/player from the target list would be damaged. When a new ability is added to the stack, a new list is created and attached to it. Actions may modify, acceess it until the ability is completely resolved.

Since:
0.54, 0.70 added modes : 'currentplayer', 'noncurrentplayer', 'context.card', 'context.player', 0.71 abortion (when no valid target are found) is supported. To support abortion, hop attribute must be set to 'all' or 'abortme', 0.82 manage "targeted" event generation for target action, 0.82 "share" options with 'same-name' option is supported. This option would add the target into the target list of the first ability of stack having the save name., 0.82 restriction zone supported to optimize the target processing., 0.86 new algorythme to determine valid targets, 0.86 a target cannot be added twice in the target-list
Author:
Fabrice Daugan

Method Summary
 boolean checkTarget(Ability ability, int hopCounter)
          Verify if this target action may cause abortion of the current ability.
 boolean choose(ActionContextWrapper actionContext, ContextEventListener context, Ability ability)
          No generated event.
 boolean clickOn(MCard target)
          Called to specify the card chosen for the current action by the handed player
 boolean clickOn(Player target)
          Called to specify the player 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).
 boolean init(ActionContextWrapper actionContext, ContextEventListener context, Ability ability)
          No generated event.
abstract  boolean isTargeting()
          Is this action is really targeting.
 boolean isValidTarget(MCard target)
          Is the specified card is a valid target?
 boolean isValidTarget(Player target)
          Is the specified player is a valid target?
 boolean manualSkip()
          Called by the handed player when he/she wants to skip/abort this action.
 boolean play(ContextEventListener context, Ability ability)
          Generate event associated to 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(MCard card)
          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(MCard) function.
 boolean succeedClickOn(Player player)
          This function should be called by the 'clickOn' caller in case of the specified player has been handled during the checking validity of this click in the clickOn(Player) function.
 java.lang.String toHtmlString(Ability ability, ContextEventListener context, ActionContextWrapper actionContext)
          Return the HTML code representing this action.
 java.lang.String toString(Ability ability)
          String representation of this action.
 
Methods inherited from class net.sf.magicproject.action.Target
getIdAction
 
Methods inherited from class net.sf.magicproject.action.UserAction
getActionName, manaNeeded, toHtmlString, 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
 

Method Detail

rollback

public final void rollback(ActionContextWrapper actionContext,
                           ContextEventListener context,
                           Ability ability)
Description copied from interface: RollBackAction
No generated event. Rollback an action.

Specified by:
rollback in interface RollBackAction
Overrides:
rollback in class Target
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.

init

public boolean init(ActionContextWrapper actionContext,
                    ContextEventListener context,
                    Ability ability)
No generated event. Let the active player playing this action.

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.
Returns:
true if the stack can be resolved just after this call.

disactivate

public void disactivate(ActionContextWrapper actionContext,
                        ContextEventListener context,
                        Ability ability)
Description copied from interface: ChoosenAction
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.
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.

replay

public final boolean replay(ActionContextWrapper actionContext,
                            ContextEventListener context,
                            Ability ability)
Description copied from class: Target
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 Replayable
Specified by:
replay in class Target
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.

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.

play

public final boolean play(ContextEventListener context,
                          Ability ability)
Description copied from interface: StandardAction
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:
play in interface StandardAction
Specified by:
play in class Target
Parameters:
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.

clickOn

public final boolean clickOn(MCard target)
Description copied from interface: WaitingCard
Called to specify the card chosen for the current action by the handed player

Specified by:
clickOn in interface WaitingCard
Parameters:
target - 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

clickOn

public final boolean clickOn(Player target)
Description copied from interface: WaitingPlayer
Called to specify the player chosen for the current action by the handed player

Specified by:
clickOn in interface WaitingPlayer
Parameters:
target - the clicked player 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 final boolean succeedClickOn(Player player)
Description copied from interface: WaitingPlayer
This function should be called by the 'clickOn' caller in case of the specified player has been handled during the checking validity of this click in the clickOn(Player) function.

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

succeedClickOn

public final boolean succeedClickOn(MCard card)
Description copied from interface: WaitingCard
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(MCard) function.

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

finished

public final void finished()
Description copied from interface: Waiting
Called when this action is finished (aborted or completed). No stack operation should be done here.

Specified by:
finished in interface Waiting
Specified by:
finished in interface WaitingCard
Specified by:
finished in interface WaitingPlayer

isValidTarget

public final boolean isValidTarget(MCard target)
Is the specified card is a valid target?

Parameters:
target - the tested card.
Returns:
true if the given card is a valid target
Since:
0.86 a target cannot be added twice in the target-list

isValidTarget

public final boolean isValidTarget(Player target)
Is the specified player is a valid target?

Parameters:
target - the tested player.
Returns:
true if the given card is a valid target

manualSkip

public final 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 WaitingCard
Specified by:
manualSkip in interface WaitingPlayer
Returns:
true if this action allow the skip/cancel.

toString

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

Specified by:
toString in class Target
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()

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.

isTargeting

public abstract boolean isTargeting()
Is this action is really targeting.

Returns:
true if this action is really targeting.

checkTarget

public final boolean checkTarget(Ability ability,
                                 int hopCounter)
Verify if this target action may cause abortion of the current ability.

Parameters:
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
hopCounter - the minimum valid target to have. If is negative or zero return true.
Returns:
true if this target action may cause abortion of the current ability.
Since:
0.86 new algorythme to determine valid targets


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