Questor.Modules.EntityCache.Approach C# (CSharp) Method

Approach() public method

public Approach ( ) : void
return void
        public void Approach()
        {
            Cache.Instance.Approaching = this;

            if (_directEntity != null)
                _directEntity.Approach();
        }

Same methods

EntityCache::Approach ( int range ) : void

Usage Example

Example #1
0
        /// <summary> Activate weapons
        /// </summary>
        private void ActivateWeapons(EntityCache target)
        {
            if (DateTime.Now < _nextWeaponAction) //if we just did something wait a fraction of a second
                return;

            var DontMoveMyShip = true; // This may become an  XML setting at some point.
            //
            // Do we really want a non-mission action moving the ship around at all!! (other than speed tanking)?
            //
            // Get lowest range
            var range = Math.Min(Cache.Instance.WeaponRange, Cache.Instance.DirectEve.ActiveShip.MaxTargetRange);

            if (Settings.Instance.SpeedTank && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != target.Id))
            {
                if ((DateTime.Now.Subtract(_lastOrbit).TotalSeconds > 15))
                {
                    target.Orbit(Cache.Instance.OrbitDistance);
                    Logging.Log("Combat.ActivateWeapons: Initiating Orbit [" + target.Name + "][ID: " + target.Id + "]");
                    _lastOrbit = DateTime.Now;
                }
            }

            if (!DontMoveMyShip) //why would we want the ship to move if we aren't speed tanking and the mission XML isn't telling us to move?
            {
                if (!Settings.Instance.SpeedTank) //we need to make sure that orbitrange is set to the range of the ship if it isn't specified in the character XML!!!!
                {
                    if (Settings.Instance.OptimalRange != 0)
                    {
                        if (target.Distance > Settings.Instance.OptimalRange + (int)Distance.OptimalRangeCushion && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != target.Id))
                        {
                            target.Approach(Settings.Instance.OptimalRange);
                            Logging.Log("Combat.ActivateWeapons:: Using Optimal Range: Approaching target [" + target.Name + "][ID: " + target.Id + "]");
                        }

                        if (target.Distance <= Settings.Instance.OptimalRange && Cache.Instance.Approaching != null)
                        {
                            Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdStopShip);
                            Cache.Instance.Approaching = null;
                            Logging.Log("Combat.ActivateWeapons: Using Optimal Range: Stop ship, target is in orbit range");
                        }
                    }
                    else
                    {
                        if (target.Distance > range && (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != target.Id))
                        {
                            target.Approach((int)(Cache.Instance.WeaponRange * 0.8d));
                            Logging.Log("Combat.ActivateWeapons: Using Weapons Range: Approaching target [" + target.Name + "][ID: " + target.Id + "]");
                        }

                        if (target.Distance <= range && Cache.Instance.Approaching != null)
                        {
                            Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdStopShip);
                            Cache.Instance.Approaching = null;
                            Logging.Log("Combat.ActivateWeapons: Using Weapons Range: Stop ship, target is in orbit range");
                        }
                    }
                }
            }

            // Get the weapons
            var weapons = Cache.Instance.Weapons;

            // TODO: Add check to see if there is better ammo to use! :)
            // Get distance of the target and compare that with the ammo currently loaded
            foreach (var weapon in weapons)
            {
                // don't waste ammo on small target if you use autocannon or siege i hope you use drone
                if (Settings.Instance.DontShootFrigatesWithSiegeorAutoCannons) //this defaults to false and needs to be changed in your characters settings xml file if you want to enable this option
                {
                    if (Settings.Instance.WeaponGroupId == 55 || Settings.Instance.WeaponGroupId == 508 || Settings.Instance.WeaponGroupId == 506)
                    {
                    if (target.Distance <= (int)Distance.InsideThisRangeIsLIkelyToBeMostlyFrigates && !target.TargetValue.HasValue && target.GroupId != (int)Group.LargeCollidableStructure)
                        {
                            weapon.Deactivate();
                        }
                    }
                }
                if (!weapon.IsActive)
                    continue;

                if (weapon.IsReloadingAmmo || weapon.IsDeactivating || weapon.IsChangingAmmo)
                    continue;

                // No ammo loaded
                if (weapon.Charge == null)
                    continue;

                var ammo = Settings.Instance.Ammo.FirstOrDefault(a => a.TypeId == weapon.Charge.TypeId);

                //use mission specific ammo
                if (Cache.Instance.missionAmmo.Count() != 0)
                {
                    ammo = Cache.Instance.missionAmmo.FirstOrDefault(a => a.TypeId == weapon.Charge.TypeId);
                }

                // How can this happen? Someone manually loaded ammo
                if (ammo == null)
                    continue;

                // If we have already activated warp, deactivate the weapons
                if (!Cache.Instance.DirectEve.ActiveShip.Entity.IsWarping)
                {
                    // Target is in range
                    if(target.Distance <= ammo.Range)
                    continue;
                }
                // Target is out of range, stop firing
                weapon.Deactivate();
            }

            // Hax for max charges returning incorrect value
            if (!weapons.Any(w => w.IsEnergyWeapon))
            {
                MaxCharges = Math.Max(MaxCharges, weapons.Max(l => l.MaxCharges));
                MaxCharges = Math.Max(MaxCharges, weapons.Max(l => l.CurrentCharges));
            }

            // Activate the weapons (it not yet activated)))
            foreach (var weapon in weapons)
            {
                // Are we reloading, deactivating or changing ammo?
                if (weapon.IsReloadingAmmo || weapon.IsDeactivating || weapon.IsChangingAmmo)
                    continue;
                // Are we on the right target?
                if (weapon.IsActive)
                {
                    if (weapon.TargetId != target.Id)
                        weapon.Deactivate();

                    continue;
                }

                // No, check ammo type and if that is correct, activate weapon
                if (ReloadAmmo(weapon, target) && CanActivate(weapon, target, true))
                {
                    Logging.Log("Combat: Activating weapon [" + weapon.ItemId + "] on [" + target.Name + "][ID: " + target.Id + "][" + Math.Round(target.Distance/1000,0) + "k away]");
                    weapon.Activate(target.Id);
                    _nextWeaponAction = DateTime.Now.AddMilliseconds((int)Time.WeaponDelay_miliseconds);
                    //we know we are connected if we were able to get this far - update the lastknownGoodConnectedTime
                    Cache.Instance.lastKnownGoodConnectedTime = DateTime.Now;
                    Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth;
                    return;
                }
            }
        }
All Usage Examples Of Questor.Modules.EntityCache::Approach