⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playerimpl.java

📁 Vyger offers a D & D and Rogue-like environment in a graphical online roleplay game.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Light And Shadow. A Persistent Universe based on Robert Jordan's Wheel of Time Books.
 * Copyright (C) 2001-2002 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.client;

import wotlas.common.screenobject.*;
import wotlas.common.character.*;
import wotlas.common.chat.*;
import wotlas.common.universe.*;
import wotlas.common.movement.*;
import wotlas.common.objects.*;
import wotlas.common.*;

import wotlas.common.message.description.PlayerPastMessage;
import wotlas.common.message.description.PlayerAwayMessage;

import wotlas.libs.graphics2D.*;
import wotlas.libs.graphics2D.drawable.*;
import wotlas.libs.graphics2D.filter.*;
import wotlas.libs.sound.*;

import wotlas.libs.net.NetMessage;

import wotlas.libs.pathfinding.*;

import wotlas.utils.*;

import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;

import java.util.Hashtable;

/** Class of a Wotlas Player.
 *
 * @author Petrus, Aldiss, Elann, Diego
 * @see wotlas.common.Player
 */

public class PlayerImpl implements Player, SpriteDataSupplier,FakeSpriteDataSupplier, Tickable {

    /** Period between the display of two away messages for ONE player.
    */
    public final static long AWAY_MSG_DISPLAY_PERIOD = 1000*20;

 /*------------------------------------------------------------------------------------*/

    /** Player's primary key (the key)
    */
    private String primaryKey;

    /** Player location
    */
    private WotlasLocation location;

    /** Player name
    */
    private String playerName;

    /** Player full name
    */
    private String fullPlayerName;

    /** Player character's past
    */
    private String playerPast;

    /** Player away message.
    */
    private String playerAwayMessage;

    /** Wotlas Character
    */
    private BasicChar wotCharacter;
  
    /** Object manager
    */
    private ClientObjectManager objectManager;
  
    /** Player state
    */
    transient private PlayerState playerState = new PlayerState();
  
    /** Current Chat PrimaryKey : the chat we are currently connected to.
    */
    private String currentChatPrimaryKey = ChatRoom.DEFAULT_CHAT; // everlasting chat set as default

    /** Time stamp for the away message : we don't display the away messages when they
    *  are asked during the AWAY_MSG_DISPLAY_PERIOD.
    */
    transient private long playerAwayMsgTimeStamp;

 /*------------------------------------------------------------------------------------*/

    /** Player's PathFollower for movements...
    */
    private MovementComposer movementComposer = (MovementComposer) new PathFollower();

 /*------------------------------------------------------------------------------------*/

    /** Our animation.
    */
    private Animation animation;

    /** Our brightness filter.
    */
    private BrightnessFilter brightnessFilter;
  
    /** Our sprite.
    */
    private Sprite sprite;

    /** Our textDrawable
    */
    private TextDrawable textDrawable;

    /** Our wave arc drawable to show our player talking.
    */
    private WaveArcDrawable waveDrawable;

    /** To get the player name to display on the left of the screen
    */
    private MultiLineText gameScreenFullPlayerName;

    /** Our current TileMap ( if we are in a TileMap, null otherwise )
    */
    private TileMap myTileMap;
  
    /** Our current Room ( if we are in a Room, null otherwise )
    */
    private Room myRoom;

    /** True if player is moving.
    */
    private boolean isMoving = false;

    /** True if this player is controlled by the client.
    */
    private boolean isMaster = false;

    /** Is this player representing a client that is connected to the game ?
    */
    private boolean isConnectedToGame = false; 

    /** 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.
    */
    private byte syncID[] = new byte[1];

 /*------------------------------------------------------------------------------------*/

    /** Locks
    */
    private byte trajectoryLock[] = new byte[0];
    private byte xLock[] = new byte[0];
    private byte yLock[] = new byte[0];
    private byte angleLock[] = new byte[0];
    private byte imageLock[] = new byte[0];

 /*------------------------------------------------------------------------------------*/

    /** Constructor
    */
    public PlayerImpl() {
    }

 /*------------------------------------------------------------------------------------*/

    /** When this method is called, the player can initialize its own fields safely : all
    *  the game data has been loaded.
    */
    public void init() {
        if(!getLocation().isTileMap())  {
            //Debug.signal( Debug.NOTICE, null, "PlayerImpl::init");
            animation = new Animation( wotCharacter.getImage(getLocation()),
                               ClientDirector.getDataManager().getImageLibrary() );
            sprite = (Sprite) wotCharacter.getDrawable(this);
            brightnessFilter = new BrightnessFilter();
            sprite.setDynamicImageFilter(brightnessFilter);
        }
        movementComposer.init( this );
    }

    /** Called after graphicsDirector's init to add some visual effects to the master player
    * or to show other players
    */
    public void initVisualProperties(GraphicsDirector gDirector) {

        if(!getLocation().isTileMap()){
            if(isMaster)
                gDirector.addDrawable(wotCharacter.getShadow()); // Drawable has already been added
            else {
                gDirector.addDrawable(wotCharacter.getDrawable(this));
                gDirector.addDrawable(wotCharacter.getShadow());
            }
        }
        else {
            gDirector.addDrawable(wotCharacter.getDrawable(this));
        }
    }

    /** To remove player from the screen
    */
    public void cleanVisualProperties(GraphicsDirector gDirector) {
        if (!isMaster) {
            gDirector.removeDrawable(wotCharacter.getDrawable(this));
            if(!getLocation().isTileMap())
            gDirector.removeDrawable(wotCharacter.getShadow());
        }
    }

 /*------------------------------------------------------------------------------------*/

    /** To get the player location.
    *
    *  @return player WotlasLocation
    */
    public WotlasLocation getLocation() {
        return location;
    }

    /** To set the player location.
    *
    *  @param new player WotlasLocation
    */
    public void setLocation(WotlasLocation myLocation) {
        location = myLocation;
        
        if ( myLocation.isRoom() )
            myRoom = ClientDirector.getDataManager().getWorldManager().getRoom( myLocation );
        else
            myRoom = null;
        if ( myLocation.isTileMap() )
            myTileMap = ClientDirector.getDataManager().getWorldManager().getTileMap( myLocation );
        else
            myTileMap = null;
    }

 /*------------------------------------------------------------------------------------*/

    /** To get the player name ( short name )
    *
    *  @return player name
    */
    public String getPlayerName() {
        return playerName;
    }

    /** To set the player's name ( short name )
    *
    *  @param player name
    */
    public void setPlayerName(String playerName) {
        this.playerName = playerName;
    }

 /*------------------------------------------------------------------------------------*/

    /** To get the player's full name.
    *
    *  @param the key of player who requested player's full name
    *  @return player full name ( should contain the player name )
    */
    public String getFullPlayerName(Player otherPlayer) {
        return fullPlayerName;
    }

    public String getFullPlayerName() {
        return fullPlayerName;
    }
  
    /** To set the player's full name.
    *
    *  @param player full name ( should contain the player name )
    */
    public void setFullPlayerName(String fullPlayerName) {
        this.fullPlayerName = fullPlayerName;

        if( textDrawable!=null )
            textDrawable.setText(fullPlayerName);

        if( gameScreenFullPlayerName!=null ) {
            String[] strTemp = { fullPlayerName };
            gameScreenFullPlayerName.setText(strTemp);
        }
    }

 /*------------------------------------------------------------------------------------*/
 
  /*** Player implementation ***/

    /** To get the player primary Key ( account name )
    *
    *  @return player primary key
    */
    public String getPrimaryKey() {
        return primaryKey;
    }

    /** To set the player's primary key.
    *
    *  @param primary key
    */
    public void setPrimaryKey(String primaryKey) {
        this.primaryKey = primaryKey;
    }

    /** To get the player's character.
    *
    *  @return player character
    */
    public BasicChar getBasicChar() {
        return wotCharacter;
    }

    /** To set the player's character.
    *
    *  @return WotCharacter player character
    */
    public void setBasicChar(BasicChar wotCharacter) {
        this.wotCharacter = wotCharacter;
    }

  
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

    /** To get the player's object manager
    *
    *  @return player object manager
    */
    public ObjectManager getObjectManager(){
        return objectManager;
    }

    /** To set the player's object manager.
    *
    *  @param objectManager player object manager
    */
    public void setObjectManager( ObjectManager objectManager ){
        this.objectManager=(ClientObjectManager)objectManager;
    }  
  
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

    /** To get the player character past.
    *
    *  @return player past
    */
    public String getPlayerPast() {
        if( playerPast==null ) {
            // we ask for the player's past
      	    sendMessage( new PlayerPastMessage( primaryKey, "") );
      	    playerPast="loading...";
      	    return playerPast;
      	}
      	
        return playerPast;
    }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

    /** To set the player's past.
    *
    *  @param playerPast past
    */
    public void setPlayerPast( String playerPast ) {
        this.playerPast = playerPast;
    }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

    /** To get the player away message.
    *
    *  @return player away Message
    */
    public String getPlayerAwayMessage() {
        if(isConnectedToGame && this!=ClientDirector.getDataManager().getMyPlayer())
            return null;

        if(playerAwayMessage==null)
            sendMessage( new PlayerAwayMessage( primaryKey, "") );

        return playerAwayMessage;
    }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

    /** Can we display the Away Message ? (method for the DataManager)
    */
    public boolean canDisplayAwayMessage() {
        long now = System.currentTimeMillis();

        if( playerAwayMsgTimeStamp+AWAY_MSG_DISPLAY_PERIOD < now ) {
            playerAwayMsgTimeStamp = now;
            return true;
        }

        return false;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -