netbattle
Class NetBattleField

java.lang.Object
  extended by shoddybattle.BattleField
      extended by netbattle.NetBattleField

public class NetBattleField
extends BattleField

This class represents an online battle field.


Nested Class Summary
 
Nested classes/interfaces inherited from class shoddybattle.BattleField
BattleField.PokemonWrapper
 
Field Summary
 
Fields inherited from class shoddybattle.BattleField
m_active, m_participants, m_pokemon
 
Constructor Summary
NetBattleField(BattleServer server, BattleMechanics mechanics)
          Allows for external construction.
 
Method Summary
 void addClient(NetClient client, Pokemon[] team)
          Add a client to this battle field, along with his team of pokemon.
 void dispose()
          Dispose of this NetBattleField.
static int getBattleCount()
          Return the number of battles currently ongoing.
static java.util.Collection getBattleList()
          Get a list of battles currently taking place.
static java.lang.String[] getBattleList(int[] fids)
          Get an array of the battles currently taking place.
 java.lang.String getDescription()
          Get a description of this battle field.
static NetBattleField getFieldByDescription(java.lang.String desc)
          Get a NetBattleField by its description.
static NetBattleField getFieldById(int id)
          Get a NetBattleField object by its absolute id, which is unique within each instance of the server.
 int getId()
          Return the absolute (unique within this instance of the server) id of this battle field.
 int getTrainerId(NetClient client)
          Get the id in this battle field of a client.
 java.lang.String getTrainerName(int idx)
          Get the name of a trainer.
 void informPokemonFainted(int party, int idx)
          Inform that a pokemon fainted.
 void informPokemonHealthChanged(Pokemon poke, int hp)
          A pokemon's health was changed.
 void informStatusApplied(Pokemon poke, StatusEffect eff)
          Inform that a status effect was applied to a pokemon.
 void informStatusRemoved(Pokemon poke, StatusEffect eff)
          Inform that a status effect was removed from a pokemon.
 void informSwitchInPokemon(int trainer, Pokemon poke)
          A pokemon was switched in.
 void informSwitchInPokemon(int trainer, Pokemon poke, boolean silent)
          A pokemon was switched in.
 void informUseMove(Pokemon poke, java.lang.String name)
          Inform that a pokemon used a move.
 void informVictory(int trainer)
          A player has won.
 void queueMove(int trainer, BattleTurn move)
          Process a move sent in by a client.
 void refreshActivePokemon()
          Refresh all active pokemon.
 void refreshStats()
          Refresh all players' statistics.
 void refreshStats(int trainer)
          Refresh a player's statistics.
 void removeClient(NetClient remove)
          Remove a client from this battle field.
 void requestAndWaitForSwitch(int party)
          Wait for a player to switch pokemon.
protected  void requestMoves()
          Request moves for the next turn.
protected  void requestPokemonReplacement(int i)
          Obtain a replacement pokemon for the team identified by the parameter.
 void showMessage(java.lang.String message)
          Narrate the battle.
 void showMessage(java.lang.String message, boolean important)
           
 
Methods inherited from class shoddybattle.BattleField
addClause, allowsStatus, applyEffect, attachField, checkBattleEnd, executeTurn, getActivePokemon, getAliveCount, getEffectByType, getEffectiveness, getEffectsByType, getMechanics, getOpponent, getParty, getPokemonTrainer, getRandom, getStruggle, isNarrationEnabled, removeEffect, replaceFaintedPokemon, setNarrationEnabled, setPokemon, switchInPokemon, synchroniseFieldEffects
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetBattleField

public NetBattleField(BattleServer server,
                      BattleMechanics mechanics)
Allows for external construction.

Method Detail

dispose

public void dispose()
Dispose of this NetBattleField.

Overrides:
dispose in class BattleField

getDescription

public java.lang.String getDescription()
Get a description of this battle field.


getBattleList

public static java.util.Collection getBattleList()
Get a list of battles currently taking place.


getBattleCount

public static int getBattleCount()
Return the number of battles currently ongoing.


getFieldByDescription

public static NetBattleField getFieldByDescription(java.lang.String desc)
Get a NetBattleField by its description.


getFieldById

public static NetBattleField getFieldById(int id)
Get a NetBattleField object by its absolute id, which is unique within each instance of the server.


getBattleList

public static java.lang.String[] getBattleList(int[] fids)
Get an array of the battles currently taking place. Each index in the array contains the description of a battle.


getId

public int getId()
Return the absolute (unique within this instance of the server) id of this battle field.


informStatusApplied

public void informStatusApplied(Pokemon poke,
                                StatusEffect eff)
Inform that a status effect was applied to a pokemon.

Specified by:
informStatusApplied in class BattleField

informStatusRemoved

public void informStatusRemoved(Pokemon poke,
                                StatusEffect eff)
Inform that a status effect was removed from a pokemon.

Specified by:
informStatusRemoved in class BattleField

getTrainerName

public java.lang.String getTrainerName(int idx)
Get the name of a trainer.

Specified by:
getTrainerName in class BattleField
Parameters:
idx - the trainer whose name to get.

getTrainerId

public int getTrainerId(NetClient client)
Get the id in this battle field of a client.


addClient

public void addClient(NetClient client,
                      Pokemon[] team)
Add a client to this battle field, along with his team of pokemon. A team does does not need to be passed (and should not be passed) if there are already two clients in the field. When the total number of clients reaches two, this method has the side effect of initialising the battle. (This is arguably bad.)


removeClient

public void removeClient(NetClient remove)
Remove a client from this battle field. This method will destroy the field if no clients remain after the removal.


informUseMove

public void informUseMove(Pokemon poke,
                          java.lang.String name)
Inform that a pokemon used a move.

Specified by:
informUseMove in class BattleField
Parameters:
poke - the pokemon who used the move
name - the name of the move that was used

requestPokemonReplacement

protected void requestPokemonReplacement(int i)
Obtain a replacement pokemon for the team identified by the parameter.

Specified by:
requestPokemonReplacement in class BattleField

showMessage

public void showMessage(java.lang.String message)
Narrate the battle.

Specified by:
showMessage in class BattleField

showMessage

public void showMessage(java.lang.String message,
                        boolean important)

informPokemonFainted

public void informPokemonFainted(int party,
                                 int idx)
Inform that a pokemon fainted.

Specified by:
informPokemonFainted in class BattleField

refreshActivePokemon

public void refreshActivePokemon()
Refresh all active pokemon. This function is used in conjunction with MoveList.SubstituteEffect to display the proper sprite.

Specified by:
refreshActivePokemon in class BattleField

informSwitchInPokemon

public void informSwitchInPokemon(int trainer,
                                  Pokemon poke,
                                  boolean silent)
A pokemon was switched in.


informSwitchInPokemon

public void informSwitchInPokemon(int trainer,
                                  Pokemon poke)
A pokemon was switched in.

Specified by:
informSwitchInPokemon in class BattleField

informPokemonHealthChanged

public void informPokemonHealthChanged(Pokemon poke,
                                       int hp)
A pokemon's health was changed.

Specified by:
informPokemonHealthChanged in class BattleField

informVictory

public void informVictory(int trainer)
A player has won.

Specified by:
informVictory in class BattleField

refreshStats

public void refreshStats()
Refresh all players' statistics.


refreshStats

public void refreshStats(int trainer)
Refresh a player's statistics.


requestAndWaitForSwitch

public void requestAndWaitForSwitch(int party)
Wait for a player to switch pokemon. This method should be called *only* from the dispatch thread. It will throw an InternalError if it is called from another thread.

Specified by:
requestAndWaitForSwitch in class BattleField

queueMove

public void queueMove(int trainer,
                      BattleTurn move)
               throws MoveQueueException
Process a move sent in by a client. If this is the second (m_participants is not referenced, although it should be) move to be added this turn then this method has the side effect of executing the round.

Specified by:
queueMove in class BattleField
Throws:
MoveQueueException

requestMoves

protected void requestMoves()
Request moves for the next turn.

Specified by:
requestMoves in class BattleField