📄 playerimpl.java
字号:
/*
* Light And Shadow. A Persistent Universe based on Robert Jordan's Wheel of Time Books.
* Copyright (C) 2001-2003 WOTLAS Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package wotlas.server;
import wotlas.common.screenobject.*;
import wotlas.common.character.*;
import wotlas.common.chat.*;
import wotlas.common.movement.*;
import wotlas.common.PlayerState;
import wotlas.common.router.*;
import wotlas.common.message.chat.SendTextMessage;
import wotlas.server.message.chat.*;
import wotlas.libs.net.NetConnectionListener;
import wotlas.libs.net.NetConnection;
import wotlas.libs.net.NetMessage;
import wotlas.libs.pathfinding.*;
import wotlas.libs.persistence.*;
import wotlas.common.*;
import wotlas.common.chat.*;
import wotlas.common.message.movement.*;
import wotlas.common.message.description.*;
import wotlas.common.universe.*;
import wotlas.common.objects.*;
import wotlas.utils.*;
import wotlas.libs.persistence.*;
import java.util.*;
import java.io.*;
/** Class of a Wotlas Player. It is the class that, in certain way, a client gets connected to.
* All the client messages have a server PlayerImpl context.
*
* @author Aldiss, Elann, Diego
* @see wotlas.common.Player
* @see wotlas.common.NetConnectionListener
*/
public class PlayerImpl implements Player, NetConnectionListener,BackupReady {
/** id used in Serialized interface.
*/
private static final long serialVersionUID = 556565L;
/** Period between two focus sounds. Focus sounds can be send by players two draw
* attention.
*/
protected static final int FOCUS_SOUND_PERIOD = 1000*10; // 10s between two sounds
/*------------------------------------------------------------------------------------*/
/** Player's primary key (usually the client account name)
*/
protected String primaryKey;
/** Player location
*/
protected WotlasLocation location;
/** Player name ( in fact it's nickname... the full name is managed by the LieManager)
*/
protected String playerName;
/** Player character's past
*/
protected String playerPast;
/** Player away message.
*/
protected String playerAwayMessage;
/** WotCharacter Class
*/
protected BasicChar wotCharacter;
/** Player state
*/
protected PlayerState playerState = new PlayerState();
/** Movement Composer
*/
protected MovementComposer movementComposer = (MovementComposer) new PathFollower();
/** Lie Manager
*/
protected LieManager lieManager = new LieManager();
/** Last time player disconnected (in days)
*/
protected long lastDisconnectedTime;
/*------------------------------------------------------------------------------------*/
/** Object manager ( possesses the player's inventory )
*/
transient protected ServerObjectManager objectManager;
/** Our NetConnection, useful if we want to send messages !
*/
transient protected NetConnection connection;
/** Our current Room ( if we are in a Room, null otherwise )
*/
transient protected Room myRoom;
/** Our current TileMap ( if we are in a TileMap, null otherwise )
*/
transient protected TileMap myTileMap;
/** SyncID for client & server. See the getter of this field for explanation.
* This field is an array and not a byte because we want to be able to
* synchronize the code that uses it.
*/
transient protected byte syncID[] = new byte[1];
/*------------------------------------------------------------------------------------*/
/** Player ChatRooms : is the list of the current chat room.
*/
transient protected ChatList chatList;
/** Current Chat PrimaryKey : the chat we are currently looking.
*/
transient protected String currentChatPrimaryKey = ChatRoom.DEFAULT_CHAT; // everlasting chat set as default
/** are we a member of this chat ? or just eavesdropping ?
*/
transient protected boolean isChatMember = true; //always member on default chat.
/** Last time this player was grant the possibility to send a focus sound to players.
*
* The period between two focus sound is set by the static FOCUS_SOUND_PERIOD.
*/
transient protected long focusSoundTimeStamp;
/*------------------------------------------------------------------------------------*/
/** Connection Lock
*/
transient protected byte connectionLock[] = new byte[0];
/** ChatList Lock
*/
transient protected byte chatListLock[] = new byte[0];
/*------------------------------------------------------------------------------------*/
/** Constructor for persistence.
*/
public PlayerImpl() {
playerAwayMessage=new String("I'm not here for the moment...");
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** When this method is called, the player can intialize its own fields safely : all
* the game data has been loaded.
*/
public void init() {
movementComposer.init( this );
setLocation( location );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** If you call this method all the local data will be replaced by the given
* player's one.
*/
public void clone( PlayerImpl playerToClone ) {
setLocation( playerToClone.getLocation() );
setPlayerName( playerToClone.getPlayerName() );
setPrimaryKey( playerToClone.getPrimaryKey() );
setPlayerPast( playerToClone.getPlayerPast() );
setPlayerAwayMessage( playerToClone.getPlayerAwayMessage() );
setMovementComposer( playerToClone.getMovementComposer() );
movementComposer.init( this );
setBasicChar( playerToClone.getBasicChar() );
setLieManager( playerToClone.getLieManager() );
setChatList( playerToClone.getChatList() );
setCurrentChatPrimaryKey( playerToClone.getCurrentChatPrimaryKey() );
setIsChatMember( playerToClone.isChatMember() );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To initialize the player location to the first existent world found.
* WARNING : the player is NOT moved to the world... thus this method
* is for player creation ONLY.
*/
public void setDefaultPlayerLocation() {
// 1 - player initial location : a World...
WorldManager worldManager = ServerDirector.getDataManager().getWorldManager();
int worldID = worldManager.getAValidWorldID();
if( worldID<0 )
Debug.signal( Debug.CRITICAL, this, "No world data given to initialize player." );
else if(worldID!=0)
Debug.signal( Debug.WARNING, this, "The default world isn't the first in the list... hope you are aware of that..." );
location = new WotlasLocation(worldID);
// we retrieve the default position.
ServerConfig cfg = ServerDirector.getServerManager().getServerConfig();
setX( cfg.getWorldFirstXPosition() );
setY( cfg.getWorldFirstYPosition() );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Is this player a Master player ? ( directly controlled by the client )
* @return true if this is a Master player, false otherwise.
*/
public boolean isMaster() {
return false; // Server PlayerImpl is only a slave player implementation
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player's X position.
*
* @return x
*/
public int getX() {
return (int)movementComposer.getXPosition();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player's Y position.
*
* @return y
*/
public int getY() {
return (int)movementComposer.getYPosition();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the player's X position.
*
* @param x
*/
public void setX( int x ) {
movementComposer.setXPosition( (float)x );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the player's Y position.
*/
public void setY( int y ) {
movementComposer.setYPosition( (float)y );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the player's orientation.
*/
public void setOrientation( float orientation ) {
movementComposer.setOrientationAngle( orientation );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player's orientation.
*/
public float getOrientation() {
return (float) movementComposer.getOrientationAngle();
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the player location.
*
* @return player WotlasLocation
*/
public WotlasLocation getLocation(){
return new WotlasLocation(location);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the player location.
*
* @param new player WotlasLocation
*/
public void setLocation( WotlasLocation myLocation ){
location = myLocation;
if( location.isRoom() && ServerDirector.getDataManager()!=null )
myRoom = ServerDirector.getDataManager().getWorldManager().getRoom( location );
else {
if( location.isRoom() )
Debug.signal( Debug.CRITICAL, this, "Room not found !!! location is:"+location );
myRoom = null;
}
if( location.isTileMap() && ServerDirector.getDataManager()!=null )
myTileMap = ServerDirector.getDataManager().getWorldManager().getTileMap( location );
else {
if( location.isTileMap() )
Debug.signal( Debug.CRITICAL, this, "TileMap not found !!! location is:"+location );
myTileMap = null;
}
// Current Chat set to default
currentChatPrimaryKey = ChatRoom.DEFAULT_CHAT;
isChatMember = false;
synchronized( chatListLock ) {
chatList = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -