private void OnAiSkill(EntityInfo npc, int skillId) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { SkillInfo skillInfo = npc.GetSkillStateInfo().GetCurSkillInfo(); if (null == skillInfo || !skillInfo.IsSkillActivated) { SkillInfo curSkillInfo = npc.GetSkillStateInfo().GetSkillInfoById(skillId); if (null != curSkillInfo) { long curTime = TimeUtility.GetLocalMilliseconds(); if (!curSkillInfo.IsInCd(curTime)) { if (scene.SkillSystem.StartSkill(npc.GetId(), curSkillInfo.ConfigData, 0)) { Msg_RC_NpcSkill skillBuilder = DataSyncUtility.BuildNpcSkillMessage(npc, skillId); LogSystem.Info("Send Msg_RC_NpcSkill, EntityId={0}, SkillId={1}", npc.GetId(), skillId); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcSkill, skillBuilder); } } } } } }
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); RoomUserManager roomUserMgr = GetRoomUserManager(); if (null != userInfo && null != roomUserMgr && null != roomUserMgr.ActiveScene) { for (LinkedListNode <EntityInfo> linkNode = EntityManager.Entities.FirstNode; 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); } } } } } }
public void ReloadObjects() { if (m_PreparedReloadMonsterCount > 0) { for (int i = 0; i < m_PreparedReloadMonsterCount; ++i) { TableConfig.LevelMonster monster = m_PreparedReloadMonsters[i]; if (null != monster) { int campId = monster.camp; int unitId = campId * 10000 + i; int objId = CreateEntity(unitId, monster.x, 0.0f, monster.y, monster.dir, campId, monster.actorID, monster.aiLogic, monster.aiParams.ToArray()); EntityInfo npc = GetEntityById(objId); if (null != npc) { npc.IsPassive = monster.passive; npc.LevelMonsterData = monster; npc.Level = monster.level; Msg_RC_CreateNpc msg = DataSyncUtility.BuildCreateNpcMessage(npc); NotifyAllUser(RoomMessageDefine.Msg_RC_CreateNpc, msg); Msg_RC_SyncProperty msg2 = DataSyncUtility.BuildSyncPropertyMessage(npc); NotifyAllUser(RoomMessageDefine.Msg_RC_SyncProperty, msg2); } } } m_PreparedReloadMonsterCount = 0; } while (m_ReloadMonstersQueue.Count > 0 && m_PreparedReloadMonsterCount < c_MaxReloadMonsterNum) { m_PreparedReloadMonsters[m_PreparedReloadMonsterCount++] = m_ReloadMonstersQueue.Dequeue(); } }
private void TickProperty() { for (LinkedListNode <EntityInfo> linkNode = EntityManager.Entities.FirstNode; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; if (!info.IsDead() && info.PropertyChanged) { info.PropertyChanged = false; Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info); NotifyAllUser(RoomMessageDefine.Msg_RC_SyncProperty, builder); } } }
private void MoveNpc(EntityInfo obj, long deltaTime) { if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition)) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving) { ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float speed = (float)obj.GetActualProperty().MoveSpeed; float distance = (speed * (float)(int)deltaTime) / 1000.0f; ScriptRuntime.Vector3 dir = msi.TargetDir; //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance); float x = 0, y = 0; if (msi.CalcDistancSquareToTarget() < distance * distance) { x = msi.TargetPosition.X; y = msi.TargetPosition.Z; ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y); msi.SetPosition2D(newPos); msi.IsMoving = false; User user = obj.CustomData as User; if (null != user) { Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(obj); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } } else { ScriptRuntime.Vector3 tpos = pos + dir * distance; msi.SetPosition(tpos); } } }
private void OnAiStopSkill(EntityInfo npc) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { SkillInfo skillInfo = npc.GetSkillStateInfo().GetCurSkillInfo(); if (null == skillInfo || skillInfo.IsSkillActivated) { scene.SkillSystem.StopAllSkill(npc.GetId(), true); } Msg_RC_NpcStopSkill skillBuilder = DataSyncUtility.BuildNpcStopSkillMessage(npc); LogSystem.Info("Send Msg_RC_NpcStopSkill, EntityId={0}", npc.GetId()); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcStopSkill, skillBuilder); } }
private void OnAiStopPursue(EntityInfo npc) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { npc.GetMovementStateInfo().IsMoving = false; if (npc.GetMovementStateInfo().IsMoveStatusChanged) { npc.GetMovementStateInfo().IsMoveStatusChanged = false; Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc); if (null != npcMoveBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
public void SyncForNewObserver(Observer observer) { if (null != observer) { RoomUserManager roomUserMgr = GetRoomUserManager(); if (null != roomUserMgr && null != roomUserMgr.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); observer.SendMessage(RoomMessageDefine.Msg_RC_CreateNpc, bder); } } } } }
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 ReloadObjects() { if (m_PreparedReloadMonsterCount > 0) { for (int i = 0; i < m_PreparedReloadMonsterCount; ++i) { TableConfig.LevelMonster monster = m_PreparedReloadMonsters[i]; if (null != monster) { int campId = monster.camp; TableConfig.Actor actor = TableConfig.ActorProvider.Instance.GetActor(monster.actorID); if (null != actor) { int unitId = campId * 10000 + i; EntityInfo npc = EntityManager.AddEntity(unitId, campId, actor, (int)AiStateLogicId.Entity_General); if (null != npc) { npc.IsPassive = monster.passive; npc.LevelMonsterData = monster; npc.SetLevel(monster.level); npc.GetMovementStateInfo().SetPosition2D(monster.x, monster.y); npc.GetMovementStateInfo().SetFaceDir(monster.dir); Msg_RC_CreateNpc msg = DataSyncUtility.BuildCreateNpcMessage(npc); NotifyAllUser(RoomMessageDefine.Msg_RC_CreateNpc, msg); Msg_RC_SyncProperty msg2 = DataSyncUtility.BuildSyncPropertyMessage(npc); NotifyAllUser(RoomMessageDefine.Msg_RC_SyncProperty, msg2); } } } } m_PreparedReloadMonsterCount = 0; } while (m_ReloadMonstersQueue.Count > 0 && m_PreparedReloadMonsterCount < c_MaxReloadMonsterNum) { m_PreparedReloadMonsters[m_PreparedReloadMonsterCount++] = m_ReloadMonstersQueue.Dequeue(); } }
public 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.OwnRoomUserManager.ActiveScene; if (null != scene) { Msg_RC_NpcStopSkill retMsg = DataSyncUtility.BuildNpcStopSkillMessage(userInfo); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcStopSkill, retMsg); } }
public 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.OwnRoomUserManager.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 = use_skill.target_dir; obj.GetMovementStateInfo().SetFaceDir(dir); aiInfo.Target = 0; } Msg_RC_NpcSkill retMsg = DataSyncUtility.BuildNpcSkillMessage(obj, use_skill.skill_id); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcSkill, retMsg); } } }
private void SyncSceneObjectsToUser(User user) { if (null != user) { EntityInfo userInfo = user.Info; RoomUserManager roomUserMgr = GetRoomUserManager(); if (null != userInfo && null != roomUserMgr && null != roomUserMgr.ActiveScene) { for (LinkedListNode <EntityInfo> linkNode = EntityManager.Entities.FirstNode; 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 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 OnAiFace(EntityInfo npc) { if (npc.GetMovementStateInfo().IsFaceDirChanged) { npc.GetMovementStateInfo().IsFaceDirChanged = false; if (null != npc) { float dir = npc.GetMovementStateInfo().GetFaceDir(); npc.GetMovementStateInfo().SetFaceDir(dir); } if (!npc.GetMovementStateInfo().IsMoving) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { Msg_RC_NpcFace npcFaceBuilder = DataSyncUtility.BuildNpcFaceMessage(npc); if (null != npcFaceBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcFace, npcFaceBuilder); } } } } }
private void OnAiPursue(EntityInfo npc, ScriptRuntime.Vector3 target) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { npc.GetMovementStateInfo().TargetPosition = target; float dir = Geometry.GetYRadian(npc.GetMovementStateInfo().GetPosition3D(), target); npc.GetMovementStateInfo().SetFaceDir(dir); npc.GetMovementStateInfo().SetMoveDir(dir); npc.GetMovementStateInfo().IsMoving = true; if (npc.GetMovementStateInfo().IsMoveStatusChanged) { npc.GetMovementStateInfo().IsMoveStatusChanged = false; Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc); if (null != npcMoveBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
private void TickEntities() { m_DeletedEntities.Clear(); for (LinkedListNode <EntityInfo> linkNode = m_EntityMgr.Entities.FirstNode; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; info.RetireAttackerInfos(60000); if (info.LevelChanged || info.GetSkillStateInfo().BuffChanged) { AttrCalculator.Calc(info); info.LevelChanged = false; info.GetSkillStateInfo().BuffChanged = false; } if (info.IsBorning) { if (info.BornTime <= 0) { SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(info.BornSkillId); if (info.BornSkillId > 0 && null != skillInfo) { info.BornTime = TimeUtility.GetLocalMilliseconds(); } else { info.IsBorning = false; info.BornTime = 0; info.SetAIEnable(true); info.RemoveState(CharacterPropertyEnum.x3009_无敌); } } else if (info.BornTime + info.BornTimeout < TimeUtility.GetLocalMilliseconds()) { info.IsBorning = false; info.BornTime = 0; info.SetAIEnable(true); info.RemoveState(CharacterPropertyEnum.x3009_无敌); } } if (info.IsDead() && !info.NeedDelete) { if (info.DeadTime <= 0) { CalcKillIncome(info); //发送npc死亡消息 Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead(); npcDeadBuilder.npc_id = info.GetId(); NotifyAllUser(RoomMessageDefine.Msg_RC_NpcDead, npcDeadBuilder); SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(info.DeadSkillId); if (info.DeadSkillId > 0 && null != skillInfo) { info.DeadTime = TimeUtility.GetLocalMilliseconds(); OnEntityKilled(info); } else { if (null == info.CustomData as User) { info.DeadTime = 0; info.NeedDelete = true; OnEntityKilled(info); } else { info.DeadTime = TimeUtility.GetLocalMilliseconds(); } } } else { if (null == info.CustomData as User && info.DeadTime + info.DeadTimeout < TimeUtility.GetLocalMilliseconds()) { info.DeadTime = 0; info.NeedDelete = true; //重新发送npc死亡消息 Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead(); npcDeadBuilder.npc_id = info.GetId(); NotifyAllUser(RoomMessageDefine.Msg_RC_NpcDead, npcDeadBuilder); } else if (null != info.CustomData as User && info.DeadTime + info.ReliveTimeout < TimeUtility.GetLocalMilliseconds()) { info.DeadTime = 0; info.Hp = info.HpMax; info.Energy = info.EnergyMax; Msg_RC_SyncProperty npcProp = DataSyncUtility.BuildSyncPropertyMessage(info); NotifyAllUser(RoomMessageDefine.Msg_RC_SyncProperty, npcProp); } } } if (info.NeedDelete) { m_DeletedEntities.Add(info); } } if (m_DeletedEntities.Count > 0) { int enemyCt = 0; int friendCt = 0; Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc(); for (int i = 0; i < m_DeletedEntities.Count; ++i) { EntityInfo ni = m_DeletedEntities[i]; if (CharacterRelation.RELATION_ENEMY == EntityInfo.GetRelation((int)CampIdEnum.Blue, ni.GetCampId())) { ++enemyCt; } else if (CharacterRelation.RELATION_FRIEND == EntityInfo.GetRelation((int)CampIdEnum.Blue, ni.GetCampId())) { ++friendCt; } //发送npc消失消息 destroyNpcBuilder.npc_id = ni.GetId(); NotifyAllUser(RoomMessageDefine.Msg_RC_DestroyNpc, destroyNpcBuilder); DestroyEntity(ni); } TryAllKilledOrAllDied(enemyCt > 0, friendCt > 0); } m_EntityMgr.ExecuteDelayAdd(); }