Add DisguiseAs and DisguiseAsType functions to lua
This commit is contained in:
@@ -84,6 +84,7 @@
|
||||
<Compile Include="Effects\TeslaZap.cs" />
|
||||
<Compile Include="Graphics\TeslaZapRenderable.cs" />
|
||||
<Compile Include="Scripting\Properties\InfiltrateProperties.cs" />
|
||||
<Compile Include="Scripting\Properties\DisguiseProperties.cs" />
|
||||
<Compile Include="Traits\Attack\AttackLeap.cs" />
|
||||
<Compile Include="Traits\Buildings\Fake.cs" />
|
||||
<Compile Include="Traits\Buildings\ClonesProducedUnits.cs" />
|
||||
|
||||
42
OpenRA.Mods.RA/Scripting/Properties/DisguiseProperties.cs
Normal file
42
OpenRA.Mods.RA/Scripting/Properties/DisguiseProperties.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Ability")]
|
||||
public class DisguiseProperties : ScriptActorProperties, Requires<DisguiseInfo>
|
||||
{
|
||||
readonly Disguise disguise;
|
||||
|
||||
public DisguiseProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
disguise = Self.Trait<Disguise>();
|
||||
}
|
||||
|
||||
[Desc("Disguises as the target actor.")]
|
||||
public void DisguiseAs(Actor target)
|
||||
{
|
||||
disguise.DisguiseAs(target);
|
||||
}
|
||||
|
||||
[Desc("Disguises as the target type with the specified owner.")]
|
||||
public void DisguiseAsType(string actorType, Player newOwner)
|
||||
{
|
||||
var actorInfo = Self.World.Map.Rules.Actors[actorType];
|
||||
disguise.DisguiseAs(actorInfo, newOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
return AsPlayer.Color.RGB;
|
||||
}
|
||||
|
||||
void DisguiseAs(Actor target)
|
||||
public void DisguiseAs(Actor target)
|
||||
{
|
||||
var oldDisguiseSetting = Disguised;
|
||||
var oldEffectiveOwner = AsPlayer;
|
||||
@@ -159,6 +159,24 @@ namespace OpenRA.Mods.RA.Traits
|
||||
AsSprite = null;
|
||||
}
|
||||
|
||||
HandleDisguise(oldEffectiveOwner, oldDisguiseSetting);
|
||||
}
|
||||
|
||||
public void DisguiseAs(ActorInfo actorInfo, Player newOwner)
|
||||
{
|
||||
var oldDisguiseSetting = Disguised;
|
||||
var oldEffectiveOwner = AsPlayer;
|
||||
|
||||
var renderSprites = actorInfo.Traits.GetOrDefault<RenderSpritesInfo>();
|
||||
AsSprite = renderSprites == null ? null : renderSprites.GetImage(actorInfo, self.World.Map.SequenceProvider, newOwner.Country.Race);
|
||||
AsPlayer = newOwner;
|
||||
AsTooltipInfo = actorInfo.Traits.WithInterface<TooltipInfo>().FirstOrDefault();
|
||||
|
||||
HandleDisguise(oldEffectiveOwner, oldDisguiseSetting);
|
||||
}
|
||||
|
||||
void HandleDisguise(Player oldEffectiveOwner, bool oldDisguiseSetting)
|
||||
{
|
||||
foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>())
|
||||
t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user