This repository has been archived by the owner on May 9, 2018. It is now read-only.
/
RevealOnFire.cs
76 lines (61 loc) · 2.34 KB
/
RevealOnFire.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#region Copyright & License Information
/*
* Copyright 2015- OpenRA.Mods.AS Developers (see AUTHORS)
* This file is a part of a third-party plugin for 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.Common.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.AS.Traits
{
[Desc("Reveal this actor to the target's owner when attacking.")]
public class RevealOnFireInfo : ConditionalTraitInfo
{
[Desc("The armament types which trigger revealing.")]
public readonly string[] ArmamentNames = { "primary", "secondary" };
[Desc("Duration of the reveal.")]
public readonly int Duration = 25;
[Desc("Radius of the reveal around this actor.")]
public readonly WDist Radius = new WDist(1536);
[Desc("Can this actor be revealed through shroud generated by the GeneratesShroud trait?")]
public readonly bool RevealedThroughGeneratedShroud = true;
public override object Create(ActorInitializer init) { return new RevealOnFire(init.Self, this); }
}
public class RevealOnFire : ConditionalTrait<RevealOnFireInfo>, INotifyAttack
{
readonly RevealOnFireInfo info;
public RevealOnFire(Actor self, RevealOnFireInfo info)
: base(info)
{
this.info = info;
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
{
if (IsTraitDisabled)
return;
if (!info.ArmamentNames.Contains(a.Info.Name))
return;
var targetPlayer = getTargetPlayer(target);
if (targetPlayer != null && targetPlayer.WinState == WinState.Undefined)
{
self.World.AddFrameEndTask(w => w.Add(new RevealShroudEffect(self.CenterPosition, info.Radius,
info.RevealedThroughGeneratedShroud ? Shroud.SourceType.Visibility : Shroud.SourceType.PassiveVisibility,
targetPlayer, Stance.Ally, duration: info.Duration)));
}
}
Player getTargetPlayer(Target target)
{
if (target.Type == TargetType.Actor)
return target.Actor.Owner;
else if (target.Type == TargetType.FrozenActor && !target.FrozenActor.Actor.IsDead)
return target.FrozenActor.Actor.Owner;
return null;
}
void INotifyAttack.PreparingAttack(Actor self, OpenRA.Traits.Target target, Armament a, Barrel barrel) { }
}
}