com.realtime.crossfire.jxclient.spells
Class SpellsManager

java.lang.Object
  extended by com.realtime.crossfire.jxclient.spells.SpellsManager
All Implemented Interfaces:
java.lang.Iterable<Spell>

public class SpellsManager
extends java.lang.Object
implements java.lang.Iterable<Spell>

Manages all known spells.


Field Summary
private  CrossfireSpellListener crossfireSpellListener
          The listener to receive updates for spell information.
private  GuiStateListener guiStateListener
          The GuiStateListener for detecting established or dropped connections.
private  java.util.Collection<SpellsManagerListener> listeners
          The SpellsManagerListeners to notify about changes.
private  java.util.Comparator<Spell> spellNameComparator
          A Comparator to compare Spell instances by spell path and name.
private  java.util.List<Spell> spells
          All known spells.
private  java.util.Map<java.lang.String,Spell> unknownSpells
          All unknown spells that have been referenced before.
 
Constructor Summary
SpellsManager(CrossfireServerConnection crossfireServerConnection, GuiStateManager guiStateManager)
          Create a new instance.
 
Method Summary
 void addCrossfireSpellChangedListener(SpellsManagerListener listener)
          Adds a SpellsManagerListener to notify about changes.
private  void addSpell(int tag, int level, int castingTime, int mana, int grace, int damage, int skill, int path, int faceNum, java.lang.String spellName, java.lang.String message)
          Adds a new spell.
private  void deleteSpell(int tag)
          Deletes a spell.
private  void deleteSpellByIndex(int index)
          Deletes a spell by index into spells.
 Spell getSpell(int index)
          Returns a Spell instance by index.
 Spell getSpell(java.lang.String spellName)
          Returns a Spell instance by spell name.
 int getSpells()
          Returns the number of known spells.
private  void initSpells()
           
 java.util.Iterator<Spell> iterator()
          
 void removeCrossfireSpellChangedListener(SpellsManagerListener listener)
          Removes a SpellsManagerListener to notify about changes.
private  void updateSpell(int flags, int tag, int mana, int grace, int damage)
          Updates spell information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

crossfireSpellListener

@NotNull
private final CrossfireSpellListener crossfireSpellListener
The listener to receive updates for spell information.


guiStateListener

@NotNull
private final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.


listeners

@NotNull
private final java.util.Collection<SpellsManagerListener> listeners
The SpellsManagerListeners to notify about changes.


spellNameComparator

@NotNull
private final java.util.Comparator<Spell> spellNameComparator
A Comparator to compare Spell instances by spell path and name.


spells

@NotNull
private final java.util.List<Spell> spells
All known spells.


unknownSpells

@NotNull
private final java.util.Map<java.lang.String,Spell> unknownSpells
All unknown spells that have been referenced before. Maps spell name to Spell instance.

Constructor Detail

SpellsManager

public SpellsManager(@NotNull
                     CrossfireServerConnection crossfireServerConnection,
                     @NotNull
                     GuiStateManager guiStateManager)
Create a new instance.

Parameters:
crossfireServerConnection - the connection to listen on
guiStateManager - the gui state manager to watch
Method Detail

addCrossfireSpellChangedListener

public void addCrossfireSpellChangedListener(@NotNull
                                             SpellsManagerListener listener)
Adds a SpellsManagerListener to notify about changes.

Parameters:
listener - the listener to add

addSpell

private void addSpell(int tag,
                      int level,
                      int castingTime,
                      int mana,
                      int grace,
                      int damage,
                      int skill,
                      int path,
                      int faceNum,
                      @NotNull
                      java.lang.String spellName,
                      @NotNull
                      java.lang.String message)
Adds a new spell. Re-uses entries from unknownSpells if possible.

Parameters:
tag - the spell's tag
level - the spell's level
castingTime - the spell's casting time
mana - the spell's mana cost
grace - the spell's grace cost
damage - the spell's damage
skill - the spell's skill
path - the spell's path
faceNum - the spell's face number
spellName - the spell's name
message - the spells' description

deleteSpell

private void deleteSpell(int tag)
Deletes a spell.

Parameters:
tag - the spell's tag

deleteSpellByIndex

private void deleteSpellByIndex(int index)
Deletes a spell by index into spells.

Parameters:
index - the index to delete

getSpell

@Nullable
public Spell getSpell(int index)
Returns a Spell instance by index.

Parameters:
index - the index
Returns:
the spell or null if the index is invalid

getSpell

@NotNull
public Spell getSpell(@NotNull
                              java.lang.String spellName)
Returns a Spell instance by spell name. Creates a new instance if the spell is unknown.

Parameters:
spellName - the spell name to find
Returns:
the spell instance

getSpells

public int getSpells()
Returns the number of known spells.

Returns:
the number of spells

initSpells

private void initSpells()

iterator

public java.util.Iterator<Spell> iterator()

Specified by:
iterator in interface java.lang.Iterable<Spell>

removeCrossfireSpellChangedListener

public void removeCrossfireSpellChangedListener(@NotNull
                                                SpellsManagerListener listener)
Removes a SpellsManagerListener to notify about changes.

Parameters:
listener - the listener to remove

updateSpell

private void updateSpell(int flags,
                         int tag,
                         int mana,
                         int grace,
                         int damage)
Updates spell information.

Parameters:
flags - specifies which fields to update
tag - the spell's tag
mana - the spell's new mana cost
grace - the spell's new grace cost
damage - the spell's new damage