コード例 #1
0
ファイル: Horsefly.cs プロジェクト: jturp/RivalAI
        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());
                }
            }
        }
コード例 #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.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());
                }
            }
        }
コード例 #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 | 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());
                }
            }
        }