diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 4e63c0ac96..094d4416b8 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -120,6 +120,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/ExperienceTrickler.cs b/OpenRA.Mods.Common/Traits/ExperienceTrickler.cs new file mode 100644 index 0000000000..2d03f33b15 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/ExperienceTrickler.cs @@ -0,0 +1,60 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Lets the actor gain experience in a set periodic time.")] + public class ExperienceTricklerInfo : PausableConditionalTraitInfo, Requires + { + [Desc("Number of ticks to wait between giving experience.")] + public readonly int Interval = 50; + + [Desc("Number of ticks to wait before giving first experience.")] + public readonly int InitialDelay = 0; + + [Desc("Amount of experience to give each time.")] + public readonly int Amount = 15; + + public override object Create(ActorInitializer init) { return new ExperienceTrickler(init.Self, this); } + } + + public class ExperienceTrickler : PausableConditionalTrait, ITick, ISync + { + readonly ExperienceTricklerInfo info; + GainsExperience gainsExperience; + [Sync] int ticks; + + public ExperienceTrickler(Actor self, ExperienceTricklerInfo info) + : base(info) + { + this.info = info; + ticks = info.InitialDelay; + gainsExperience = self.Trait(); + } + + void ITick.Tick(Actor self) + { + if (IsTraitDisabled) + ticks = info.Interval; + + if (IsTraitPaused || IsTraitDisabled) + return; + + if (--ticks < 0) + { + ticks = info.Interval; + gainsExperience.GiveExperience(info.Amount); + } + } + } +}