-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFloatingAway.cs
97 lines (86 loc) · 2.68 KB
/
FloatingAway.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
namespace XRL.World.Effects
{
public class helado_AntiweightOrbs_FloatingAway : Effect
{
const string ASPHYXIATE_DEATH_MESSAGE = "You floated away and asphyxiated in the void of space.";
const string GENERIC_DEATH_MESSAGE = "You floated away into the void of space.";
public static bool CanFloatAway(GameObject floater)
{
return
floater != null &&
!floater.IsInGraveyard() &&
floater.IsUnderSky() &&
floater.Weight < 0;
}
public helado_AntiweightOrbs_FloatingAway()
{
DisplayName = "{{B|floating away}}";
Duration = DURATION_INDEFINITE;
}
public override bool Apply(GameObject floater)
{
// Only one instance of floating away is allowed per object.
if (floater.HasEffect(GetType()))
{
return false;
}
floater.ModIntProperty("IgnoresGravity", 1);
return true;
}
public override void Remove(GameObject floater)
{
floater.ModIntProperty("IgnoresGravity", -1, RemoveIfZero: true);
floater.Gravitate();
}
public override bool WantEvent(int id, int cascade)
{
return
id == EndTurnEvent.ID ||
base.WantEvent(id, cascade);
}
public override bool HandleEvent(EndTurnEvent @event)
{
if (!CanFloatAway(Object))
{
Object.RemoveEffect(this);
return true;
}
XDidY(
what: Object,
verb: "float",
extra: "away",
terminalPunctuation: "!",
ColorAsBadFor: Object
);
if (Object.CurrentZone.Z > 0)
{
Object.Move(
Direction: "U",
Forced: true,
IgnoreGravity: true
);
}
else
{
var deathMessage =
Object.Respires ? ASPHYXIATE_DEATH_MESSAGE :
/* otherwise */ GENERIC_DEATH_MESSAGE;
if (Object.IsPlayer())
{
Object.Die(
Reason: deathMessage,
Accidental: true
);
}
else
{
Object.Destroy(
Reason: deathMessage,
Obliterate: true
);
}
}
return true;
}
}
}