-
Notifications
You must be signed in to change notification settings - Fork 4
/
Plugin.cs
173 lines (158 loc) · 6.69 KB
/
Plugin.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System.Collections.Generic;
using Archipelago.MultiClient.Net.Enums;
using BepInEx;
using BepInEx.Logging;
using LunacidAP.Data;
using UnityEngine.SceneManagement;
namespace LunacidAP
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public ManualLogSource Log { get; private set; }
public ArchipelagoClient Archipelago {get; private set;}
public LogicHelper LunacidLogic {get; private set;}
public static ManualLogSource LOG {get; private set;}
public LocationHandler LocationHandler {get; private set;}
public ItemHandler ItemHandler {get; private set;}
public SwitchLocker SwitchLocker {get; private set;}
public DoorHandler DoorHandler {get; private set;}
public TeleportHandler TeleportHandler {get; private set;}
public ShopHandler ShopHandler {get; private set;}
public WeaponHandler WeaponHandler {get; private set;}
public SaveHandler SaveHandler {get; private set;}
public ExpHandler ExpHandler {get; private set;}
public SwapperHandler SwapperHandler {get; private set;}
public MuseHandler MuseHandler {get; private set;}
public EnemyHandler EnemyHandler {get; private set;}
public NewGameUI UI {get; private set;}
private void Awake()
{
try
{
// Plugin startup logic
Log = new ManualLogSource("LunacidAP");
LOG = Log;
BepInEx.Logging.Logger.Sources.Add(Log);
Archipelago = new ArchipelagoClient();
ArchipelagoClient.Setup(Log);
LocationHandler = new LocationHandler(Log);
LunacidLogic = new LogicHelper(Log);
ItemHandler = new ItemHandler(LunacidLogic, Log);
SwitchLocker = new SwitchLocker(Log);
DoorHandler = new DoorHandler(Log);
SaveHandler = new SaveHandler(Log);
ExpHandler = new ExpHandler(Log);
WeaponHandler = new WeaponHandler(Log);
ShopHandler = new ShopHandler(Log);
TeleportHandler = new TeleportHandler(Log);
SwapperHandler = new SwapperHandler(Log);
EnemyHandler = new EnemyHandler(Log);
FlagHandler.Awake(Log);
CommunionHint.Awake(Log);
ReadDialogueHelper.Awake(Log);
UI = new NewGameUI(Log);
MuseHandler = new MuseHandler(Log);
Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} has been loaded! Have fun!");
}
catch
{
Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} failed to load session!");
}
}
private void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
var sceneName = scene.name;
ArchipelagoClient.IsInGame = !ArchipelagoClient.ScenesNotInGame.Contains(sceneName);
if (!ArchipelagoClient.IsInGame && ArchipelagoClient.AP.Session is not null)
{
ArchipelagoClient.AP.Disconnect();
ConnectionData.WriteConnectionData();
}
if (ArchipelagoClient.IsInGame)
{
CheckForVictory(sceneName);
CheckForDeath(sceneName);
AddSceneIfNotIncluded(sceneName);
}
if (sceneName == "CHAR_CREATE")
{
UI.ModifyCharCreateForArchipelago();
}
}
private void AddSceneIfNotIncluded(string sceneName)
{
ConnectionData.EnteredScenes ??= new List<string>();
if (!LunacidDoors.SceneToDisplayName.TryGetValue(sceneName, out var displayName))
{
Log.LogWarning($"Could not find appropriate scene for {sceneName}");
return;
}
if (ConnectionData.EnteredScenes.Contains(displayName))
{
return;
}
ConnectionData.EnteredScenes.Add(displayName);
ArchipelagoClient.AP.Session.DataStorage[Scope.Slot, "CurrentMap"] = displayName;
ArchipelagoClient.AP.Session.DataStorage[Scope.Slot, "EnteredScenes"] = ConnectionData.EnteredScenes.ToArray();
}
private void CheckForVictory(string sceneName)
{
if (!ArchipelagoClient.AP.Authenticated)
{
return;
}
var anyEndingScenes = new List<string>(){"END_E", "END_B", "END_A", "WhatWillBeAtTheEnd"};
if (sceneName == "END_E" && ArchipelagoClient.AP.HasGoal(Goal.EndingE))
{
CallForVictory();
}
else if (sceneName == "END_B" && ArchipelagoClient.AP.HasGoal(Goal.EndingB))
{
CallForVictory();
}
else if(sceneName == "END_A" && ArchipelagoClient.AP.HasGoal(Goal.EndingA))
{
CallForVictory();
}
else if (sceneName == "WhatWillBeAtTheEnd" && ArchipelagoClient.AP.HasGoal(Goal.EndingCD))
{
CallForVictory();
}
else if (anyEndingScenes.Contains(sceneName) && ArchipelagoClient.AP.SlotData.Ending == Goal.AnyEnding) // Done because its zero.
{
CallForVictory();
}
}
private void CallForVictory()
{
ArchipelagoClient.AP.Session.SetGoalAchieved();
}
private void CheckForDeath(string sceneName)
{
if (!ArchipelagoClient.AP.Authenticated || !ConnectionData.DeathLink)
{
return;
}
if (sceneName == "GAME_OVER")
{
ArchipelagoClient.AP.SendDeathLink();
}
else if ((ArchipelagoClient.IsInGame && ArchipelagoClient.AP.IsCurrentlyDeathLinked) || !ArchipelagoClient.IsInGame)
{
ArchipelagoClient.AP.IsCurrentlyDeathLinked = false;
}
}
private void Update()
{
if (ArchipelagoClient.AP.Authenticated && ArchipelagoClient.AP.IsCurrentlyDeathLinked)
{
StartCoroutine(ArchipelagoClient.AP.ReceiveDeathLink(ArchipelagoClient.AP.CurrentDLData[0], ArchipelagoClient.AP.CurrentDLData[1]));
}
}
}
}