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

📄 crystalplayer.java

📁 一套MMORPG手机网络游戏的服务端
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *            Object
     * @return boolean
     */
    public boolean containsEquip(String id) {
        if (this.equips.containsKey(id))
            return true;
        else
            return false;
    }

    /**
     * 使用装备
     * 
     * @param name
     *            String
     * @param number
     *            int
     */
    public void useEquip(String id, int number) {
        // 使用装备时得加相关属性
        Object o = this.equips.get(id);
        if (o != null) {
            int num = Integer.parseInt(o.toString());
            if (num - 1 <= 0)
                this.equips.remove(id);
            else
                this.equips.put(id, String.valueOf(num - 1));
            Equip e = (Equip) CrystalController.WeaponMapping.get(id);
            int cap = e.capacity;
            this.capacity += (byte) (cap * number);
            if (this.capacity > DEFAULT_CAPACITY)
                this.capacity = DEFAULT_CAPACITY;

            // 加HP
            if (e.target.charAt(0) == '1') {
                this.hp -= e.attack;
                this.hp %= (this.hpLimit + 1);
            }
            // 加POW
            if (e.target.charAt(1) == '1') {
                this.power -= e.attack;
                this.power %= (this.powerLimit + 1);
            }
            // 加经验??
            if (e.target.charAt(2) == '1') {
                this.exp -= e.attack;
                // 升级问题
            }
        }
    }

    /**
     * 给玩家添加某装备
     * 
     * @param name
     *            String
     */
    public void addEquip(String id, String number) {
        this.equips.put(id, number);
        int cap = ((Equip) CrystalController.WeaponMapping.get(id)).capacity;
        this.capacity -= (byte) (cap * Integer.parseInt(number));
        if (this.capacity < 0)
            this.capacity = 0;
    }

    /**
     * 玩家丢弃某装备
     * 
     * @param id
     *            String
     */
    public void removeEquip(String id) {
        int number = Integer.parseInt((String) this.equips.get(id));
        this.equips.put(id, String.valueOf(number - 1));
        if (number == 0)
            this.equips.remove(id);
        int cap = ((Equip) CrystalController.WeaponMapping.get(id)).capacity;
        this.capacity += (byte) (cap * number);
        if (this.capacity > DEFAULT_CAPACITY)
            this.capacity = DEFAULT_CAPACITY;
    }

    /**
     * 返回装备链表ID
     * 
     * @return Iterator
     */
    public Set getEquips() {
        return this.equips.keySet();
    }

    /**
     * 取得玩家持有某装备的数量
     * 
     * @param id
     *            String
     * @return String
     */
    public String getCountOfEquip(String id) {
        return (String) this.equips.get(id);
    }

    //    PK相关
    /**
     * 玩家在PK过程中用到的数据缓存
     */
    public StringBuffer pkData = new StringBuffer();

    /**
     * 玩家是否结束PK
     */
    public boolean isPkOver = false;

    /**
     * 玩家的PK开关,表示玩家是否接受PK
     */
    public boolean pkSwitch;

    //    玩家状态相关
    /**
     * 表示玩家的状态 0:在行进系统中 1:玩家在操作菜单 2:玩家与NPC PK中 3:玩家与其他玩家PK中
     */
    public int status;

    public void setStatus(int status) {
        this.status = status;
    }

    public int getStatus() {
        return this.status;
    }

    //    帮助类
    /**
     * 当前地图内的每个玩家都要维护地图内其他所有玩家的引用
     */
    public Map others = null;

    /**
     * 为玩家删除地图内其他玩家的引用
     * 
     * @param user
     *            User
     */
    public void removeUsers(CrystalPlayer user) {
        this.time = System.currentTimeMillis();
        if (this.connectionKind == Attachment.SOCKET) {
            sendMessage ("T " + user.id + " Q");
            this.others.remove(user.id);
        } else {
            if (this.others != null && this.others.containsKey(user.id)) {
                // notify that user have left this map
                this.othersData.put(user.id, "Q");
                this.others.remove(user.id);
                System.out.println("User:" + this.id + " remove User:"
                        + user.id);
                System.out.println("User:" + this.id + " others.size()="
                        + others.size());
            }
        }
    }

    /**
     * 为玩家添加地图内其他玩家的引用
     * 
     * @param user
     *            User
     */
    public void addUsers(CrystalPlayer user) {
        if (this.others == null) {
            this.others = new HashMap();
            this.others.put(user.id, user);
            StringBuffer sb = new StringBuffer();
            sb.append(user.kind);
            sb.append(" ");
            sb.append(user.mapXPosition);
            sb.append(" ");
            sb.append(user.mapYPosition);
            sb.append("|");
            if (this.othersData == null)
                this.othersData = new HashMap();
            if (this.connectionKind == Attachment.SOCKET)
                sendMessage("T " + user.id + " " + sb.toString());
            else
                this.othersData.put(user.id, sb.toString());
        } else {
            if (!this.others.containsKey(user.id)) {
                this.others.put(user.id, user);
                StringBuffer sb = new StringBuffer();
                sb.append(user.kind);
                sb.append(" ");
                sb.append(user.mapXPosition);
                sb.append(" ");
                sb.append(user.mapYPosition);
                sb.append("|");
                if (this.othersData == null)
                    this.othersData = new HashMap();
                if (this.connectionKind == Attachment.SOCKET)
                    sendMessage("T " + user.id + " " + sb.toString());
                else
                    this.othersData.put(user.id, sb.toString());
            }
        }
    }

    public List tradeData = null;

    public void addTradeData(String data) {
        if (this.tradeData == null)
            this.tradeData = new ArrayList();
        if (this.connectionKind == Attachment.SOCKET)
            sendMessage(data);
        else
            this.tradeData.add(data);
    }

    /**
     * 其他玩家的移动信息
     */
    public Map othersData = null;

    /**
     * 为当前玩家添加其他玩家的移动轨迹信息
     * 
     * @param id
     *            String
     * @param track
     *            String
     */
    public void addUserTrack(String id, String track) {
        try {
            if (this.othersData == null)
                this.othersData = new HashMap();
            if (this.othersData.containsKey(id)) {
                if (this.connectionKind == Attachment.SOCKET)
                    sendMessage("T " + id + " " + track);
                else
                    this.othersData.put(id, this.othersData.get(id).toString()
                            + track);
            } else {
                if (this.connectionKind == Attachment.SOCKET)
                    sendMessage("T " + id + " " + track);
                else
                    this.othersData.put(id, track);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 取得下行给玩家的信息
     * 
     * @return String
     */
    public String getAllData() {
        StringBuffer sbb = new StringBuffer();
        // 当玩家处于与其他玩家的PK过程中时,只接收与PK有关的信息
        if (this.status == UserStatus.USER_PKING) {
            System.out.println(this.pkData.toString());
            if (this.pkData.length() != 0)
                sbb.append(this.pkData.toString());
            this.pkData.delete(0, this.pkData.length());
            if (this.isPkOver) {
                this.status = UserStatus.MENUING;
                this.isPkOver = false;
            }

        }
        // 玩家处于行进状态时才会接收诸如聊天,行进轨迹等信息
        else if (this.status == UserStatus.WALKING) {
            if (this.othersData != null && this.othersData.size() != 0) {
                sbb.append("T ");
                for (Iterator iter = this.othersData.keySet().iterator(); iter
                        .hasNext();) {
                    String key = (String) iter.next();
                    sbb.append(key);
                    sbb.append(" ");
                    sbb.append(this.othersData.get(key));
                    //     if(sbb.charAt(sbb.length()-1)!='|')
                    sbb.append("|");
                }
                this.othersData.clear();
            }

            if (sbb.length() > 0)
                sbb.append("*");

            if (this.news != null && this.news.size() != 0) {
                sbb.append("N ");
                for (Iterator iter = this.news.iterator(); iter.hasNext();) {
                    sbb.append((String) iter.next());
                    sbb.append("|");
                }
                this.news.clear();
            }

            if (sbb.length() > 0 && sbb.charAt(sbb.length() - 1) != '*')
                sbb.append("*");

            if (this.chats != null && this.chats.size() != 0) {
                sbb.append("C ");
                for (Iterator iter = this.chats.iterator(); iter.hasNext();) {
                    sbb.append((String) iter.next());
                    sbb.append("|");
                }
                this.chats.clear();
            }

            if (sbb.length() > 0 && sbb.charAt(sbb.length() - 1) != '*')
                sbb.append("*");

            if (this.tradeData != null && this.tradeData.size() != 0) {
                for (Iterator iter = this.tradeData.iterator(); iter.hasNext();) {
                    sbb.append((String) iter.next());
                    // 由于买卖命令和其他上面那些命令是同级的,所以用*
                    sbb.append("*");
                }
                this.tradeData.clear();
            }
        }
        return sbb.toString();
    }

    public void refresh() {
        Person p = (Person) CrystalController.PersonMapping.get(String
                .valueOf(this.kind));
        this.hpLimit = p.hp + (this.level - 1) * 7;
        this.powerLimit = p.power + (this.level - 1) * 7;
        this.expLimit = (this.level + 1) * (this.level + 2);
    }

    public void copy(CrystalPlayer u) {
        this.agility = u.agility;
        this.attack = u.attack;
        this.capacity = u.capacity;
        this.career = u.career;
        if (u.chats != null) {
            this.chats = new ArrayList();
            for (int i = 0; i < u.chats.size(); i++)
                this.chats.add(u.chats.get(i));
        }
        this.curShoe = u.curShoe;
        this.curSuit = u.curSuit;
        this.defense = u.defense;
        if (u.equips != null) {
            this.equips = new HashMap();
            for (Iterator i = u.equips.keySet().iterator(); i.hasNext();) {
                String key = (String) i.next();
                this.equips.put(key, u.equips.get(key));
            }
        }
        this.exp = u.exp;
        this.expLimit = u.expLimit;

        if (u.friends != null) {
            this.friends = new ArrayList();
            for (int i = 0; i < u.friends.size(); i++)
                this.friends.add(u.friends.get(i));
        }
        this.hp = u.hp;
        this.hpLimit = u.hpLimit;
        this.level = u.level;
        this.mapCode = u.mapCode;
        this.mapXPosition = u.mapXPosition;
        this.mapYPosition = u.mapYPosition;
        this.money = u.money;
        if (u.news != null) {
            this.news = new ArrayList();
            for (int i = 0; i < u.news.size(); i++)
                this.news.add(u.news.get(i));
        }
        if (u.others != null) {
            this.others = new HashMap();
            for (Iterator i = u.others.keySet().iterator(); i.hasNext();) {
                String key = (String) i.next();
                this.others.put(key, u.others.get(key));
            }
        }
        if (u.othersData != null) {
            this.othersData = new HashMap();
            for (Iterator i = u.othersData.keySet().iterator(); i.hasNext();) {
                String key = (String) i.next();
                this.othersData.put(key, u.othersData.get(key));
            }
        }
        this.pkData = new StringBuffer(u.pkData.toString());
        this.pkSwitch = u.pkSwitch;
        this.power = u.power;
        this.powerLimit = u.powerLimit;
        this.resurrection = u.resurrection;
        this.sp = u.sp;
    }
}

⌨️ 快捷键说明

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