Merge pull request #11868 from abcdefg30/gpsBounty
Fix the floating text for bounties of actors not being InWorld showing up
This commit is contained in:
@@ -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<GainsExperience>();
|
||||
cargo = self.TraitOrDefault<Cargo>();
|
||||
}
|
||||
|
||||
// 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<GainsExperience>();
|
||||
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<GivesBounty>();
|
||||
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<PlayerResources>().GiveCash(bounty);
|
||||
e.Attacker.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(GetBountyValue(self));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user