Exemplo n.º 1
0
        public void ReturnToDespawn()
        {
            if (Mode == BehaviorMode.ApproachTarget)
            {
                BehaviorTriggerC = true;
            }

            ChangeCoreBehaviorMode(BehaviorMode.ApproachWaypoint);
            AutoPilot.SetAutoPilotDataMode(AutoPilotDataMode.Primary);
            AutoPilot.ActivateAutoPilot(Settings.DespawnCoords, NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            _checkActiveTargetTimer = MyAPIGateway.Session.GameDateTime;
        }
Exemplo n.º 2
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            base.MainBehavior();

            //Logger.MsgDebug(Mode.ToString(), DebugTypeEnum.General);

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.LevelWithGravity | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.WaterNavigation);
            }

            if (Mode == BehaviorMode.Init)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                    BehaviorTriggerD = true;
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.LevelWithGravity | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.WaterNavigation);
                }
            }

            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (AutoPilot.CurrentMode != AutoPilot.UserCustomModeIdle)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.LevelWithGravity);
                }

                if (AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.LevelWithGravity | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.WaterNavigation);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                    BehaviorTriggerD = true;
                }
            }

            if (!AutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat && Mode != BehaviorMode.WaitingForTarget)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.LevelWithGravity);
                BehaviorTriggerD = true;
            }

            //A - Stop All Movement
            if (BehaviorActionA)
            {
                BehaviorActionA = false;
                ChangeCoreBehaviorMode(BehaviorMode.WaitAtWaypoint);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.LevelWithGravity);
                WaitTime         = MyAPIGateway.Session.GameDateTime;
                BehaviorTriggerC = true;
            }

            //WaitAtWaypoint
            if (Mode == BehaviorMode.WaitAtWaypoint)
            {
                var timespan = MyAPIGateway.Session.GameDateTime - WaitTime;

                if (timespan.TotalSeconds >= AutoPilot.Data.WaypointWaitTimeTrigger)
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                    BehaviorTriggerD = true;
                }
            }

            //Approach
            if (Mode == BehaviorMode.ApproachTarget)
            {
                bool inRange = false;

                if (!AutoPilot.InGravity() && AutoPilot.DistanceToTargetWaypoint < AutoPilot.Data.EngageDistanceSpace)
                {
                    inRange = true;
                }

                if (AutoPilot.InGravity() && AutoPilot.DistanceToTargetWaypoint < AutoPilot.Data.EngageDistancePlanet)
                {
                    inRange = true;
                }

                if (inRange)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToTarget | NewAutoPilotMode.LevelWithGravity | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.WaterNavigation);
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                    BehaviorTriggerA = true;
                }
            }

            //Engage
            if (Mode == BehaviorMode.EngageTarget)
            {
                bool outRange = false;

                if (!AutoPilot.InGravity() && AutoPilot.DistanceToTargetWaypoint > AutoPilot.Data.DisengageDistanceSpace)
                {
                    outRange = true;
                }

                if (AutoPilot.InGravity() && AutoPilot.DistanceToTargetWaypoint > AutoPilot.Data.DisengageDistancePlanet)
                {
                    outRange = true;
                }

                if (outRange)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.LevelWithGravity | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.WaterNavigation);
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    BehaviorTriggerB = true;
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    AutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Exemplo n.º 3
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            base.MainBehavior();

            //Logger.MsgDebug(Mode.ToString(), DebugTypeEnum.General);

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            }

            if (Mode == BehaviorMode.Init)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.OffsetWaypoint);
                }
            }

            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (AutoPilot.CurrentMode != AutoPilot.UserCustomMode)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
                }

                if (AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.OffsetWaypoint);
                    BehaviorTriggerA = true;
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!AutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat && Mode != BehaviorMode.WaitingForTarget)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
            }

            //TimerThing
            var modeTime = MyAPIGateway.Session.GameDateTime - HorseFighterModeSwitchTime;

            if (modeTime.TotalSeconds > (FighterMode ? HorseFighterTimeEngaging : HorseFighterTimeApproaching))
            {
                HorseFighterModeSwitchTime = MyAPIGateway.Session.GameDateTime;
                FighterMode = FighterMode ? false : true;
                Logger.MsgDebug("HorseFighter Using Fighter Mode: " + FighterMode.ToString(), DebugTypeEnum.General);
            }

            //Approach
            if (Mode == BehaviorMode.ApproachTarget)
            {
                if (FighterMode && AutoPilot.DistanceToTargetWaypoint < (AutoPilot.InGravity() ? HorseFighterEngageDistancePlanet : HorseFighterEngageDistanceSpace))
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.Strafe | NewAutoPilotMode.WaypointFromTarget);
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                    BehaviorTriggerC = true;
                }
                else
                {
                    var timeSpan = MyAPIGateway.Session.GameDateTime - this.HorseFighterWaypointAbandonTime;

                    if (AutoPilot.ArrivedAtOffsetWaypoint())
                    {
                        ChangeCoreBehaviorMode(BehaviorMode.WaitAtWaypoint);
                        this.HorseFighterWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                        AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
                        BehaviorTriggerB = true;
                    }
                    else if (timeSpan.TotalSeconds >= this.HorseFighterWaypointAbandonTimeTrigger)
                    {
                        this.HorseFighterWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                        AutoPilot.OffsetWaypointGenerator(true);
                    }
                    else if (AutoPilot.IsWaypointThroughVelocityCollision())
                    {
                        this.HorseFighterWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                        AutoPilot.OffsetWaypointGenerator(true);
                    }
                }
            }

            //Engage
            if (Mode == BehaviorMode.EngageTarget)
            {
                bool outRange = false;

                if (FighterMode)
                {
                    outRange = AutoPilot.DistanceToTargetWaypoint > (AutoPilot.InGravity() ? HorseFighterDisengageDistancePlanet : HorseFighterDisengageDistanceSpace);
                }
                else
                {
                    outRange = true;
                }

                if (outRange)
                {
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.OffsetWaypoint);
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    BehaviorTriggerA = true;
                }
            }

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

                if (timeSpan.TotalSeconds >= this.HorseFighterWaypointWaitTimeTrigger)
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    this.HorseFighterWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.OffsetWaypoint);
                    BehaviorTriggerA = true;
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    AutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Exemplo n.º 4
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            base.MainBehavior();

            bool skipEngageCheck = false;

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                Mode = BehaviorMode.Retreat;
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            }

            //Init
            if (Mode == BehaviorMode.Init)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    EngageOverrideTimer = MyAPIGateway.Session.GameDateTime;
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    CreateAndMoveToOffset();
                    skipEngageCheck = true;
                }
            }

            //Waiting For Target
            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (AutoPilot.CurrentMode != AutoPilot.UserCustomMode)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
                }

                if (AutoPilot.Targeting.HasTarget())
                {
                    EngageOverrideTimer = MyAPIGateway.Session.GameDateTime;
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    CreateAndMoveToOffset();
                    skipEngageCheck  = true;
                    BehaviorTriggerA = true;
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

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

            //Approach Target
            if (Mode == BehaviorMode.ApproachTarget && !skipEngageCheck)
            {
                double distance       = AutoPilot.InGravity() ? this.StrikeBeginPlanetAttackRunDistance : this.StrikeBeginSpaceAttackRunDistance;
                bool   engageOverride = false;

                if (EngageOverrideWithDistanceAndTimer)
                {
                    if (AutoPilot.DistanceToCurrentWaypoint < EngageOverrideDistance)
                    {
                        var time = MyAPIGateway.Session.GameDateTime - EngageOverrideTimer;

                        if (time.TotalSeconds > EngageOverrideTimerTrigger)
                        {
                            engageOverride = true;
                        }
                    }
                }

                if ((engageOverride || AutoPilot.DistanceToCurrentWaypoint <= distance) && AutoPilot.Targeting.Target.Distance(RemoteControl.GetPosition()) > this.StrikeBreakawayDistance && !AutoPilot.IsAvoidingCollision())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | (StrikeEngageUseSafePlanetPathing ? NewAutoPilotMode.PlanetaryPathing : NewAutoPilotMode.None) | NewAutoPilotMode.WaypointFromTarget);
                    skipEngageCheck  = true;
                    BehaviorTriggerB = true;
                }

                if (skipEngageCheck == false)
                {
                    var timeSpan = MyAPIGateway.Session.GameDateTime - LastOffsetCalculation;

                    if (timeSpan.TotalSeconds >= StrikeOffsetRecalculationTime)
                    {
                        skipEngageCheck      = true;
                        AutoPilot.DebugDataA = "Offset Expire, Recalc";
                        CreateAndMoveToOffset();
                    }


                    if (AutoPilot.Data.ReverseOffsetDistAltAboveHeight)
                    {
                        if (TargetIsHigh && AutoPilot.Targeting.Target.CurrentAltitude() < AutoPilot.Data.ReverseOffsetHeight)
                        {
                            TargetIsHigh         = false;
                            AutoPilot.DebugDataA = "Target is Low";
                            CreateAndMoveToOffset();
                        }
                        else if (!TargetIsHigh && AutoPilot.Targeting.Target.CurrentAltitude() > AutoPilot.Data.ReverseOffsetHeight)
                        {
                            TargetIsHigh         = true;
                            AutoPilot.DebugDataA = "Target is High";
                            CreateAndMoveToOffset();
                        }
                    }
                }
            }

            //Engage Target
            if (Mode == BehaviorMode.EngageTarget && !skipEngageCheck)
            {
                Logger.MsgDebug("Strike: " + StrikeBreakawayDistance.ToString() + " - " + AutoPilot.DistanceToInitialWaypoint, DebugTypeEnum.General);
                if (AutoPilot.DistanceToInitialWaypoint <= StrikeBreakawayDistance || (AutoPilot.Data.UseVelocityCollisionEvasion && AutoPilot.Collision.VelocityResult.CollisionImminent()))
                {
                    EngageOverrideTimer = MyAPIGateway.Session.GameDateTime;
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    CreateAndMoveToOffset();
                    BehaviorTriggerA = true;
                }
            }
        }
Exemplo n.º 5
0
 private void CreateAndMoveToOffset()
 {
     AutoPilot.OffsetWaypointGenerator(true);
     LastOffsetCalculation = MyAPIGateway.Session.GameDateTime;
     AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode | NewAutoPilotMode.OffsetWaypoint);
 }
Exemplo n.º 6
0
        //A: Found Target (Approach)
        //B: Lost Target (Still Approach)
        //C: Lost Target (Go To Despawn)
        //D: Engage Target
        //E: Engage In Range
        //F: Engage Out Range


        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            base.MainBehavior();

            //Logger.MsgDebug(Mode.ToString(), DebugTypeEnum.General);

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            }

            if (Mode == BehaviorMode.Init)
            {
                if (Settings.DespawnCoords == Vector3D.Zero)
                {
                    Settings.DespawnCoords = MESApi.GetDespawnCoords(RemoteControl.SlimBlock.CubeGrid);

                    if (Settings.DespawnCoords == Vector3D.Zero)
                    {
                        Settings.DespawnCoords = AutoPilot.CalculateDespawnCoords(this.RemoteControl.GetPosition());
                    }
                }

                ReturnToDespawn();
            }

            if (BehaviorActionA && Mode != BehaviorMode.EngageTarget)
            {
                //Logger.MsgDebug("Hunter BehaviorActionA Triggered", DebugTypeEnum.General);

                BehaviorActionA = false;

                if (Settings.LastDamagerEntity != 0)
                {
                    //Logger.MsgDebug("Damager Entity Id Valid" + Settings.LastDamagerEntity.ToString(), DebugTypeEnum.General);

                    IMyEntity tempEntity = null;

                    if (MyAPIGateway.Entities.TryGetEntityById(Settings.LastDamagerEntity, out tempEntity))
                    {
                        //Logger.MsgDebug("Damager Entity Valid", DebugTypeEnum.General);

                        var parentEnt = tempEntity.GetTopMostParent();

                        if (parentEnt != null)
                        {
                            //Logger.MsgDebug("Damager Parent Entity Valid", DebugTypeEnum.General);
                            var  gridGroup           = MyAPIGateway.GridGroups.GetGroup(RemoteControl.SlimBlock.CubeGrid, GridLinkTypeEnum.Physical);
                            bool isSameGridConstrust = false;

                            foreach (var grid in gridGroup)
                            {
                                if (grid.EntityId == tempEntity.GetTopMostParent().EntityId)
                                {
                                    //Logger.MsgDebug("Damager Parent Entity Was Same Grid", DebugTypeEnum.General);
                                    isSameGridConstrust = true;
                                    break;
                                }
                            }

                            if (!isSameGridConstrust)
                            {
                                //Logger.MsgDebug("Damager Parent Entity Was External", DebugTypeEnum.General);
                                AutoPilot.Targeting.ForceTargetEntityId = parentEnt.EntityId;
                                AutoPilot.Targeting.ForceTargetEntity   = parentEnt;
                                AutoPilot.Targeting.ForceRefresh        = true;
                                AutoPilot.SetAutoPilotDataMode(AutoPilotDataMode.Secondary);
                                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                                ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                                Logger.MsgDebug("Hunter Approaching Potential Target From Damage", DebugTypeEnum.BehaviorSpecific);
                                return;
                            }
                        }
                    }
                }
            }

            if (Mode == BehaviorMode.ApproachWaypoint)
            {
                var time = MyAPIGateway.Session.GameDateTime - _checkActiveTargetTimer;

                if (time.TotalSeconds > TimeBetweenNewTargetChecks)
                {
                    _checkActiveTargetTimer = MyAPIGateway.Session.GameDateTime;

                    if (AutoPilot.Targeting.HasTarget())
                    {
                        ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                        _lostTargetTimer = MyAPIGateway.Session.GameDateTime;
                        BehaviorTriggerA = true;
                        AutoPilot.SetAutoPilotDataMode(AutoPilotDataMode.Secondary);
                        AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                        Logger.MsgDebug("Hunter Approaching Potential Target", DebugTypeEnum.BehaviorSpecific);
                    }
                }
            }

            if (Mode == BehaviorMode.ApproachTarget)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    AutoPilot.SetInitialWaypoint(AutoPilot.Targeting.TargetLastKnownCoords);
                    var time = MyAPIGateway.Session.GameDateTime - _lostTargetTimer;

                    if (time.TotalSeconds > LostTargetTimerTrigger)
                    {
                        Logger.MsgDebug("Hunter Returning To Despawn", DebugTypeEnum.BehaviorSpecific);
                        ReturnToDespawn();
                        return;
                    }

                    return;
                }

                _lostTargetTimer = MyAPIGateway.Session.GameDateTime;
                bool engageTarget = false;
                var  targetDist   = Vector3D.Distance(RemoteControl.GetPosition(), AutoPilot.Targeting.TargetLastKnownCoords);

                //Check Turret
                if (EngageOnWeaponActivation == true)
                {
                    if (AutoPilot.Weapons.GetTurretTarget() != 0)
                    {
                        Logger.MsgDebug("Hunter Turrets Detected Target", DebugTypeEnum.BehaviorSpecific);
                        engageTarget = true;
                    }
                }

                //Check Visual Range
                if (!engageTarget && EngageOnCameraDetection && targetDist < CameraDetectionMaxRange)
                {
                    if (Grid.RaycastGridCheck(AutoPilot.Targeting.TargetLastKnownCoords))
                    {
                        Logger.MsgDebug("Hunter Raycast Target Success", DebugTypeEnum.BehaviorSpecific);
                    }
                    engageTarget = true;
                }

                //Check Collision Data
                if (!engageTarget && EngageOnTargetLineOfSight && AutoPilot.Targeting.Data.MaxLineOfSight > 0 && AutoPilot.Collision.TargetResult.HasTarget(AutoPilot.Targeting.Data.MaxLineOfSight))
                {
                    if (AutoPilot.Targeting.Target.GetParentEntity().EntityId == AutoPilot.Collision.TargetResult.GetCollisionEntity().EntityId)
                    {
                        Logger.MsgDebug("Hunter Has Line of Sight to Target", DebugTypeEnum.BehaviorSpecific);
                        engageTarget = true;
                    }
                }

                if (engageTarget)
                {
                    Logger.MsgDebug("Hunter Engaging Target", DebugTypeEnum.BehaviorSpecific);
                    BehaviorTriggerD = true;
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                }
            }

            //Engage
            if (Mode == BehaviorMode.EngageTarget)
            {
                if (AutoPilot.Targeting.HasTarget())
                {
                    var targetDist = Vector3D.Distance(RemoteControl.GetPosition(), AutoPilot.Targeting.TargetLastKnownCoords);

                    if (!_inRange)
                    {
                        if (targetDist < (AutoPilot.InGravity() ? AutoPilot.Data.EngageDistancePlanet : AutoPilot.Data.EngageDistanceSpace))
                        {
                            Logger.MsgDebug("Hunter Within Engage Range", DebugTypeEnum.BehaviorSpecific);
                            _inRange         = true;
                            BehaviorTriggerE = true;
                            AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.Strafe | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                        }
                    }
                    else
                    {
                        if (targetDist > (AutoPilot.InGravity() ? AutoPilot.Data.DisengageDistancePlanet : AutoPilot.Data.DisengageDistanceSpace))
                        {
                            Logger.MsgDebug("Hunter Outside Engage Range", DebugTypeEnum.BehaviorSpecific);
                            _inRange         = false;
                            BehaviorTriggerF = true;
                            AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                        }
                    }
                }
                else
                {
                    Logger.MsgDebug("Hunter Lost Target While Engaging", DebugTypeEnum.BehaviorSpecific);
                    BehaviorTriggerB = true;
                    _inRange         = false;
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    AutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Exemplo n.º 7
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            base.MainBehavior();

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            }

            //Init
            if (Mode == BehaviorMode.Init)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.OffsetWaypoint);
                }
            }

            //Waiting For Target
            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.OffsetWaypoint);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!AutoPilot.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 (AutoPilot.ArrivedAtOffsetWaypoint())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitAtWaypoint);
                    this.HorseflyWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
                    BehaviorTriggerA = true;
                }
                else if (timeSpan.TotalSeconds >= this.HorseflyWaypointAbandonTimeTrigger)
                {
                    Logger.MsgDebug("Horsefly Timeout, Getting New Offset", DebugTypeEnum.General);
                    this.HorseflyWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.OffsetWaypointGenerator(true);
                }
                else if (AutoPilot.IsWaypointThroughVelocityCollision())
                {
                    Logger.MsgDebug("Horsefly Velocity Through Collision, Getting New Offset", DebugTypeEnum.General);
                    this.HorseflyWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.OffsetWaypointGenerator(true);
                }
            }

            //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;
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.OffsetWaypoint);
                    BehaviorTriggerB = true;
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    AutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Exemplo n.º 8
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            base.MainBehavior();

            //Logger.MsgDebug(Mode.ToString(), DebugTypeEnum.General);

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            }

            if (Mode == BehaviorMode.Init)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                }
            }

            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (AutoPilot.CurrentMode != AutoPilot.UserCustomModeIdle)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
                }

                if (AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!AutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat && Mode != BehaviorMode.WaitingForTarget)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
            }

            //Approach
            if (Mode == BehaviorMode.ApproachTarget)
            {
                bool inRange = false;

                if (!AutoPilot.InGravity() && AutoPilot.DistanceToTargetWaypoint < this.FighterEngageDistanceSpace)
                {
                    inRange = true;
                }

                if (AutoPilot.InGravity() && AutoPilot.DistanceToTargetWaypoint < this.FighterEngageDistancePlanet)
                {
                    inRange = true;
                }

                if (inRange)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.Strafe | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                    BehaviorTriggerA = true;
                }
            }

            //Engage
            if (Mode == BehaviorMode.EngageTarget)
            {
                bool outRange = false;

                if (!AutoPilot.InGravity() && AutoPilot.DistanceToTargetWaypoint > this.FighterDisengageDistanceSpace)
                {
                    outRange = true;
                }

                if (AutoPilot.InGravity() && AutoPilot.DistanceToTargetWaypoint > this.FighterDisengageDistancePlanet)
                {
                    outRange = true;
                }

                if (outRange)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    BehaviorTriggerB = true;
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    AutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Exemplo n.º 9
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            base.MainBehavior();

            //Logger.MsgDebug(Mode.ToString(), DebugTypeEnum.General);

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            }

            if (Mode == BehaviorMode.Init)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode | NewAutoPilotMode.OffsetWaypoint);
                }
            }

            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (AutoPilot.CurrentMode != AutoPilot.UserCustomModeIdle)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
                }

                if (AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode | NewAutoPilotMode.OffsetWaypoint);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!AutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat && Mode != BehaviorMode.WaitingForTarget)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
            }

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

                if (AutoPilot.ArrivedAtOffsetWaypoint())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                    this.SniperWaypointWaitTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.WaypointFromTarget);
                    BehaviorTriggerA = true;
                }
                else if (timeSpan.TotalSeconds >= AutoPilot.Data.WaypointAbandonTimeTrigger)
                {
                    Logger.MsgDebug("Sniper Timeout, Getting New Offset", DebugTypeEnum.General);
                    this.SniperWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.OffsetWaypointGenerator(true);
                }
                else if (AutoPilot.IsWaypointThroughVelocityCollision())
                {
                    Logger.MsgDebug("Sniper Velocity Through Collision, Getting New Offset", DebugTypeEnum.General);
                    this.SniperWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.OffsetWaypointGenerator(true);
                }
            }

            //ApproachWaypoint
            if (Mode == BehaviorMode.ApproachWaypoint)
            {
                var engageDistance    = AutoPilot.InGravity() ? AutoPilot.Data.EngageDistancePlanet : AutoPilot.Data.EngageDistanceSpace;
                var disengageDistance = AutoPilot.InGravity() ? AutoPilot.Data.DisengageDistancePlanet : AutoPilot.Data.DisengageDistanceSpace;

                if (AutoPilot.DistanceToTargetWaypoint < engageDistance)
                {
                    var distanceDifference      = engageDistance - AutoPilot.DistanceToTargetWaypoint;
                    var engageDifferenceHalved  = (disengageDistance - engageDistance) / 2;
                    var directionAwayFromTarget = Vector3D.Normalize(RemoteControl.GetPosition() - AutoPilot.Targeting.TargetLastKnownCoords);
                    var fallbackCoords          = directionAwayFromTarget * (distanceDifference + engageDifferenceHalved) + RemoteControl.GetPosition();
                    AutoPilot.SetInitialWaypoint(fallbackCoords);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.EngageTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.WaypointFromTarget);
                }
            }

            //Engage
            if (Mode == BehaviorMode.EngageTarget)
            {
                var timeSpan          = MyAPIGateway.Session.GameDateTime - this.SniperWaypointWaitTime;
                var engageDistance    = AutoPilot.InGravity() ? AutoPilot.Data.EngageDistancePlanet : AutoPilot.Data.EngageDistanceSpace;
                var disengageDistance = AutoPilot.InGravity() ? AutoPilot.Data.DisengageDistancePlanet : AutoPilot.Data.DisengageDistanceSpace;

                if (timeSpan.TotalSeconds >= AutoPilot.Data.WaypointWaitTimeTrigger || AutoPilot.DistanceToTargetWaypoint > disengageDistance)
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    this.SniperWaypointAbandonTime = MyAPIGateway.Session.GameDateTime;
                    AutoPilot.OffsetWaypointGenerator(true);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode | NewAutoPilotMode.WaypointFromTarget | NewAutoPilotMode.OffsetWaypoint);
                }

                if (AutoPilot.DistanceToTargetWaypoint < engageDistance)
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachWaypoint);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
                }
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    AutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Exemplo n.º 10
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            Logger.MsgDebug(Mode.ToString(), DebugTypeEnum.General);

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            }

            if (Mode == BehaviorMode.Init)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                }
            }

            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (AutoPilot.CurrentMode != AutoPilot.UserCustomModeIdle)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
                }

                if (AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!AutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat && Mode != BehaviorMode.WaitingForTarget)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
            }

            //Approach
            if (Mode == BehaviorMode.ApproachTarget)
            {
            }

            //WaitWaitAtWaypoint
            if (Mode == BehaviorMode.WaitAtWaypoint)
            {
            }

            //Retreat
            if (Mode == BehaviorMode.Retreat)
            {
                if (Despawn.NearestPlayer?.Controller?.ControlledEntity?.Entity != null)
                {
                    //Logger.AddMsg("DespawnCoordsCreated", true);
                    AutoPilot.SetInitialWaypoint(VectorHelper.GetDirectionAwayFromTarget(this.RemoteControl.GetPosition(), Despawn.NearestPlayer.GetPosition()) * 1000 + this.RemoteControl.GetPosition());
                }
            }
        }
Exemplo n.º 11
0
        public override void MainBehavior()
        {
            if (RAI_SessionCore.IsServer == false)
            {
                return;
            }

            base.MainBehavior();

            //Logger.MsgDebug(Mode.ToString(), DebugTypeEnum.General);

            if (Mode != BehaviorMode.Retreat && Despawn.DoRetreat == true)
            {
                ChangeCoreBehaviorMode(BehaviorMode.Retreat);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | AutoPilot.UserCustomMode);
            }

            if (Mode == BehaviorMode.Init)
            {
                if (!AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                }
                else
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                }
            }

            if (Mode == BehaviorMode.WaitingForTarget)
            {
                if (AutoPilot.CurrentMode != AutoPilot.UserCustomModeIdle)
                {
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
                }

                if (AutoPilot.Targeting.HasTarget())
                {
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                }
                else if (Despawn.NoTargetExpire == true)
                {
                    Despawn.Retreat();
                }
            }

            if (!AutoPilot.Targeting.HasTarget() && Mode != BehaviorMode.Retreat && Mode != BehaviorMode.WaitingForTarget)
            {
                ChangeCoreBehaviorMode(BehaviorMode.WaitingForTarget);
                AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), AutoPilot.UserCustomModeIdle);
            }

            //Approach
            if (Mode == BehaviorMode.ApproachTarget)
            {
                var targetDist = Vector3D.Distance(RemoteControl.GetPosition(), AutoPilot.Targeting.TargetLastKnownCoords);

                if (targetDist < MaxDistanceFromTarget)
                {
                    if (AutoPilot.Data.PadDistanceFromTarget > 0 && targetDist > AutoPilot.Data.PadDistanceFromTarget)
                    {
                        //Nothing
                    }
                    else
                    {
                        BehaviorTriggerA = true;
                        ChangeCoreBehaviorMode(BehaviorMode.WaitAtWaypoint);
                        AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), (RotateToTargetWithinRange ? NewAutoPilotMode.RotateToWaypoint : NewAutoPilotMode.None) | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                    }
                }
            }

            //Engage
            if (Mode == BehaviorMode.WaitAtWaypoint)
            {
                var targetDist = Vector3D.Distance(RemoteControl.GetPosition(), AutoPilot.Targeting.TargetLastKnownCoords);

                if (AutoPilot.Data.PadDistanceFromTarget > 0 && targetDist > AutoPilot.Data.PadDistanceFromTarget)
                {
                    BehaviorTriggerC = true;
                    ChangeCoreBehaviorMode(BehaviorMode.ApproachTarget);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                }
                else if (targetDist > MaxDistanceFromTarget)
                {
                    BehaviorTriggerB = true;
                    ChangeCoreBehaviorMode(BehaviorMode.WaitAtWaypoint);
                    AutoPilot.ActivateAutoPilot(this.RemoteControl.GetPosition(), NewAutoPilotMode.RotateToWaypoint | NewAutoPilotMode.ThrustForward | NewAutoPilotMode.PlanetaryPathing | NewAutoPilotMode.WaypointFromTarget | AutoPilot.UserCustomMode);
                }
            }

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