Implements a disguise decoration to Spies. Deprecates WithDecorationDisguised in favor of a refactor in Disguise.

This commit is contained in:
Zimmermann Gyula
2015-06-13 21:35:49 +02:00
parent be99ba7d61
commit 8a94caab3c
9 changed files with 59 additions and 53 deletions

View File

@@ -114,7 +114,6 @@
<Compile Include="Scripting\Properties\ParadropProperties.cs" /> <Compile Include="Scripting\Properties\ParadropProperties.cs" />
<Compile Include="Scripting\Properties\ParatroopersProperties.cs" /> <Compile Include="Scripting\Properties\ParatroopersProperties.cs" />
<Compile Include="Traits\Render\WithDisguisingInfantryBody.cs" /> <Compile Include="Traits\Render\WithDisguisingInfantryBody.cs" />
<Compile Include="Traits\Render\WithDecorationDisguised.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj"> <ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
@@ -61,18 +62,15 @@ namespace OpenRA.Mods.RA.Traits
{ {
[VoiceReference] public readonly string Voice = "Action"; [VoiceReference] public readonly string Voice = "Action";
[UpgradeGrantedReference]
[Desc("Upgrades to grant when disguised.")]
public readonly string[] Upgrades = { "disguise" };
public object Create(ActorInitializer init) { return new Disguise(init.Self, this); } public object Create(ActorInitializer init) { return new Disguise(init.Self, this); }
} }
class Disguise : IEffectiveOwner, IIssueOrder, IResolveOrder, IOrderVoice, IRadarColorModifier, INotifyAttack class Disguise : IEffectiveOwner, IIssueOrder, IResolveOrder, IOrderVoice, IRadarColorModifier, INotifyAttack
{ {
readonly DisguiseInfo info;
public Disguise(Actor self, DisguiseInfo info)
{
this.info = info;
}
public Player AsPlayer { get; private set; } public Player AsPlayer { get; private set; }
public string AsSprite { get; private set; } public string AsSprite { get; private set; }
public ITooltipInfo AsTooltipInfo { get; private set; } public ITooltipInfo AsTooltipInfo { get; private set; }
@@ -80,6 +78,18 @@ namespace OpenRA.Mods.RA.Traits
public bool Disguised { get { return AsPlayer != null; } } public bool Disguised { get { return AsPlayer != null; } }
public Player Owner { get { return AsPlayer; } } public Player Owner { get { return AsPlayer; } }
readonly Actor self;
readonly DisguiseInfo info;
readonly Lazy<UpgradeManager> um;
public Disguise(Actor self, DisguiseInfo info)
{
this.self = self;
this.info = info;
um = Exts.Lazy(() => self.TraitOrDefault<UpgradeManager>());
}
public IEnumerable<IOrderTargeter> Orders public IEnumerable<IOrderTargeter> Orders
{ {
get get
@@ -101,7 +111,7 @@ namespace OpenRA.Mods.RA.Traits
if (order.OrderString == "Disguise") if (order.OrderString == "Disguise")
{ {
var target = order.TargetActor != self && order.TargetActor.IsInWorld ? order.TargetActor : null; var target = order.TargetActor != self && order.TargetActor.IsInWorld ? order.TargetActor : null;
DisguiseAs(self, target); DisguiseAs(target);
} }
} }
@@ -118,8 +128,9 @@ namespace OpenRA.Mods.RA.Traits
return AsPlayer.Color.RGB; return AsPlayer.Color.RGB;
} }
void DisguiseAs(Actor self, Actor target) void DisguiseAs(Actor target)
{ {
var oldDisguiseSetting = Disguised;
var oldEffectiveOwner = AsPlayer; var oldEffectiveOwner = AsPlayer;
if (target != null) if (target != null)
@@ -150,8 +161,22 @@ namespace OpenRA.Mods.RA.Traits
foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>()) foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>())
t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer); t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer);
if (Disguised != oldDisguiseSetting && um.Value != null)
{
foreach (var u in info.Upgrades)
{
if (!um.Value.AcceptsUpgrade(self, u))
continue;
if (Disguised)
um.Value.GrantUpgrade(self, u, this);
else
um.Value.RevokeUpgrade(self, u, this);
}
}
} }
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { DisguiseAs(self, null); } public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { DisguiseAs(null); }
} }
} }

View File

@@ -1,42 +0,0 @@
#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;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
public class WithDecorationDisguisedInfo : WithDecorationInfo, Requires<DisguiseInfo>
{
[Desc("Require an active disguise to render this decoration?")]
public readonly bool RequireDisguise = true;
public override object Create(ActorInitializer init) { return new WithDecorationDisguised(init.Self, this); }
}
public class WithDecorationDisguised : WithDecoration
{
readonly WithDecorationDisguisedInfo info;
readonly Disguise disguise;
public WithDecorationDisguised(Actor self, WithDecorationDisguisedInfo info)
: base(self, info)
{
this.info = info;
disguise = self.Trait<Disguise>();
}
public override bool ShouldRender(Actor self)
{
return !info.RequireDisguise || disguise.Disguised;
}
}
}

Binary file not shown.

View File

@@ -235,6 +235,15 @@ SPY:
AttackSequence: shoot AttackSequence: shoot
IdleSequences: idle1,idle2 IdleSequences: idle1,idle2
StandSequences: stand,stand2 StandSequences: stand,stand2
WithDecoration@disguise:
Image: pips
Sequence: pip-disguise
Palette: effect
ReferencePoint: Top, Right
Offset: 4, -2
ZOffset: 256
UpgradeTypes: disguise
UpgradeMinEnabledLevel: 1
Armament: Armament:
Weapon: SilencedPPK Weapon: SilencedPPK
AttackFrontal: AttackFrontal:

View File

@@ -84,6 +84,9 @@ pips:
Start: 4 Start: 4
pip-blue: pips2 pip-blue: pips2
Start: 5 Start: 5
pip-disguise: pip-disguise
Length: *
Tick: 300
v2: v2:
idle: idle:

Binary file not shown.

View File

@@ -58,6 +58,15 @@ CHAMSPY:
Range: 9c0 Range: 9c0
Passenger: Passenger:
Disguise: Disguise:
WithDecoration@disguise:
Image: pips
Sequence: pip-disguise
Palette: pips
ReferencePoint: Top, Right
Offset: 4, -2
ZOffset: 256
UpgradeTypes: disguise
UpgradeMinEnabledLevel: 1
Infiltrates: Infiltrates:
Types: SpyInfiltrate Types: SpyInfiltrate
-AutoTarget: -AutoTarget:

View File

@@ -94,6 +94,9 @@ pips:
pip-ammo: ammopips pip-ammo: ammopips
pip-ammoempty: ammopips pip-ammoempty: ammopips
Start: 1 Start: 1
pip-disguise: pip-disguise
Length: *
Tick: 300
# TODO: # TODO:
pip-empty-building: pip-empty-building:
pip-green-building: pip-green-building: