Repository navigation
Expand file tree
/
Copy pathModEntry.cs
More file actions
79 lines (71 loc) · 2.49 KB
/
Copy pathModEntry.cs
File metadata and controls
79 lines (71 loc) · 2.49 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
using MIR;
using HarmonyLib;
using Inputsoldatcc.Zedifier.Disks;
using Walgelijk;
using Inputsoldatcc.Zedifier.Components;
namespace Inputsoldatcc.Zedifier;
public class ModEntry : IModEntry
{
/// <summary>
/// Called immediately after this mod is loaded. Beware that some resources might not yet be present.
/// </summary>
/// <param name="mod">Your mod instance</param>
/// <param name="harmony">Your Harmony instance</param>
public void OnLoad(Mod mod, Harmony harmony)
{
}
/// <summary>
/// Called when everything is ready.
/// </summary>
public void OnReady()
{
ImprobabilityDisks.All.Add("Enmeshment", new ZedDisk());
ImprobabilityDisks.SetIncompatible("Enmeshment", "tricky", "grunt", "agent", "engineer", "soldat");
// Attach plz
Game.Main.OnSceneChange.AddListener(Scenes =>
{
if (Scenes.New != null && (ImprobabilityDisks.IsEnabled("Enmeshment") || ImprobabilityDisks.IsEnabled("PartialEnmeshment")))
{
MadnessUtils.Delay(1.5f, () => {
foreach (var character in Scenes.New.GetAllComponentsOfType<CharacterComponent>())
AttachEnmesher(character.Entity, character);
});
Scenes.New.OnCreateEntity += DetectCharacter;
}
});
}
/// <summary>
/// Called when the game closes and this mod is unloaded.
/// </summary>
public void OnUnload()
{
}
/// <summary>
/// Tries to attach the <see cref="EnmeshmentComponent"/> to the <see cref="CharacterComponent"/>'s <see cref="Entity"/>
/// </summary>
/// <param name="entity"></param>
/// <param name="character"></param>
public static void AttachEnmesher(Entity entity, CharacterComponent character)
{
if (MadnessUtils.FindPlayer(Game.Main.Scene, out var _, out var playerCharacter))
{
if (playerCharacter != character)
{
Game.Main.Scene.AttachComponent(character.Entity, new EnmeshmentComponent());
}
}
}
/// <summary>
/// Tries to find a character from the <paramref name="entity"/>
/// </summary>
public static void DetectCharacter(Entity entity)
{
_ = MadnessUtils.Delay(1.5f, () =>
{
if (Game.Main.Scene.TryGetComponentFrom(entity, out CharacterComponent? character))
{
AttachEnmesher(entity, character);
}
});
}
}