• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            focus on linux, c/c++, lua

            游戲中的容器設計

            經過幾天的思考,我開始動手寫游戲容器這塊,我設計的初衷就是KISS。基本上把容器的類別定格為:背包,倉庫,快捷欄,郵箱。多人共享的容器被我砍掉了,目前還無此需求。我做的方向就是,把容器做成部件,每個部件僅有一個admin。

            容器中的物品類:
            struct IGoods : public IThing
            {
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: NULL
                 
            */

                
            virtual int GetGoodsID() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: NULL
                 
            */

                
            virtual void SetBind(char cBind) = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: NULL
                 
            */

                
            virtual char GetBind() = 0;
            }
            ;

            我做了這樣一個設計,物品全部由資源管理器生成,背包中的物品單獨做擴展,如下:
            struct IContainerGoods
            {
                
            /*
                 *    @Param: bReleaseGoods為false,只刪除背包物品,為true,真實的IGoods*
                            也要刪除
                 *    @Return:
                 *    @Description: NULL
                 
            */

                
            virtual void Release(bool bReleaseGoods = true= 0;
                
            /*
                 *    @Param: 獲得物品ID
                 *    @Return: NULL
                 *    @Description: NULL
                 
            */

                
            virtual int GetGoodsID() = 0;    
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 獲取在容器中的位置
                 
            */

                
            virtual int GetLocation() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 獲取所在的容器
                 
            */

                
            virtual IContainer* GetContainer() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 獲取該物品的真實物品指針
                 
            */

                
            virtual IGoods* GetGoods() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 鎖定該物品
                 
            */

                
            virtual bool LockGoods() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 解鎖該物品
                 
            */

                
            virtual bool UnlockGoods() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 是否被鎖定
                 
            */

                
            virtual bool IsLocked() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: NULL
                 
            */

                
            virtual int GetCount() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: NULL
                 
            */

                
            virtual void SetCount(int nCnt) = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: NULL
                 
            */

                
            virtual char GetBind() = 0;
            }
            ;

            背包的接口,提供最基本的幾個功能,消息格式我是這樣設計的:
            1,玩家第一次進入游戲后,服務器把整個背包內容發給玩家更新
            2,玩家(服務器)對某個格子的物品做更新時,單獨對該格子做消息更新,這樣就會在玩家頻繁操作背包的時候,同一格式(注意是格式)的消息
                  會頻繁發送多條,當然每個消息內容是不一樣的。
            有個問題待思考:無聊的玩家在背包中,把兩個物品頻繁做調換位置,服務器肯定也要同時更新的,那么服務器是否讓客戶端做cold down??
            struct IContainer : public IThingPart
            {
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 銷毀容器,徹底銷毀容器內的物品
                 
            */

                
            virtual void Release() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 獲得容器ID
                 
            */

                
            virtual int GetContainerID() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 獲得容器尺寸
                 
            */

                
            virtual int GetSize() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 獲取容器類型
                 
            */

                
            virtual char GetType() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 判斷容器是否是空
                 
            */

                
            virtual bool IsEmpty() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 獲取一個空的位置,為-1時表示無空位置
                 
            */

                
            virtual int GetOneFreeLocation() = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 根據位置獲取容器物品
                 
            */

                
            virtual IContainerGoods* GetGoodsByLoc(uint nLocation) = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 根據GoodsID獲取容器物品
                 
            */

                
            virtual IContainerGoods* GetGoodsByID(int nGoodsID) = 0;
                
            /*
                *    @Param: NULL
                *    @Return: NULL
                *    @Description: NULL
                
            */

                
            virtual int GetGoodsCount(int nGoodsID, char cBind) = 0;
                
            /*
                *    @Param: NULL
                *    @Return: NULL
                *    @Description: 能否向容器中添加若干個物品
                
            */

                
            virtual bool CanAddGoods(int nGoodsID, int nCount, char cBind = 0= 0;
                
            /*
                 *    @Param: uDstContainerID:把物品移向的容器ID
                 *    @Return: NULL
                 *    @Description: NULL
                 
            */

                
            virtual bool CanRemoveGoods(int nPID, IContainerGoods* pGoods) = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 向容器的固定位置放置物品
                 
            */

                
            virtual bool AddGoods(int nPID, IContainerGoods* pGoods) = 0;
                
            /*
                *    @Param: bUpdateClient:是否發消息通知客戶端 bPile:是否堆疊
                *    @Return: 成功添加的物品數量
                *    @Description: NULL
                
            */

                
            virtual bool AddGoods(int nPID, int nGoodsID, int nCount, 
                    
            bool bUpdateClient = truechar cBind = 0= 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 從容器中移除物品
                 
            */

                
            virtual bool RemoveGoods(int nPID, IContainerGoods* pGoods) = 0;
                
            /*
                *    @Param: bUpdateClient:是否發消息通知客戶端 bPile:是否堆疊
                *    @Return: 成功刪除的物品數量
                *    @Description: NULL
                
            */

                
            virtual bool RemoveGoods(int nPID, int nGoodsID, int nCount, 
                    
            bool bUpdateClient = truechar cBind = 0= 0;    
                
            /*
                *    @Param: nPID:玩家角色ID nCount:分割出去的數量 pContainer:分割出去的目的容器為
                            NULL時即為本容器  nDstPos:為分割出去的目的位置,為-1為自動尋找
                            的第一
                *    @Return: 分割后的物品指針
                *    @Description: NULL
                
            */

                
            virtual IContainerGoods* SplitGoods(int nPID, IContainerGoods* pSrcGoods, int nCount, 
                    IContainer
            * pContainer = NULL, int nDstPos = -1= 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 容器的物品位置交換操作
                 
            */

                
            virtual bool SwapGoods(int nPID, IContainerGoods* pSrcGoods, 
                    IContainer
            * pContainer, IContainerGoods* pDstGoods) = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 判斷該容器是否有效
                 
            */

                
            virtual bool IsValid() = 0;
            }
            ;

            posted on 2010-05-01 09:44 zuhd 閱讀(1703) 評論(2)  編輯 收藏 引用 所屬分類: server

            評論

            # re: 游戲中的容器設計 2010-05-02 10:56 expter

            對于物品背包一般采用容器這種設計。而你說的物品移動都會與服務器驗證應該是必須得...。  回復  更多評論   

            # re: 游戲中的容器設計 2010-05-03 09:15 zuhd

            @expter
            是必須的,我思考的是無聊的玩家頻繁交換兩個格子內的物品,不做增減操作,是否有必要給個cold down?  回復  更多評論   

            国产精品久久自在自线观看| 亚洲精品乱码久久久久久按摩 | 精品久久人人做人人爽综合| 久久这里只有精品视频99| 中文字幕乱码人妻无码久久| 99国产精品久久| 久久久久国产精品人妻| 国产成人综合久久久久久| 日韩人妻无码精品久久免费一| 国内精品久久久久久麻豆| 亚洲AV无码久久寂寞少妇| 久久久久久国产精品无码下载 | 无码久久精品国产亚洲Av影片 | 理论片午午伦夜理片久久 | 久久99精品久久久久久齐齐| 久久天天躁狠狠躁夜夜网站 | 国内精品欧美久久精品| 久久午夜综合久久| 怡红院日本一道日本久久| 久久久久亚洲Av无码专| 久久精品国产秦先生| 久久久女人与动物群交毛片| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 亚洲女久久久噜噜噜熟女| 伊人久久精品影院| 久久综合视频网站| 久久久久久青草大香综合精品| 99久久精品免费| 99久久亚洲综合精品网站| 精品久久8x国产免费观看| 久久久精品人妻一区二区三区四 | 久久99国产综合精品免费| 国内精品九九久久久精品| 色综合久久久久无码专区 | 77777亚洲午夜久久多喷| 伊人久久大香线蕉亚洲| 综合久久一区二区三区 | 嫩草影院久久国产精品| 国产成人久久精品麻豆一区| 亚洲国产成人久久综合碰碰动漫3d| 91精品国产高清91久久久久久|