From 81bdea1107f7b542e8de6bb70070f4d87c6e69c2 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Tue, 23 Aug 2016 21:36:27 +0200 Subject: [PATCH 1/4] Fix the floating text for bounties of actors not being InWorld showing up --- OpenRA.Mods.Common/Traits/GivesBounty.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index d3ed043cf8..ccb0614e07 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits // 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)) + if (info.ShowBounty && self.IsInWorld && 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); From 278a812eec365008629ac14ebaa342a5407abc5d Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 27 Aug 2016 17:56:56 +0200 Subject: [PATCH 2/4] Display the value of the destroyed cargo actors --- OpenRA.Mods.Common/Traits/GivesBounty.cs | 35 ++++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index ccb0614e07..8663860fb9 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -58,6 +58,29 @@ namespace OpenRA.Mods.Common.Traits return (slevel > 0) ? slevel * info.LevelMod : 100; } + int GetBountyValue(Actor self, int percentage) + { + // Divide by 10000 because of GetMultiplier and info.Percentage. + return self.GetSellValue() * GetMultiplier(self) * percentage / 10000; + } + + int GetDisplayedBountyValue(Actor self) + { + var bounty = GetBountyValue(self, info.Percentage); + var cargo = self.TraitOrDefault(); + 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 +92,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 && self.IsInWorld && 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, info.Percentage)); } } } From a76672b0291c5584bb45af4bbfa4b8c87ed5c905 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 3 Sep 2016 15:29:39 +0200 Subject: [PATCH 3/4] Cache GainsExperience and Cargo in GivesBounty --- OpenRA.Mods.Common/Traits/GivesBounty.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index 8663860fb9..41e31962b8 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; @@ -61,13 +68,12 @@ namespace OpenRA.Mods.Common.Traits int GetBountyValue(Actor self, int percentage) { // Divide by 10000 because of GetMultiplier and info.Percentage. - return self.GetSellValue() * GetMultiplier(self) * percentage / 10000; + return self.GetSellValue() * GetMultiplier() * percentage / 10000; } int GetDisplayedBountyValue(Actor self) { var bounty = GetBountyValue(self, info.Percentage); - var cargo = self.TraitOrDefault(); if (cargo == null) return bounty; From 9f72772a37b5de166762eece33ca00a31919be6c Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 3 Sep 2016 15:30:06 +0200 Subject: [PATCH 4/4] Remove the percentage parameter from GetBountyValue --- OpenRA.Mods.Common/Traits/GivesBounty.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index 41e31962b8..e1dc5add00 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -65,15 +65,15 @@ namespace OpenRA.Mods.Common.Traits return (slevel > 0) ? slevel * info.LevelMod : 100; } - int GetBountyValue(Actor self, int percentage) + int GetBountyValue(Actor self) { // Divide by 10000 because of GetMultiplier and info.Percentage. - return self.GetSellValue() * GetMultiplier() * percentage / 10000; + return self.GetSellValue() * GetMultiplier() * info.Percentage / 10000; } int GetDisplayedBountyValue(Actor self) { - var bounty = GetBountyValue(self, info.Percentage); + var bounty = GetBountyValue(self); if (cargo == null) return bounty; @@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits 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))); - e.Attacker.Owner.PlayerActor.Trait().GiveCash(GetBountyValue(self, info.Percentage)); + e.Attacker.Owner.PlayerActor.Trait().GiveCash(GetBountyValue(self)); } } }