Made Valued optional for traits who do not require it.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user