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

            評論

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

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

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

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

            日韩久久久久中文字幕人妻| 99久久精品国产毛片| 99久久99久久精品国产片| 久久精品欧美日韩精品| 91精品免费久久久久久久久| 伊人色综合久久天天| 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久久亚洲精品蜜桃臀| 久久精品国产99久久久古代 | 免费观看成人久久网免费观看| 久久久久18| 国产成人久久精品激情| 日韩久久久久中文字幕人妻 | 久久精品国产99久久香蕉| 国内精品伊人久久久影院| 亚洲综合久久综合激情久久| 无夜精品久久久久久| 人人狠狠综合久久亚洲88| 伊人久久综合精品无码AV专区| 深夜久久AAAAA级毛片免费看| 久久久久亚洲AV无码永不| 久久人人爽人爽人人爽av| 日韩av无码久久精品免费| 无码专区久久综合久中文字幕| 无码国内精品久久人妻麻豆按摩| 99久久人妻无码精品系列蜜桃| 久久精品国产男包| 亚洲va久久久久| 亚洲国产成人久久精品动漫| 亚洲色欲久久久综合网| 久久亚洲国产成人影院网站| 99热精品久久只有精品| 久久久亚洲精品蜜桃臀| 国产农村妇女毛片精品久久| 国产精品岛国久久久久| 伊人丁香狠狠色综合久久| 久久男人Av资源网站无码软件 | 国产叼嘿久久精品久久| 久久精品国产福利国产秒| 中文精品久久久久国产网址| 99国产精品久久|