-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuickStash.cs
199 lines (167 loc) · 6.29 KB
/
QuickStash.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using PugMod;
using UnityEngine;
using Rewired;
using CoreLib;
using CoreLib.RewiredExtension;
using CoreLib.Util;
using CoreLib.Util.Extensions;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using Unity.NetCode;
using static CreditsData;
using System;
public class QuickStash : IMod
{
public const string VERSION = "1.0.3";
public const string NAME = "QuickStashAndGet";
public const string AUTHOR = "Futroo";
private LoadedMod modInfo;
private Player player;
private int lastUsed = 0;
private int cooldown = 60;
private float nearbyDistance = 5f;
public void EarlyInit()
{
UnityEngine.Debug.Log($"[{NAME}]: Version: {VERSION}");
modInfo = API.ModLoader.LoadedMods.FirstOrDefault(obj => obj.Handlers.Contains(this));
if (modInfo == null)
{
UnityEngine.Debug.Log($"[{NAME}]: Failed to load {NAME}!");
return;
}
UnityEngine.Debug.Log($"[{NAME}]: Mod loaded successfully!");
CoreLibMod.LoadModules(typeof(RewiredExtensionModule));
RewiredExtensionModule.AddKeybind("FutrooModQuickStashToNearby", "Quick stash to nearby (Futroo's Mod)", KeyboardKeyCode.A, ModifierKey.Control);
RewiredExtensionModule.AddKeybind("FutrooModQuickGetFromNearby", "Quick get from nearby (Futroo's Mod)", KeyboardKeyCode.D, ModifierKey.Control);
RewiredExtensionModule.rewiredStart += OnRewiredStart;
}
public void Init()
{
UnityEngine.Debug.Log("Successfully initiated QuickStashAndGet V" + VERSION);
}
public void Shutdown()
{
}
public void ModObjectLoaded(UnityEngine.Object obj)
{
}
public bool CanBeUnloaded()
{
return true;
}
public void Update()
{
if (GameManagers.GetMainManager() == null || !GameManagers.GetMainManager().currentSceneHandler.isInGame || player == null)
{
return;
}
if (player.GetButtonDown("FutrooModQuickStashToNearby"))
{
QuickStashToNearby();
}
if (player.GetButtonDown("FutrooModQuickGetFromNearby"))
{
QuickGetFromNearby();
}
}
private void OnRewiredStart()
{
player = ReInput.players.GetPlayer(0);
}
private void QuickStashToNearby()
{
if (Time.frameCount - lastUsed < cooldown)
{
return;
}
lastUsed = Time.frameCount;
PlayerController pl = GameManagers.GetMainManager().player;
if (pl == null || pl.playerInventoryHandler == null)
{
return;
}
int chestCount = 0;
Transform poolChest = GameObject.Find("Pool Chest").transform;
Transform poolBossChest = GameObject.Find("Pool BossChest").transform;
Transform poolNonPaintableChest = GameObject.Find("Pool NonPaintableChest").transform;
List<Transform> allChests = poolChest.GetAllChildren().Where(obj =>obj.gameObject.activeSelf).ToList();
allChests.AddRange(poolBossChest.GetAllChildren().Where(obj => obj.gameObject.activeSelf).ToList());
allChests.AddRange(poolNonPaintableChest.GetAllChildren().Where(obj => obj.gameObject.activeSelf).ToList());
foreach (Transform t in allChests)
{
Chest _chestComponent = t.GetComponent<Chest>();
if (_chestComponent != null && IsInRange(pl.WorldPosition, _chestComponent.WorldPosition, nearbyDistance))
{
InventoryHandler chestInventoryHandler = _chestComponent.inventoryHandler;
if (chestInventoryHandler != null)
{
pl.playerInventoryHandler.QuickStack(chestInventoryHandler);
chestCount++;
}
}
}
if (chestCount > 0)
{
Vector3 _textPos = GameManagers.GetMainManager().player.RenderPosition + new Vector3(0, 1.5f, 0);
CreateCoolText("Stashing to " + chestCount + " chest(s).", new Color(1f, 0f, 0.5f), _textPos);
}
else
{
Vector3 _textPos = GameManagers.GetMainManager().player.RenderPosition + new Vector3(0, 1.5f, 0);
CreateCoolText("Chests not found.", new Color(1f, 0f, 0f), _textPos);
}
}
private void QuickGetFromNearby()
{
if (Time.frameCount - lastUsed < cooldown)
{
return;
}
lastUsed = Time.frameCount;
PlayerController pl = GameManagers.GetMainManager().player;
if (pl == null || pl.playerInventoryHandler == null)
{
return;
}
int chestCount = 0;
Transform poolChest = GameObject.Find("Pool Chest").transform;
Transform poolBossChest = GameObject.Find("Pool BossChest").transform;
Transform poolNonPaintableChest = GameObject.Find("Pool NonPaintableChest").transform;
List<Transform> allChests = poolChest.GetAllChildren().Where(obj => obj.gameObject.activeSelf).ToList();
allChests.AddRange(poolBossChest.GetAllChildren().Where(obj => obj.gameObject.activeSelf).ToList());
allChests.AddRange(poolNonPaintableChest.GetAllChildren().Where(obj => obj.gameObject.activeSelf).ToList());
foreach (Transform t in allChests)
{
Chest _chestComponent = t.GetComponent<Chest>();
if (_chestComponent != null && IsInRange(pl.WorldPosition, _chestComponent.WorldPosition, nearbyDistance))
{
InventoryHandler chestInventoryHandler = _chestComponent.inventoryHandler;
if (chestInventoryHandler != null)
{
chestInventoryHandler.QuickStack(pl.playerInventoryHandler);
chestCount++;
}
}
}
if (chestCount > 0)
{
Vector3 _textPos = GameManagers.GetMainManager().player.RenderPosition + new Vector3(0, 1.5f, 0);
CreateCoolText("Getting from " + chestCount + " chest(s).", new Color(0.451f, 0.902f, 0f), _textPos);
}
else
{
Vector3 _textPos = GameManagers.GetMainManager().player.RenderPosition + new Vector3(0, 1.5f, 0);
CreateCoolText("Chests not found.", new Color(1f, 0f, 0f), _textPos);
}
}
private bool IsInRange(Vector3 position1, Vector3 position2, float distanceThreshold)
{
float distance = Vector3.Distance(position1, position2);
return distance < distanceThreshold;
}
private static void CreateCoolText(string text, Color color, Vector3 pos)
{
GameManagers.GetManager<TextManager>().SpawnCoolText(text, pos, color, TextManager.FontFace.thinSmall, 0.2f, 1, 2, 0.8f, 0.8f);
}
}