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

📄 datamanager.java

📁 Vyger offers a D & D and Rogue-like environment in a graphical online roleplay game.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * 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.client.gui.*;
import wotlas.client.screen.*;
import wotlas.client.screen.extraplugin.*;
import wotlas.client.screen.JPanelPlugIn;
import wotlas.client.screen.plugin.InfoPlugIn;

import wotlas.common.character.*;
import wotlas.common.*;
import wotlas.common.message.account.*;
import wotlas.common.message.description.*;
import wotlas.common.PlayerState;
import wotlas.common.universe.*;

import wotlas.libs.graphics2D.*;
import wotlas.libs.graphics2D.drawable.*;
import wotlas.libs.graphics2D.policy.*;
import wotlas.libs.graphics2D.menu.*;
import wotlas.libs.net.*;
import wotlas.libs.net.utils.NetQueue;
import wotlas.libs.persistence.*;
import wotlas.libs.sound.SoundLibrary;
import wotlas.libs.aswing.*;

import wotlas.utils.*;
import wotlas.common.action.*;
import wotlas.common.message.action.*;
import wotlas.common.screenobject.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.swing.*;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;

/** A DataManager manages Game Data and client's connection.
 * It possesses a WorldManager
 *
 * @author Petrus, Aldiss
 * @see wotlas.common.NetConnectionListener
 */

public class DataManager extends Thread implements NetConnectionListener, Tickable,
                                                   Menu2DListener {

  public final static byte COMMAND_NOTHING  = 0;
  public final static byte COMMAND_CAST     = 1;
  public final static byte COMMAND_ABILITY  = 2;
  public final static byte COMMAND_BASIC    = 3;

  public byte commandRequest = COMMAND_NOTHING;
  public UserAction commandAction = null;

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

  /** Image Library
   */
    public final static String IMAGE_LIBRARY = "graphics/imagelib";

  /** size of a mask's cell (in pixels)
   */
    public final static int TILE_SIZE = 5;

  /** TIMEOUT to the Account Server
   */
    private static final int CONNECTION_TIMEOUT = 30000;

  /** Number of tick before destroying the circle
   */
    private static final int CIRCLE_LIFETIME = 20;

  /** True if we show debug informations
   */
    public static boolean SHOW_DEBUG = false;

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

  /*** THE MAIN DATA WE MANAGE ***/

  /** Our World Manager
   */
    private WorldManager worldManager;

  /** Our MapData : data of the current map displayed on screen.
   */
    private MapData myMapData;

  /** Our NetConnection, represents the connection with the server.
   */
    private NetConnection connection;

  /** Our player's profile ( serverID, login, etc... ).
   */
    private ProfileConfig currentProfileConfig;

  /** Our ImageLibrary.
   */
    private ImageLibrary imageLib;

  /** Our Graphics Director.
   */
    private GraphicsDirector gDirector;

  /** Our client interface frame.
   */
    private JClientScreen clientScreen;

  /** NetQueue for synchronous messages. Messages that want to be run after the current
   *  tick should call a queueMessage() on this NetQueue.
   *  NetMessageBehaviours should use the invokeLater() method to queue a message.
   */
    private NetQueue syncMessageQueue;

  /** Our player data.
   */
    private PlayerImpl myPlayer;
  
  /** The selected player on screen.
   */
    private PlayerImpl selectedPlayer;

  /** List of all the players displayed on screen.
   */
    private Hashtable players;

  /** List of all the ScreenObjects displayed on screen.
   */
    private Hashtable screenObjects;
    
  /** Our menu manager.
   */
    private MenuManager menuManager;

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

  /*** DATA ACCESS CONTROLLER ***/

  /** Connection Lock
   */
    private byte connectionLock[] = new byte[1];

  /** Game Lock (unlocked by client.message.description.YourPlayerDataMsgBehaviour)
   */
    private Object startGameLock = new Object();

  /** Tick Thread Lock.
   */
    private Object pauseTickThreadLock = new Object();

  /** Do we have to pause the tick thread ?
   */
    private boolean pauseTickThread;

  /** Are we changing the MapData ?
   */
    private boolean updatingMapData = false;

  /** True if player was diconnected end resumed the game
   */
    private boolean isResuming = false;

  /** Ghost orientation (to limit the update massages sent)
   */
    private double ghostOrientation;

  /** Reference orientation
   */
    private double refOrientation;

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

  /*** SELECTION CIRCLE ***/

  /** Circle selection
   */
    private CircleDrawable circle;

  /** Number of tick since circle creation
   */
    private int circleLife = 0;

  /** Circle Lock
   */
    private byte circleLock[] = new byte[1];


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

  /** Constructor with resource manager.
   */
    public DataManager( ResourceManager rManager ) {

      // 1 - We create our world Manager. It will load the universe data.
         worldManager = new WorldManager( rManager, false );

      // 2 - Misc inits
         syncMessageQueue = new NetQueue(1,3);
         players = new Hashtable();
         screenObjects = new Hashtable();
         connectionLock = new byte[1];
         startGameLock = new Object();

         pauseTickThreadLock = new Object();
         pauseTickThread = false;
         updatingMapData = false;
         isResuming = false;

         circleLife = 0;
         circleLock= new byte[1];
    }

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

  /** To get the world manager.
   *
   * @return the world manager.
   */
    public WorldManager getWorldManager() {
      return worldManager;
    } 

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

  /** To get the graphicsDirector
   *
   * @return the graphicsDirector
   */
    public GraphicsDirector getGraphicsDirector() {
       return gDirector;
    }

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

  /** To get the image Library
   *
   * @return the image library
   */
    public ImageLibrary getImageLibrary() {
       return imageLib;
    }

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

  /*** GETTERS ***/

  /** To get MapData
   */
    public MapData getMapData() {
      return myMapData;
    }
  /** To get JClientScreen.
   */
    public JClientScreen getClientScreen() {
      return clientScreen;
    }

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

  /** Set to true to show debug information
   */
    public void showDebug(boolean value) {
      SHOW_DEBUG = value;
    }

 /*------------------------------------------------------------------------------------*/
  
  /** To get the hashtable players
   */
    public Hashtable getPlayers() {
      return players;
    }
 
  /** To get the hashtable screenObjects
   */
    public Hashtable getScreenObjects() {
      return screenObjects;
    }
    
  /** To get selected player
   */
    public String getSelectedPlayerKey() {
      if (selectedPlayer!=null)
          return selectedPlayer.getPrimaryKey();
      return null;
    }
  
  /** To remove the circle
   */
    public void removeCircle() {
      gDirector.removeDrawable(circle);
      circle = null;
    }

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

  /** To set the current profileConfig<br>
   * (called by client.message.account.AccountCreatedMsgBehaviour)
   */
    public void setCurrentProfileConfig(ProfileConfig currentProfileConfig) {
      this.currentProfileConfig = currentProfileConfig;
    }

  /** To get the current profileConfig.
   */
    public ProfileConfig getCurrentProfileConfig() {
      return currentProfileConfig;
    }

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

  /** To test if player was diconnected
   *
   * @return true if player was disconnected
   */
    public boolean isResuming() {
      return isResuming;
    }
  
  /** To set whether player has finished resuming the game
   */
    public void setIsResuming(boolean value) {
      this.isResuming = value;
    }
  
 /*------------------------------------------------------------------------------------*/

  /** This method is called when a new network connection is created
   *

⌨️ 快捷键说明

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