Class 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 Detail

      • AbstractPlayer

        public AbstractPlayer​(java.lang.String name)
        Create a new player
        Parameters:
        name - the unique name
    • 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()
      • 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)