📄 crystalplayer.java
字号:
/*
* Created on 2005-6-30
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.swing.game.crystal;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import com.swing.game.crystal.utils.Equip;
import com.swing.game.crystal.utils.Person;
import com.swing.game.crystal.utils.UserStatus;
import com.swing.server.common.Attachment;
import com.swing.server.common.GameEvent;
import com.swing.server.common.Player;
/**
* @author vampire_a
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class CrystalPlayer implements Player {
public static Logger logger = Logger.getLogger(CrystalPlayer.class);
static {
PropertyConfigurator.configure("./cfg/Log4j.properties");
}
public static final long INTERVAL = 300000; //60 seconds
public static final byte UP = 'n';
public static final byte LEFT = 'w';
public static final byte DOWN = 's';
public static final byte RIGHT = 'e';
public static final int DEFAULT_CAPACITY = 100;
/**
* 缓冲区
*/
/**
* 玩家的唯一ID
*/
public String id;
/**
* 玩家用来传送数据的管道
*/
private SocketChannel channel;
/**
* 表示玩家是否处于活动状态
*/
private boolean alive;
/**
* 玩家最后一次操作的时间
*/
public long time;
/**
* 玩家当前所在地图的编号
*/
public int mapCode;
/**
* 玩家在地图中X方向的坐标(以格为单位)
*/
public int mapXPosition;
/**
* 玩家在地图中Y方向的坐标(以格为单位)
*/
public int mapYPosition;
/**
* 玩家的种类 1:雷神 2:智者
*/
public byte kind;
/**
* 玩家的级别
*/
public byte level;
/**
* 玩家HP的当前值
*/
public int hp;
/**
* 玩家HP的上限
*/
public int hpLimit;
/**
* 玩家的当前能源
*/
public int power;
/**
* 玩家能源上限
*/
public int powerLimit;
/**
* 精神力级别
*/
public int sp;
/**
* 玩家的基础攻击力
*/
public int attack;
/**
* 玩家的基础攻击力+防具提供的攻击力
*/
public int defense;
/**
* 玩家的恢复力
*/
public int resurrection;
/**
* 玩家的敏捷度
*/
public int agility;
/**
* 玩家的金钱
*/
public int money;
/**
* 玩家当前经验值
*/
public int exp;
/**
* 玩家升级经验界限
*/
public int expLimit;
/**
* 玩家的职业
*/
public int career;
/**
* 玩家背包的当前剩余容量
*/
public int capacity;
/**
* 玩家当前的防具ID,初始值为0
*/
public String curSuit;
/**
* 玩家当前鞋子ID,初始值为0
*/
public String curShoe;
/**
* 允许打哪个BOSS
*/
public int boss;
/**
* 广播信息
*/
private final List bc = new ArrayList();
/**
* 玩家连接类型 SOCKET : 0 POST : 1 GET : 2 OTHER : 3
*/
private int connectionKind;
public CrystalPlayer(int connectionKind) {
this.connectionKind = connectionKind;
this.status = 0;
this.pkSwitch = true;
}
public String getPlayerId() {
return id;
}
public void setPlayerId(String arg0) {
this.id = arg0;
}
public SocketChannel getChannel() {
return channel;
}
public void setChannel(SocketChannel arg0) {
this.channel = arg0;
}
public boolean loggedIn() {
return alive;
}
public void setLoggedIn(boolean arg0) {
this.alive = arg0;
}
public int getConnKind() {
return this.connectionKind;
}
public void setConnKind(int arg0) {
this.connectionKind = arg0;
}
/**
* 根据arg0的类型把广播插入到自己的某个队列中
*/
public void sendMessage(Object message) {
// 用SOCKET连接的客户,有信息直接发回
if (this.connectionKind == Attachment.SOCKET) {
GameEvent ge = new CrystalEvent();
ge.setGameCode(CrystalController.gameCode);
ge.addResponse(message);
ge.setPlayerId(this.id);
CrystalController.getGameController().sendEvent(ge, this);
}
// 用HTTP方式连接的客户,有信息先缓存
else {
this.bc.add(message);
}
}
// 当前的套装
public String getCurSuit() {
return this.curSuit;
}
public void setCurSuit(String id) {
Equip old = (Equip) CrystalController.WeaponMapping.get(curSuit);
Equip n = (Equip) CrystalController.WeaponMapping.get(id);
if (n != null) {
if (old != null) {
// 加defense
if (old.target.charAt(0) == '1')
this.defense += old.attack;
// 加resurrection
if (old.target.charAt(2) == '1')
this.resurrection += old.attack;
}
this.curSuit = id;
// 加defense
if (n.target.charAt(0) == '1')
this.defense -= n.attack;
// 加resurrection
if (n.target.charAt(2) == '1')
this.resurrection -= n.attack;
this.defense %= 100;
this.resurrection %= 100;
}
}
public String getCurShoe() {
return this.curShoe;
}
public void setCurShoe(String id) {
Equip old = (Equip) CrystalController.WeaponMapping.get(curShoe);
Equip n = (Equip) CrystalController.WeaponMapping.get(id);
if (n != null) {
if (old != null) {
// 加agility
if (old.target.charAt(0) == '1')
this.agility += old.attack;
// 加resurrection
if (old.target.charAt(2) == '1')
this.resurrection += old.attack;
}
this.curShoe = id;
// 加agility
if (n.target.charAt(0) == '1')
this.agility -= n.attack;
// 加resurrection
if (n.target.charAt(2) == '1')
this.resurrection -= n.attack;
this.agility %= 100;
this.resurrection %= 100;
}
}
// 好友相关
/**
* 玩家好友的ID列表
*/
public List friends = null;
/**
* 给玩家添加好友
*
* @param id
* Object
*/
public void addFriend(Object id) {
if (this.friends == null)
this.friends = new ArrayList();
if (!this.friends.contains(id))
this.friends.add(id);
}
/**
* 为玩家删除好友
*
* @param id
* Object
*/
public void removeFriend(Object id) {
if (this.friends != null)
this.friends.remove(id);
}
// 消息相关
/**
* 系统广播消息和地图广播消息
*/
public List news = null;
/**
* 向玩家发送系统或地图广播
*
* @param news
* String
*/
public void sendNews(String news) {
if (this.news == null) {
this.news = new ArrayList();
}
if (this.connectionKind == Attachment.SOCKET)
sendMessage("N " + news);
else
this.news.add(news);
}
/**
* 点对点聊天信息
*/
public List chats = null;
/**
* 向玩家发送单聊信息
*
* @param chats
* String
*/
public void sendChats(String chats) {
if (this.chats == null) {
this.chats = new ArrayList();
}
if (this.connectionKind == Attachment.SOCKET)
sendMessage("C " + chats);
else
this.chats.add(chats);
}
// 装备相关
/**
* 玩家持有的装备、物品列表
*/
public Map equips = new HashMap();
/**
* 查看玩家是否持有某装备
*
* @param o
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -