internal static void Execute(object msg, User user) { Msg_CR_GiveUpBattle gub_msg = msg as Msg_CR_GiveUpBattle; if (null == gub_msg) return; Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.StorySystem.SendMessage("mission_failed"); } }
internal static void Execute(object msg, User user) { Msg_CR_DlgClosed dialog_msg = msg as Msg_CR_DlgClosed; if (dialog_msg == null) return; Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.StorySystem.SendMessage("dialog_over:" + dialog_msg.dialog_id); } }
internal bool Init(uint pool_size) { pool_size_ = pool_size; free_size_ = pool_size_; data_pool_ = new User[pool_size]; for (uint i = 0; i < pool_size; ++i) { data_pool_[i] = new User(); data_pool_[i].LocalID = i; data_pool_[i].IsIdle = true; } this_lock_ = new object(); return true; }
internal void HandleClientMsg(int id, object msg, User user) { if (msg == null) { LogSys.Log(LOG_TYPE.ERROR, "{0}", "can't handle null msg"); return; } ClientMsgHandler handler; if (!client_msg_handlers_.TryGetValue(id, out handler)) { if (client_default_handler_ != null) { client_default_handler_(msg, user); } else { LogSys.Log(LOG_TYPE.ERROR, "{0}", "message no deal&default handler!"); } return; } if (handler != null) { handler(msg, user); } }
internal static void Execute(object msg, User user) { Msg_CR_Enter enter_msg = msg as Msg_CR_Enter; if (enter_msg == null) { return; } LogSys.Log(LOG_TYPE.DEBUG, "user {0}({1},{2},{3}) enter.", user.RoleId, user.GetKey(), user.Guid, user.Name); user.UserControlState = (int)UserControlState.User; user.IsEntered = true; Room room = user.OwnRoom; if (null != room) { Scene scene = room.ActiveScene; if (null != scene) { EntityInfo userInfo = user.Info; if (null != userInfo) { if (scene.SceneState == SceneState.Running) { scene.SyncForNewUser(user); scene.StorySystem.SendMessage("user_enter_scene", userInfo.GetId(), userInfo.GetUnitId(), userInfo.GetCampId(), userInfo.GetMovementStateInfo().PositionX, userInfo.GetMovementStateInfo().PositionZ); } } } } }
private void RemoveUser(User user, bool free) { if (user == null) { return; } foreach (User otheruser in room_users_) { if (null != otheruser && otheruser != user) { otheruser.RemoveSameRoomUser(user); } } user.ClearSameRoomUser(); if (null != m_ActiveScene) { Scene scene = m_ActiveScene; scene.LeaveScene(user); } LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for {1} {2}, [Room.RemoveUser]", user.LocalID, user.Guid, user.GetKey()); room_users_.Remove(user); if (free) { user_pool_.FreeUser(user.LocalID); } }
private void RemoveUser(User user) { RemoveUser(user, true); }
internal static void Execute(object msg, User user) { Msg_CR_SwitchDebug switchDebug = msg as Msg_CR_SwitchDebug; if (switchDebug == null) return; user.IsDebug = switchDebug.is_debug; }
internal static void Execute(object msg, User user) { Msg_CR_Skill use_skill = msg as Msg_CR_Skill; if (null == use_skill) return; EntityInfo userObj = user.Info; if (null == userObj) { LogSys.Log(LOG_TYPE.DEBUG, "UseSkillHandler, charactor {0}({1},{2},{3}) not exist", user.RoleId, user.GetKey(), user.Guid, user.Name); return; } Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { EntityInfo obj = scene.GetEntityById(use_skill.role_id); if (null != obj) { AiStateInfo aiInfo = obj.GetAiStateInfo(); if (use_skill.target_id > 0) { aiInfo.Target = use_skill.target_id; } else if (use_skill.target_dir > 0) { float dir = ProtoHelper.DecodeFloat(use_skill.target_dir); obj.GetMovementStateInfo().SetFaceDir(dir); aiInfo.Target = 0; } if (aiInfo.AiLogic == (int)AiStateLogicId.Entity_Leader) { AiData_Leader data = aiInfo.AiDatas.GetData<AiData_Leader>(); if (null == data) { data = new AiData_Leader(); aiInfo.AiDatas.AddData(data); } data.ManualSkillId = use_skill.skill_id; } else { AiData_General data = aiInfo.AiDatas.GetData<AiData_General>(); if (null == data) { data = new AiData_General(); aiInfo.AiDatas.AddData(data); } data.ManualSkillId = use_skill.skill_id; } aiInfo.ChangeToState((int)AiStateId.SkillCommand); } } }
internal void LeaveScene(User user) { EntityInfo info = user.Info; RemoveCareList(info); m_StorySystem.SendMessage("user_leave_scene", info.GetId(), info.GetUnitId(), info.GetCampId(), info.GetMovementStateInfo().PositionX, info.GetMovementStateInfo().PositionZ); user.SetHpArmor(info.Hp, info.Energy); user.HaveEnterPosition = false; user.IsEntered = false; info.NeedDelete = true; user.Info = null; }
internal void RemoveUserFromRoomThread(User user, bool free) { RemoveUser(user, free); }
private void SyncSceneObjectsToUser(User user) { if (null != user) { EntityInfo userInfo = user.Info; Room room = GetRoom(); if (null != userInfo && null != room && null != room.ActiveScene) { for (LinkedListNode<EntityInfo> linkNode = EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) { EntityInfo npc = linkNode.Value; if (null != npc) { Msg_RC_CreateNpc bder = DataSyncUtility.BuildCreateNpcMessage(npc); user.SendMessage(RoomMessageDefine.Msg_RC_CreateNpc, bder); Msg_RC_SyncProperty msg = DataSyncUtility.BuildSyncPropertyMessage(npc); user.SendMessage(RoomMessageDefine.Msg_RC_SyncProperty, msg); } } } } }
internal void AddSameRoomUser(User user) { peer_.AddSameRoomPeer(user.GetPeer()); }
internal static void Execute(object msg, User user) { Msg_CR_OperateMode modeMsg = msg as Msg_CR_OperateMode; if (null == modeMsg) return; EntityInfo userInfo = user.Info; if (null == userInfo) return; AiStateInfo aiInfo = userInfo.GetAiStateInfo(); AiData_Leader data = aiInfo.AiDatas.GetData<AiData_Leader>(); if (null == data) { data = new AiData_Leader(); aiInfo.AiDatas.AddData(data); } data.IsAutoOperate = modeMsg.isauto; }
internal void AddUser(User user, int roomId, MyAction<bool, int, User> callbackOnFinish) { AddUser(new User[] { user }, roomId, (bool ret, int sceneId, IList<User> users) => { if(users.Count>0) callbackOnFinish(ret, sceneId, users[0]); else callbackOnFinish(ret, sceneId, null); }); }
internal static void Execute(object msg, User user) { LogSys.Log(LOG_TYPE.DEBUG, "Unhandled msg {0} user {1}({2},{3},{4})!!!", msg.GetType(), user.RoleId, user.GetKey(), user.Guid, user.Name); }
internal void RemoveSameRoomUser(User user) { peer_.RemoveSameRoomPeer(user.GetPeer()); }
internal void RemoveCareMeUser(User user) { peer_.RemoveCareMePeer(user.GetPeer()); }
internal static void Execute(object msg, User user) { Msg_CR_GmCommand cmdMsg = msg as Msg_CR_GmCommand; if (cmdMsg == null) { return; } if (!GlobalVariables.Instance.IsDebug) return; Scene scene = user.OwnRoom.ActiveScene; if (scene != null) { switch (cmdMsg.type) { case 0: //resetdsl scene.GmStorySystem.Reset(); if (scene.GmStorySystem.GlobalVariables.ContainsKey("EntityInfo")) { scene.GmStorySystem.GlobalVariables["EntityInfo"] = user.Info; } else { scene.GmStorySystem.GlobalVariables.Add("EntityInfo", user.Info); } StorySystem.StoryConfigManager.Instance.Clear(); scene.StorySystem.ClearStoryInstancePool(); scene.StorySystem.PreloadSceneStories(); scene.StorySystem.StartStory("local_main"); scene.StorySystem.StartStory("story_main"); break; case 1: //script if (null != cmdMsg.content) { scene.GmStorySystem.Reset(); if (scene.GmStorySystem.GlobalVariables.ContainsKey("EntityInfo")) { scene.GmStorySystem.GlobalVariables["EntityInfo"] = user.Info; } else { scene.GmStorySystem.GlobalVariables.Add("EntityInfo", user.Info); } scene.GmStorySystem.LoadStory(cmdMsg.content); scene.GmStorySystem.StartStory("main"); } break; case 2: //command if (null != cmdMsg.content) { string cmd = cmdMsg.content; int stIndex = cmd.IndexOf('('); if (stIndex > 0) { #if DEBUG scene.GmStorySystem.Reset(); if (scene.GmStorySystem.GlobalVariables.ContainsKey("EntityInfo")) { scene.GmStorySystem.GlobalVariables["EntityInfo"] = user.Info; } else { scene.GmStorySystem.GlobalVariables.Add("EntityInfo", user.Info); } scene.GmStorySystem.LoadStoryText("script(main){onmessage(\"start\"){" + cmd + "}}"); scene.GmStorySystem.StartStory("main"); #else if (scene.GmStorySystem.GlobalVariables.ContainsKey("EntityInfo")) { scene.GmStorySystem.GlobalVariables["EntityInfo"] = user.Info; } else { scene.GmStorySystem.GlobalVariables.Add("EntityInfo", user.Info); } int edIndex = cmd.IndexOf(')'); if (edIndex > 0) { string msgId = cmd.Substring(0, stIndex); string[] args = cmd.Substring(stIndex + 1, edIndex - stIndex).Split(','); scene.GmStorySystem.SendMessage(msgId, args); } #endif } else { if (scene.GmStorySystem.GlobalVariables.ContainsKey("EntityInfo")) { scene.GmStorySystem.GlobalVariables["EntityInfo"] = user.Info; } else { scene.GmStorySystem.GlobalVariables.Add("EntityInfo", user.Info); } stIndex = cmd.IndexOf(' '); if (stIndex > 0) { string msgId = cmd.Substring(0, stIndex); string[] args = cmd.Substring(stIndex + 1).Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); scene.GmStorySystem.SendMessage(msgId, args); } else { scene.GmStorySystem.SendMessage(cmd); } } } break; } } }
internal static void SyncBuffListToUser(EntityInfo obj, User user) { List<ImpactInfo> impacts = obj.GetSkillStateInfo().GetAllImpact(); foreach (ImpactInfo info in impacts) { } }
internal static void Execute(object msg, User user) { Msg_CR_Quit quitClient = msg as Msg_CR_Quit; if (quitClient == null) return; if (null != user.OwnRoom) { if (quitClient.is_force) { user.OwnRoom.DeleteUser(user); } else { user.OwnRoom.DropUser(user); } } }
internal void AddCareMeUser(User user) { peer_.AddCareMePeer(user.GetPeer()); }
private void RemoveUserForChangeScene(Room room, User user, ulong userGuid, int roomId, int targetRoomId, PBChannel channel, int handle, uint seq) { Msg_RL_ChangeSceneResult replyBuilder = new Msg_RL_ChangeSceneResult(); EntityInfo info = user.Info; if (null != info) { replyBuilder.HP = info.Hp; replyBuilder.MP = info.Energy; } room.RemoveUserFromRoomThread(user, true); replyBuilder.UserGuid = userGuid; replyBuilder.RoomID = roomId; replyBuilder.TargetRoomID = targetRoomId; replyBuilder.Result = (int)SceneOperationResultEnum.Success; channel.Send(replyBuilder); }
internal static void Execute(object msg, User user) { Msg_CR_StopSkill stopMsg = msg as Msg_CR_StopSkill; if (null == stopMsg) return; EntityInfo userInfo = user.Info; if (null == userInfo) return; Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.SkillSystem.StopAllSkill(userInfo.GetId(), true); Msg_RC_NpcStopSkill retMsg = DataSyncUtility.BuildNpcStopSkillMessage(userInfo); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcStopSkill, retMsg); } }
private void SyncUserObjectToOtherUsers(User user) { if (null != user) { EntityInfo userInfo = user.Info; Msg_RC_CreateNpc bder = DataSyncUtility.BuildCreateNpcMessage(userInfo); Msg_RC_SyncProperty msg = DataSyncUtility.BuildSyncPropertyMessage(userInfo); Room room = GetRoom(); if (null != userInfo && null != room && null != room.ActiveScene) { for (LinkedListNode<EntityInfo> linkNode = EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) { EntityInfo npc = linkNode.Value; if (null != npc && npc != userInfo) { User other = npc.CustomData as User; if (null != other) { other.SendMessage(RoomMessageDefine.Msg_RC_CreateNpc, bder); other.SendMessage(RoomMessageDefine.Msg_RC_SyncProperty, msg); } } } } } }
internal static void Execute(object msg, User user) { Msg_CR_UserMoveToPos move_msg = msg as Msg_CR_UserMoveToPos; if (move_msg == null) return; EntityInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.DEBUG, "charactor {0}({1},{2},{3}) not exist", user.RoleId, user.GetKey(), user.Guid, user.Name); return; } /// if (charactor.GetAIEnable()) { float tx, tz; ProtoHelper.DecodePosition2D(move_msg.target_pos, out tx, out tz); ScriptRuntime.Vector3 pos = new ScriptRuntime.Vector3(tx, 0, tz); MovementStateInfo msi = charactor.GetMovementStateInfo(); msi.IsMoving = true; msi.TargetPosition = pos; float dir = Geometry.GetYRadian(msi.GetPosition3D(), pos); msi.SetFaceDir(dir); msi.SetMoveDir(dir); Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(charactor); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
internal void EnterScene(User newUser) { Msg_LR_RoomUserInfo lobbyUserData = newUser.LobbyUserData; if (null == lobbyUserData) return; TableConfig.Actor cfg = TableConfig.ActorProvider.Instance.GetActor(lobbyUserData.Hero); EntityInfo info = m_EntityMgr.AddEntity(0, lobbyUserData.Camp, cfg, (int)AiStateLogicId.Entity_Leader); info.SetUnitId(EntityInfo.c_StartUserUnitId + info.GetId()); info.GetMovementStateInfo().FormationIndex = 0; if (null != m_SceneConfig) { info.GetMovementStateInfo().SetPosition2D(m_SceneConfig.EnterX + (Helper.Random.NextFloat() - 0.5f) * m_SceneConfig.EnterRadius, m_SceneConfig.EnterY + (Helper.Random.NextFloat() - 0.5f) * m_SceneConfig.EnterRadius); } newUser.Info = info; AttrCalculator.Calc(info); if (newUser.HaveHpArmor) { info.SetHp(Operate_Type.OT_Absolute, newUser.Hp); info.SetEnergy(Operate_Type.OT_Absolute, newUser.Energy); } else { info.SetHp(Operate_Type.OT_Absolute, newUser.Info.GetActualProperty().HpMax); info.SetEnergy(Operate_Type.OT_Absolute, newUser.Info.GetActualProperty().EnergyMax); } info.SceneContext = m_SceneContext; AddCareList(info); if (newUser.IsEntered) { m_StorySystem.SendMessage("user_enter_scene", info.GetId(), info.GetUnitId(), info.GetCampId(), info.GetMovementStateInfo().PositionX, info.GetMovementStateInfo().PositionZ); } }
internal static void Execute(object msg, User user) { Msg_CRC_StoryMessage target_msg = msg as Msg_CRC_StoryMessage; if (target_msg == null) { return; } Scene scene = user.OwnRoom.ActiveScene; if (scene != null) { try { //�ͻ��˷�������Ϣ������ǰclient����ֱֹ�ӵ��÷�������������������Ϣ������clientǰ���� string msgId = string.Format("client:{0}", target_msg.m_MsgId); ArrayList args = new ArrayList(); args.Add(user.RoleId); for (int i = 0; i < target_msg.m_Args.Count; i++) { switch (target_msg.m_Args[i].val_type) { case ArgType.NULL://null args.Add(null); break; case ArgType.INT://int args.Add(int.Parse(target_msg.m_Args[i].str_val)); break; case ArgType.FLOAT://float args.Add(float.Parse(target_msg.m_Args[i].str_val)); break; default://string args.Add(target_msg.m_Args[i].str_val); break; } } object[] objArgs = args.ToArray(); scene.StorySystem.SendMessage(msgId, objArgs); } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_StoryMessage throw exception:{0}\n{1}", ex.Message, ex.StackTrace); } } }
internal void SyncForNewUser(User user) { if (null != user) { EntityInfo userInfo = user.Info; Room room = GetRoom(); if (null != userInfo && null != room && null != room.ActiveScene) { //发阵营给自己 Msg_RC_CampChanged msg = new Msg_RC_CampChanged(); msg.obj_id = 0; msg.camp_id = user.LobbyUserData.Camp; user.SendMessage(RoomMessageDefine.Msg_RC_CampChanged, msg); //同步场景数据给自己 SyncSceneObjectsToUser(user); SyncUserObjectToOtherUsers(user); } } }
internal void PickMoney(User user, int money) { Msg_RL_PickMoney builder = new Msg_RL_PickMoney(); builder.UserGuid = user.Guid; builder.Num = money; connector_.SendMsgToLobby(builder); }