From a86f41cd5cf3d23b49bea2f6fe51a8c62083b341 Mon Sep 17 00:00:00 2001 From: Andre Mohren Date: Sun, 22 Jul 2018 12:25:10 +0200 Subject: [PATCH] Made Valued optional for traits who do not require it. --- OpenRA.Mods.Common/Activities/Repair.cs | 3 ++- OpenRA.Mods.Common/Traits/GainsExperience.cs | 13 +++++++++---- OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs | 10 +++++++++- .../Widgets/Logic/Ingame/ProductionTooltipLogic.cs | 3 ++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Repair.cs b/OpenRA.Mods.Common/Activities/Repair.cs index 27e4b7a719..b765419f9b 100644 --- a/OpenRA.Mods.Common/Activities/Repair.cs +++ b/OpenRA.Mods.Common/Activities/Repair.cs @@ -98,7 +98,8 @@ namespace OpenRA.Mods.Common.Activities if (remainingTicks == 0) { - var unitCost = self.Info.TraitInfo().Cost; + var valued = self.Info.TraitInfoOrDefault(); + var unitCost = valued != null ? valued.Cost : 0; var hpToRepair = repairable != null && repairable.Info.HpPerStep > 0 ? repairable.Info.HpPerStep : repairsUnits.Info.HpPerStep; // Cast to long to avoid overflow when multiplying by the health diff --git a/OpenRA.Mods.Common/Traits/GainsExperience.cs b/OpenRA.Mods.Common/Traits/GainsExperience.cs index 9710437db6..094e00b7c1 100644 --- a/OpenRA.Mods.Common/Traits/GainsExperience.cs +++ b/OpenRA.Mods.Common/Traits/GainsExperience.cs @@ -19,7 +19,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("This actor's experience increases when it has killed a GivesExperience actor.")] - public class GainsExperienceInfo : ITraitInfo, Requires + public class GainsExperienceInfo : ITraitInfo { [FieldLoader.Require] [Desc("Condition to grant at each level.", @@ -33,6 +33,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Palette for the level up sprite.")] [PaletteReference] public readonly string LevelUpPalette = "effect"; + [Desc("Multiplier to apply to the Conditions keys. Defaults to the actor's value.")] + public readonly int ExperienceModifier = -1; + [Desc("Should the level-up animation be suppressed when actor is created?")] public readonly bool SuppressLevelupAnimation = true; @@ -63,9 +66,6 @@ namespace OpenRA.Mods.Common.Traits this.info = info; MaxLevel = info.Conditions.Count; - var cost = self.Info.TraitInfo().Cost; - foreach (var kv in info.Conditions) - nextLevel.Add(Pair.New(kv.Key * cost, kv.Value)); if (init.Contains()) initialExperience = init.Get(); @@ -73,6 +73,11 @@ namespace OpenRA.Mods.Common.Traits void INotifyCreated.Created(Actor self) { + var valued = self.Info.TraitInfoOrDefault(); + var requiredExperience = info.ExperienceModifier < 0 ? (valued != null ? valued.Cost : 1) : info.ExperienceModifier; + foreach (var kv in info.Conditions) + nextLevel.Add(Pair.New(kv.Key * requiredExperience, kv.Value)); + conditionManager = self.TraitOrDefault(); if (initialExperience > 0) GiveExperience(initialExperience, info.SuppressLevelupAnimation); diff --git a/OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs b/OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs index e60468fc63..58ecaf3f2c 100644 --- a/OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs +++ b/OpenRA.Mods.Common/Traits/SpawnActorsOnSell.cs @@ -69,7 +69,15 @@ namespace OpenRA.Mods.Common.Traits var buildingInfo = self.Info.TraitInfoOrDefault(); var eligibleLocations = buildingInfo != null ? buildingInfo.Tiles(self.Location).ToList() : new List(); - var actorTypes = Info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].TraitInfo().Cost }).ToList(); + var actorTypes = Info.ActorTypes.Select(a => + { + var av = self.World.Map.Rules.Actors[a].TraitInfoOrDefault(); + return new + { + Name = a, + Cost = av != null ? av.Cost : 0 + }; + }).ToList(); while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue)) { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs index 7db41fd9bd..aa326235dc 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs @@ -70,7 +70,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic var tooltip = actor.TraitInfos().FirstOrDefault(info => info.EnabledByDefault); var name = tooltip != null ? tooltip.Name : actor.Name; var buildable = actor.TraitInfo(); - var cost = actor.TraitInfo().Cost; + var valued = actor.TraitInfoOrDefault(); + var cost = valued != null ? valued.Cost : 0; nameLabel.Text = name;