-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTerramon.cs
118 lines (96 loc) · 3.67 KB
/
Terramon.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
using EasyPacketsLib;
using Terramon.Content.GUI;
using Terramon.Core.Loaders.UILoading;
namespace Terramon;
public class Terramon : Mod
{
/*
* TODO:
* This will be removed at a later date.
* It exists because there are Pokémon in the DB that shouldn't be loaded as mod content (yet).
*/
public const ushort MaxPokemonID = 151;
/// <summary>
/// The maximum level a Pokémon can reach.
/// </summary>
public const ushort MaxPokemonLevel = 100;
static Terramon()
{
if (!Main.dedServ) MenuSocialWidget.Setup();
}
/// <summary>
/// The amount of Pokémon that have actually been loaded into the game.
/// This is the minimum of the amount of Pokémon in the database and <see cref="MaxPokemonID" />.
/// </summary>
public static int LoadedPokemonCount => Math.Min(MaxPokemonID, DatabaseV2.Pokemon.Count);
public static Terramon Instance => ModContent.GetInstance<Terramon>();
public static DatabaseV2 DatabaseV2 { get; private set; }
/// <summary>
/// The amount of times the mod has been loaded by the player.
/// The only way for one to change or reset this is to edit or delete the file <c>TerramonLoadCount.dat</c> in the save directory.
/// </summary>
public static uint TimesLoaded { get; private set; }
/// <summary>
/// Forces a full refresh of the party UI (<see cref="PartyDisplay" /> and <see cref="InventoryParty" />), updating all
/// slots.
/// </summary>
public static void RefreshPartyUI()
{
var partyData = TerramonPlayer.LocalPlayer.Party;
PartyDisplay.UpdateAllSlots(partyData); // Update the party sidebar display
InventoryParty.UpdateAllSlots(partyData); // Update the inventory party display
}
/// <summary>
/// Resets UI states for reuse with other players. Called when the player leaves the world in
/// <see cref="TerramonWorld.PreSaveAndQuit" />.
/// </summary>
public static void ResetUI()
{
PartyDisplay.ClearAllSlots();
InventoryParty.ClearAllSlots();
UILoader.GetUIState<HubUI>().ResetPokedex();
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
EasyPacketDLL.HandlePacket(reader, whoAmI);
}
private void SetupCrossModCompatibility()
{
if (Main.dedServ) return;
// Wikithis compatibility
if (!ModLoader.TryGetMod("Wikithis", out var wikiThis)) return;
wikiThis.Call(0, this, "https://terrariamods.wiki.gg/wiki/Terramon_Mod/{}");
wikiThis.Call(3, this, ModContent.Request<Texture2D>("Terramon/icon_small"));
}
private static uint CheckLoadCount()
{
var datFilePath = Path.Combine(Main.SavePath, "TerramonLoadCount.dat");
if (!File.Exists(datFilePath))
{
File.WriteAllText(datFilePath, "1");
return 1;
}
var count = File.ReadAllText(datFilePath);
if (!uint.TryParse(count, out var result)) return 1;
result++;
File.WriteAllText(datFilePath, result.ToString());
return result;
}
public override void Load()
{
// Load the database
var dbStream = GetFileStream("Assets/Data/PokemonDB-min.json");
DatabaseV2 = DatabaseV2.Parse(dbStream);
// Register the mod in EasyPacketsLib
EasyPacketDLL.RegisterMod(this);
// Setup cross-mod compatibility
SetupCrossModCompatibility();
// Check how many times the mod has been loaded
TimesLoaded = CheckLoadCount();
}
public override void Unload()
{
DatabaseV2 = null;
EasyPacketDLL.Unload();
}
}