Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8a8509
commit 1a728ee
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<GainsExperienceInfo> | ||
{ | ||
[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<ExperienceTricklerInfo>, 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<GainsExperience>(); | ||
} | ||
|
||
void ITick.Tick(Actor self) | ||
{ | ||
if (IsTraitDisabled) | ||
ticks = info.Interval; | ||
|
||
if (IsTraitPaused || IsTraitDisabled) | ||
return; | ||
|
||
if (--ticks < 0) | ||
{ | ||
ticks = info.Interval; | ||
gainsExperience.GiveExperience(info.Amount); | ||
} | ||
} | ||
} | ||
} |