Ejemplo n.º 1
0
        protected override Task AliveAsync()
        {
            // await base.AliveAsync();

            foreach (var sensor in Sensors)
            {
                sensor.Sense();
            }
            var contexts = ContextBehaviors.Select(b => b.Behave(Steps)).ToList();

            (var finalRing, var angle, var boost) = ContextRingBlending.Blend(contexts, true);
            SteerAngle(angle);
            var willShoot = CanShoot;

            if (CanBoost && boost && (this.SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold)
            {
                if (ShootUntil < GameTime)
                {
                    Boost();
                }
                willShoot = false;
            }
            if (CanShoot && willShoot)
            {
                var target = (AttackFleets ? FleetTargeting.ChooseTarget() : null)
                             ?? (AttackAbandoned ? AbandonedTargeting.ChooseTarget() : null)
                             ?? (AttackFish ? FishTargeting.ChooseTarget() : null);

                if (target != null)
                {
                    var  shootAngle = MathF.Atan2(target.Position.Y - this.Position.Y, target.Position.X - this.Position.X);
                    bool dangerous  = false;
                    if (!AttackFleets && this.SensorFleets.MyFleet != null)
                    {
                        var flets = FleetTargeting.PotentialTargetFleets();
                        foreach (var flet in flets)
                        {
                            if (RoboMath.MightHit(this.HookComputer, this.SensorFleets.MyFleet, flet, shootAngle))
                            {
                                dangerous = true;
                            }
                        }
                    }
                    if (!Safe || !dangerous)
                    {
                        ShootAt(target.Position);
                    }
                }
            }



            if (ReloadConfigAfter > 0 && ReloadConfigAfter < GameTime)
            {
                LoadConfig();
                ReloadConfigAfter = 0;
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 2
0
        protected async override Task AliveAsync()
        {
            await base.AliveAsync();

            // when shooting becomes available
            // lets see if we should delay
            if (!LastCanShoot && CanShoot)
            {
                DeferShootUntil = GameTime + FiringDelayMS;
            }
            LastCanShoot = CanShoot;

            if (CanShoot && DeferShootUntil < GameTime)
            {
                var target = (AttackFleets ? FleetTargeting.ChooseTarget() : null)
                             ?? (AttackAbandoned ? AbandonedTargeting.ChooseTarget() : null)
                             ?? (AttackFish ? FishTargeting.ChooseTarget() : null);

                if (target != null)
                {
                    var  shootAngle = MathF.Atan2(target.Position.Y - this.Position.Y, target.Position.X - this.Position.X);
                    bool dangerous  = false;
                    if (!AttackFleets && this.SensorFleets.MyFleet != null)
                    {
                        var flets = FleetTargeting.PotentialTargetFleets();
                        foreach (var flet in flets)
                        {
                            if (RoboMath.MightHit(this.HookComputer, this.SensorFleets.MyFleet, flet, shootAngle))
                            {
                                dangerous = true;
                            }
                        }
                    }
                    if (!Safe || !dangerous)
                    {
                        ShootAt(target.Position);
                    }
                }
            }

            if (CanBoost && (this.SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold)
            {
                Boost();
            }
        }