net.sf.magicproject.clickable.ability
Class Ability

java.lang.Object
  extended by net.sf.magicproject.clickable.ability.Ability
All Implemented Interfaces:
Unregisterable, ResolveStackHandler
Direct Known Subclasses:
AbstractAbility, SystemAbility, UserAbility

public abstract class Ability
extends java.lang.Object
implements ResolveStackHandler, Unregisterable

An ability contains a cost part and an effect part. Each ability is associated to an event conditionning it's activation.

Since:
0.1, 0.60 name attribute added, 0.86 Object to be removed from a component are checked be enabling an ability., 0.86 The controller of this ability may be any player., 0.90 linked abilities added.
Author:
Fabrice Daugan

Field Summary
 Optimization optimizer
          The optimizer to use to manage the 'add' method to the TBZ
 Priority priority
          The resolution selector choose the right abstract zone where an hidden ability would be added.
 
Method Summary
abstract  MAction[] actionList()
          Return list of actions to play to cast this ability
 void addLinkedAbility(Ability ability)
          Add a linked ability.
 boolean checkObjectActions()
          Checks too the other actions requiring a particular state, such as the presence of an object.
 boolean checkTargetActions()
          Verify in the 'cost' part there is no target action may cause abortion of this ability.
 Ability clone(MCard container)
          return a copy of this ability
TODO remove param container since it is not used in this constructor As default, return null
abstract  MAction[] effectList()
          Return list of actions effects of this ability
 boolean equals(ContextEventListener thisContext, Ability ability, ContextEventListener context)
          Compare two abilities the specified ability to the TBZ.
 MEventListener eventComing()
          Return matched to activate this ability matched to activate this ability.
 java.lang.String getAbilityTitle()
          Return ability html title.
abstract  MCard getCard()
          Return card where is this ability.
 CardCopy getCardCopy()
          Return a card representing this ability.
 Player getController()
          Return the controller of this ability
abstract  java.lang.String getLog(ContextEventListener context)
          Return a String identifying this ability with the name and/or card name.
 java.lang.String getName()
          Return the name of this ability
 java.lang.String getPictureName()
          Return the picture name associated to this ability.
 Targetable getTargetable()
          Return card where is this ability
 TriggeredCard getTriggeredClone(ContextEventListener context)
          Return a MTriggeredCard representing this ability.
 TriggeredCardChoice getTriggeredCloneChoice(ContextEventListener context)
          Return a MTriggeredCard representing this ability.
 int hashCode()
           
 boolean hasHighPriority()
          Indicates wether this ability is choosen in priority to the others without this tag.
 boolean isAutoResolve()
          Indicates if this ability is immediatly after it has been added to the stack.
 boolean isHidden()
          Indicates if this ability is immediatly after it has been added to the stack (like isAutoResolve), and if no information is displayed or prompted to the users.
abstract  boolean isMatching()
          compare the current event to the event activating this ability.
 boolean isPlayAsSpell()
          Is this ability is played as a spell.
 int[] manaNeeded(ContextEventListener context)
          return the amount of mana needed (constant part only) to play this ability
 void optimizeRegisterToManager()
          Register this abilty to manager trying to append test on existing ability with same effects.
 boolean recheckTargets()
          Is this ability contains targeting action.
 void registerToManager()
          Add this ability to the looked for events.
 void removeFromManager()
          Remove from the event manager this listener.
 void resolveStack()
          called when the stack is resolving
 void setEvent(MEventListener event)
          Set the new event for this ability.
 java.lang.String toHtmlString(ContextEventListener context)
          Return the HTML code representing this ability.
 java.lang.String toString()
           
 boolean triggerIt(ContextEventListener context)
          called when this ability is going to be triggered This method would add this ability to the triggered zone, or perform another play action
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

optimizer

public Optimization optimizer
The optimizer to use to manage the 'add' method to the TBZ


priority

public Priority priority
The resolution selector choose the right abstract zone where an hidden ability would be added.

Method Detail

optimizeRegisterToManager

public void optimizeRegisterToManager()
Register this abilty to manager trying to append test on existing ability with same effects.

Since:
0.82

getName

public java.lang.String getName()
Return the name of this ability

Returns:
the new name

checkTargetActions

public boolean checkTargetActions()
Verify in the 'cost' part there is no target action may cause abortion of this ability.

Returns:
true if all actions in the 'cost' part can be played.

checkObjectActions

public boolean checkObjectActions()
Checks too the other actions requiring a particular state, such as the presence of an object.

Returns:
true if the other actions requiring a particular state, such as the presence of an object are OK.

recheckTargets

public boolean recheckTargets()
Is this ability contains targeting action.

Returns:
true if this ability contains targeting action.

getCard

public abstract MCard getCard()
Return card where is this ability. As default, it return null.

Specified by:
getCard in interface Unregisterable
Returns:
true card where is this ability

getTargetable

public Targetable getTargetable()
Return card where is this ability

Returns:
true card where is this ability

isAutoResolve

public boolean isAutoResolve()
Description copied from interface: ResolveStackHandler
Indicates if this ability is immediatly after it has been added to the stack. Note it's not says immediatly it has been triggered or playable, but says it has been activated - so added directly to the stack -, or has been triggered - so added to the triggered buffer zone - and then has been selected to be moved to the stack.

Specified by:
isAutoResolve in interface ResolveStackHandler
Returns:
true if this ability is immediatly after it has been added to the stack.

isHidden

public boolean isHidden()
Description copied from interface: ResolveStackHandler
Indicates if this ability is immediatly after it has been added to the stack (like isAutoResolve), and if no information is displayed or prompted to the users. Users would not see this ability played.

Specified by:
isHidden in interface ResolveStackHandler
Returns:
true if this ability is immediatly after it has been added to the stack (like isAutoResolve), and if no information is displayed or prompted to the users. Users would not see this ability played.
See Also:
ResolveStackHandler.isAutoResolve()

hasHighPriority

public boolean hasHighPriority()
Indicates wether this ability is choosen in priority to the others without this tag.

Returns:
true if this ability is choosen in priority to the others without this tag.

isMatching

public abstract boolean isMatching()
compare the current event to the event activating this ability. If matching, verify that there enougth mana in the player's mana pool

Returns:
true if this ability can be played responding the current event

getCardCopy

public CardCopy getCardCopy()
Return a card representing this ability.

Returns:
a card representing this ability

getPictureName

public java.lang.String getPictureName()
Return the picture name associated to this ability. Is null if no picture is used with this ability.

Returns:
the picture name associated to this ability.

manaNeeded

public int[] manaNeeded(ContextEventListener context)
return the amount of mana needed (constant part only) to play this ability

Parameters:
context - the current context of this ability.
Returns:
array of mana needed to play this ability

actionList

public abstract MAction[] actionList()
Return list of actions to play to cast this ability

Returns:
list of actions to play to cast this ability

effectList

public abstract MAction[] effectList()
Return list of actions effects of this ability

Returns:
list of actions effects of this ability

eventComing

public MEventListener eventComing()
Return matched to activate this ability matched to activate this ability. As default, return null.

Returns:
event matched to activate this ability

setEvent

public void setEvent(MEventListener event)
Set the new event for this ability.

Parameters:
event - the new event for this ability.

clone

public Ability clone(MCard container)
return a copy of this ability
TODO remove param container since it is not used in this constructor As default, return null

Parameters:
container - is not used here
Returns:
copy of this ability

getTriggeredClone

public TriggeredCard getTriggeredClone(ContextEventListener context)
Return a MTriggeredCard representing this ability. This clone should used to be added into the triggered buffer zone of player contrilling this ability.

Parameters:
context - the attached context of this ability
Returns:
a TriggeredCard object built from this and the specified context

getTriggeredCloneChoice

public TriggeredCardChoice getTriggeredCloneChoice(ContextEventListener context)
Return a MTriggeredCard representing this ability. This clone should used to be added into the triggered buffer zone of player contrilling this ability.

Parameters:
context - the attached context of this ability
Returns:
a TriggeredCardChoice object built from this and the specified context

resolveStack

public void resolveStack()
Description copied from interface: ResolveStackHandler
called when the stack is resolving

Specified by:
resolveStack in interface ResolveStackHandler
See Also:
StackManager.resolveStack()

triggerIt

public boolean triggerIt(ContextEventListener context)
called when this ability is going to be triggered This method would add this ability to the triggered zone, or perform another play action

Parameters:
context - the context needed by event activated
Returns:
true if this ability has been added to the triggered buffer zone, return false otherwise

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toHtmlString

public java.lang.String toHtmlString(ContextEventListener context)
Return the HTML code representing this ability.

Parameters:
context - the context needed by event activated
Returns:
the HTML code representing this ability.
Since:
0.85 Event is displayed

getAbilityTitle

public java.lang.String getAbilityTitle()
Return ability html title. Type of ability and a few other information

Returns:
ability html title. Type of ability and a few other information

removeFromManager

public void removeFromManager()
Description copied from interface: Unregisterable
Remove from the event manager this listener.

Specified by:
removeFromManager in interface Unregisterable

registerToManager

public void registerToManager()
Add this ability to the looked for events. Linked abilities are also registered.


getController

public Player getController()
Return the controller of this ability

Returns:
the controller of this ability

addLinkedAbility

public final void addLinkedAbility(Ability ability)
Add a linked ability.

Parameters:
ability - a linked ability to add.

equals

public boolean equals(ContextEventListener thisContext,
                      Ability ability,
                      ContextEventListener context)
Compare two abilities the specified ability to the TBZ.

Parameters:
thisContext - the attached context of this ability
ability - the ability to add
context - the attached context of given ability
Returns:
true if the abilities are functionnaly equal in this context.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

isPlayAsSpell

public boolean isPlayAsSpell()
Is this ability is played as a spell.

Returns:
true if this ability is played as a spell.

getLog

public abstract java.lang.String getLog(ContextEventListener context)
Return a String identifying this ability with the name and/or card name.

Parameters:
context - the current context of this ability.
Returns:
a String identifying this ability with the name and/or card name.


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