GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PathsPlusPlus/UpgradePlusPlus.cs at main · doombubbles/PathsPlusPlus

Expand file tree

/

UpgradePlusPlus.cs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
258 lines (220 loc) · 8.71 KB
/

UpgradePlusPlus.cs

Copy path

File metadata and controls

258 lines (220 loc) · 8.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using System;
using System.Collections.Generic;
using System.Linq;
using BTD_Mod_Helper;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Enums;
using BTD_Mod_Helper.Api.ModOptions;
using Il2CppAssets.Scripts.Models.Towers;
using Il2CppAssets.Scripts.Models.Towers.Upgrades;
using Il2CppAssets.Scripts.Simulation.Towers;
using Il2CppNinjaKiwi.Common.ResourceUtils;
namespace PathsPlusPlus;
/// <summary>
/// Class to define an upgrade for your PathPlusPlus
/// </summary>
public abstract class UpgradePlusPlus : NamedModContent
{
/// <inheritdoc />
protected sealed override float RegistrationPriority => 10f;
internal readonly HashSet<Tower> currentlyAppliedOn = [];
/// <summary>
/// The PathPlusPlus this upgrade is a part of
/// </summary>
public abstract PathPlusPlus Path { get; }
/// <summary>
/// Name of the icon, either the name of a png within your mod or a VanillaSprites string
/// </summary>
public virtual string Icon => Name;
/// <summary>
/// Sprite reference for the icon
/// </summary>
public virtual SpriteReference IconReference => GetSpriteReferenceOrDefault(Icon);
/// <summary>
/// The base cost of this upgrade (medium difficulty)
/// </summary>
public abstract int Cost { get; }
/// <summary>
/// Whether this upgrade adds an Ability to the tower
/// </summary>
public virtual bool Ability => false;
/// <summary>
/// What tier this upgrade is
/// </summary>
public abstract int Tier { get; }
/// <summary>
/// Name of the icon, either the name of a png within your mod or a VanillaSprites string
/// </summary>
public virtual string? Portrait => null;
/// <summary>
/// The maximum number of times this upgrade can be used on towers in a game at any one time
/// <br/>
/// -1 for unlimited
/// </summary>
public virtual int MaxAtOnce =>
Tier >= 5 &&
!(ModHelper.HasMod("Unlimited5thTiers", out var u) &&
u.ModSettings.TryGetValue("AllowUnlimited5thTiers", out var setting) &&
setting is ModSettingBool value && value)
? 1
: 999999999;
/// <summary>
/// Sprite reference for the portrait
/// </summary>
public virtual SpriteReference? PortraitReference =>
!string.IsNullOrEmpty(Portrait)
? GetSpriteReferenceOrDefault(Portrait)
: GetSpriteReferenceOrNull(Path.Name) ??
GetSpriteReferenceOrNull(Path.Name + Tier) ??
CreateSpriteReference(VanillaSprites.ByName.GetValueOrDefault(VanillaPortrait));
private string VanillaPortrait
{
get
{
var vanillaPortraitAttempt = Path.Tower.Replace(TowerType.WizardMonkey, "Wizard");
for (var p = 0; p <= 2; p++)
{
if (Path.Path == p && Tier < 6)
{
vanillaPortraitAttempt += Tier;
}
else
{
vanillaPortraitAttempt += "0";
}
}
return vanillaPortraitAttempt;
}
}
/// <summary>
/// Override the texture to use for the container for the upgrade in the upgrades screen
/// </summary>
public virtual string? Container => null;
/// <summary>
/// Sprite reference for the container
/// </summary>
public virtual SpriteReference? ContainerReference =>
string.IsNullOrEmpty(Container) ? null : GetSpriteReferenceOrDefault(Container);
/// <summary>
/// Whether this upgrade requires a confirmation popup
/// </summary>
public virtual bool NeedsConfirmation => false;
/// <summary>
/// The title for the confirmation popup, if needed
/// </summary>
public virtual string? ConfirmationTitle => null;
/// <summary>
/// The body text for the confirmation popup, if needed
/// </summary>
public virtual string? ConfirmationBody => null;
private UpgradeModel? upgradeModel;
/// <summary>
/// A Platinum version of the Tier 5 Upgrade Container
/// </summary>
protected static string UpgradeContainerPlatinum => GetTextureGUID<PathsPlusPlusMod>("UpgradeContainerPlatinum");
/// <summary>
/// A Diamond version of the Tier 5 Upgrade Container
/// </summary>
protected static string UpgradeContainerDiamond => GetTextureGUID<PathsPlusPlusMod>("UpgradeContainerDiamond");
/// <summary>
/// A Rainbow version of the Tier 5 Upgrade Container
/// </summary>
protected static string UpgradeContainerRainbow => GetTextureGUID<PathsPlusPlusMod>("UpgradeContainerRainbow");
/// <inheritdoc />
public override void Register()
{
if (Tier <= 0) throw new Exception($"Tier of {Id} must be greater than {0}");
if (!Path.Upgrades.TryAdd(Tier - 1, this))
{
throw new Exception($"Tier {Tier} of {Path.Id} is used by both {Id} and {Path.Upgrades[Tier - 1].Id}");
}
PathsPlusPlusMod.UpgradesById[Id] = this;
}
/// <inheritdoc />
public override void RegisterText(Il2CppSystem.Collections.Generic.Dictionary<string, string> textTable)
{
base.RegisterText(textTable);
if (NeedsConfirmation)
{
if (ConfirmationTitle != null)
{
textTable[Id + " Title"] = ConfirmationTitle;
}
if (ConfirmationBody != null)
{
textTable[Id + " Body"] = ConfirmationBody;
}
}
}
/// <summary>
/// Gets or constructs the UpgradeModel for this UpgradePlusPlus
/// </summary>
/// <returns></returns>
public UpgradeModel GetUpgradeModel() => upgradeModel ??= new UpgradeModel(Id, Cost, 0, IconReference, Path.Path,
Tier - 1, 0, NeedsConfirmation ? Id : "", "");
/// <summary>
/// Returns whether this Upgrade is of a higher tier than any other base or PathsPlusPlus upgrade that the tower has
/// </summary>
/// <param name="towerModel">The TowerModel</param>
/// <param name="highestOrEqual">Whether to still return true if this is tied for being the highest tier upgrade</param>
/// <returns></returns>
public bool IsHighestUpgrade(TowerModel towerModel, bool highestOrEqual = false) =>
towerModel.GetAllTiers().All(t => highestOrEqual ? Tier >= t : Tier > t);
/// <summary>
/// The effects on the TowerModel that obtaining this upgrade should have.
/// </summary>
/// <param name="towerModel">The tower to apply to</param>
public virtual void ApplyUpgrade(TowerModel towerModel)
{
}
/// <summary>
/// The effects on the TowerModel that obtaining this upgrade should have.
/// <br/>
/// The tier parameter is mostly useful for skipping applying any effects that would be overriden by later upgrades
/// in this path
/// </summary>
/// <param name="towerModel">The tower to apply to</param>
/// <param name="tier">The total tier that this tower has in this Upgrade Path</param>
public virtual void ApplyUpgrade(TowerModel towerModel, int tier)
{
}
/// <summary>
/// Runs in game when this upgrade is applied to a Tower for the first time
/// </summary>
/// <param name="tower">The tower being upgraded</param>
public virtual void OnUpgraded(Tower tower)
{
}
/// <summary>
/// Runs in game when this upgrade is attached to a Tower, whether by having just purchased the upgrade or the tower being loaded from save, etc
/// Note that this may apply to a tower multiple times
/// </summary>
/// <param name="tower">The tower getting the upgrade</param>
public virtual void OnAttached(Tower tower)
{
}
/// <summary>
/// Like <see cref="ApplyUpgrade(TowerModel)"/>, but runs after all other upgrades have been applied."/>
/// </summary>
/// <param name="towerModel">The tower to apply to</param>
public virtual void LateApplyUpgrade(TowerModel towerModel)
{
}
/// <summary>
/// Like <see cref="ApplyUpgrade(TowerModel,int)"/>, but runs after all other upgrades have been applied."/>
/// <br/>
/// The tier parameter is mostly useful for skipping applying any effects that would be overriden by later upgrades
/// in this path
/// </summary>
/// <param name="towerModel">The tower to apply to</param>
/// <param name="tier">The total tier that this tower has in this Upgrade Path</param>
public virtual void LateApplyUpgrade(TowerModel towerModel, int tier)
{
}
}
/// <inheritdoc />
public abstract class UpgradePlusPlus<T> : UpgradePlusPlus where T : PathPlusPlus
{
/// <inheritdoc /> TODO change this type to T when there are enough breaking changes for Mods already happening
public sealed override PathPlusPlus Path => GetInstance<T>();
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.