fix #772 -- GivesBounty uses Actor.GetSellValue

This commit is contained in:
Chris Forbes
2011-05-11 07:55:07 +12:00
parent 0807f4ca8d
commit 3bbcbf4701
4 changed files with 19 additions and 8 deletions

View File

@@ -23,9 +23,8 @@ namespace OpenRA.Mods.RA.Activities
var h = self.TraitOrDefault<Health>();
var si = self.Info.Traits.Get<SellableInfo>();
var pr = self.Owner.PlayerActor.Trait<PlayerResources>();
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
var cost = self.GetSellValue();
var refund = (cost * si.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
pr.GiveCash(refund);

View File

@@ -21,4 +21,18 @@ namespace OpenRA.Mods.RA.Buildings
}
public class CustomSellValue { }
public static class CustomSellValueExts
{
public static int GetSellValue( this Actor a )
{
var csv = a.Info.Traits.GetOrDefault<CustomSellValueInfo>();
if (csv != null) return csv.Value;
var valued = a.Info.Traits.GetOrDefault<ValuedInfo>();
if (valued != null) return valued.Cost;
return 0;
}
}
}

View File

@@ -52,8 +52,7 @@ namespace OpenRA.Mods.RA.Buildings
if (remainingTicks == 0)
{
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var buildingValue = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
var buildingValue = self.GetSellValue();
var hpToRepair = Math.Min(Info.RepairStep, Health.MaxHP - Health.HP);
var cost = (hpToRepair * Info.RepairPercent * buildingValue) / (Health.MaxHP * 100);

View File

@@ -10,6 +10,7 @@
using OpenRA.Traits;
using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Mods.RA
{
@@ -21,7 +22,6 @@ namespace OpenRA.Mods.RA
class GivesBounty : INotifyKilled
{
int GetMultiplier(Actor self)
{
// returns 100's as 1, so as to keep accuracy for longer.
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA
if (gainsExp == null)
return 100;
var slevel = self.Trait<GainsExperience>().Level;
var slevel = gainsExp.Level;
return (slevel > 0) ? slevel * info.LevelMod : 100;
}
@@ -41,8 +41,7 @@ namespace OpenRA.Mods.RA
if (e.Attacker == null || e.Attacker.Destroyed || e.Attacker.Owner.Stances[self.Owner] == Stance.Ally)
return;
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
var cost = valued != null ? valued.Cost : 0;
var cost = self.GetSellValue();
// 2 hundreds because of GetMultiplier and info.Percentage.
var bounty = cost * GetMultiplier(self) * info.Percentage / 10000;