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
5bf4dad
commit f8c5263
Showing
7 changed files
with
134 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright 2007-2020 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 System.Linq; | ||
using OpenRA.Traits; | ||
|
||
namespace OpenRA.Mods.Common.Traits | ||
{ | ||
[Desc("Any actor with this trait enabled has a chance to affect others with this trait.")] | ||
public class SpreadsConditionInfo : ConditionalTraitInfo | ||
{ | ||
[Desc("The chance this actor is going to affect an adjacent actor.")] | ||
public readonly int Probability = 5; | ||
|
||
[Desc("How far the condition can spread from one actor to another.")] | ||
public readonly WDist Range = WDist.FromCells(3); | ||
|
||
[GrantedConditionReference] | ||
[Desc("Condition to grant onto another actor in range with the same trait.")] | ||
public readonly string SpreadCondition = "spreading"; | ||
|
||
[Desc("Time in ticks to wait between spreading further.")] | ||
public int Delay = 5; | ||
|
||
public override object Create(ActorInitializer init) { return new SpreadsCondition(this); } | ||
} | ||
|
||
public class SpreadsCondition : ConditionalTrait<SpreadsConditionInfo>, ITick | ||
{ | ||
readonly SpreadsConditionInfo info; | ||
|
||
int delay; | ||
|
||
public SpreadsCondition(SpreadsConditionInfo info) | ||
: base(info) | ||
{ | ||
this.info = info; | ||
delay = info.Delay; | ||
} | ||
|
||
void ITick.Tick(Actor self) | ||
{ | ||
if (IsTraitDisabled) | ||
return; | ||
|
||
if (delay-- > 0) | ||
return; | ||
|
||
delay = info.Delay; | ||
|
||
if (self.World.SharedRandom.Next(100) <= info.Probability) | ||
{ | ||
var actorsInRange = self.World.FindActorsInCircle(self.CenterPosition, info.Range) | ||
.Where(a => a.TraitOrDefault<SpreadsCondition>() != null); | ||
|
||
if (!actorsInRange.Any()) | ||
return; | ||
|
||
var target = actorsInRange.Random(self.World.SharedRandom); | ||
target.GrantCondition(info.SpreadCondition); | ||
} | ||
} | ||
} | ||
} |
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
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
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