private void FireOnTargetNonVisible(Weapon w, GameplayObject fireTarget) { if (this.Owner.Ordinance < w.OrdinanceRequiredToFire || this.Owner.PowerCurrent < w.PowerRequiredToFire) { return; } w.timeToNextFire = w.fireDelay; if (w.IsRepairDrone) { return; } if (TargetShip == null || !TargetShip.Active || TargetShip.dying || !w.TargetValid(TargetShip.Role) || TargetShip.engineState == Ship.MoveState.Warp || !this.Owner.CheckIfInsideFireArc(w, TargetShip)) return; Ship owner = this.Owner; owner.Ordinance = owner.Ordinance - w.OrdinanceRequiredToFire; Ship powerCurrent = this.Owner; powerCurrent.PowerCurrent = powerCurrent.PowerCurrent - w.PowerRequiredToFire; powerCurrent.PowerCurrent -= w.BeamPowerCostPerSecond * w.BeamDuration; this.Owner.InCombatTimer = 15f; if (fireTarget is Projectile) { fireTarget.Damage(w.GetOwner(), w.DamageAmount); return; } if (!(fireTarget is Ship)) { if (fireTarget is ShipModule) { w.timeToNextFire = w.fireDelay; IOrderedEnumerable<ModuleSlot> sortedList = from slot in (fireTarget as ShipModule).GetParent().ExternalSlots orderby Vector2.Distance(slot.module.Center, this.Owner.Center) select slot; float damage = w.DamageAmount; if (w.isBeam) { damage = damage * 90f; } if (w.SalvoCount > 0) { damage = damage * (float)w.SalvoCount; } sortedList.First<ModuleSlot>().module.Damage(this.Owner, damage); } return; } w.timeToNextFire = w.fireDelay; if ((fireTarget as Ship).ExternalSlots.Count == 0) { (fireTarget as Ship).Die(null, true); return; } float nearest = 0; ModuleSlot ClosestES = null; foreach (ModuleSlot ES in (fireTarget as Ship).ExternalSlots) { if (ES.module.ModuleType == ShipModuleType.Dummy || !ES.module.Active || ES.module.Health <= 0) continue; float temp = Vector2.Distance(ES.module.Center, w.GetOwner().Center); if (nearest == 0 || temp < nearest) { nearest = temp; ClosestES = ES; } } if (ClosestES == null) return; // List<ModuleSlot> IEnumerable<ModuleSlot> ExternalSlots = (fireTarget as Ship).ExternalSlots.Where(close => close.module.Active && close.module.quadrant == ClosestES.module.quadrant && close.module.Health > 0);//.ToList(); //.OrderByDescending(shields=> shields.Shield_Power >0);//.ToList(); if ((fireTarget as Ship).shield_power > 0f) { for (int i = 0; i < (fireTarget as Ship).GetShields().Count; i++) { if ((fireTarget as Ship).GetShields()[i].Active && (fireTarget as Ship).GetShields()[i].shield_power > 0f) { float damage = w.DamageAmount; if (w.isBeam) { damage = damage * 90f; } if (w.SalvoCount > 0) { damage = damage * (float)w.SalvoCount; } (fireTarget as Ship).GetShields()[i].Damage(this.Owner, damage); return; } } return; } //this.Owner.GetSystem() != null ? this.Owner.GetSystem().RNG : ArtificialIntelligence.universeScreen.DeepSpaceRNG)).RandomBetween(0f, 100f) <= 50f || if (ExternalSlots.ElementAt(0).module.shield_power > 0f) { for (int i = 0; i < ExternalSlots.Count(); i++) { if (ExternalSlots.ElementAt(i).module.Active && ExternalSlots.ElementAt(i).module.shield_power <= 0f) { float damage = w.DamageAmount; if (w.isBeam) { damage = damage * 90f; } if (w.SalvoCount > 0) { damage = damage * (float)w.SalvoCount; } ExternalSlots.ElementAt(i).module.Damage(this.Owner, damage); return; } } return; } for (int i = 0; i < ExternalSlots.Count(); i++) { if (ExternalSlots.ElementAt(i).module.Active && ExternalSlots.ElementAt(i).module.shield_power <= 0f) { float damage = w.DamageAmount; if (w.isBeam) { damage = damage * 90f; } if (w.SalvoCount > 0) { damage = damage * (float)w.SalvoCount; } ExternalSlots.ElementAt(i).module.Damage(this.Owner, damage); return; } } }
public bool CheckRangeToTarget(Weapon w, GameplayObject target) { if (target == null || !target.Active || target.Health <= 0) return false; if (this.engineState == MoveState.Warp) return false; Ship targetship = target as Ship; ShipModule targetModule = target as ShipModule; if (targetship == null && targetModule != null) targetship = targetModule.GetParent(); if (targetship != null) { if (targetship.engineState == MoveState.Warp || targetship.dying || !targetship.Active || targetship.ExternalSlots.Count <= 0 || !w.TargetValid(targetship.Role) ) return false; } Vector2 PickedPos = target.Center; //radius = target.Radius; //added by gremlin attackrun compensator float modifyRangeAR = 50f; Vector2 pos = PickedPos; if (w.PrimaryTarget && !w.isBeam && this.GetAI().CombatState == CombatState.AttackRuns && this.maxWeaponsRange < 2000 && w.SalvoCount > 0) { modifyRangeAR = this.speed; if (modifyRangeAR < 50) modifyRangeAR = 50; } if (Vector2.Distance(pos, w.moduleAttachedTo.Center) > w.GetModifiedRange() + modifyRangeAR)//+radius) { return false; } return true; }