• <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 閱讀(1683) 評論(2)  編輯 收藏 引用 所屬分類: server

            評論

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

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

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

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

            久久国产热精品波多野结衣AV| 欧美久久一区二区三区| 久久99国产精品久久久 | 久久精品一区二区三区不卡| 国产精品无码久久综合| 国产精久久一区二区三区| 久久人妻少妇嫩草AV无码蜜桃| 九九精品久久久久久噜噜| 久久精品aⅴ无码中文字字幕重口| 久久香综合精品久久伊人| 国产精品亚洲美女久久久| 91麻豆国产精品91久久久| 国产一级持黄大片99久久| 久久免费视频一区| 亚洲av日韩精品久久久久久a | 2021国产精品午夜久久| 丰满少妇高潮惨叫久久久| 亚洲国产成人久久一区WWW| 欧美一区二区三区久久综 | 亚洲va久久久噜噜噜久久男同| 曰曰摸天天摸人人看久久久| 久久人做人爽一区二区三区 | 亚洲狠狠综合久久| 精品一二三区久久aaa片| 国内精品久久久久久中文字幕 | 久久久久无码精品| 精品国产乱码久久久久久郑州公司 | 久久无码高潮喷水| 久久国产成人午夜aⅴ影院| 亚洲国产精品无码久久久蜜芽| 久久精品成人免费观看97| 国产午夜精品久久久久免费视| 伊人久久大香线蕉AV一区二区| 国产精品美女久久久网AV| AV色综合久久天堂AV色综合在 | 狠狠人妻久久久久久综合蜜桃| 久久香蕉国产线看观看精品yw| 久久只有这里有精品4| 久久精品无码av| 国产成人精品久久亚洲高清不卡| 色欲av伊人久久大香线蕉影院|