public RenderRangeCircle(Actor self) { this.self = self; attack = self.Trait <AttackBase>(); }
// Note: facing is only used by the legacy positioning code // The world coordinate model uses Actor.Orientation public void CheckFire(Actor self, AttackBase attack, IFacing facing, Target target) { if (FireDelay > 0) { return; } var limitedAmmo = self.TraitOrDefault <LimitedAmmo>(); if (limitedAmmo != null && !limitedAmmo.HasAmmo()) { return; } // TODO: Define weapon ranges as WRange var range = new WRange((int)(1024 * Weapon.Range)); var minRange = new WRange((int)(1024 * Weapon.MinRange)); if (!target.IsInRange(self.CenterPosition, range)) { return; } if (minRange != WRange.Zero && target.IsInRange(self.CenterPosition, minRange)) { return; } if (!Weapon.IsValidAgainst(target, self.World)) { return; } var barrel = Barrels[Burst % Barrels.Length]; var muzzlePosition = self.CenterPosition + MuzzleOffset(self, barrel); var legacyFacing = MuzzleOrientation(self, barrel).Yaw.Angle / 4; var args = new ProjectileArgs { Weapon = Weapon, Facing = legacyFacing, FirepowerModifier = self.TraitsImplementing <IFirepowerModifier>() .Select(a => a.GetFirepowerModifier()) .Product(), Source = muzzlePosition, SourceActor = self, PassiveTarget = target.CenterPosition, GuidedTarget = target }; attack.ScheduleDelayedAction(Info.FireDelay, () => { if (args.Weapon.Projectile != null) { var projectile = args.Weapon.Projectile.Create(args); if (projectile != null) { self.World.Add(projectile); } if (args.Weapon.Report != null && args.Weapon.Report.Any()) { Sound.Play(args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition); } } }); foreach (var na in self.TraitsImplementing <INotifyAttack>()) { na.Attacking(self, target, this, barrel); } Recoil = Info.Recoil; if (--Burst > 0) { FireDelay = Weapon.BurstDelay; } else { FireDelay = Weapon.ROF; Burst = Weapon.Burst; } }
public void CheckFire(Actor self, AttackBase attack, IMove move, IFacing facing, Target target) { if (FireDelay > 0) { return; } var limitedAmmo = self.TraitOrDefault <LimitedAmmo>(); if (limitedAmmo != null && !limitedAmmo.HasAmmo()) { return; } if (!Combat.IsInRange(self.CenterLocation, Info.Range, target)) { return; } if (Combat.IsInRange(self.CenterLocation, Info.MinRange, target)) { return; } if (!IsValidAgainst(self.World, target)) { return; } var barrel = Barrels[Burst % Barrels.Length]; var destMove = target.IsActor ? target.Actor.TraitOrDefault <IMove>() : null; var turreted = self.TraitOrDefault <Turreted>(); var args = new ProjectileArgs { weapon = Info, firedBy = self, target = target, src = (self.CenterLocation + Combat.GetBarrelPosition(self, facing, Turret, barrel)).ToInt2(), srcAltitude = move != null ? move.Altitude : 0, dest = target.CenterLocation, destAltitude = destMove != null ? destMove.Altitude : 0, facing = barrel.Facing + (turreted != null ? turreted.turretFacing : facing != null ? facing.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)), firepowerModifier = self.TraitsImplementing <IFirepowerModifier>() .Select(a => a.GetFirepowerModifier()) .Product() }; attack.ScheduleDelayedAction(attack.FireDelay(self, target, self.Info.Traits.Get <AttackBaseInfo>()), () => { if (args.weapon.Projectile != null) { var projectile = args.weapon.Projectile.Create(args); if (projectile != null) { self.World.Add(projectile); } if (!string.IsNullOrEmpty(args.weapon.Report)) { Sound.Play(args.weapon.Report + ".aud", self.CenterLocation); } } }); foreach (var na in self.TraitsImplementing <INotifyAttack>()) { na.Attacking(self, target); } FiredShot(); }