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

            久久综合色之久久综合| 无码任你躁久久久久久老妇App| 精品久久久无码人妻中文字幕| 欧美成人免费观看久久| 久久久精品国产免大香伊| 91久久婷婷国产综合精品青草 | 99久久国产宗和精品1上映| 日产精品久久久一区二区| 国产L精品国产亚洲区久久| 久久久久人妻一区二区三区| 久久精品成人免费看| 婷婷久久五月天| 亚洲国产精品人久久| 老色鬼久久亚洲AV综合| 亚洲人AV永久一区二区三区久久| 国产成人精品免费久久久久| 亚州日韩精品专区久久久| 国产一级做a爰片久久毛片| 香蕉久久久久久狠狠色| 久久av高潮av无码av喷吹| 国产精品99久久99久久久| 国产精品美女久久福利网站| 久久成人永久免费播放| 99精品伊人久久久大香线蕉| 久久ZYZ资源站无码中文动漫| 2021国产精品午夜久久 | 亚洲午夜久久久精品影院| 精品久久久久久无码免费| 精品久久久久久久久午夜福利| 伊色综合久久之综合久久| 久久99精品久久久久久不卡| 亚洲成色999久久网站| 91精品国产色综合久久| 久久成人国产精品二三区| 久久99精品久久久久久久久久| 欧美牲交A欧牲交aⅴ久久| 热re99久久精品国99热| 人妻精品久久久久中文字幕一冢本| 亚洲精品无码久久千人斩| 亚洲中文精品久久久久久不卡| 日韩乱码人妻无码中文字幕久久|