-
Notifications
You must be signed in to change notification settings - Fork 17
/
ModSuitAddon.cs
203 lines (172 loc) · 6.92 KB
/
ModSuitAddon.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
200
201
202
203
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using System;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using MetroidMod.Default;
using MetroidMod.ID;
namespace MetroidMod
{
public abstract class ModSuitAddon : ModType
{
public int Type { get; private set; }
internal void ChangeType(int type) => Type = type;
/// <summary>
/// The <see cref="ModItem"/> this addon controls.
/// </summary>
public ModItem ModItem;
/// <summary>
/// The <see cref="ModTile"/> this addon controls.
/// </summary>
public ModTile ModTile;
/// <summary>
/// The <see cref="Item"/> this addon controls.
/// </summary>
public Item Item;
public int ItemType { get; internal set; }
public int TileType { get; internal set; }
/// <summary>
/// The translations for the display name of this item.
/// </summary>
public ModTranslation DisplayName { get; internal set; }
/// <summary>
/// The translations for the tooltip of this item.
/// </summary>
public ModTranslation Tooltip { get; internal set; }
public abstract string ItemTexture { get; }
public virtual string ArmorTextureHead { get; }
public virtual string ArmorTextureTorso { get; }
public virtual string ArmorTextureArmsGlow { get; }
public virtual string ArmorTextureLegs { get; }
public abstract string TileTexture { get; }
/// <summary>
/// The path to the texture shown for the visor in the visor select. <br />
/// Note: This is only used for Visors, such as the X-Ray Scope.
/// </summary>
public virtual string VisorSelectIcon { get; }
/// <summary>
/// The Sound to be played when the visor is in use. <br />
/// Note: This is only used for Visors, such as the Scan Visor.
/// </summary>
public virtual SoundStyle? VisorBackgroundNoise => null;
/// <summary>
/// The Color to set the hud to when the visor is in use. <br />
/// Note: This is only used for Visors.
/// </summary>
public virtual Color VisorColor { get; } = Color.LightBlue;
public abstract bool AddOnlyAddonItem { get; }
public int SacrificeTotal { get; set; } = 1;
public bool ItemNameLiteral { get; set; } = true;
public virtual int AddonSlot { get; set; } = SuitAddonSlotID.None;
internal bool IsArmor => ArmorTextureHead != null && ArmorTextureHead != "" && ArmorTextureTorso != null && ArmorTextureTorso != "" && ArmorTextureLegs != null && ArmorTextureLegs != "";
public string GetAddonSlotName() => SuitAddonLoader.GetAddonSlotName(AddonSlot);
/// <summary>
/// Determines if the addon can generate on Chozo Statues during world generation.
/// </summary>
/// <param name="x">The X location of the tile</param>
/// <param name="y">The Y location of the tile</param>
public virtual bool CanGenerateOnChozoStatue(int x, int y) => false;
/// <summary>
/// Determines how likely the addon will generate on Chozo Statues.
/// </summary>
/// <param name="x">The X location of the tile</param>
/// <param name="y">The Y location of the tile</param>
public virtual double GenerationChance(int x, int y) { return 0; }
public override sealed void SetupContent()
{
SetStaticDefaults();
ModItem.SetStaticDefaults();
SetupDrawing();
}
public override void Load()
{
ModItem = new SuitAddonItem(this);
ModTile = new SuitAddonTile(this);
if (ModItem == null) { throw new Exception("WTF happened here? SuitAddonItem is null!"); }
if (ModTile == null) { throw new Exception("WTF happened here? SuitAddonTile is null!"); }
Mod.AddContent(ModItem);
Mod.AddContent(ModTile);
if (IsArmor && Main.netMode != NetmodeID.Server)
{
EquipLoader.AddEquipTexture(Mod, ArmorTextureHead, EquipType.Head, name: Name);
EquipLoader.AddEquipTexture(Mod, ArmorTextureTorso, EquipType.Body, name: Name);
EquipLoader.AddEquipTexture(Mod, ArmorTextureLegs, EquipType.Legs, name: Name);
}
}
private void SetupDrawing()
{
if (Main.netMode == NetmodeID.Server || !IsArmor) { return; }
int equipSlotHead = EquipLoader.GetEquipSlot(Mod, Name, EquipType.Head);
int equipSlotBody = EquipLoader.GetEquipSlot(Mod, Name, EquipType.Body);
int equipSlotLegs = EquipLoader.GetEquipSlot(Mod, Name, EquipType.Legs);
ArmorIDs.Head.Sets.DrawHead[equipSlotHead] = false;
ArmorIDs.Body.Sets.HidesTopSkin[equipSlotBody] = true;
//ArmorIDs.Body.Sets.HidesArms[equipSlotBody] = true;
ArmorIDs.Legs.Sets.HidesBottomSkin[equipSlotLegs] = true;
}
public override void Unload()
{
ModItem.Unload();
ModTile.Unload();
ModItem = null;
ModTile = null;
Item = null;
base.Unload();
}
protected override sealed void Register()
{
DisplayName = LocalizationLoader.CreateTranslation(Mod, $"SuitAddonName.{Name}");
Tooltip = LocalizationLoader.CreateTranslation(Mod, $"SuitAddonTooltip.{Name}");
if (!AddOnlyAddonItem)
{
Type = SuitAddonLoader.AddonCount;
if (Type > 127)
{
throw new Exception("Suit Addons Limit Reached. (Max: 128)");
}
SuitAddonLoader.addons.Add(this);
}
MetroidMod.Instance.Logger.Info("Register new Suit Addon: " + FullName + ", OnlyAddonItem: " + AddOnlyAddonItem);
}
public override void SetStaticDefaults()
{
base.SetStaticDefaults();
}
/// <inheritdoc cref="ModItem.SetDefaults()"/>
public virtual void SetItemDefaults(Item item) { }
public virtual bool ShowTileHover(Player player) => player.InInteractionRange(Player.tileTargetX, Player.tileTargetY);
/// <inheritdoc cref="ModItem.UpdateAccessory(Player, bool)"/>
public virtual void UpdateAccessory(Player player, bool hideVisual) { UpdateInventory(player); }
/// <inheritdoc cref="ModItem.UpdateInventory(Player)"/>
public virtual void UpdateInventory(Player player) { }
/// <inheritdoc cref="ModItem.UpdateArmorSet(Player)"/>
public virtual void OnUpdateArmorSet(Player player, int stack) { }
/// <inheritdoc cref="ModItem.UpdateVanitySet(Player)"/>
public virtual void OnUpdateVanitySet(Player player) { }
/// <inheritdoc cref="ModItem.ArmorSetShadows(Player)"/>
public virtual void ArmorSetShadows(Player player) { }
/// <inheritdoc cref="ModItem.AltFunctionUse(Player)"/>
public virtual bool AltFunctionUse(Player player) { return false; }
/// <inheritdoc cref="ModItem.CanUseItem(Player)"/>
public virtual bool CanUseItem(Player player) { return true; }
/// <inheritdoc cref="ModItem.UseItem(Player)"/>
public virtual bool? UseItem(Player player) { return null; }
/// <summary>
/// Allows you to do things when this visor is equipped and in use. <br />
/// Note: This is only called for Visors, such as the X-Ray Scope.
/// </summary>
/// <param name="player">The player.</param>
public virtual void DrawVisor(Player player) { }
public virtual string GetSetBonusText()
{
return null;
}
/// <inheritdoc cref="ModItem.AddRecipes"/>
public virtual void AddRecipes() { }
public Recipe CreateRecipe(int amount = 1) => ModItem.CreateRecipe(amount);
}
}