-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpgradeObjectPlusPlus.cs
More file actions
152 lines (125 loc) · 4.08 KB
/
Copy pathUpgradeObjectPlusPlus.cs
File metadata and controls
152 lines (125 loc) · 4.08 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
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
using System;
using System.Linq;
using BTD_Mod_Helper;
using BTD_Mod_Helper.Api.Components;
using BTD_Mod_Helper.Api.Enums;
using BTD_Mod_Helper.Extensions;
using Il2CppAssets.Scripts.Unity.Bridge;
using Il2CppAssets.Scripts.Unity.Menu;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using UnityEngine;
namespace PathsPlusPlus;
[RegisterTypeInIl2Cpp(false)]
internal class UpgradeObjectPlusPlus(IntPtr ptr) : MonoBehaviour(ptr)
{
public UpgradeObject upgradeObject = null!;
public string? pathId;
public bool overrideParagon; // whether upgradeplusplus on this object should show even if paragon available
public ModHelperButton? cycle;
public Il2CppStringArray? cyclePathIds;
public void InitForTower(TowerToSimulation tts, string path)
{
var pathPlusPlus = PathsPlusPlusMod.PathsById[path];
pathId = pathPlusPlus.Id;
upgradeObject.path = pathPlusPlus.Path;
upgradeObject.tts = tts;
upgradeObject.upgradeButton.tts = tts;
if (tts.tower.GetTier(path) is var tier && tier > upgradeObject.tier)
{
upgradeObject.tier = tier;
}
try
{
if (IsExtra)
{
upgradeObject.LoadUpgrades();
}
}
catch (Exception e)
{
ModHelper.Warning<PathsPlusPlusMod>(e);
}
}
public void CycleShowing(bool showing, Il2CppStringArray pathIds)
{
cyclePathIds = pathIds;
if (showing)
{
if (cycle == null)
{
cycle = ModHelperButton.Create(new Info("Cycle", 150, 150, new Vector2(0.55f, 0.5f)),
VanillaSprites.RestartIcon, null);
cycle.transform.Rotate(0, 0, 180);
cycle.SetParent(upgradeObject.transform);
}
cycle.gameObject.SetActive(true);
cycle.Button.SetOnClick(CycleUpgrade);
}
else if (cycle != null)
{
cycle.gameObject.SetActive(false);
}
}
/// <summary>
/// Whether the current UpgradeObject will be showing an upgrade beyond what it could with just Vanilla ones
/// </summary>
public bool IsExtra =>
upgradeObject.path >= 3 ||
PathPlusPlus.TryGetPath(upgradeObject.towerSelectionMenu.selectedTower.tower, upgradeObject.path,
upgradeObject.tier + 1, out var p) &&
upgradeObject.tier >= p.StartTier;
public void CycleUpgrade()
{
if (cyclePathIds == null || !cyclePathIds.Any() || cycle == null) return;
MenuManager.instance.buttonClick3Sound.Play();
var paths = cyclePathIds.Select(s => PathsPlusPlusMod.PathsById[s]).ToList();
var tier = upgradeObject.tier;
var tts = upgradeObject.tts;
var path = upgradeObject.path;
var paragonInvolved = tts.CanUpgradeToParagon(true) && tier >= 5;
PathPlusPlus? nextPath;
var showingPath = PathPlusPlus.GetPath(tts.tower, path, tier + 1);
if (!overrideParagon && paragonInvolved)
{
overrideParagon = true;
nextPath = paths.First();
}
else if (overrideParagon && showingPath == paths.Last() && paragonInvolved)
{
overrideParagon = false;
nextPath = null;
}
else if (showingPath == null)
{
nextPath = paths.First();
}
else
{
var index = paths.IndexOf(showingPath) + 1;
nextPath = index >= paths.Count ? null : paths[index];
}
foreach (var p in paths)
{
tts.tower.RemoveMutatorsById(p.Id);
}
nextPath?.SetTier(tts.tower, -1);
pathId = nextPath?.Id;
upgradeObject.LoadUpgrades();
}
private int delay;
private void Update()
{
if (delay > 0)
{
delay--;
return;
}
if (Input.GetKeyDown(KeyCode.Mouse2))
{
delay = 30;
CycleUpgrade();
}
}
}