From c205afcf4d495e0d830c67f0b9afdf62bcde3f11 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 24 Jul 2015 14:29:07 +0200 Subject: [PATCH] Add descriptions and LoadedChance to Explodes trait 'Chance' only allows to control whether the actor explodes at all. 'LoadedChance' allows to control how likely the actor will explode violently using Weapon, and otherwise falls back to EmptyWeapon. --- OpenRA.Mods.Common/Traits/Explodes.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Explodes.cs b/OpenRA.Mods.Common/Traits/Explodes.cs index 3dcf1ad02c..a0a55f4544 100644 --- a/OpenRA.Mods.Common/Traits/Explodes.cs +++ b/OpenRA.Mods.Common/Traits/Explodes.cs @@ -14,14 +14,22 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { + [Desc("This actor explodes when killed.")] public class ExplodesInfo : ITraitInfo { - [WeaponReference] + [WeaponReference, Desc("Weapon to use for explosion if ammo/payload is loaded.")] public readonly string Weapon = "UnitExplode"; - [WeaponReference] + + [WeaponReference, Desc("Weapon to use for explosion if no ammo/payload is loaded.")] public readonly string EmptyWeapon = "UnitExplode"; + [Desc("Chance that the explosion will use Weapon if the actor has ammo/payload.")] + public readonly int LoadedChance = 100; + + [Desc("Chance that this actor will explode at all.")] public readonly int Chance = 100; + + [Desc("DeathType(s) to apply upon explosion.")] public readonly string[] DeathType = null; public object Create(ActorInitializer init) { return new Explodes(this); } @@ -60,7 +68,8 @@ namespace OpenRA.Mods.Common.Traits string ChooseWeaponForExplosion(Actor self) { var shouldExplode = self.TraitsImplementing().All(a => a.ShouldExplode(self)); - return shouldExplode ? info.Weapon : info.EmptyWeapon; + var useFullExplosion = self.World.SharedRandom.Next(100) <= info.LoadedChance; + return (shouldExplode && useFullExplosion) ? info.Weapon : info.EmptyWeapon; } } }