private void TickPreloading() { long curTime = TimeUtility.GetServerMilliseconds(); if (m_LastPreloadingTickTime + c_PreloadingTickInterval < curTime) { m_LastPreloadingTickTime = curTime; bool canStart = true; foreach (User us in m_Room.RoomUsers) { if (!us.IsEntered && !us.IsTimeout()) { canStart = false; } } if (canStart) { LoadObjects(); CalculateDropOut(); m_StorySystem.StartStory(1); for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next) { UserInfo user = linkNode.Value; UserAttrCalculator.Calc(user); user.LevelChanged = false; user.SetHp(Operate_Type.OT_Absolute, user.GetActualProperty().HpMax); user.SetEnergy(Operate_Type.OT_Absolute, user.GetActualProperty().EnergyMax); } //先让各客户端创建自己与场景相关信息 foreach (User us in m_Room.RoomUsers) { if (us.IsEntered) { SyncUserToSelf(us); SyncSceneObjectsToUser(us); } } //再通知其他客户端看见自己 foreach (User us in m_Room.RoomUsers) { if (us.IsEntered) { SyncUserToOthers(us); } } //给观察者发初始玩家与场景对象信息 foreach (Observer observer in m_Room.RoomObservers) { if (null != observer && !observer.IsIdle && observer.IsEntered) { SyncForNewObserver(observer); } } } } }
internal void OnUserRevive(Msg_LR_UserReLive msg) { User user = m_Room.GetUserByGuid(msg.UserGuid); if (null != user) { UserInfo info = user.Info; info.SetHp(Operate_Type.OT_Absolute, info.GetActualProperty().HpMax); info.SetEnergy(Operate_Type.OT_Absolute, info.GetActualProperty().EnergyMax); info.DeadTime = 0; DataSyncUtility.SyncUserPropertyToCaredUsers(info); DataSyncUtility.SyncUserReliveToCaredUsers(info); } }
public void StartGame() { UserInfo user = GetPlayerSelf(); if (null != user) { EntityManager.Instance.DestroyUserView(user.GetId()); DestroyCharacterById(user.GetId()); } user = CreatePlayerSelf(1, NetworkSystem.Instance.HeroId); user.SetCampId(NetworkSystem.Instance.CampId); Data_Unit unit = m_CurScene.StaticData.ExtractData(DataMap_Type.DT_Unit, GlobalVariables.GetUnitIdByCampId(NetworkSystem.Instance.CampId)) as Data_Unit; if (null != unit) { user.GetMovementStateInfo().SetPosition(unit.m_Pos); user.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle); user.SetHp(Operate_Type.OT_Absolute, user.GetActualProperty().HpMax); } EntityManager.Instance.CreatePlayerSelfView(1); UserView view = EntityManager.Instance.GetUserViewById(1); if (null != view) { view.Visible = true; } foreach (Data_Unit npcUnit in m_CurScene.StaticData.m_UnitMgr.GetData().Values) { if (npcUnit.m_IsEnable) { NpcInfo npc = m_NpcMgr.GetNpcInfoByUnitId(npcUnit.GetId()); if (null == npc) { npc = m_NpcMgr.AddNpc(npcUnit); } if (null != npc) { EntityManager.Instance.CreateNpcView(npc.GetId()); } } } GfxSystem.PublishGfxEvent("ge_on_game_start", "story"); LogSystem.Debug("start game"); }
public void ChangeHero() { UserInfo user = GetPlayerSelf(); if (null != user) { Vector3 pos = user.GetMovementStateInfo().GetPosition3D(); float dir = user.GetMovementStateInfo().GetFaceDir(); int hp = user.Hp; int rage = user.Rage; EntityManager.Instance.DestroyUserView(user.GetId()); DestroyCharacterById(user.GetId()); NetworkSystem.Instance.HeroId = (NetworkSystem.Instance.HeroId + 1) % 4; if (NetworkSystem.Instance.HeroId == 0) { NetworkSystem.Instance.HeroId = 1; } user = CreatePlayerSelf(1, NetworkSystem.Instance.HeroId); user.SetCampId(NetworkSystem.Instance.CampId); /*Data_Unit unit = m_CurScene.StaticData.ExtractData(DataMap_Type.DT_Unit, GlobalVariables.GetUnitIdByCampId(NetworkSystem.Instance.CampId)) as Data_Unit; * if (null != unit) { * user.GetMovementStateInfo().SetPosition(unit.m_Pos); * user.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle); * user.SetHp(Operate_Type.OT_Absolute, 1000); * }*/ user.GetMovementStateInfo().SetPosition(pos); user.GetMovementStateInfo().SetFaceDir(dir); user.SetHp(Operate_Type.OT_Absolute, hp); user.SetRage(Operate_Type.OT_Absolute, rage); EntityManager.Instance.CreatePlayerSelfView(1); UserView view = EntityManager.Instance.GetUserViewById(1); if (null != view) { view.Visible = true; } } }
private void OnLoadFinish() { if (WorldSystem.Instance.IsObserver) { UserInfo myself = WorldSystem.Instance.CreatePlayerSelf(0x0ffffffe, 1); if (null != myself)//观战客户端创建一个虚拟玩家(不关联view,血量不要为0,主要目的是为了适应客户端代码里对主角的判断) { myself.SetLevel(16); myself.SetHp(Operate_Type.OT_Absolute, 999999); } NotifyUserEnter(); } if (WorldSystem.Instance.IsObserver) { DashFireMessage.Msg_CR_Observer build = new DashFireMessage.Msg_CR_Observer(); NetworkSystem.Instance.SendMessage(build); LogSystem.Debug("send Msg_CR_Observer to roomserver"); } else if (WorldSystem.Instance.IsPveScene()) { //单机游戏逻辑启动 WorldSystem.Instance.StartGame(); NotifyUserEnter(); } else { DashFireMessage.Msg_CRC_Create build = new DashFireMessage.Msg_CRC_Create(); NetworkSystem.Instance.SendMessage(build); LogSystem.Debug("send Msg_CRC_Create to roomserver"); } GfxSystem.GfxLog("SceneResource.OnLoadFinish"); m_IsWaitSceneLoad = false; GfxSystem.PublishGfxEvent("ge_loading_finish", "ui"); }
private void TickRecover() { float hp_coefficient = 1.0f; float mp_coefficient = 1.0f; Data_SceneConfig scene_data = SceneConfigProvider.Instance.GetSceneConfigById(m_SceneResId); if (null != scene_data) { hp_coefficient = scene_data.m_RecoverHpCoefficient; mp_coefficient = scene_data.m_RecoverMpCoefficient; } for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next) { UserInfo info = linkNode.Value; if (!info.IsDead()) { float hpRecover = info.GetActualProperty().HpRecover *hp_coefficient; float epRecover = info.GetActualProperty().EnergyRecover *mp_coefficient; if (hpRecover > 0.0001) { if (info.Hp + (int)hpRecover >= info.GetActualProperty().HpMax) { info.SetHp(Operate_Type.OT_Absolute, (int)info.GetActualProperty().HpMax); } else { info.SetHp(Operate_Type.OT_Relative, (int)hpRecover); } } if (epRecover > 0.0001) { if (info.Energy + (int)epRecover >= info.GetActualProperty().EnergyMax) { info.SetEnergy(Operate_Type.OT_Absolute, (int)info.GetActualProperty().EnergyMax); } else { info.SetEnergy(Operate_Type.OT_Relative, (int)epRecover); } } if (hpRecover > 0.0001 || epRecover > 0.0001) { Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info); NotifyAreaUser(info, builder, false); } } } for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next) { NpcInfo info = linkNode.Value; if (!info.IsDead()) { float hpRecover = info.GetActualProperty().HpRecover; float npRecover = info.GetActualProperty().EnergyRecover; if (hpRecover > 0.0001) { if (info.Hp + (int)hpRecover >= info.GetActualProperty().HpMax) { info.SetHp(Operate_Type.OT_Absolute, (int)info.GetActualProperty().HpMax); } else { info.SetHp(Operate_Type.OT_Relative, (int)hpRecover); } } if (npRecover > 0.0001) { if (info.Energy + (int)npRecover >= info.GetActualProperty().EnergyMax) { info.SetEnergy(Operate_Type.OT_Absolute, (int)info.GetActualProperty().EnergyMax); } else { info.SetEnergy(Operate_Type.OT_Relative, (int)npRecover); } } if (hpRecover > 0.0001 || npRecover > 0.0001) { Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info); NotifyAreaUser(info, builder, false); } } } }