Package com.tenio.entity
Class AbstractPlayer
- java.lang.Object
-
- com.tenio.entity.AbstractPlayer
-
public abstract class AbstractPlayer extends java.lang.Object
A player is one of the base elements in your server. It is a representation of one client in the server and helps that client and this server communicates with each other. You can handle the message that sent from the client or send a message back via a player's instance. Most important here, a player should not be a part of your logic game. A player is better to work as an inspector with 'control' power. For example, when a player joins one game, you need to create for him a corresponding entity. Now, the play will control that entity in the same way you control one chess in a board game. Something like HP status, the number of manas, etc, should not be an attribute of a player, it is a part of an entity's attributes. So, for some interrupt accidents, your character (entity) is still alive and waiting for player re-connect to control it. Look like a soul (player) with a body (entity).- Author:
- kong
-
-
Constructor Summary
Constructors Constructor Description AbstractPlayer(java.lang.String name)
Create a new player
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeAllConnections()
void
closeConnection(int index)
Connection
getConnection(int index)
java.lang.String
getEntityId()
java.lang.String
getName()
long
getReaderTime()
AbstractRoom
getRoom()
int
getState()
long
getWriterTime()
boolean
hasConnection(int index)
void
initializeConnections(int size)
boolean
isIgnoreTimeout()
boolean
isNPC()
Check the player's roleboolean
isState(int state)
void
setConnection(Connection connection, int index)
void
setCurrentReaderTime()
void
setCurrentWriterTime()
void
setEntityId(java.lang.String entityId)
void
setIgnoreTimeout(boolean flagIgnoreTimeout)
void
setRoom(AbstractRoom room)
void
setState(int state)
-
-
-
Method Detail
-
getEntityId
public java.lang.String getEntityId()
-
setEntityId
public void setEntityId(java.lang.String entityId)
-
getName
public java.lang.String getName()
-
isState
public boolean isState(int state)
-
getState
public int getState()
-
setState
public void setState(int state)
-
isNPC
public boolean isNPC()
Check the player's role- Returns:
- true if the player is a NPC (non player character), otherwise return false (A NPC is a player without a connection).
-
hasConnection
public boolean hasConnection(int index)
-
getConnection
public Connection getConnection(int index)
-
initializeConnections
public void initializeConnections(int size)
-
setConnection
public void setConnection(Connection connection, int index)
-
closeConnection
public void closeConnection(int index)
-
closeAllConnections
public void closeAllConnections()
-
getRoom
public AbstractRoom getRoom()
-
setRoom
public void setRoom(AbstractRoom room)
-
getReaderTime
public long getReaderTime()
-
setCurrentReaderTime
public void setCurrentReaderTime()
-
getWriterTime
public long getWriterTime()
-
setCurrentWriterTime
public void setCurrentWriterTime()
-
isIgnoreTimeout
public boolean isIgnoreTimeout()
-
setIgnoreTimeout
public void setIgnoreTimeout(boolean flagIgnoreTimeout)
-
-