-
Notifications
You must be signed in to change notification settings - Fork 1
/
UpgradePlusPlus.cs
192 lines (160 loc) · 6.33 KB
/
UpgradePlusPlus.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
using System;
using System.Collections.Generic;
using System.Linq;
using BTD_Mod_Helper.Api;
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;
/// <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, from 1 to 5
/// </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>
/// Sprite reference for the portrait
/// </summary>
public virtual SpriteReference? PortraitReference => string.IsNullOrEmpty(Portrait)
? GetSpriteReferenceOrNull(Path.Name)
: GetSpriteReferenceOrDefault(Portrait);
/// <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.ExtendVanillaPath >= 0 && Tier < 6)
{
throw new Exception($"Tier of {Id} can't be less than 6 when using ExtendsVanillaPath");
}
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)
{
}
}
/// <inheritdoc />
public abstract class UpgradePlusPlus<T> : UpgradePlusPlus where T : PathPlusPlus
{
/// <inheritdoc />
public sealed override PathPlusPlus Path => GetInstance<T>();
}