diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index d3ed043cf8..e1dc5add00 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -38,19 +38,26 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new GivesBounty(init.Self, this); } } - class GivesBounty : INotifyKilled + class GivesBounty : INotifyKilled, INotifyCreated { readonly GivesBountyInfo info; + GainsExperience gainsExp; + Cargo cargo; public GivesBounty(Actor self, GivesBountyInfo info) { this.info = info; } - int GetMultiplier(Actor self) + void INotifyCreated.Created(Actor self) + { + gainsExp = self.TraitOrDefault(); + cargo = self.TraitOrDefault(); + } + + // Returns 100's as 1, so as to keep accuracy for longer. + int GetMultiplier() { - // returns 100's as 1, so as to keep accuracy for longer. - var gainsExp = self.TraitOrDefault(); if (gainsExp == null) return 100; @@ -58,6 +65,28 @@ namespace OpenRA.Mods.Common.Traits return (slevel > 0) ? slevel * info.LevelMod : 100; } + int GetBountyValue(Actor self) + { + // Divide by 10000 because of GetMultiplier and info.Percentage. + return self.GetSellValue() * GetMultiplier() * info.Percentage / 10000; + } + + int GetDisplayedBountyValue(Actor self) + { + var bounty = GetBountyValue(self); + if (cargo == null) + return bounty; + + foreach (var a in cargo.Passengers) + { + var givesBounty = a.TraitOrDefault(); + if (givesBounty != null) + bounty += givesBounty.GetDisplayedBountyValue(a); + } + + return bounty; + } + void INotifyKilled.Killed(Actor self, AttackInfo e) { if (e.Attacker == null || e.Attacker.Disposed) @@ -69,15 +98,11 @@ namespace OpenRA.Mods.Common.Traits if (info.DeathTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(info.DeathTypes)) return; - var cost = self.GetSellValue(); + var displayedBounty = GetDisplayedBountyValue(self); + if (info.ShowBounty && self.IsInWorld && displayedBounty > 0 && e.Attacker.Owner.IsAlliedWith(self.World.RenderPlayer)) + e.Attacker.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, FloatingText.FormatCashTick(displayedBounty), 30))); - // 2 hundreds because of GetMultiplier and info.Percentage. - var bounty = cost * GetMultiplier(self) * info.Percentage / 10000; - - if (info.ShowBounty && bounty > 0 && e.Attacker.Owner.IsAlliedWith(self.World.RenderPlayer)) - e.Attacker.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, FloatingText.FormatCashTick(bounty), 30))); - - e.Attacker.Owner.PlayerActor.Trait().GiveCash(bounty); + e.Attacker.Owner.PlayerActor.Trait().GiveCash(GetBountyValue(self)); } } }