• <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国产精品成人欧美| 久久人人爽爽爽人久久久| 国产精品成人99久久久久91gav | 久久精品人人做人人爽电影| 午夜精品久久久久久影视777| 久久久久高潮毛片免费全部播放| 久久人人爽人爽人人爽av| 99re久久精品国产首页2020| 人妻中文久久久久| segui久久国产精品| 国产产无码乱码精品久久鸭| 欧美精品九九99久久在观看| 国产精品成人99久久久久| 99国产欧美精品久久久蜜芽| 国产美女亚洲精品久久久综合 | 亚洲国产高清精品线久久| 狠狠色丁香婷综合久久| 久久婷婷国产综合精品 | 日韩欧美亚洲综合久久影院Ds| 国产精品久久久久影视不卡| 亚洲国产精品久久电影欧美| 国产精品中文久久久久久久| 久久亚洲欧洲国产综合| 久久亚洲天堂| segui久久国产精品| 久久久久久极精品久久久 | 91精品无码久久久久久五月天 | 香蕉久久夜色精品国产2020| 久久免费99精品国产自在现线| 国产激情久久久久影院小草| 国产成人无码精品久久久免费| 亚洲狠狠综合久久| 久久91这里精品国产2020| 青青草国产97免久久费观看| 亚洲国产精品无码久久青草| 亚洲午夜久久久影院伊人| 久久精品国产亚洲AV无码偷窥|