private FightRoomDTO fightRoomDTO = null;//缓存战斗房间信息 /// <summary> /// 处理网络消息 /// </summary> /// <param name="sm"></param> public override void OnMessageReceived(SocketModel sm) { switch (sm.command) { case FightProtocol.START_BRO: fightRoomDTO = sm.GetMessage <FightRoomDTO>(); CreateBattelField(fightRoomDTO); Debug.LogError("收到创建战场信息"); break; case FightProtocol.ATK_TO_POS_SCMD: PosDTO atkToPosDTO = sm.GetMessage <PosDTO>(); MgrCenter.Instance.SendMsg(Msgs.GetMsgPos((ushort)SoilderFightEvent.SoilderAtkToPosServerCmd, atkToPosDTO)); break; case FightProtocol.MOVE_TARGET_SRES: PosDTO moveToTargetDTO = sm.GetMessage <PosDTO>(); MgrCenter.Instance.SendMsg(Msgs.GetMsgPos((ushort)MoveEvent.MoveServerRes, moveToTargetDTO)); break; case FightProtocol.SKILL_UP_SRES: break; case FightProtocol.POS_SYNC_BRO: PosSyncDTO posSyncDTO = sm.GetMessage <PosSyncDTO>(); //得到的PosSync是服务器处理时认可的服务器时间 //这里将它转化成client认可的时间 //floating = client - server //client = server + floating long timeStampClient = GetTimeStampClient(posSyncDTO.timeStamp); MgrCenter.Instance.SendMsg(Msgs.GetMsgPosSync((ushort)MoveEvent.PosSync, posSyncDTO.instanceId, new Vector3(posSyncDTO.x, posSyncDTO.y, posSyncDTO.z), new Vector3(posSyncDTO.dirX, posSyncDTO.dirY, posSyncDTO.dirZ), timeStampClient)); break; case FightProtocol.SKILL_BRO: break; case FightProtocol.ATTACK_BRO: break; case FightProtocol.DAMAGE_BRO: Damage(sm.GetMessage <DamageDTO>()); break; case FightProtocol.IDLE_BRO: int idleEntityId = sm.GetMessage <int>(); MgrCenter.Instance.SendMsg(Msgs.GetMsgInt((ushort)SoilderFightEvent.SoilderIdleServerAllow, idleEntityId)); break; } }
/// <summary> /// 创建战场所需的entity和建筑entity /// </summary> /// <param name="fightRoomDTO"></param> private void CreateBattelField(FightRoomDTO fightRoomDTO) { foreach (BuildingInstance building in fightRoomDTO.buildingEntities) { SendMsg(Msgs.GetMsgBuildingCreate((ushort)EntityEnum.CreateBuilding, building, fightRoomDTO.isHost)); } foreach (AbsFightInstance creature in fightRoomDTO.entities) { SendMsg(Msgs.GetMsgNPCCreate((ushort)EntityEnum.CreateEntity, creature, fightRoomDTO.isHost)); } }