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 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 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); } } } }
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 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); } } } }