• <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

            游戲中的容器設(shè)計(jì)

            經(jīng)過(guò)幾天的思考,我開(kāi)始動(dòng)手寫(xiě)游戲容器這塊,我設(shè)計(jì)的初衷就是KISS。基本上把容器的類(lèi)別定格為:背包,倉(cāng)庫(kù),快捷欄,郵箱。多人共享的容器被我砍掉了,目前還無(wú)此需求。我做的方向就是,把容器做成部件,每個(gè)部件僅有一個(gè)admin。

            容器中的物品類(lèi):
            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;
            }
            ;

            我做了這樣一個(gè)設(shè)計(jì),物品全部由資源管理器生成,背包中的物品單獨(dú)做擴(kuò)展,如下:
            struct IContainerGoods
            {
                
            /*
                 *    @Param: bReleaseGoods為false,只刪除背包物品,為true,真實(shí)的IGoods*
                            也要?jiǎng)h除
                 *    @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: 獲取該物品的真實(shí)物品指針
                 
            */

                
            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;
            }
            ;

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

                
            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: 獲取容器類(lèi)型
                 
            */

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

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

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

                
            virtual IContainerGoods* GetGoodsByLoc(uint nLocation) = 0;
                
            /*
                 *    @Param: NULL
                 *    @Return: NULL
                 *    @Description: 根據(jù)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: 能否向容器中添加若干個(gè)物品
                
            */

                
            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:是否發(fā)消息通知客戶(hù)端 bPile:是否堆疊
                *    @Return: 成功添加的物品數(shù)量
                *    @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:是否發(fā)消息通知客戶(hù)端 bPile:是否堆疊
                *    @Return: 成功刪除的物品數(shù)量
                *    @Description: NULL
                
            */

                
            virtual bool RemoveGoods(int nPID, int nGoodsID, int nCount, 
                    
            bool bUpdateClient = truechar cBind = 0= 0;    
                
            /*
                *    @Param: nPID:玩家角色I(xiàn)D nCount:分割出去的數(shù)量 pContainer:分割出去的目的容器為
                            NULL時(shí)即為本容器  nDstPos:為分割出去的目的位置,為-1為自動(dòng)尋找
                            的第一
                *    @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) 評(píng)論(2)  編輯 收藏 引用 所屬分類(lèi): server

            評(píng)論

            # re: 游戲中的容器設(shè)計(jì) 2010-05-02 10:56 expter

            對(duì)于物品背包一般采用容器這種設(shè)計(jì)。而你說(shuō)的物品移動(dòng)都會(huì)與服務(wù)器驗(yàn)證應(yīng)該是必須得...。  回復(fù)  更多評(píng)論   

            # re: 游戲中的容器設(shè)計(jì) 2010-05-03 09:15 zuhd

            @expter
            是必須的,我思考的是無(wú)聊的玩家頻繁交換兩個(gè)格子內(nèi)的物品,不做增減操作,是否有必要給個(gè)cold down?  回復(fù)  更多評(píng)論   

            亚洲国产精品无码久久一区二区 | 热久久这里只有精品| 久久久www免费人成精品| 久久精品国产亚洲αv忘忧草| 无码AV波多野结衣久久| 久久99毛片免费观看不卡| 久久99精品国产99久久6| 久久久亚洲裙底偷窥综合| 青青热久久综合网伊人| 亚洲国产成人久久综合野外| 日日躁夜夜躁狠狠久久AV| 久久国产成人午夜AV影院| 精品久久久噜噜噜久久久 | 久久精品国产亚洲AV忘忧草18| 人妻少妇久久中文字幕| 久久久久亚洲精品男人的天堂| 久久99精品久久只有精品| 亚洲精品97久久中文字幕无码| 91久久精品91久久性色| 久久www免费人成看片| 久久99精品国产麻豆婷婷| 俺来也俺去啦久久综合网| 中文字幕日本人妻久久久免费| 久久国产精品免费| 99久久国产亚洲高清观看2024| 国内精品久久久久影院日本| 无码国内精品久久综合88| 久久精品国产精品亚洲艾草网美妙| 日韩久久久久久中文人妻 | 一级做a爰片久久毛片人呢| 亚洲成色WWW久久网站| 久久成人国产精品免费软件| 午夜视频久久久久一区| 久久伊人五月天论坛| 久久久国产精品| 久久久久久亚洲精品不卡 | AV色综合久久天堂AV色综合在| 亚洲精品高清国产一线久久| 伊人久久综合无码成人网| 精品国产乱码久久久久久呢| 久久精品国产AV一区二区三区|