private void OnCreateEntity(EntityInfo entity) { if (null != entity) { StorySystem.SendMessage("obj_created", entity.GetId()); StorySystem.SendMessage(string.Format("npc_created:{0}", entity.GetUnitId()), entity.GetId()); } }
private void OnAiAddImpact(EntityInfo entity, int impactId) { ImpactInfo impactInfo = new ImpactInfo(impactId); impactInfo.StartTime = TimeUtility.GetLocalMilliseconds(); impactInfo.ImpactSenderId = entity.GetId(); impactInfo.SkillId = 0; if (null != impactInfo.ConfigData) { entity.GetSkillStateInfo().AddImpact(impactInfo); int seq = impactInfo.Seq; if (GfxSkillSystem.Instance.StartSkill(entity.GetId(), impactInfo.ConfigData, seq)) { } } }
internal static Msg_RC_NpcFace BuildNpcFaceMessage(EntityInfo npc) { Msg_RC_NpcFace npcFaceBuilder = new Msg_RC_NpcFace(); npcFaceBuilder.npc_id = npc.GetId(); npcFaceBuilder.face_direction = ProtoHelper.EncodeFloat(npc.GetMovementStateInfo().GetFaceDir()); return npcFaceBuilder; }
internal static Msg_RC_NpcMove BuildNpcMoveMessage(EntityInfo npc) { ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); Msg_RC_NpcMove npcMoveBuilder = new Msg_RC_NpcMove(); if (npc.GetMovementStateInfo().IsMoving) { npcMoveBuilder.npc_id = npc.GetId(); npcMoveBuilder.velocity = ProtoHelper.EncodeFloat(npc.GetActualProperty().MoveSpeed); ScriptRuntime.Vector3 targetPos = npc.GetMovementStateInfo().TargetPosition; npcMoveBuilder.target_pos = ProtoHelper.EncodePosition2D(targetPos.X, targetPos.Z); npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z); } else { npcMoveBuilder.npc_id = npc.GetId(); npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z); } return npcMoveBuilder; }
internal static Msg_RC_CampChanged BuildCampChangedMessage(EntityInfo obj) { Msg_RC_CampChanged msg = new Msg_RC_CampChanged(); msg.obj_id = obj.GetId(); msg.camp_id = obj.GetCampId(); return msg; }
internal static Msg_RC_CreateNpc BuildCreateNpcMessage(EntityInfo npc, int rate = -1) { Msg_RC_CreateNpc bder = new Msg_RC_CreateNpc(); bder.npc_id = npc.GetId(); bder.unit_id = npc.GetUnitId(); ScriptRuntime.Vector3 pos = npc.GetMovementStateInfo().GetPosition3D(); GameFrameworkMessage.Position pos_bd = new GameFrameworkMessage.Position(); pos_bd.x = (float)pos.X; pos_bd.z = (float)pos.Z; bder.cur_pos = pos_bd; bder.face_direction = (float)npc.GetMovementStateInfo().GetFaceDir(); bder.link_id = npc.GetLinkId(); bder.camp_id = npc.GetCampId(); if (npc.OwnerId > 0) { bder.owner_id = npc.OwnerId; } if (npc.GetAiStateInfo().LeaderID > 0) { bder.leader_id = npc.GetAiStateInfo().LeaderID; } User user = npc.CustomData as User; if (null != user) { bder.key = user.GetKey(); } bder.level = npc.GetLevel(); return bder; }
private void OnAiFace(EntityInfo entity) { if (null != entity && entity.EntityType != (int)EntityTypeEnum.Tower) { float dir = entity.GetMovementStateInfo().GetFaceDir(); GameObject actor = EntityController.Instance.GetGameObject(entity.GetId()); actor.transform.localRotation = Quaternion.Euler(0, Utility.RadianToDegree(dir), 0); } }
private void OnAiAddImpact(EntityInfo npc, int impactId) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { ImpactInfo impactInfo = new ImpactInfo(impactId); impactInfo.StartTime = TimeUtility.GetLocalMilliseconds(); impactInfo.ImpactSenderId = npc.GetId(); impactInfo.SkillId = 0; if (null != impactInfo.ConfigData) { npc.GetSkillStateInfo().AddImpact(impactInfo); int seq = impactInfo.Seq; if (scene.SkillSystem.StartSkill(npc.GetId(), impactInfo.ConfigData, seq)) { Msg_RC_AddImpact addImpactBuilder = new Msg_RC_AddImpact(); addImpactBuilder.sender_id = npc.GetId(); addImpactBuilder.target_id = npc.GetId(); addImpactBuilder.impact_id = impactId; addImpactBuilder.skill_id = -1; addImpactBuilder.duration = impactInfo.DurationTime; scene.NotifyAllUser(RoomMessageDefine.Msg_RC_AddImpact, addImpactBuilder); } } } }
internal static Msg_RC_NpcSkill BuildNpcSkillMessage(EntityInfo obj, int skillId) { MovementStateInfo msi = obj.GetMovementStateInfo(); ScriptRuntime.Vector3 pos = msi.GetPosition3D(); Msg_RC_NpcSkill msg = new Msg_RC_NpcSkill(); msg.npc_id = obj.GetId(); msg.skill_id = skillId; msg.stand_pos = ProtoHelper.EncodePosition2D(pos.X, pos.Z); msg.face_direction = ProtoHelper.EncodeFloat(msi.GetFaceDir()); msg.target_id = obj.GetAiStateInfo().Target; return msg; }
public EntityInfo AddEntity(int id, int unitId, int camp, TableConfig.Actor cfg, string ai, params string[] aiParams) { if (m_Entities.Contains(id)) { LogSystem.Warn("duplicate entity {0} !!!", id); return(null); } EntityInfo entity = NewEntityInfo(id); entity.SceneContext = m_SceneContext; entity.LoadData(unitId, camp, cfg, ai, aiParams); entity.IsBorning = true; entity.BornTime = 0; entity.SetAIEnable(false); m_Entities.AddLast(entity.GetId(), entity); return(entity); }
private void AttachAiLogic(EntityInfo npc) { AiStateInfo aiInfo = npc.GetAiStateInfo(); string storyId = aiInfo.AiLogic; string storyFile = aiInfo.AiParam[0]; if (!string.IsNullOrEmpty(storyId) && !string.IsNullOrEmpty(storyFile)) { aiInfo.HomePos = npc.GetMovementStateInfo().GetPosition3D(); aiInfo.ChangeToState((int)PredefinedAiStateId.Idle); aiInfo.AiStoryInstanceInfo = GfxStorySystem.Instance.NewAiStoryInstance(storyId, string.Empty, storyFile); if (null != aiInfo.AiStoryInstanceInfo) { aiInfo.AiStoryInstanceInfo.m_StoryInstance.SetVariable("@objid", npc.GetId()); aiInfo.AiStoryInstanceInfo.m_StoryInstance.Start(); } } }
public int CreateEntity(int unitId, float x, float y, float z, float dir, int camp, int linkId, string ai, params string[] aiParams) { int objId = 0; TableConfig.Actor cfg = TableConfig.ActorProvider.Instance.GetActor(linkId); if (null != cfg) { EntityInfo entity = m_EntityMgr.AddEntity(unitId, camp, cfg, ai, aiParams); if (null != entity) { entity.GetMovementStateInfo().SetPosition(x, y, z); entity.GetMovementStateInfo().SetFaceDir(dir); objId = entity.GetId(); OnCreateEntity(entity); } } return(objId); }
public void Create(EntityInfo entity) { if (null != entity) { m_Entity = entity; MovementStateInfo msi = m_Entity.GetMovementStateInfo(); ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float dir = msi.GetFaceDir(); CreateActor(m_Entity.GetId(), m_Entity.GetModel(), pos.X, pos.Y, pos.Z, dir, m_Entity.Scale, m_Entity.GetRadius(), entity.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度)); if (null != Actor) { m_Agent = Actor.GetComponent <NavMeshAgent>(); if (m_Agent == null) { m_Agent = Actor.AddComponent <NavMeshAgent>(); m_Agent.angularSpeed = c_AngularSpeed; m_Agent.acceleration = c_Acceleration; m_Agent.radius = entity.GetRadius(); m_Agent.speed = entity.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度); m_Agent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; } m_Animator = Actor.GetComponentInChildren <Animator>(); EntityDrawGizmos gizmos = Actor.GetComponent <EntityDrawGizmos>(); if (null == gizmos) { gizmos = Actor.AddComponent <EntityDrawGizmos>(); gizmos.npcInfo = m_Entity; } else { gizmos.npcInfo = m_Entity; } SetMoveAgentEnable(true); try{ if (null != m_Agent) { m_Agent.ResetPath(); } } catch { m_Agent.enabled = true; } } } }
private void RefreshRoomScene() { LogSystem.Warn("ClientModule.RefreshRoomScene Destory Objects..."); for (LinkedListNode <EntityInfo> linkNode = m_EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; if (null != info) { EntityViewModelManager.Instance.DestroyEntityView(info.GetId()); } } LogSystem.Warn("ClientModule.RefreshRoomScene Destory Objects Finish."); m_EntityManager.Reset(); GameFrameworkMessage.Msg_CR_Enter build = new GameFrameworkMessage.Msg_CR_Enter(); NetworkSystem.Instance.SendMessage(RoomMessageDefine.Msg_CR_Enter, build); LogSystem.Warn("RefreshRoomScene send Msg_CR_Enter to roomserver"); }
internal static void DoMoveCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic) { //执行状态处理 AiData_ForMoveCommand data = GetAiDataForMoveCommand(entity); if (null == data) { return; } if (!data.IsFinish) { if (WayPointArrived(entity, data)) { Vector3 targetPos = new Vector3(); MoveToNext(entity, data, ref targetPos); if (!data.IsFinish) { logic.NotifyAiPursue(entity, targetPos); } } else { AiStateInfo info = entity.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 500) { info.Time = 0; Vector3 targetPos = data.WayPoints[data.Index]; logic.NotifyAiPursue(entity, targetPos); } } } //判断是否状态结束并执行相应处理 if (data.IsFinish) { logic.AiSendStoryMessage(entity, "npc_arrived:" + entity.GetUnitId(), entity.GetId()); logic.AiSendStoryMessage(entity, "obj_arrived", entity.GetId()); logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } }
private void OnStoryStateChanged() { for (LinkedListNode <EntityInfo> linkNode = m_EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; if (null != info && info.IsServerEntity && info.GetId() != LeaderID) { EntityViewModel view = EntityController.Instance.GetEntityViewById(info.GetId()); if (IsStoryState) { view.Visible = false; } else { view.Visible = true; } } } ; }
private void RecycleEntityInfo(EntityInfo npcInfo) { if (null != npcInfo) { int id = npcInfo.GetId(); if (id >= c_StartId && id < c_StartId + c_MaxIdNum) { m_UnusedIds.Push(id); } if (id >= c_StartId_Client && id < c_StartId_Client + c_MaxIdNum) { m_UnusedClientIds.Push(id); } if (m_UnusedEntities.Count < m_EntityPoolSize) { npcInfo.Reset(); m_UnusedEntities.Enqueue(npcInfo); } } }
internal static void DoSkillCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic, int skillId) { if (entity.GetMovementStateInfo().IsMoving) { logic.NotifyAiStopPursue(entity); } if (skillId > 0) { AiStateInfo aiInfo = entity.GetAiStateInfo(); SkillInfo skillInfo = entity.GetSkillStateInfo().GetSkillInfoById(skillId); if (null != skillInfo) { if (aiInfo.Target <= 0) { EntityInfo info; if (skillInfo.ConfigData.targetType == (int)SkillTargetType.Enemy || skillInfo.ConfigData.targetType == (int)SkillTargetType.RandEnemy) { info = GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY); } else { info = GetNearstTargetHelper(entity, CharacterRelation.RELATION_FRIEND); } if (null != info) { aiInfo.Target = info.GetId(); } } if (aiInfo.Target > 0) { logic.NotifyAiSkill(entity, skillId); } } } else if (!entity.GetSkillStateInfo().IsSkillActivated()) { logic.AiSendStoryMessage(entity, "npc_skill_finish:" + entity.GetUnitId(), entity.GetId()); logic.AiSendStoryMessage(entity, "obj_skill_finish", entity.GetId()); logic.ChangeToState(entity, (int)AiStateId.Idle); } }
public void LeaveScene(User user) { user.HaveEnterPosition = false; user.IsEntered = false; EntityInfo info = user.Info; if (null != info) { RemoveCareList(info); var args = m_StorySystem.NewBoxedValueList(); args.Add(info.GetId()); args.Add(info.GetUnitId()); args.Add(info.GetCampId()); args.Add(info.GetMovementStateInfo().PositionX); args.Add(info.GetMovementStateInfo().PositionZ); m_StorySystem.SendMessage("user_leave_scene", args); user.SetHpArmor(info.Hp, info.Energy); info.NeedDelete = true; user.Info = null; } }
public int GetRandFriendId(int campId) { int id = 0; List <int> ids = new List <int>(); for (LinkedListNode <EntityInfo> linkNode = PluginFramework.Instance.EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; if (EntityInfo.GetRelation(campId, info.GetCampId()) == CharacterRelation.RELATION_FRIEND && info.EntityType != (int)EntityTypeEnum.Tower) { ids.Add(info.GetId()); } } int index = Helper.Random.Next(ids.Count); if (index >= 0 && index < ids.Count) { id = ids[index]; } return(id); }
internal int GetRandEnemyId(int campId) { int id = 0; List <int> ids = new List <int>(); for (LinkedListNode <EntityInfo> linkNode = m_Scene.EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; if (EntityInfo.GetRelation(campId, info.GetCampId()) == CharacterRelation.RELATION_ENEMY && info.EntityType != (int)EntityTypeEnum.Tower) { ids.Add(info.GetId()); } } int index = Helper.Random.Next(ids.Count); if (index >= 0 && index < ids.Count) { id = ids[index]; } return(id); }
private static void StepCalcNearstTarget(EntityInfo srcObj, CharacterRelation relation, AiTargetType type, float powDist, EntityInfo obj, ref float minPowDist, ref EntityInfo nearstTarget) { EntityInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, obj.GetId()); if (null != target && !target.IsDead()) { if (!target.IsTargetNpc()) { return; } if (type == AiTargetType.HERO && target.EntityType != (int)EntityTypeEnum.Hero) { return; } if (type == AiTargetType.TOWER && target.EntityType != (int)EntityTypeEnum.Tower) { return; } if (type == AiTargetType.BOSS && target.EntityType != (int)EntityTypeEnum.Boss) { return; } if (type == AiTargetType.NPC && target.EntityType != (int)EntityTypeEnum.Normal) { return; } if (relation == EntityInfo.GetRelation(srcObj, target)) { if (powDist < minPowDist) { if (powDist > c_MaxViewRangeSqr || CanSee(srcObj, target)) { nearstTarget = target; minPowDist = powDist; } } } } }
private static void DoMoveCommandState(EntityInfo npc, long deltaTime) { //执行状态处理 AiData_ForMoveCommand data = GetAiDataForMoveCommand(npc); if (null == data) { return; } if (!data.IsFinish) { if (WayPointArrived(npc, data)) { ScriptRuntime.Vector3 targetPos = new ScriptRuntime.Vector3(); MoveToNext(npc, data, ref targetPos); if (!data.IsFinish) { AiPursue(npc, targetPos); } } else { ScriptRuntime.Vector3 targetPos = data.WayPoints[data.Index]; AiPursue(npc, targetPos); } } //判断是否状态结束并执行相应处理 if (data.IsFinish) { if (!string.IsNullOrEmpty(data.Event)) { GfxStorySystem.Instance.SendMessage(data.Event, npc.GetId(), npc.GetUnitId()); } AiStopPursue(npc); npc.GetAiStateInfo().ChangeToState((int)PredefinedAiStateId.Idle); } }
public 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; RoomUserManager roomUserMgr = user.OwnRoomUserManager; if (null != roomUserMgr) { Scene scene = roomUserMgr.ActiveScene; if (null != scene) { EntityInfo userInfo = user.Info; if (null != userInfo) { if (scene.SceneState == SceneState.Running) { scene.SyncForNewUser(user); var args = scene.StorySystem.NewBoxedValueList(); args.Add(userInfo.GetId()); args.Add(userInfo.GetUnitId()); args.Add(userInfo.GetCampId()); args.Add(userInfo.GetMovementStateInfo().PositionX); args.Add(userInfo.GetMovementStateInfo().PositionZ); scene.StorySystem.SendMessage("user_enter_scene", args); } } } } }
private void TickDebugSpaceInfo() { if (GlobalVariables.Instance.IsDebug) { bool needDebug = false; foreach (User user in m_RoomInfo.RoomUsers) { if (user.IsDebug) { needDebug = true; break; } } if (needDebug) { Msg_RC_DebugSpaceInfo builder = new Msg_RC_DebugSpaceInfo(); for (LinkedListNode <EntityInfo> linkNode = EntityManager.Entities.FirstNode; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; Msg_RC_DebugSpaceInfo.DebugSpaceInfo infoBuilder = new Msg_RC_DebugSpaceInfo.DebugSpaceInfo(); infoBuilder.obj_id = info.GetId(); infoBuilder.is_player = false; infoBuilder.pos_x = (float)info.GetMovementStateInfo().GetPosition3D().X; infoBuilder.pos_z = (float)info.GetMovementStateInfo().GetPosition3D().Z; infoBuilder.face_dir = (float)info.GetMovementStateInfo().GetFaceDir(); builder.space_infos.Add(infoBuilder); } foreach (User user in m_RoomInfo.RoomUsers) { if (user.IsDebug) { user.SendMessage(RoomMessageDefine.Msg_RC_DebugSpaceInfo, builder); } } } } }
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 OnAiPursue(EntityInfo entity, ScriptRuntime.Vector3 target) { if (null != entity) { EntityViewModel npcViewModel = EntityViewModelManager.Instance.GetEntityViewById(entity.GetId()); npcViewModel.MoveTo(target.X, target.Y, target.Z); } }
internal void RemoveCareList(EntityInfo info) { User leave_user = info.CustomData as User; if (leave_user == null) { return; } IList<EntityInfo> users = new List<EntityInfo>(); foreach (EntityInfo user_info in users) { if (user_info.GetId() == info.GetId()) continue; User user = user_info.CustomData as User; if (null == user) continue; user.RemoveCareMeUser(leave_user); leave_user.RemoveCareMeUser(user); } }
internal static void DoSkillCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic, int skillId) { if (entity.GetMovementStateInfo().IsMoving) { logic.NotifyAiStopPursue(entity); } if (skillId > 0) { AiStateInfo aiInfo = entity.GetAiStateInfo(); SkillInfo skillInfo = entity.GetSkillStateInfo().GetSkillInfoById(skillId); if (null != skillInfo) { if (aiInfo.Target <= 0) { EntityInfo info; if (skillInfo.ConfigData.targetType == (int)SkillTargetType.Enemy || skillInfo.ConfigData.targetType == (int)SkillTargetType.RandEnemy) { info = GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY); } else { info = GetNearstTargetHelper(entity, CharacterRelation.RELATION_FRIEND); } if (null != info) { aiInfo.Target = info.GetId(); } } if (aiInfo.Target > 0) { logic.NotifyAiSkill(entity, skillId); } } } else if(!entity.GetSkillStateInfo().IsSkillActivated()) { logic.AiSendStoryMessage(entity, "npc_skill_finish:" + entity.GetUnitId(), entity.GetId()); logic.AiSendStoryMessage(entity, "obj_skill_finish", entity.GetId()); logic.ChangeToState(entity, (int)AiStateId.Idle); } }
internal static void DoPatrolCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic) { AiStateInfo info = entity.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; EntityInfo target = null; if (info.IsExternalTarget) { target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(entity, info.Target); if (null == target) { target = AiLogicUtility.GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY); if (null != target) info.Target = target.GetId(); } } else { target = AiLogicUtility.GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY); if (null != target) info.Target = target.GetId(); } if (null != target) { logic.AiSendStoryMessage(entity, "obj_patrol_exit", entity.GetId()); logic.AiSendStoryMessage(entity, string.Format("npc_patrol_exit:{0}", entity.GetUnitId()), entity.GetId()); logic.ChangeToState(entity, (int)AiStateId.Idle); } else { AiData_ForPatrolCommand data = GetAiDataForPatrolCommand(entity); if (null != data) { ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D(); if (data.PatrolPath.HavePathPoint && !data.PatrolPath.IsReached(srcPos)) { logic.NotifyAiPursue(entity, data.PatrolPath.CurPathPoint); } else { data.PatrolPath.UseNextPathPoint(); if (data.PatrolPath.HavePathPoint) { logic.NotifyAiPursue(entity, data.PatrolPath.CurPathPoint); } else { if (data.IsLoopPatrol) { logic.AiSendStoryMessage(entity, "obj_patrol_restart", entity.GetId()); logic.AiSendStoryMessage(entity, string.Format("npc_patrol_restart:{0}", entity.GetUnitId()), entity.GetId()); data.PatrolPath.Restart(); } else { logic.AiSendStoryMessage(entity, "obj_patrol_finish", entity.GetId()); logic.AiSendStoryMessage(entity, string.Format("npc_patrol_finish:{0}", entity.GetUnitId()), entity.GetId()); logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } } } info.HomePos = entity.GetMovementStateInfo().GetPosition3D(); } else { logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } } } }
public void Execute(EntityInfo entity, long deltaTime) { if (entity.IsUnderControl()) { return; } if (entity.GetAIEnable()) { AiStateInfo npcAi = entity.GetAiStateInfo(); if (!npcAi.IsInited) { OnStateLogicInit(entity, deltaTime); npcAi.IsInited = true; } int curState = npcAi.CurState; if (curState > (int)AiStateId.Invalid && curState < (int)AiStateId.MaxNum) { AiStateHandler handler; if (m_Handlers.TryGetValue(curState, out handler)) { if (OnStateLogicCheck(entity, deltaTime) && null != handler) { handler(entity, deltaTime); } } else { LogSystem.Error("Illegal ai state: " + curState + " entity:" + entity.GetId()); } } else { ChangeToState(entity, (int)AiStateId.Idle); } } }
private void TickEntities() { m_DeletedEntities.Clear(); for (LinkedListNode <EntityInfo> linkNode = m_EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) { EntityInfo info = linkNode.Value; info.RetireAttackerInfos(10000); 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(); GfxSkillSystem.Instance.StartSkill(info.GetId(), skillInfo.ConfigData, 0); } else { info.IsBorning = false; info.BornTime = 0; info.SetAIEnable(true); info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible); } } else if (info.BornTime + info.BornTimeout < TimeUtility.GetLocalMilliseconds()) { info.IsBorning = false; info.BornTime = 0; info.SetAIEnable(true); info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible); } } if (info.IsDead() && !info.NeedDelete) { if (info.CanDead) { if (info.DeadTime <= 0) { SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(info.DeadSkillId); if (info.DeadSkillId > 0 && null != skillInfo) { info.DeadTime = TimeUtility.GetLocalMilliseconds(); GfxSkillSystem.Instance.StopAllSkill(info.GetId(), true, false, true); GfxSkillSystem.Instance.StartSkill(info.GetId(), skillInfo.ConfigData, 0); OnEntityKilled(info); EntityDrop(info); // 掉落 } else { info.DeadTime = 0; info.NeedDelete = true; OnEntityKilled(info); EntityDrop(info); // 掉落 } } else if (info.DeadTime + info.DeadTimeout < TimeUtility.GetLocalMilliseconds()) { info.DeadTime = 0; info.NeedDelete = true; } } else { info.CanDead = true; } } else { //每个tick复位CanDead,技能里需要鞭尸时应使用触发器每帧标记目标不可死亡(keeplive) info.CanDead = true; } if (info.NeedDelete) { m_DeletedEntities.Add(info); } } if (m_DeletedEntities.Count > 0) { int enemyCt = 0; int friendCt = 0; for (int i = 0; i < m_DeletedEntities.Count; ++i) { EntityInfo ni = m_DeletedEntities[i]; if (CharacterRelation.RELATION_ENEMY == EntityInfo.GetRelation(CampId, ni.GetCampId())) { ++enemyCt; } else if (CharacterRelation.RELATION_FRIEND == EntityInfo.GetRelation(CampId, ni.GetCampId())) { ++friendCt; } DestroyEntity(ni); } TryAllKilledOrAllDied(enemyCt > 0, friendCt > 0); } }
public UnityEngine.GameObject GetGameObjectByEntity(EntityInfo info) { return(GetGameObject(info.GetId())); }
private static void AiPursue(EntityInfo npc, ScriptRuntime.Vector3 target) { EntityViewModel npcView = EntityViewModelManager.Instance.GetEntityViewById(npc.GetId()); npcView.MoveTo(target.X, target.Y, target.Z); }
internal static Msg_RC_SyncProperty BuildSyncPropertyMessage(EntityInfo obj) { Msg_RC_SyncProperty builder = new Msg_RC_SyncProperty(); builder.role_id = obj.GetId(); builder.hp = obj.Hp; builder.np = obj.Energy; builder.shield = obj.Shield; builder.state = obj.StateFlag; return builder; }
private static void AiStopPursue(EntityInfo npc) { EntityViewModel npcView = EntityViewModelManager.Instance.GetEntityViewById(npc.GetId()); npcView.StopMove(); }
private void DestroyEntity(EntityInfo ni) { m_SkillSystem.StopAllSkill(ni.GetId(), true, true, true); ni.GetSkillStateInfo().RemoveAllImpact(); OnDestroyEntity(ni); if (ni.IsCombatNpc()) { ni.DeadTime = 0; } DestroyEntityById(ni.GetId()); }
private void OnEntityKilled(EntityInfo ni) { int leftEnemyCt = GetBattleNpcCount((int)CampIdEnum.Blue, CharacterRelation.RELATION_ENEMY); int leftFriendCt = GetBattleNpcCount((int)CampIdEnum.Blue); m_StorySystem.SendMessage("obj_killed", ni.GetId(), leftEnemyCt, leftFriendCt); m_StorySystem.SendMessage("npc_killed:" + ni.GetUnitId(), ni.GetId(), leftEnemyCt, leftFriendCt); }
private void OnAiRemoveImpact(EntityInfo npc, int impactId) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { ImpactInfo impactInfo = npc.GetSkillStateInfo().FindImpactInfoById(impactId); if (null != impactInfo) { Msg_RC_RemoveImpact removeImpactBuilder = new Msg_RC_RemoveImpact(); removeImpactBuilder.obj_id = npc.GetId(); removeImpactBuilder.impact_id = impactId; scene.NotifyAllUser(RoomMessageDefine.Msg_RC_RemoveImpact, removeImpactBuilder); scene.SkillSystem.StopSkill(npc.GetId(), impactId, impactInfo.Seq, false); } } }
private void OnAiInitDslLogic(EntityInfo entity) { AiStateInfo aiInfo = entity.GetAiStateInfo(); if (aiInfo.AiParam.Length >= 2) { string storyId = aiInfo.AiParam[0]; string storyFile = aiInfo.AiParam[1]; if (!string.IsNullOrEmpty(storyId) && !string.IsNullOrEmpty(storyFile)) { aiInfo.AiStoryInstanceInfo = GfxStorySystem.Instance.NewAiStoryInstance(storyId, string.Empty, storyFile); if (null != aiInfo.AiStoryInstanceInfo) { aiInfo.AiStoryInstanceInfo.m_StoryInstance.SetVariable("@objid", entity.GetId()); aiInfo.AiStoryInstanceInfo.m_StoryInstance.Start(); } } } }
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 OnAiStopPursue(EntityInfo entity) { EntityViewModel npcView = EntityViewModelManager.Instance.GetEntityViewById(entity.GetId()); npcView.StopMove(); }
public void NotifyAiMeetEnemy(EntityInfo entity) { if (null != OnAiMeetEnemy) { OnAiMeetEnemy(entity); } AiSendStoryMessage(entity, "obj_meet_enemy", entity.GetId()); AiSendStoryMessage(entity, "npc_meet_enemy:" + entity.GetUnitId(), entity.GetId()); }
internal void Create(EntityInfo entity) { if (null != entity) { m_Entity = entity; MovementStateInfo msi = m_Entity.GetMovementStateInfo(); ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float dir = msi.GetFaceDir(); CreateActor(m_Entity.GetId(), m_Entity.GetModel(), pos.X, pos.Y, pos.Z, dir, m_Entity.Scale, m_Entity.GetRadius(), m_Entity.GetActualProperty().MoveSpeed); if (null != Actor) { m_Agent = Actor.GetComponent<NavMeshAgent>(); if (m_Agent == null) { m_Agent = Actor.AddComponent<NavMeshAgent>(); m_Agent.angularSpeed = c_AngularSpeed; m_Agent.acceleration = c_Acceleration; m_Agent.radius = entity.GetRadius(); m_Agent.speed = entity.GetActualProperty().MoveSpeed; m_Agent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; m_Agent.ResetPath(); } m_Animator = Actor.GetComponentInChildren<Animator>(); EntityDrawGizmos gizmos = Actor.GetComponent<EntityDrawGizmos>(); if (null == gizmos) { gizmos = Actor.AddComponent<EntityDrawGizmos>(); gizmos.npcInfo = m_Entity; } else { gizmos.npcInfo = m_Entity; } SetMoveAgentEnable(true); } } }
internal static void DoMoveCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic) { //执行状态处理 AiData_ForMoveCommand data = GetAiDataForMoveCommand(entity); if (null == data) return; if (!data.IsFinish) { if (WayPointArrived(entity, data)) { Vector3 targetPos = new Vector3(); MoveToNext(entity, data, ref targetPos); if (!data.IsFinish) { logic.NotifyAiPursue(entity, targetPos); } } else { AiStateInfo info = entity.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 500) { info.Time = 0; Vector3 targetPos = data.WayPoints[data.Index]; logic.NotifyAiPursue(entity, targetPos); } } } //判断是否状态结束并执行相应处理 if (data.IsFinish) { logic.AiSendStoryMessage(entity, "npc_arrived:" + entity.GetUnitId(), entity.GetId()); logic.AiSendStoryMessage(entity, "obj_arrived", entity.GetId()); logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } }
internal static Msg_RC_NpcStopSkill BuildNpcStopSkillMessage(EntityInfo obj) { Msg_RC_NpcStopSkill msg = new Msg_RC_NpcStopSkill(); msg.npc_id = obj.GetId(); return msg; }
internal static void DoPursuitCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic) { AiStateInfo info = entity.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 200) { EntityInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.Target); if (null != target) { float minDist = entity.GetRadius() + target.GetRadius(); float dist = (float)entity.GetActualProperty().AttackRange + minDist; float distGoHome = entity.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D(); float dir = Geometry.GetYRadian(new Vector2(targetPos.X, targetPos.Z), new Vector2(srcPos.X, srcPos.Z)); targetPos.X += (float)(minDist * Math.Sin(dir)); targetPos.Z += (float)(minDist * Math.Cos(dir)); float powDist = Geometry.DistanceSquare(srcPos, targetPos); if (powDist < dist * dist) { logic.AiSendStoryMessage(entity, "npc_pursuit_finish:" + entity.GetUnitId(), entity.GetId()); logic.AiSendStoryMessage(entity, "obj_pursuit_finish", entity.GetId()); logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } else { logic.NotifyAiPursue(entity, targetPos); } } else { logic.AiSendStoryMessage(entity, "npc_pursuit_exit:" + entity.GetUnitId(), entity.GetId()); logic.AiSendStoryMessage(entity, "obj_pursuit_exit", entity.GetId()); logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } } }
internal static Msg_RC_SyncNpcOwnerId BuildSyncNpcOwnerIdMessage(EntityInfo npc) { Msg_RC_SyncNpcOwnerId builder = new Msg_RC_SyncNpcOwnerId(); builder.npc_id = npc.GetId(); builder.owner_id = npc.OwnerId; return builder; }
public void ImpactDamage(int srcObjId, int targetId, int impactId, int seq, bool isFinal) { if (!PluginFramework.Instance.IsBattleScene) { return; } EntityViewModel view = GetEntityViewById(targetId); EntityViewModel srcView = GetEntityViewById(srcObjId); if (null != view && null != view.Entity && null != view.Actor) { EntityInfo targetObj = view.Entity; EntityInfo srcObj = null; if (null != srcView && null != srcView.Entity) { srcObj = srcView.Entity; } if (null != targetObj && !view.Entity.IsDeadSkillCasting()) { ImpactInfo impactInfo = targetObj.GetSkillStateInfo().GetImpactInfoBySeq(seq); if (null != impactInfo && impactId == impactInfo.ImpactId) { EntityInfo ownerObj = GetRootSummoner(srcObj); int ownerId = 0; if (null != ownerObj) { ownerId = ownerObj.GetId(); } int addsc = impactInfo.DamageData.AddSc; int adduc = impactInfo.DamageData.AddUc; int index = impactInfo.CurDamageCount; ++impactInfo.CurDamageCount; int multiple = impactInfo.DamageData.GetMultiple(index); int damage = impactInfo.DamageData.GetDamage(index); long hitrate = 0; long critrate = 0; long blockrate = 0; long phyDamage = 0; long magDamage = 0; hitrate = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "hitrate"); critrate = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "critrate"); blockrate = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "blockrate"); long rnd = Helper.Random.Next(); long critonoff = 0; long blockonoff = 0; if (rnd <= critrate) { critonoff = 1; } else if (rnd > critrate && rnd <= critrate + blockrate) { blockonoff = 1; } impactInfo.DamageData.IsCritical = critonoff > 0; impactInfo.DamageData.IsBlock = blockonoff > 0; phyDamage = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "phydamage", multiple, damage, critonoff, blockonoff); magDamage = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "magdamage", multiple, damage, critonoff, blockonoff); damage = (int)(phyDamage + magDamage); if (damage < 0) { damage = 0; } int vampire = impactInfo.DamageData.GetVampire(index); bool isKiller = false; if (targetObj.Shield >= damage) { targetObj.Shield -= (int)damage; } else if (targetObj.Shield > 0) { int leftDamage = (int)damage - targetObj.Shield; targetObj.Shield = 0; if (targetObj.GetId() == PluginFramework.Instance.LeaderID && targetObj.Hp <= leftDamage) { //队长不死,demo专用代码 } else { targetObj.Hp -= (int)leftDamage; if (targetObj.Hp <= 0) { isKiller = true; } } } else { if (targetObj.GetId() == PluginFramework.Instance.LeaderID && targetObj.Hp <= damage) { //队长不死,demo专用代码 } else { targetObj.Hp -= (int)damage; if (targetObj.Hp <= 0) { isKiller = true; } } } if (isKiller) { targetObj.GetCombatStatisticInfo().AddDeadCount(1); if (null != srcObj) { EntityInfo killer = srcObj; if (killer.SummonerId > 0) { EntityViewModel npcViewModel = GetEntityViewById(killer.SummonerId); if (null != npcViewModel) { killer = npcViewModel.Entity; } } if (targetObj.EntityType == (int)EntityTypeEnum.Tower) { killer.GetCombatStatisticInfo().AddKillTowerCount(1); } else if (targetObj.EntityType == (int)EntityTypeEnum.Hero) { killer.GetCombatStatisticInfo().AddKillHeroCount(1); killer.GetCombatStatisticInfo().AddMultiKillCount(1); } else { killer.GetCombatStatisticInfo().AddKillNpcCount(1); } } } targetObj.SetAttackerInfo(srcObjId, isKiller, true, false, (int)damage, 0); } } } }
private void CombatHandler(EntityInfo npc, long deltaTime) { if (npc.GetSkillStateInfo().IsSkillActivated()) { return; } AiStateInfo info = npc.GetAiStateInfo(); EntityInfo leader = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.LeaderID); bool isAutoOperate = IsAutoOperate(leader); ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); Vector3 homePos = Vector3.Zero; if (null != leader) { GetHomePos(npc.GetMovementStateInfo().FormationIndex, leader); } float distSqrToHome = Geometry.DistanceSquare(srcPos, homePos); if (distSqrToHome > npc.GohomeRange * npc.GohomeRange) { NotifyAiStopPursue(npc); ChangeToState(npc, (int)AiStateId.GoHome); return; } /// EntityInfo attackTarget = null; SkillStateInfo currSkInfo = npc.GetSkillStateInfo(); ///找到可以使用的技能 SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), isAutoOperate); NotifyAiSelectSkill(npc, skInfo); if (skInfo == null) { //没有可以使用的技能就切换到Idle状态 ChangeToState(npc, (int)AiStateId.Idle); return; } CharacterRelation relation = (skInfo.TargetType == SkillTargetType.Friend || skInfo.TargetType == SkillTargetType.RandFriend) ? CharacterRelation.RELATION_FRIEND : CharacterRelation.RELATION_ENEMY; attackTarget = AiLogicUtility.GetNearstTargetHelper( npc, skInfo.Distance, relation); if (attackTarget != null && null != skInfo) //攻击范围内找到可攻击目标 { info.Target = attackTarget.GetId(); NotifyAiStopPursue(npc); NotifyAiSkill(npc, skInfo.SkillId); //攻击目标 return; } attackTarget = AiLogicUtility.GetNearstTargetHelper( npc, npc.ViewRange, relation); if (attackTarget != null && isAutoOperate) //视野范围内找到可攻击目标 { NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标 return; } currSkInfo.SetCurSkillInfo(0); NotifyAiStopPursue(npc); ChangeToState(npc, (int)AiStateId.GoHome); }
private void OnAiInitDslLogic(EntityInfo npc) { AiStateInfo aiInfo = npc.GetAiStateInfo(); if (aiInfo.AiParam.Length >= 2) { string storyId = aiInfo.AiLogic; string storyFile = aiInfo.AiParam[0]; if (!string.IsNullOrEmpty(storyId) && !string.IsNullOrEmpty(storyFile)) { aiInfo.HomePos = npc.GetMovementStateInfo().GetPosition3D(); aiInfo.ChangeToState((int)PredefinedAiStateId.Idle); aiInfo.AiStoryInstanceInfo = StorySystem.NewAiStoryInstance(storyId, string.Empty, storyFile); if (null != aiInfo.AiStoryInstanceInfo) { aiInfo.AiStoryInstanceInfo.m_StoryInstance.Context = this; aiInfo.AiStoryInstanceInfo.m_StoryInstance.SetVariable("@objid", npc.GetId()); aiInfo.AiStoryInstanceInfo.m_StoryInstance.Start(); } } } m_EntitiesForAi.Add(npc); }
internal int GetRootSummonerId(EntityInfo obj) { int ret = 0; obj = GetRootSummoner(obj); if (null != obj) { ret = obj.GetId(); } return ret; }
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(); }
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); } }
internal static void DoPatrolCommandState(EntityInfo entity, long deltaTime, AbstractAiStateLogic logic) { AiStateInfo info = entity.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; EntityInfo target = null; if (info.IsExternalTarget) { target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(entity, info.Target); if (null == target) { target = AiLogicUtility.GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY); if (null != target) { info.Target = target.GetId(); } } } else { target = AiLogicUtility.GetNearstTargetHelper(entity, CharacterRelation.RELATION_ENEMY); if (null != target) { info.Target = target.GetId(); } } if (null != target) { logic.AiSendStoryMessage(entity, "obj_patrol_exit", entity.GetId()); logic.AiSendStoryMessage(entity, string.Format("npc_patrol_exit:{0}", entity.GetUnitId()), entity.GetId()); logic.ChangeToState(entity, (int)AiStateId.Idle); } else { AiData_ForPatrolCommand data = GetAiDataForPatrolCommand(entity); if (null != data) { ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D(); if (data.PatrolPath.HavePathPoint && !data.PatrolPath.IsReached(srcPos)) { logic.NotifyAiPursue(entity, data.PatrolPath.CurPathPoint); } else { data.PatrolPath.UseNextPathPoint(); if (data.PatrolPath.HavePathPoint) { logic.NotifyAiPursue(entity, data.PatrolPath.CurPathPoint); } else { if (data.IsLoopPatrol) { logic.AiSendStoryMessage(entity, "obj_patrol_restart", entity.GetId()); logic.AiSendStoryMessage(entity, string.Format("npc_patrol_restart:{0}", entity.GetUnitId()), entity.GetId()); data.PatrolPath.Restart(); } else { logic.AiSendStoryMessage(entity, "obj_patrol_finish", entity.GetId()); logic.AiSendStoryMessage(entity, string.Format("npc_patrol_finish:{0}", entity.GetUnitId()), entity.GetId()); logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } } } info.HomePos = entity.GetMovementStateInfo().GetPosition3D(); } else { logic.NotifyAiStopPursue(entity); logic.ChangeToState(entity, (int)AiStateId.Idle); } } } }