예제 #1
0
파일: Combat.cs 프로젝트: below0isk/Questor
        /// <summary>
        ///   Returns true if it can activate the weapon on the target
        /// </summary>
        /// <remarks>
        ///   The idea behind this function is that a target that explodes isnt being fired on within 5 seconds
        /// </remarks>
        /// <param name = "module"></param>
        /// <param name = "entity"></param>
        /// <param name = "isWeapon"></param>
        /// <returns></returns>
        public bool CanActivate(ModuleCache module, EntityCache entity, bool isWeapon)
        {
            // We have changed target, allow activation
            if (entity.Id != module.LastTargetId)
            {
                return(true);
            }

            // We have reloaded, allow activation
            if (isWeapon && module.CurrentCharges == MaxCharges)
            {
                return(true);
            }

            // We havent reloaded, insert a wait-time
            if (_lastModuleActivation.ContainsKey(module.ItemId))
            {
                if (DateTime.Now.Subtract(_lastModuleActivation[module.ItemId]).TotalSeconds < 3)
                {
                    return(false);
                }

                _lastModuleActivation.Remove(module.ItemId);
                return(true);
            }

            _lastModuleActivation.Add(module.ItemId, DateTime.Now);
            return(false);
        }
예제 #2
0
파일: Combat.cs 프로젝트: below0isk/Questor
        /// <summary>
        ///   Reload correct (tm) ammo for the NPC
        /// </summary>
        /// <param name = "weapon"></param>
        /// <param name = "entity"></param>
        /// <returns>True if the (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded</returns>
        public bool ReloadAmmo(ModuleCache weapon, EntityCache entity)
        {
            // We need the cargo bay open for both reload actions
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();

            if (cargo.Window == null)
            {
                Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip);
                return(false);
            }

            if (!cargo.IsReady)
            {
                return(false);
            }

            return(weapon.IsEnergyWeapon ? ReloadEnergyWeaponAmmo(weapon, entity) : ReloadNormalAmmo(weapon, entity));
        }
예제 #3
0
파일: Combat.cs 프로젝트: rixim/Questor
        /// <summary>
        ///   Reload correct (tm) ammo for the NPC
        /// </summary>
        /// <param name = "weapon"></param>
        /// <param name = "entity"></param>
        /// <returns>True if the (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded</returns>
        public bool ReloadNormalAmmo(ModuleCache weapon, EntityCache entity)
        {
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();

            // Get ammo based on damage type
            var correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType);

            // Check if we still have that ammo in our cargo
            correctAmmo = correctAmmo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges));

            //check if mission specific ammo is defined
            if (Cache.Instance.missionAmmo.Count() != 0)
            {
                correctAmmo = Cache.Instance.missionAmmo.Where(a => a.DamageType == Cache.Instance.DamageType);
            }

            // Check if we still have that ammo in our cargo
            correctAmmo = correctAmmo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges));
            if (Cache.Instance.missionAmmo.Count() != 0)
            {
                correctAmmo = Cache.Instance.missionAmmo;
            }

            // We are out of ammo! :(
            if (correctAmmo.Count() == 0)
            {
                State = CombatState.OutOfAmmo;
                return false;
            }

            // Get the best possible ammo
            var ammo = correctAmmo.Where(a => a.Range > entity.Distance).OrderBy(a => a.Range).FirstOrDefault();

            // We do not have any ammo left that can hit targets at that range!
            if (ammo == null)
                return false;

            // We have enough ammo loaded
            if (weapon.Charge != null && weapon.Charge.TypeId == ammo.TypeId && weapon.CurrentCharges >= Settings.Instance.MinimumAmmoCharges)
                return true;

            // Retry later, assume its ok now
            if (weapon.MatchingAmmo.Count() == 0)
                return true;

            var charge = cargo.Items.FirstOrDefault(i => i.TypeId == ammo.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges);
            // This should have shown up as "out of ammo"
            if (charge == null)
                return false;

            // We are reloading, wait at least 11 seconds
            if (_lastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.Now < _lastWeaponReload[weapon.ItemId].AddSeconds(22))
                return false;
            _lastWeaponReload[weapon.ItemId] = DateTime.Now;

            // Reload or change ammo
            if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId)
            {
                Logging.Log("Combat: Reloading [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
                weapon.ReloadAmmo(charge);
            }
            else
            {
                Logging.Log("Combat: Changing [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
                weapon.ChangeAmmo(charge);
            }

            // Return false as we are reloading ammo
            return false;
        }
예제 #4
0
파일: Combat.cs 프로젝트: rixim/Questor
        public bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity)
        {
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();

            // Get ammo based on damage type
            var correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType);

            // Check if we still have that ammo in our cargo
            correctAmmo = correctAmmo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId));

            // We are out of ammo! :(
            if (correctAmmo.Count() == 0)
            {
                State = CombatState.OutOfAmmo;
                return false;
            }

            // Get the best possible ammo
            var ammo = correctAmmo.Where(a => a.Range > entity.Distance).OrderBy(a => a.Range).FirstOrDefault();

            // We do not have any ammo left that can hit targets at that range!
            if (ammo == null)
                return false;

            var charge = cargo.Items.OrderBy(i => i.Quantity).FirstOrDefault(i => i.TypeId == ammo.TypeId);
            // We do not have any ammo left that can hit targets at that range!
            if (charge == null)
                return false;

            // We have enough ammo loaded
            if (weapon.Charge != null && weapon.Charge.TypeId == ammo.TypeId)
                return true;

            // We are reloading, wait at least 5 seconds
            if (_lastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.Now < _lastWeaponReload[weapon.ItemId].AddSeconds(5))
                return false;
            _lastWeaponReload[weapon.ItemId] = DateTime.Now;

            // Reload or change ammo
            if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId)
            {
                Logging.Log("Combat: Reloading [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
                weapon.ReloadAmmo(charge);
            }
            else
            {
                Logging.Log("Combat: Changing [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
                weapon.ChangeAmmo(charge);
            }

            // Return false as we are reloading ammo
            return false;
        }
예제 #5
0
파일: Combat.cs 프로젝트: rixim/Questor
        /// <summary>
        ///   Reload correct (tm) ammo for the NPC
        /// </summary>
        /// <param name = "weapon"></param>
        /// <param name = "entity"></param>
        /// <returns>True if the (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded</returns>
        public bool ReloadAmmo(ModuleCache weapon, EntityCache entity)
        {
            // We need the cargo bay open for both reload actions
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();
            if (cargo.Window == null)
            {
                Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip);
                return false;
            }

            if (!cargo.IsReady)
                return false;

            return weapon.IsEnergyWeapon ? ReloadEnergyWeaponAmmo(weapon, entity) : ReloadNormalAmmo(weapon, entity);
        }
예제 #6
0
파일: Combat.cs 프로젝트: rixim/Questor
        /// <summary>
        ///   Returns true if it can activate the weapon on the target
        /// </summary>
        /// <remarks>
        ///   The idea behind this function is that a target that explodes isnt being fired on within 5 seconds
        /// </remarks>
        /// <param name = "module"></param>
        /// <param name = "entity"></param>
        /// <param name = "isWeapon"></param>
        /// <returns></returns>
        public bool CanActivate(ModuleCache module, EntityCache entity, bool isWeapon)
        {
            // We have changed target, allow activation
            if (entity.Id != module.LastTargetId)
                return true;

            // We have reloaded, allow activation
            if (isWeapon && module.CurrentCharges == MaxCharges)
                return true;

            // We havent reloaded, insert a wait-time
            if (_lastModuleActivation.ContainsKey(module.ItemId))
            {
                if (DateTime.Now.Subtract(_lastModuleActivation[module.ItemId]).TotalSeconds < 3)
                    return false;

                _lastModuleActivation.Remove(module.ItemId);
                return true;
            }

            _lastModuleActivation.Add(module.ItemId, DateTime.Now);
            return false;
        }
예제 #7
0
파일: Combat.cs 프로젝트: below0isk/Questor
        /// <summary>
        ///   Reload correct (tm) ammo for the NPC
        /// </summary>
        /// <param name = "weapon"></param>
        /// <param name = "entity"></param>
        /// <returns>True if the (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded</returns>
        public bool ReloadNormalAmmo(ModuleCache weapon, EntityCache entity)
        {
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();

            // Get ammo based on damage type
            var correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType);

            // Check if we still have that ammo in our cargo
            correctAmmo = correctAmmo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges));

            // We are out of ammo! :(
            if (correctAmmo.Count() == 0)
            {
                State = CombatState.OutOfAmmo;
                return(false);
            }

            // Get the best possible ammo
            var ammo = correctAmmo.Where(a => a.Range > entity.Distance).OrderBy(a => a.Range).FirstOrDefault();

            // We do not have any ammo left that can hit targets at that range!
            if (ammo == null)
            {
                return(false);
            }

            // We have enough ammo loaded
            if (weapon.Charge != null && weapon.Charge.TypeId == ammo.TypeId && weapon.CurrentCharges >= Settings.Instance.MinimumAmmoCharges)
            {
                return(true);
            }

            // Retry later, assume its ok now
            if (weapon.MatchingAmmo.Count() == 0)
            {
                return(true);
            }

            var charge = cargo.Items.FirstOrDefault(i => i.TypeId == ammo.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges);

            // This should have shown up as "out of ammo"
            if (charge == null)
            {
                return(false);
            }

            // We are reloading, wait at least 11 seconds
            if (_lastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.Now < _lastWeaponReload[weapon.ItemId].AddSeconds(22))
            {
                return(false);
            }
            _lastWeaponReload[weapon.ItemId] = DateTime.Now;

            // Reload or change ammo
            if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId)
            {
                Logging.Log("Combat: Reloading [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
                weapon.ReloadAmmo(charge);
            }
            else
            {
                Logging.Log("Combat: Changing [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
                weapon.ChangeAmmo(charge);
            }

            // Return false as we are reloading ammo
            return(false);
        }
예제 #8
0
파일: Combat.cs 프로젝트: ahaw/Questor
        public bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity)
        {
            var cargo = Cache.Instance.DirectEve.GetShipsCargo();

            // Get ammo based on damage type
            var correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType);

            // Check if we still have that ammo in our cargo
            correctAmmo = correctAmmo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId));

            // We are out of ammo! :(
            if (correctAmmo.Count() == 0)
            {
                State = CombatState.OutOfAmmo;
                return(false);
            }

            // Get the best possible ammo - energy weapons change ammo near instantly
            var ammo = correctAmmo.Where(a => a.Range > (entity.Distance)).OrderBy(a => a.Range).FirstOrDefault(); //default

            // We do not have any ammo left that can hit targets at that range!
            if (ammo == null)
            {
                return(false);
            }

            var charge = cargo.Items.OrderBy(i => i.Quantity).FirstOrDefault(i => i.TypeId == ammo.TypeId);

            // We do not have any ammo left that can hit targets at that range!
            if (charge == null)
            {
                return(false);
            }

            // We have enough ammo loaded
            if (weapon.Charge != null && weapon.Charge.TypeId == ammo.TypeId)
            {
                return(true);
            }

            // We are reloading, wait at least 5 seconds
            if (_lastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.Now < _lastWeaponReload[weapon.ItemId].AddSeconds(5))
            {
                return(false);
            }
            _lastWeaponReload[weapon.ItemId] = DateTime.Now;

            // Reload or change ammo
            if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId)
            {
                Logging.Log("Combat: Reloading [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
                weapon.ReloadAmmo(charge);
            }
            else
            {
                Logging.Log("Combat: Changing [" + weapon.ItemId + "] with [" + charge.TypeName + "][" + charge.TypeId + "]");
                weapon.ChangeAmmo(charge);
            }

            // Return false as we are reloading ammo
            return(false);
        }