From 4c04d4fa30f747de9fc5e45f43cf5d56f658ebea Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:59:05 +0200 Subject: [PATCH] Add death types --- .../Traits/FireProjectilesOnDeath.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/FireProjectilesOnDeath.cs b/OpenRA.Mods.Common/Traits/FireProjectilesOnDeath.cs index 2deb98d8fe..cbb9f23bfe 100644 --- a/OpenRA.Mods.Common/Traits/FireProjectilesOnDeath.cs +++ b/OpenRA.Mods.Common/Traits/FireProjectilesOnDeath.cs @@ -11,6 +11,7 @@ using System.Linq; using OpenRA.GameRules; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -23,6 +24,16 @@ namespace OpenRA.Mods.Common.Traits [Desc("The weapons used for shrapnel.")] public readonly string[] Weapons = []; + [Desc("What damage type needs to kill the actor to trigger the firing of projectiles? " + + "Leave empty to ignore damage types.")] + public readonly BitSet DeathTypes = default; + + [Desc("The minimal amount of health loss required to trigger projectiles.")] + public readonly int MinimumDamage = 0; + + [Desc("The maximum amount of health loss required to trigger projectiles.")] + public readonly int MaximumDamage = int.MaxValue; + [Desc("The amount of pieces of shrapnel to expel. Two values indicate a range.")] public readonly int[] Pieces = [3, 10]; @@ -51,11 +62,17 @@ namespace OpenRA.Mods.Common.Traits public FireProjectilesOnDeath(FireProjectilesOnDeathInfo info) : base(info) { } - public void Killed(Actor self, AttackInfo attack) + void INotifyKilled.Killed(Actor self, AttackInfo attack) { if (IsTraitDisabled) return; + if (!Info.DeathTypes.IsEmpty && !attack.Damage.DamageTypes.Overlaps(Info.DeathTypes)) + return; + + if (attack.Damage.Value <= Info.MinimumDamage || attack.Damage.Value >= Info.MaximumDamage) + return; + foreach (var wep in Info.WeaponInfos) { var pieces = Util.RandomInRange(self.World.SharedRandom, Info.Pieces);