Add 'AddToAssetsValue' to 'UpdatesPlayerStatistics'

This commit is contained in:
abcdefg30
2020-09-06 16:25:09 +02:00
committed by reaperrr
parent f9bb663f6b
commit 3fc5859f08
2 changed files with 29 additions and 6 deletions

View File

@@ -56,6 +56,7 @@ namespace OpenRA.Mods.Common.Traits
public int BuildingsDead; public int BuildingsDead;
public int ArmyValue; public int ArmyValue;
public int AssetsValue;
// High resolution (every second) record of earnings, limited to the last minute // High resolution (every second) record of earnings, limited to the last minute
readonly Queue<int> earnedSeconds = new Queue<int>(60); readonly Queue<int> earnedSeconds = new Queue<int>(60);
@@ -186,6 +187,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Add to army value in statistics")] [Desc("Add to army value in statistics")]
public bool AddToArmyValue = false; public bool AddToArmyValue = false;
[Desc("Add to assets value in statistics")]
public bool AddToAssetsValue = true;
[ActorReference] [ActorReference]
[Desc("Count this actor as a different type in the spectator army display.")] [Desc("Count this actor as a different type in the spectator army display.")]
public string OverrideActor = null; public string OverrideActor = null;
@@ -201,6 +205,7 @@ namespace OpenRA.Mods.Common.Traits
PlayerStatistics playerStats; PlayerStatistics playerStats;
bool includedInArmyValue = false; bool includedInArmyValue = false;
bool includedInAssetsValue = false;
public UpdatesPlayerStatistics(UpdatesPlayerStatisticsInfo info, Actor self) public UpdatesPlayerStatistics(UpdatesPlayerStatisticsInfo info, Actor self)
{ {
@@ -236,17 +241,26 @@ namespace OpenRA.Mods.Common.Traits
includedInArmyValue = false; includedInArmyValue = false;
playerStats.Units[actorName].Count--; playerStats.Units[actorName].Count--;
} }
if (includedInAssetsValue)
{
playerStats.AssetsValue -= cost;
includedInAssetsValue = false;
}
} }
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
includedInArmyValue = info.AddToArmyValue; includedInArmyValue = info.AddToArmyValue;
if (includedInArmyValue) if (includedInArmyValue)
{ {
playerStats.ArmyValue += cost; playerStats.ArmyValue += cost;
playerStats.Units[actorName].Count++; playerStats.Units[actorName].Count++;
} }
includedInAssetsValue = info.AddToAssetsValue;
if (includedInAssetsValue)
playerStats.AssetsValue += cost;
} }
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
@@ -260,6 +274,12 @@ namespace OpenRA.Mods.Common.Traits
newOwnerStats.Units[actorName].Count++; newOwnerStats.Units[actorName].Count++;
} }
if (includedInAssetsValue)
{
playerStats.AssetsValue -= cost;
newOwnerStats.AssetsValue += cost;
}
playerStats = newOwnerStats; playerStats = newOwnerStats;
} }
@@ -271,6 +291,12 @@ namespace OpenRA.Mods.Common.Traits
includedInArmyValue = false; includedInArmyValue = false;
playerStats.Units[actorName].Count--; playerStats.Units[actorName].Count--;
} }
if (includedInAssetsValue)
{
playerStats.AssetsValue -= cost;
includedInAssetsValue = false;
}
} }
} }
} }

View File

@@ -386,11 +386,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
SetupPlayerColor(player, template, playerColor, playerGradient); SetupPlayerColor(player, template, playerColor, playerGradient);
var res = player.PlayerActor.Trait<PlayerResources>();
var stats = player.PlayerActor.TraitOrDefault<PlayerStatistics>(); var stats = player.PlayerActor.TraitOrDefault<PlayerStatistics>();
if (stats == null) if (stats == null)
return template; return template;
var res = player.PlayerActor.Trait<PlayerResources>();
var cashText = new CachedTransform<int, string>(i => "$" + i); var cashText = new CachedTransform<int, string>(i => "$" + i);
template.Get<LabelWidget>("CASH").GetText = () => cashText.Update(res.Cash + res.Resources); template.Get<LabelWidget>("CASH").GetText = () => cashText.Update(res.Cash + res.Resources);
@@ -404,10 +404,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
template.Get<LabelWidget>("SPENT").GetText = () => spentText.Update(res.Spent); template.Get<LabelWidget>("SPENT").GetText = () => spentText.Update(res.Spent);
var assetsText = new CachedTransform<int, string>(i => "$" + i); var assetsText = new CachedTransform<int, string>(i => "$" + i);
var assets = template.Get<LabelWidget>("ASSETS"); template.Get<LabelWidget>("ASSETS").GetText = () => assetsText.Update(stats.AssetsValue);
assets.GetText = () => assetsText.Update(world.ActorsHavingTrait<Valued>()
.Where(a => a.Owner == player && !a.IsDead)
.Sum(a => a.Info.TraitInfos<ValuedInfo>().First().Cost));
var harvesters = template.Get<LabelWidget>("HARVESTERS"); var harvesters = template.Get<LabelWidget>("HARVESTERS");
harvesters.GetText = () => world.ActorsHavingTrait<Harvester>().Count(a => a.Owner == player && !a.IsDead).ToString(); harvesters.GetText = () => world.ActorsHavingTrait<Harvester>().Count(a => a.Owner == player && !a.IsDead).ToString();