• <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久久精品国产麻豆| 69国产成人综合久久精品| 久久精品国产半推半就| 久久99精品久久久久久野外| 伊人久久大香线蕉成人| 99久久国产热无码精品免费| 成人a毛片久久免费播放| 九九热久久免费视频| 久久精品国产AV一区二区三区| 午夜人妻久久久久久久久| 亚洲国产精品久久久久婷婷老年| 久久精品成人一区二区三区| 久久久久久国产精品无码下载| 久久超乳爆乳中文字幕| 污污内射久久一区二区欧美日韩| 亚洲午夜久久久影院| 国内精品久久久久久中文字幕| 久久婷婷五月综合色奶水99啪| www.久久精品| 亚洲AV日韩精品久久久久久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 国产一区二区三区久久精品| 热综合一本伊人久久精品 | 伊人久久精品线影院| 色综合久久久久综合体桃花网| 国产精品无码久久四虎|