Made Valued optional for traits who do not require it.

This commit is contained in:
Andre Mohren
2018-07-22 12:25:10 +02:00
committed by Paul Chote
parent ec15acbc80
commit a86f41cd5c
4 changed files with 22 additions and 7 deletions

View File

@@ -98,7 +98,8 @@ namespace OpenRA.Mods.Common.Activities
if (remainingTicks == 0)
{
var unitCost = self.Info.TraitInfo<ValuedInfo>().Cost;
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();
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

View File

@@ -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<ValuedInfo>
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<ValuedInfo>().Cost;
foreach (var kv in info.Conditions)
nextLevel.Add(Pair.New(kv.Key * cost, kv.Value));
if (init.Contains<ExperienceInit>())
initialExperience = init.Get<ExperienceInit, int>();
@@ -73,6 +73,11 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self)
{
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();
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<ConditionManager>();
if (initialExperience > 0)
GiveExperience(initialExperience, info.SuppressLevelupAnimation);

View File

@@ -69,7 +69,15 @@ namespace OpenRA.Mods.Common.Traits
var buildingInfo = self.Info.TraitInfoOrDefault<BuildingInfo>();
var eligibleLocations = buildingInfo != null ? buildingInfo.Tiles(self.Location).ToList() : new List<CPos>();
var actorTypes = Info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].TraitInfo<ValuedInfo>().Cost }).ToList();
var actorTypes = Info.ActorTypes.Select(a =>
{
var av = self.World.Map.Rules.Actors[a].TraitInfoOrDefault<ValuedInfo>();
return new
{
Name = a,
Cost = av != null ? av.Cost : 0
};
}).ToList();
while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))
{

View File

@@ -70,7 +70,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var tooltip = actor.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
var name = tooltip != null ? tooltip.Name : actor.Name;
var buildable = actor.TraitInfo<BuildableInfo>();
var cost = actor.TraitInfo<ValuedInfo>().Cost;
var valued = actor.TraitInfoOrDefault<ValuedInfo>();
var cost = valued != null ? valued.Cost : 0;
nameLabel.Text = name;