副本是游戏的重要部分,主要是玩家刷怪刷和获取奖励的地方。
副本服务器常常会以一个服务器进程的形式存在,如世界副本、房间副本,优点是可以减少副本出错的影响和减少单进程的负载,缺点是角色跨进程存在时间消耗。
副本类型可分为动态副本和静态副本。动态副本是副本对象动态创建和销毁。静态副本则在进程启动时就创建,直到进程结束。
本文目录:
1、地图配置
(1)地图配置的读取
2、副本配置3、副本逻辑循环
(1)副本管理器的状态机
(2)房间状态机
4、副本房间管理
(1)创建副本房间
(2)查找副本房间
5、角色进入副本
(1)社会关系服务器处理消息
(2)场景服务器处理消息
(3)玩家进入副本具体检查
(4)处理进入的玩家
本文内容:
1、地图配置
(1)地图配置的读取
地图配置加载是加载到地图管理器。
地图的配置格式是xml,内容大致如下:
配置的是地图中文名、拼音、大小、进入要求和进入消耗资源。
<!-- maptype:1(普通地图),2(黄金怪地图),4(恶魔广场地图),8(pk地图),16(血色城堡),32(战盟地盘),64(赤色要塞),128(战盟领地) -->
<mapinfo>
<map id="1" name="勇者大陆" filename="yongzhedalu" xmlname="yongzhedalu" width="616" height="432" function="16" checklevel="1" needmoney="35" maptype="3"/>
<map id="2" name="地下城1" filename="dixiacheng1" xmlname="dixiacheng1" width="384" height="224" function="16" checklevel="30" needmoney="1440" maptype="3"/>
<map id="3" name="地下城2" filename="dixiacheng2" xmlname="dixiacheng2" width="568" height="384" function="16" checklevel="40" needmoney="2160" maptype="3"/>
<map id="4" name="地下城3" filename="dixiacheng3" xmlname="dixiacheng3" width="304" height="160" function="16" checklevel="50" needmoney="2880" maptype="3"/>
<map id="5" name="亚特兰蒂斯" filename="yatelandisi" xmlname="yatelandisi" width="594" height="454" function="16" checklevel="70" needmoney="2880" maptype="3"/>
...
<mapinfo>
2、副本配置
副本配置含有一些定时器、进入副本的条件(物品、金钱、等级)、掉落物品等。对于爬塔类有层数。
<!-- 注释
hour ,min = 开启时间,小时和分钟
mapId 地图id
mapName 地图名称
level 限制等级
needGold 进入需要金币
-->
<!-- 注释flag:0保留不使用;1交宝物奖励;2副本胜利奖;3副本失败奖励 -->
<!--maptype:地图类型 copylift:副本时间(分钟) entertime:进场时间 npcwave:一波npc时间-->
<opentime>
<timer maptype="4" hour="9" min="0" interval="0"/>
<timer maptype="4" hour="12" min="0" interval="0"/>
<timer maptype="4" hour="15" min="0" interval="0"/>
<timer maptype="4" hour="18" min="0" interval="0"/>
...
</opentime>
<copytime>
<!--地图类型 活动时间 公告时间长度 进场时间 准备时间 npc加载时间>
<tiptime maptype="4" copylift="15" noticetime="3" entertime="2" preptime="1" npcwave="5"/>
<tiptime maptype="16" copylift="10" noticetime="3" entertime="2" preptime="1" npcwave="1"/>
<tiptime maptype="64" copylift="15" noticetime="3" entertime="2" preptime="1" npcwave="1"/>
</copytime>
<entermap>
<condition mapid="51" smalllevel="50" maxlevel="100" needgold="50" needitem="100587" entermoney="0" playernum="15" floor="1" maptype="16"/>
<condition mapid="53" smalllevel="101" maxlevel="150" needgold="60" needitem="100588" entermoney="0" playernum="15" floor="2" maptype="16"/>
<condition mapid="55" smalllevel="151" maxlevel="200" needgold="70" needitem="100589" entermoney="0" playernum="15" floor="3" maptype="16"/>
<condition mapid="57" smalllevel="201" maxlevel="250" needgold="80" needitem="100590" entermoney="0" playernum="15" floor="4" maptype="16"/>
<condition mapid="59" smalllevel="251" maxlevel="300" needgold="90" needitem="100591" entermoney="0" playernum="15" floor="5" maptype="16"/>
......
3、副本逻辑循环
副本的逻辑循环是以副本状态机来实现。
(1)副本管理器的状态机
副本管理器的状态机,可以拓展处理管理器的资源加载和销毁
void copyscene_manager::csManageLoop(uint32 &group)
{
switch(csManageState)
{
case CSManageState_None:
{
csManageState = CSManageState_WorkLogic;
}
break;
case CSManageState_WorkLogic:
{
roomManagerLoop(group);
}
break;
case CSManageState_End:
{
}
break;
default:
break;
}
}
(2)房间状态机
副本状态机的逻辑循环,处理副本的具体逻辑。
这里是以
void copyscene_manager::roomManagerLoop(uint32 &group)
{
// 如果没有副本地图直接返回
if(getCopySceneMapCnt() <= 0)
{
return;
}
switch(roomManagerState)
{
case RoomState_None:
{
roomManagerState = RoomState_Create;
}
break;
case RoomState_Create://创建副本