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

📄 gameeventdefault.java

📁 一个MMORPG手机游戏的服务器端程序源代码
💻 JAVA
字号:
package zsw_mmorpg.common;import java.nio.ByteBuffer;/** * GameEventDefault.java * <p/> * 游戏事件的定义 * * @author <a href="mailto:shiwei@raymobile.com">朱世伟</a> * @version 1.0 *//**游戏事件的定义*/public class GameEventDefault implements GameEvent {    /** request to login */    public static final int C_LOGIN = 1;    /**     * login ok     */    public static final int S_LOGIN_ACK_OK = 2;    /**     * login failed     */    public static final int S_LOGIN_ACK_FAIL = 3;    /**     * broadcast notice of a player login     */    public static final int SB_LOGIN = 4;    /**     * logout request     */    public static final int C_LOGOUT = 5;    /**     * broadcast notice of a player logout     */    public static final int SB_LOGOUT = 6;    /**     * notice of disconnect     */    public static final int S_DISCONNECT = 7;    /**     * request to join a game     */    public static final int C_JOIN_GAME = 8;    /**     * join success     */    public static final int S_JOIN_GAME_ACK_OK = 9;    /**     * join failure     */    public static final int S_JOIN_GAME_ACK_FAIL = 10;    /**     * broadcast notice that player has joined     */    public static final int SB_PLAYER_JOINED = 11;    /**     * request to quit game     */    public static final int C_QUIT_GAME = 12;    /**     * broadcast notice that player has quit     */    public static final int SB_PLAYER_QUIT = 13;    /**     * request to get player list     */    public static final int C_GET_PLAYERS = 14;    /**     * notice of player list     */    public static final int S_GET_PLAYERS = 15;    /**     * client chat mesg     */    public static final int C_CHAT_MSG = 16;    /**     * server broadcast chat mesg     */    public static final int SB_CHAT_MSG = 17;    /**     * client move     */    public static final int C_MOVE = 18;    /**     * move ok     */    public static final int S_MOVE_ACK_OK = 19;    /**     * move failed     */    public static final int S_MOVE_ACK_FAIL = 20;    /**     * round is complete     */    public static final int S_ROUND_COMPLETE = 21;    /**     * game over notice     */    public static final int S_GAME_OVER = 22;    /**     * used internally in client     */    public static final int C_CMD_ACK =23;    /**     * generic ok response     */    public static final int S_ACK_OK = 24;    /**     * generic fail response     */    public static final int S_ACK_FAIL =25;    /**     * first id that a subclass should use for events     */    public static final int SUBCLASS_FIRST_CMD_ID = 26;    /**walk*/    public static final int C_walk = 27;    /**密码错误*/    public static final int S_Playerid_Psd_Not_Correct = 28;    /**玩家升级了*/     public static final int S_Playerid_level_up = 29;    /**战斗胜利*/    public static final int C_War_win = 30;    /**玩家已经登陆了,目前在线*/    public static final int S_P_already_login = 31;    /**单独跟某玩家密聊*/    public static final int  C_CHAT_To_Player_MSG =32 ;    /**分配技能点数*/    public static final int  C_Distribute_Point =33 ;    /**装备道具*/    public static final int  C_Item_Action =34 ;    /**增加好友*/        public static final int  C_Friends_Add =35 ;    /**删除好友*/        public static final int  C_Friends_Del =36 ;/**好友上线*/        public static final int  C_Friends_online =37 ;/**好友下线*/        public static final int  C_Friends_offline =38 ;    /**商店买*/        public static final int  C_shop_buy =39 ;    /**商店卖*/        public static final int  C_shop_sell =40 ;    /**钱不够*/    public static final int  S_no_enough_money =41 ;    /**装备道具*/        public static final int  C_item_equip =34 ;    /**卸载道具*/        public static final int  C_item_un_equip =43 ;    /**使用道具*/    public static final int  C_item_use =44 ;    /**     * event type     */    protected int eventType;    /**     * playerID that sent the message (for client mesgs)     */    protected String playerId;    /**     * player's session id     */    protected String sessionId;     // no use    /**     * gameID that the event belongs to, if any     */    protected int gameId = -1;      // no use    /**     * gameName that the event belongs to     */    protected String gameName;      //no use    /**     * # of recipients     */    protected int numRecipients;    /**     * array of event recipient playerIDs     */    protected String[] recipients;    /**     * chat message or other command specific string     */    protected String message;    public GameEventDefault() {    }    public GameEventDefault(int type) {        this.eventType = type;    }    public GameEventDefault(int type, String message) {        this.eventType = type;        this.message = message;    }    public void setType(int type) {        eventType = type;    }    public int getType() {        return eventType;    }    public void setGameName(String gameName) {        this.gameName = gameName;    }    public String getGameName() {        return gameName;    }    public String getMessage() {        return message;    }    public void setMessage(String message) {        this.message = message;    }    public String getPlayerId() {        return playerId;    }    public void setPlayerId(String id) {        playerId = id;    }    public String getSessionId() {        return sessionId;    }    public void setSessionId(String id) {        sessionId = id;    }    public String[] getRecipients() {        return recipients;    }    public void setRecipients(String[] recipients) {        this.recipients = recipients;        numRecipients = recipients.length;    }    /**     *往给定的BUFFER里面写事件     */    public int write(ByteBuffer buff) {        int pos = buff.position();        buff.putInt(eventType);        System.out.println("eventType:" + eventType);        NIOUtils.putStr(buff, playerId);        System.out.println("playerId:" + playerId);        //NIOUtils.putStr(buff, sessionId);        //buff.putInt(gameId);//保留,以后开PK可能会用//      NIOUtils.putStr(buff, gameName);        buff.putInt(numRecipients);//        System.out.println("numRecipients:" + numRecipients);//        for (int i = 0; i < numRecipients; i++) {//            NIOUtils.putStr(buff, recipients[i]);//            System.out.println("recipients[" + i + "]:" + recipients[i]);//        }        NIOUtils.putStr(buff, message);        System.out.println("message:" + message);        // return the length of the event, this will get inserted at the beginning of the buffer        // in the EventWriter so the Reader knows how many bytes to read for the payload        return buff.position() - pos;    }    /**     * 从给定的BUFFER里面读事件     */    public void read(ByteBuffer buff) {        eventType = buff.getInt();        System.out.println("eventType:" + eventType);        playerId = NIOUtils.getStr(buff);        System.out.println("playerId:" + playerId);        // sessionId = NIOUtils.getStr(buff);        //gameId = buff.getInt();//       gameName = NIOUtils.getStr(buff);        numRecipients = buff.getInt();//        recipients = new String[numRecipients];//        System.out.println("numRecipients:" + numRecipients);//        for (int i = 0; i < numRecipients; i++) {//            recipients[i] = NIOUtils.getStr(buff);//            System.out.println("recipients[" + i + "]:" + recipients[i]);//        }        message = NIOUtils.getStr(buff);        System.out.println("message:" + message);    }}// GameEvent

⌨️ 快捷键说明

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