forked from Pryaxis/TSAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldHooks.cs
More file actions
97 lines (85 loc) · 2.96 KB
/
WorldHooks.cs
File metadata and controls
97 lines (85 loc) · 2.96 KB
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
using OTAPI;
using Terraria;
namespace TerrariaApi.Server.Hooking;
internal static class WorldHooks
{
private static HookManager _hookManager;
/// <summary>
/// Attaches any of the OTAPI World hooks to the existing <see cref="HookManager"/> implementation
/// </summary>
/// <param name="hookManager">HookManager instance which will receive the events</param>
public static void AttachTo(HookManager hookManager)
{
_hookManager = hookManager;
HookEvents.Terraria.IO.WorldFile._SaveWorld += WorldFile_SaveWorld;
HookEvents.Terraria.WorldGen.StartHardmode += WorldGen_StartHardmode;
HookEvents.Terraria.WorldGen.SpreadGrass += WorldGen_SpreadGrass;
HookEvents.Terraria.Main.checkXMas += Main_checkXMas;
HookEvents.Terraria.Main.checkHalloween += Main_checkHalloween;
Hooks.Collision.PressurePlate += OnPressurePlate;
Hooks.WorldGen.Meteor += OnDropMeteor;
}
static void OnPressurePlate(object sender, Hooks.Collision.PressurePlateEventArgs e)
{
if (e.Result == HookResult.Cancel)
{
return;
}
if (e.Entity is NPC npc)
{
if (_hookManager.InvokeNpcTriggerPressurePlate(npc, e.X, e.Y))
e.Result = HookResult.Cancel;
}
else if (e.Entity is Player player)
{
if (_hookManager.InvokePlayerTriggerPressurePlate(player, e.X, e.Y))
e.Result = HookResult.Cancel;
}
else if (e.Entity is Projectile projectile)
{
if (_hookManager.InvokeProjectileTriggerPressurePlate(projectile, e.X, e.Y))
e.Result = HookResult.Cancel;
}
}
static void WorldFile_SaveWorld(object? sender, HookEvents.Terraria.IO.WorldFile._SaveWorldEventArgs args)
{
if (!args.ContinueExecution) return;
if (_hookManager.InvokeWorldSave(args.resetTime))
args.ContinueExecution = false;
}
private static void WorldGen_StartHardmode(object? sender, HookEvents.Terraria.WorldGen.StartHardmodeEventArgs args)
{
if (!args.ContinueExecution) return;
if (_hookManager.InvokeWorldStartHardMode())
args.ContinueExecution = false;
}
static void OnDropMeteor(object sender, Hooks.WorldGen.MeteorEventArgs e)
{
if (e.Result == HookResult.Cancel)
{
return;
}
if (_hookManager.InvokeWorldMeteorDrop(e.X, e.Y))
{
e.Result = HookResult.Cancel;
}
}
private static void Main_checkXMas(object? sender, HookEvents.Terraria.Main.checkXMasEventArgs args)
{
if (!args.ContinueExecution) return;
if (_hookManager.InvokeWorldChristmasCheck(ref Terraria.Main.xMas))
args.ContinueExecution = false;
}
private static void Main_checkHalloween(object? sender, HookEvents.Terraria.Main.checkHalloweenEventArgs args)
{
if (!args.ContinueExecution) return;
if (_hookManager.InvokeWorldHalloweenCheck(ref Main.halloween))
args.ContinueExecution = false;
}
private static void WorldGen_SpreadGrass(object? sender, HookEvents.Terraria.WorldGen.SpreadGrassEventArgs args)
{
if (!args.ContinueExecution) return;
if (_hookManager.InvokeWorldGrassSpread(args.i, args.j, args.dirt, args.grass, args.repeat, args.color))
args.ContinueExecution = false;
}
}