Add GrantConditionOnLineBuildDirection trait.
This commit is contained in:
@@ -800,6 +800,7 @@
|
|||||||
<Compile Include="Traits\Render\WithChargeAnimation.cs" />
|
<Compile Include="Traits\Render\WithChargeAnimation.cs" />
|
||||||
<Compile Include="Traits\Render\WithChargeOverlay.cs" />
|
<Compile Include="Traits\Render\WithChargeOverlay.cs" />
|
||||||
<Compile Include="WebServices.cs" />
|
<Compile Include="WebServices.cs" />
|
||||||
|
<Compile Include="Traits\Conditions\GrantConditionOnLineBuildDirection.cs" />
|
||||||
<Compile Include="Traits\Conditions\LineBuildSegmentExternalCondition.cs" />
|
<Compile Include="Traits\Conditions\LineBuildSegmentExternalCondition.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
|
public enum LineBuildDirection { Unset, X, Y }
|
||||||
|
public class LineBuildDirectionInit : IActorInit<LineBuildDirection>
|
||||||
|
{
|
||||||
|
[FieldFromYamlKey] readonly LineBuildDirection value = LineBuildDirection.Unset;
|
||||||
|
public LineBuildDirectionInit() { }
|
||||||
|
public LineBuildDirectionInit(LineBuildDirection init) { value = init; }
|
||||||
|
public LineBuildDirection Value(World world) { return value; }
|
||||||
|
}
|
||||||
|
|
||||||
public class LineBuildParentInit : IActorInit<Actor[]>
|
public class LineBuildParentInit : IActorInit<Actor[]>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey] public readonly string[] ParentNames = new string[0];
|
[FieldFromYamlKey] public readonly string[] ParentNames = new string[0];
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2017 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
|
||||||
|
{
|
||||||
|
public class GrantConditionOnLineBuildDirectionInfo : ITraitInfo, Requires<LineBuildInfo>
|
||||||
|
{
|
||||||
|
[FieldLoader.Require]
|
||||||
|
[GrantedConditionReference]
|
||||||
|
[Desc("Condition to grant.")]
|
||||||
|
public readonly string Condition = null;
|
||||||
|
|
||||||
|
[FieldLoader.Require]
|
||||||
|
[Desc("Line build direction to trigger the condition.")]
|
||||||
|
public readonly LineBuildDirection Direction = LineBuildDirection.X;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new GrantConditionOnLineBuildDirection(init, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GrantConditionOnLineBuildDirection : INotifyCreated
|
||||||
|
{
|
||||||
|
readonly GrantConditionOnLineBuildDirectionInfo info;
|
||||||
|
readonly LineBuildDirection direction;
|
||||||
|
|
||||||
|
public GrantConditionOnLineBuildDirection(ActorInitializer init, GrantConditionOnLineBuildDirectionInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
direction = init.Get<LineBuildDirectionInit>().Value(init.World);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyCreated.Created(Actor self)
|
||||||
|
{
|
||||||
|
if (direction != info.Direction)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||||
|
if (conditionManager != null && !string.IsNullOrEmpty(info.Condition))
|
||||||
|
conditionManager.GrantCondition(self, info.Condition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -103,6 +103,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
new LocationInit(t.First),
|
new LocationInit(t.First),
|
||||||
new OwnerInit(order.Player),
|
new OwnerInit(order.Player),
|
||||||
new FactionInit(faction),
|
new FactionInit(faction),
|
||||||
|
new LineBuildDirectionInit(t.First.X == order.TargetLocation.X ? LineBuildDirection.Y : LineBuildDirection.X),
|
||||||
new LineBuildParentInit(new[] { t.Second, placed })
|
new LineBuildParentInit(new[] { t.Second, placed })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user