Example #1
0
        private void CreateAndMoveToOffset()
        {
            if (NewAutoPilot.InGravity())
            {
                if (NewAutoPilot.Targeting.Target.CurrentAltitude() > NewAutoPilot.OffsetPlanetMinTargetAltitude)
                {
                    //Logger.MsgDebug("Target Is High", DebugTypeEnum.General);
                    NewAutoPilot.SetRandomOffset(VectorHelper.RandomDistance(NewAutoPilot.OffsetPlanetMinTargetAltitude, NewAutoPilot.OffsetPlanetMaxTargetAltitude), 0, NewAutoPilot.Targeting.Target.GetEntity());
                }
                else
                {
                    //Logger.MsgDebug("Target Is Low", DebugTypeEnum.General);
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity());
                }
            }
            else
            {
                //Logger.MsgDebug("Target Is Space", DebugTypeEnum.General);
                NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity());
            }

            LastOffsetCalculation = MyAPIGateway.Session.GameDateTime;
            NewAutoPilot.ActivateAutoPilot(AutoPilotType.RivalAI, NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward, RemoteControl.GetPosition(), true, true, true);
        }
Example #2
0
        public override void MainBehavior()
        {
            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                Mode = BehaviorMode.Retreat;
                NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), false, true, true);
            }

            //Init
            if (Mode == BehaviorMode.Init)
            {
                if (!NewAutoPilot.Targeting.HasTarget())
                {
                    Mode = BehaviorMode.WaitingForTarget;
                }
                else
                {
                    Mode = BehaviorMode.WaitAtWaypoint;
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                }
            }

            //Waiting For Target
            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (NewAutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity(), false);
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!NewAutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
            }

            //Approach
            if (Mode == BehaviorMode.ApproachTarget)
            {
                var timeSpan = MyAPIGateway.Session.GameDateTime - this.HorseflyWaypointAbandonTime;
                //Logger.MsgDebug("Distance To Waypoint: " + NewAutoPilot.DistanceToCurrentWaypoint.ToString(), DebugTypeEnum.General);

                if (ArrivedAtWaypoint())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitAtWaypoint);
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.None, NewAutoPilotMode.None, Vector3D.Zero);
                }
                else if (timeSpan.TotalSeconds >= this.HorseflyWaypointAbandonTimeTrigger)
                {
                    Logger.MsgDebug("Horsefly Timeout, Getting New Offset", DebugTypeEnum.General);
                    this.HorseflyWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity(), false);
                }
                else if (NewAutoPilot.IsWaypointThroughVelocityCollision())
                {
                    Logger.MsgDebug("Horsefly Velocity Through Collision, Getting New Offset", DebugTypeEnum.General);
                    this.HorseflyWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity(), false);
                }
            }

            //WaitAtWaypoint
            if (Mode == BehaviorMode.WaitAtWaypoint)
            {
                var timeSpan = MyAPIGateway.Session.GameDateTime - this.HorseflyWaypointWaitTime;

                if (timeSpan.TotalSeconds >= this.HorseflyWaypointWaitTimeTrigger)
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    this.HorseflyWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    NewAutoPilot.SetRandomOffset(NewAutoPilot.Targeting.Target.GetEntity(), false);
                    NewAutoPilot.ActivateAutoPilot(AutoPilotType.Legacy, NewAutoPilotMode.None, this.RemoteControl.GetPosition(), true, true, true);
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    NewAutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }