public GetMovementStateInfo ( ) : |
||
리턴 |
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; }
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; }
protected override void OnStateLogicInit(EntityInfo entity, long deltaTime) { AiStateInfo info = entity.GetAiStateInfo(); info.Time = 0; info.HomePos = entity.GetMovementStateInfo().GetPosition3D(); info.Target = 0; }
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 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 CombatHandler(EntityInfo npc, long deltaTime) { if (npc.GetSkillStateInfo().IsSkillActivated()) { return; } AiStateInfo info = npc.GetAiStateInfo(); Vector3 targetPos = info.HomePos; ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float distSqrToHome = Geometry.DistanceSquare(srcPos, info.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), true); 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) //视野范围内找到可攻击目标 { NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标 return; } currSkInfo.SetCurSkillInfo(0); NotifyAiStopPursue(npc); ChangeToState(npc, (int)AiStateId.GoHome); }
private void CombatHandler(EntityInfo npc, long deltaTime) { AiStateInfo aiInfo = npc.GetAiStateInfo(); AiData_Leader aiData = GetAiData(npc); if (npc.GetSkillStateInfo().IsSkillActivated()) { return; } /// SkillStateInfo currSkInfo = npc.GetSkillStateInfo(); ///找到可以使用的技能 SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), aiData.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; EntityInfo attackTarget = AiLogicUtility.GetNearstAttackerHelper(npc, relation, aiData); if (null != attackTarget) { NotifyAiTarget(npc, attackTarget); if (Geometry.DistanceSquare(npc.GetMovementStateInfo().GetPosition3D(), attackTarget.GetMovementStateInfo().GetPosition3D()) < skInfo.Distance * skInfo.Distance) { aiInfo.Target = attackTarget.GetId(); NotifyAiStopPursue(npc); NotifyAiSkill(npc, skInfo.SkillId); return; } } attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, skInfo.Distance, relation); if (attackTarget != null && null != skInfo) { //攻击范围内找到可攻击目标 NotifyAiTarget(npc, attackTarget); aiInfo.Target = attackTarget.GetId(); NotifyAiStopPursue(npc); NotifyAiSkill(npc, skInfo.SkillId); //攻击目标 return; } if (aiData.IsAutoOperate) { attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, npc.ViewRange, relation); if (attackTarget != null && null != skInfo) { //视野内找到可攻击目标 NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); return; } } ///退出战斗模式清理一下手动技能 currSkInfo.SetCurSkillInfo(0); aiData.ManualSkillId = 0; NotifyAiStopPursue(npc); ChangeToState(npc, (int)AiStateId.Idle); }
public static EntityInfo GetNearstAttackerHelper(EntityInfo srcObj, CharacterRelation relation, AiData_General aidata) { EntityInfo ret = null; float minDistSqr = 999999; Vector2 dir = srcObj.GetMovementStateInfo().GetFaceDir2D(); Vector2 pos = srcObj.GetMovementStateInfo().GetPosition2D(); if (relation == CharacterRelation.RELATION_ENEMY) { foreach (var pair in srcObj.AttackerInfos) { EntityInfo target = srcObj.SceneContext.GetEntityById(pair.Key); if (null != target) { float distSqr = Geometry.DistanceSquare(pos, target.GetMovementStateInfo().GetPosition2D()); if (distSqr <= (srcObj.ViewRange + target.GetRadius()) * (srcObj.ViewRange + target.GetRadius())) { if (distSqr <= minDistSqr) { ret = target; minDistSqr = distSqr; } } } } } return ret; }
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; }
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 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); } } }
public static bool CanSee(EntityInfo source, EntityInfo target) { bool ret = false; if (null != source && null != target) { Vector3 pos1 = source.GetMovementStateInfo().GetPosition3D(); Vector3 pos2 = target.GetMovementStateInfo().GetPosition3D(); float distSqr = GameFramework.Geometry.DistanceSquare(pos1, pos2); return CanSee(source, target, distSqr, pos1, pos2); } return ret; }
public bool CastSkill(int objId, int skillId) { bool ret = false; EntityInfo obj = GetEntityById(objId); if (null != obj) { SkillInfo skillInfo = obj.GetSkillStateInfo().GetSkillInfoById(skillId); if (null != skillInfo) { if (!skillInfo.IsInCd(TimeUtility.GetLocalMilliseconds())) { int targetId = 0; if (null != SelectedTarget) { targetId = SelectedTarget.TargetId; } if (IsStoryScene || IsActivityScene) { Network.NetworkSystem.Instance.SyncPlayerSkill(obj, skillId, targetId, obj.GetMovementStateInfo().GetFaceDir()); } else { AiStateInfo aiInfo = obj.GetAiStateInfo(); aiInfo.Target = targetId; GfxSkillSystem.Instance.StartSkill(objId, skillInfo.ConfigData, 0); } ret = true; } } } return(ret); }
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 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 Query(EntityInfo obj, float range, MyFunc <float, KdTreeObject, bool> visitor) { Query(obj.GetMovementStateInfo().GetPosition3D(), range, visitor); }
private static bool WayPointArrived(EntityInfo charObj, AiData_ForMoveCommand data) { bool ret = false; var move_info = charObj.GetMovementStateInfo(); float powDistDest = move_info.CalcDistancSquareToTarget(); if (powDistDest <= 1f) { ret = true; } return ret; }
private void IdleHandler(EntityInfo npc, long deltaTime) { if (npc.GetMovementStateInfo().IsMoving) NotifyAiStopPursue(npc); ChangeToState(npc, (int)AiStateId.Combat); }
private void GoHomeHandler(EntityInfo entity, long deltaTime) { AiStateInfo info = entity.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > c_IntervalTime) { info.Time = 0; AiData_General data = GetAiData(entity); if (null != data) { EntityInfo leader = AiLogicUtility.GetLivingCharacterInfoHelper(entity, info.LeaderID); if (null != leader) { float minDist = entity.GetRadius() + leader.GetRadius(); Vector3 targetPos = GetHomePos(entity.GetMovementStateInfo().FormationIndex, leader); ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D(); float powDistToHome = Geometry.DistanceSquare(srcPos, targetPos); if (powDistToHome <= (minDist + 1) * (minDist + 1)) { NotifyAiStopPursue(entity); ChangeToState(entity, (int)AiStateId.Idle); } else { NotifyAiPursue(entity, targetPos); } } else { NotifyAiStopPursue(entity); ChangeToState(entity, (int)AiStateId.Idle); } } } }
private Vector3 GetHomePos(int formationIndex, EntityInfo leader) { Vector3 pos; int id = GetFormationId(leader); TableConfig.Formation formation = TableConfig.FormationProvider.Instance.GetFormation(id); if (null != formation) { TableConfig.Formation.PosDir posDir = formation.GetPosDir(formationIndex); float dir; pos = posDir.CalcPosDir(leader.GetMovementStateInfo().TargetPosition, leader.GetMovementStateInfo().GetFaceDir(), out dir); } else { pos = Vector3.Zero; } return pos; }
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); } } }
public void CopyFrom(EntityInfo obj) { if (null != obj) { Object = obj; Position = obj.GetMovementStateInfo().GetPosition3D(); Radius = obj.GetRadius(); MaxX = Position.X + Radius; MinX = Position.X - Radius; MaxZ = Position.Z + Radius; MinZ = Position.Z - Radius; Indexed = false; } else { Object = null; Position = new Vector3(); Radius = 0; MaxX = MinX = 0; MaxZ = MinZ = 0; Indexed = false; } }
public void Query(EntityInfo obj, float range, MyFunc<float, KdTreeObject, bool> visitor) { Query(obj.GetMovementStateInfo().GetPosition3D(), range, visitor); }
public bool CastSkill(int objId, int skillId) { bool ret = false; EntityInfo obj = GetEntityById(objId); if (null != obj) { SkillInfo skillInfo = obj.GetSkillStateInfo().GetSkillInfoById(skillId); if (null != skillInfo) { if (obj.Energy >= obj.GetActualProperty().EnergyMax) { if (!skillInfo.IsInCd(TimeUtility.GetLocalMilliseconds())) { int targetId = 0; if (null != SelectedTarget) { targetId = SelectedTarget.TargetId; } if (IsRoomScene) { Network.NetworkSystem.Instance.SyncPlayerSkill(obj, skillId, targetId, obj.GetMovementStateInfo().GetFaceDir()); } else { AiStateInfo aiInfo = obj.GetAiStateInfo(); aiInfo.Target = targetId; 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 = skillId; } else { AiData_General data = aiInfo.AiDatas.GetData <AiData_General>(); if (null == data) { data = new AiData_General(); aiInfo.AiDatas.AddData(data); } data.ManualSkillId = skillId; } aiInfo.ChangeToState((int)AiStateId.SkillCommand); } ret = true; } } } } return(ret); }
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); } } }
private void GoHomeHandler(EntityInfo entity, long deltaTime) { AiStateInfo info = entity.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > c_IntervalTime) { info.Time = 0; AiData_General data = GetAiData(entity); if (null != data) { Vector3 targetPos = info.HomePos; ScriptRuntime.Vector3 srcPos = entity.GetMovementStateInfo().GetPosition3D(); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); if (powDistToHome <= 1) { NotifyAiStopPursue(entity); ChangeToState(entity, (int)AiStateId.Idle); } else { NotifyAiPursue(entity, targetPos); } } } }
private static void MoveToNext(EntityInfo charObj, AiData_ForMoveCommand data, ref Vector3 targetPos) { if (++data.Index >= data.WayPoints.Count) { data.IsFinish = true; return; } var move_info = charObj.GetMovementStateInfo(); targetPos = data.WayPoints[data.Index]; move_info.TargetPosition = targetPos; }
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 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); } } }
private void CombatHandler(EntityInfo npc, long deltaTime) { AiStateInfo aiInfo = npc.GetAiStateInfo(); AiData_Leader aiData = GetAiData(npc); if (npc.GetSkillStateInfo().IsSkillActivated()) { return; } /// SkillStateInfo currSkInfo = npc.GetSkillStateInfo(); ///找到可以使用的技能 SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), aiData.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; EntityInfo attackTarget = AiLogicUtility.GetNearstAttackerHelper(npc, relation, aiData); if (null != attackTarget) { NotifyAiTarget(npc, attackTarget); if (Geometry.DistanceSquare(npc.GetMovementStateInfo().GetPosition3D(), attackTarget.GetMovementStateInfo().GetPosition3D()) < skInfo.Distance * skInfo.Distance) { aiInfo.Target = attackTarget.GetId(); NotifyAiStopPursue(npc); NotifyAiSkill(npc, skInfo.SkillId); return; } } attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, skInfo.Distance, relation); if (attackTarget != null && null != skInfo) //攻击范围内找到可攻击目标 { NotifyAiTarget(npc, attackTarget); aiInfo.Target = attackTarget.GetId(); NotifyAiStopPursue(npc); NotifyAiSkill(npc, skInfo.SkillId); //攻击目标 return; } if (aiData.IsAutoOperate) { attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, npc.ViewRange, relation); if (attackTarget != null && null != skInfo) //视野内找到可攻击目标 { NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); return; } } ///退出战斗模式清理一下手动技能 currSkInfo.SetCurSkillInfo(0); aiData.ManualSkillId = 0; NotifyAiStopPursue(npc); ChangeToState(npc, (int)AiStateId.Idle); }