-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomWorld.cs
519 lines (487 loc) · 26.7 KB
/
CustomWorld.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
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using Terraria.ModLoader.IO;
using Terraria;
using System.IO;
using CustomNPCNames.Network;
namespace CustomNPCNames
{
public class CustomWorld : ModWorld
{
public static Dictionary<short, List<StringWrapper>> CustomNames;
public static byte mode;
public static bool tryUnique;
public static bool saveAndExit = false; // this is turned to true in CustomNPCNames.PreSaveAndExit() to distinguish autosave from save&exit
public static bool updateNameList = false; // this is turned to true in NetReceive() to print renameUI's panelList's contents to the screen
public static int receivedPackets = 0; // these two are used exclusively with SEND_COPY_DATA (i.e. pasting everything) so that the world sync occurs only once
public static int packetsTillSync = 0; // after all the packets have arrived, as opposed to syncing a bunch of times every single packet. Just for optimization.
public static List<BusyField> busyFields; // this list contains references to fields which are being edited by other players, and therefore locked from access
public CustomWorld()
{
ResetCustomNames();
mode = 0;
tryUnique = true;
}
public override void Initialize()
{
base.Initialize();
busyFields = new List<BusyField>();
}
public static void Unload()
{
CustomNames = null;
busyFields = null;
}
public static void ResetCustomNames()
{
CustomNames = new Dictionary<short, List<StringWrapper>>();
foreach (short i in CustomNPCNames.TownNPCs) {
CustomNames.Add(i, new List<StringWrapper>());
}
CustomNames.Add(1000, new List<StringWrapper>()); //
CustomNames.Add(1001, new List<StringWrapper>()); // for Male, Female and Global respectively
CustomNames.Add(1002, new List<StringWrapper>()); //
}
public override TagCompound Save()
{
base.Save();
Dictionary<short, List<string>> nameStrings = new Dictionary<short, List<string>>();
foreach (KeyValuePair<short, List<StringWrapper>> i in CustomNames) {
List<string> list = new List<string>();
foreach (StringWrapper j in i.Value) {
list.Add((string)j);
list.Add(System.Convert.ToString((long)j.ID));
}
nameStrings.Add(i.Key, list);
}
TagCompound tag = new TagCompound();
tag.Add("guide", nameStrings[NPCID.Guide]);
tag.Add("merchant", nameStrings[NPCID.Merchant]);
tag.Add("nurse", nameStrings[NPCID.Nurse]);
tag.Add("demolitionist", nameStrings[NPCID.Demolitionist]);
tag.Add("dyetrader", nameStrings[NPCID.DyeTrader]);
tag.Add("dryad", nameStrings[NPCID.Dryad]);
tag.Add("tavernkeep", nameStrings[NPCID.DD2Bartender]);
tag.Add("armsdealer", nameStrings[NPCID.ArmsDealer]);
tag.Add("stylist", nameStrings[NPCID.Stylist]);
tag.Add("painter", nameStrings[NPCID.Painter]);
tag.Add("angler", nameStrings[NPCID.Angler]);
tag.Add("goblintinkerer", nameStrings[NPCID.GoblinTinkerer]);
tag.Add("witchdoctor", nameStrings[NPCID.WitchDoctor]);
tag.Add("clothier", nameStrings[NPCID.Clothier]);
tag.Add("mechanic", nameStrings[NPCID.Mechanic]);
tag.Add("partygirl", nameStrings[NPCID.PartyGirl]);
tag.Add("wizard", nameStrings[NPCID.Wizard]);
tag.Add("taxcollector", nameStrings[NPCID.TaxCollector]);
tag.Add("truffle", nameStrings[NPCID.Truffle]);
tag.Add("pirate", nameStrings[NPCID.Pirate]);
tag.Add("steampunker", nameStrings[NPCID.Steampunker]);
tag.Add("cyborg", nameStrings[NPCID.Cyborg]);
tag.Add("skeletonmerchant", nameStrings[NPCID.SkeletonMerchant]);
tag.Add("travellingmerchant", nameStrings[NPCID.TravellingMerchant]);
tag.Add("male", nameStrings[1000]);
tag.Add("female", nameStrings[1001]);
tag.Add("global", nameStrings[1002]);
tag.Add("guide-gender", NPCs.CustomNPC.isMale[NPCID.Guide]);
tag.Add("merchant-gender", NPCs.CustomNPC.isMale[NPCID.Merchant]);
tag.Add("nurse-gender", NPCs.CustomNPC.isMale[NPCID.Nurse]);
tag.Add("demolitionist-gender", NPCs.CustomNPC.isMale[NPCID.Demolitionist]);
tag.Add("dyetrader-gender", NPCs.CustomNPC.isMale[NPCID.DyeTrader]);
tag.Add("dryad-gender", NPCs.CustomNPC.isMale[NPCID.Dryad]);
tag.Add("tavernkeep-gender", NPCs.CustomNPC.isMale[NPCID.DD2Bartender]);
tag.Add("armsdealer-gender", NPCs.CustomNPC.isMale[NPCID.ArmsDealer]);
tag.Add("stylist-gender", NPCs.CustomNPC.isMale[NPCID.Stylist]);
tag.Add("painter-gender", NPCs.CustomNPC.isMale[NPCID.Painter]);
tag.Add("angler-gender", NPCs.CustomNPC.isMale[NPCID.Angler]);
tag.Add("goblintinkerer-gender", NPCs.CustomNPC.isMale[NPCID.GoblinTinkerer]);
tag.Add("witchdoctor-gender", NPCs.CustomNPC.isMale[NPCID.WitchDoctor]);
tag.Add("clothier-gender", NPCs.CustomNPC.isMale[NPCID.Clothier]);
tag.Add("mechanic-gender", NPCs.CustomNPC.isMale[NPCID.Mechanic]);
tag.Add("partygirl-gender", NPCs.CustomNPC.isMale[NPCID.PartyGirl]);
tag.Add("wizard-gender", NPCs.CustomNPC.isMale[NPCID.Wizard]);
tag.Add("taxcollector-gender", NPCs.CustomNPC.isMale[NPCID.TaxCollector]);
tag.Add("truffle-gender", NPCs.CustomNPC.isMale[NPCID.Truffle]);
tag.Add("pirate-gender", NPCs.CustomNPC.isMale[NPCID.Pirate]);
tag.Add("steampunker-gender", NPCs.CustomNPC.isMale[NPCID.Steampunker]);
tag.Add("cyborg-gender", NPCs.CustomNPC.isMale[NPCID.Cyborg]);
tag.Add("skeletonmerchant-gender", NPCs.CustomNPC.isMale[NPCID.SkeletonMerchant]);
tag.Add("travellingmerchant-gender", NPCs.CustomNPC.isMale[NPCID.TravellingMerchant]);
tag.Add("mode", mode);
tag.Add("tryunique", tryUnique);
tag.Add("selected-npc", (short)(UI.UINPCButton.Selection != null ? UI.UINPCButton.Selection.npcId : 0)); // 0 is conventional for none, -1 is conventional for reset
// Reset everything if this is a save&exit moment (as opposed to autosave)
if (saveAndExit) {
UI.RenameUI.Visible = false;
UI.UINPCButton.Deselect();
UI.RenameUI.panelList.Clear();
UI.RenameUI.removeMode = false;
busyFields.Clear();
if (!ClientConfig.Carry) {
ResetCustomNames();
NPCs.CustomNPC.ResetCurrentGender();
UI.RenameUI.modeCycleButton.State = 0;
UI.RenameUI.uniqueNameButton.State = true;
}
saveAndExit = false;
}
return tag;
}
public override void Load(TagCompound tag)
{
if (tag.ContainsKey("guide")) {
CustomNames[NPCID.Guide] = StringWrapper.ConvertSaveList(tag.GetList<string>("guide"));
CustomNames[NPCID.Merchant] = StringWrapper.ConvertSaveList(tag.GetList<string>("merchant"));
CustomNames[NPCID.Nurse] = StringWrapper.ConvertSaveList(tag.GetList<string>("nurse"));
CustomNames[NPCID.Demolitionist] = StringWrapper.ConvertSaveList(tag.GetList<string>("demolitionist"));
CustomNames[NPCID.DyeTrader] = StringWrapper.ConvertSaveList(tag.GetList<string>("dyetrader"));
CustomNames[NPCID.Dryad] = StringWrapper.ConvertSaveList(tag.GetList<string>("dryad"));
CustomNames[NPCID.DD2Bartender] = StringWrapper.ConvertSaveList(tag.GetList<string>("tavernkeep"));
CustomNames[NPCID.ArmsDealer] = StringWrapper.ConvertSaveList(tag.GetList<string>("armsdealer"));
CustomNames[NPCID.Stylist] = StringWrapper.ConvertSaveList(tag.GetList<string>("stylist"));
CustomNames[NPCID.Painter] = StringWrapper.ConvertSaveList(tag.GetList<string>("painter"));
CustomNames[NPCID.Angler] = StringWrapper.ConvertSaveList(tag.GetList<string>("angler"));
CustomNames[NPCID.GoblinTinkerer] = StringWrapper.ConvertSaveList(tag.GetList<string>("goblintinkerer"));
CustomNames[NPCID.WitchDoctor] = StringWrapper.ConvertSaveList(tag.GetList<string>("witchdoctor"));
CustomNames[NPCID.Clothier] = StringWrapper.ConvertSaveList(tag.GetList<string>("clothier"));
CustomNames[NPCID.Mechanic] = StringWrapper.ConvertSaveList(tag.GetList<string>("mechanic"));
CustomNames[NPCID.PartyGirl] = StringWrapper.ConvertSaveList(tag.GetList<string>("partygirl"));
CustomNames[NPCID.Wizard] = StringWrapper.ConvertSaveList(tag.GetList<string>("wizard"));
CustomNames[NPCID.TaxCollector] = StringWrapper.ConvertSaveList(tag.GetList<string>("taxcollector"));
CustomNames[NPCID.Truffle] = StringWrapper.ConvertSaveList(tag.GetList<string>("truffle"));
CustomNames[NPCID.Pirate] = StringWrapper.ConvertSaveList(tag.GetList<string>("pirate"));
CustomNames[NPCID.Steampunker] = StringWrapper.ConvertSaveList(tag.GetList<string>("steampunker"));
CustomNames[NPCID.Cyborg] = StringWrapper.ConvertSaveList(tag.GetList<string>("cyborg"));
CustomNames[NPCID.SkeletonMerchant] = StringWrapper.ConvertSaveList(tag.GetList<string>("skeletonmerchant"));
CustomNames[NPCID.TravellingMerchant] = StringWrapper.ConvertSaveList(tag.GetList<string>("travellingmerchant"));
CustomNames[1000] = StringWrapper.ConvertSaveList(tag.GetList<string>("male"));
CustomNames[1001] = StringWrapper.ConvertSaveList(tag.GetList<string>("female"));
CustomNames[1002] = StringWrapper.ConvertSaveList(tag.GetList<string>("global"));
NPCs.CustomNPC.isMale[NPCID.Guide] = tag.GetBool("guide-gender");
NPCs.CustomNPC.isMale[NPCID.Merchant] = tag.GetBool("merchant-gender");
NPCs.CustomNPC.isMale[NPCID.Nurse] = tag.GetBool("nurse-gender");
NPCs.CustomNPC.isMale[NPCID.Demolitionist] = tag.GetBool("demolitionist-gender");
NPCs.CustomNPC.isMale[NPCID.DyeTrader] = tag.GetBool("dyetrader-gender");
NPCs.CustomNPC.isMale[NPCID.Dryad] = tag.GetBool("dryad-gender");
NPCs.CustomNPC.isMale[NPCID.DD2Bartender] = tag.GetBool("tavernkeep-gender");
NPCs.CustomNPC.isMale[NPCID.ArmsDealer] = tag.GetBool("armsdealer-gender");
NPCs.CustomNPC.isMale[NPCID.Stylist] = tag.GetBool("stylist-gender");
NPCs.CustomNPC.isMale[NPCID.Painter] = tag.GetBool("painter-gender");
NPCs.CustomNPC.isMale[NPCID.Angler] = tag.GetBool("angler-gender");
NPCs.CustomNPC.isMale[NPCID.GoblinTinkerer] = tag.GetBool("goblintinkerer-gender");
NPCs.CustomNPC.isMale[NPCID.WitchDoctor] = tag.GetBool("witchdoctor-gender");
NPCs.CustomNPC.isMale[NPCID.Clothier] = tag.GetBool("clothier-gender");
NPCs.CustomNPC.isMale[NPCID.Mechanic] = tag.GetBool("mechanic-gender");
NPCs.CustomNPC.isMale[NPCID.PartyGirl] = tag.GetBool("partygirl-gender");
NPCs.CustomNPC.isMale[NPCID.Wizard] = tag.GetBool("wizard-gender");
NPCs.CustomNPC.isMale[NPCID.TaxCollector] = tag.GetBool("taxcollector-gender");
NPCs.CustomNPC.isMale[NPCID.Truffle] = tag.GetBool("truffle-gender");
NPCs.CustomNPC.isMale[NPCID.Pirate] = tag.GetBool("pirate-gender");
NPCs.CustomNPC.isMale[NPCID.Steampunker] = tag.GetBool("steampunker-gender");
NPCs.CustomNPC.isMale[NPCID.Cyborg] = tag.GetBool("cyborg-gender");
NPCs.CustomNPC.isMale[NPCID.SkeletonMerchant] = tag.GetBool("skeletonmerchant-gender");
NPCs.CustomNPC.isMale[NPCID.TravellingMerchant] = tag.GetBool("travellingmerchant-gender");
mode = tag.GetByte("mode");
tryUnique = tag.GetBool("tryunique");
UI.RenameUI.savedSelectedNPC = tag.ContainsKey("selected-npc") ? tag.GetShort("selected-npc") : (short)-1; // 0 is conventional for none, -1 is conventional for "Do Nothing"
}
}
public override void NetSend(BinaryWriter packet)
{
packet.Write(SyncType.Get);
switch (SyncType.Get) {
case SyncType.MODE:
packet.Write(mode);
break;
case SyncType.TRY_UNIQUE:
packet.Write(tryUnique);
break;
case SyncType.NAME: {
short id = ModSync.ID;
packet.Write(id);
packet.Write(NPCs.CustomNPC.FindFirstNPC(id)?.GivenName);
}
break;
case SyncType.GENDER: {
short id = ModSync.ID;
packet.Write(id);
packet.Write(NPCs.CustomNPC.isMale[id]);
}
break;
case SyncType.CUSTOM_NAMES: {
short id = ModSync.ID;
packet.Write(id);
packet.Write(CustomNames[id].Count);
foreach (var i in CustomNames[id]) {
packet.Write(i.ToString());
packet.Write(i.ID);
}
}
break;
case SyncType.EVERYTHING:
packet.Write(mode);
packet.Write(tryUnique);
foreach (KeyValuePair<short, List<StringWrapper>> i in CustomNames) {
packet.Write(i.Value.Count);
foreach (StringWrapper j in i.Value) {
packet.Write(j.ToString());
packet.Write(j.ID);
}
}
foreach (short i in CustomNPCNames.TownNPCs) {
packet.Write(NPCs.CustomNPC.isMale[i]);
}
break;
case SyncType.BUSY_FIELDS:
packet.Write(busyFields.Count);
foreach(BusyField i in busyFields) {
packet.Write(i.ID);
packet.Write(i.player);
}
break;
}
}
public override void NetReceive(BinaryReader reader)
{
byte syncType = reader.ReadByte();
// Main.NewText("Receiving (" + syncType + ")! " + Main.time); DEBUG
switch (syncType) {
case SyncType.MODE: {
var readMode = reader.ReadByte();
if (CustomNPCNames.WaitForServerResponse) { return; }
mode = readMode;
}
break;
case SyncType.TRY_UNIQUE: {
var readTryUnique = reader.ReadBoolean();
if (CustomNPCNames.WaitForServerResponse) { return; }
tryUnique = readTryUnique;
}
break;
case SyncType.NAME: {
var readId = reader.ReadInt16();
var readName = reader.ReadString();
if (CustomNPCNames.WaitForServerResponse) { return; }
short id = readId;
string name = readName;
if (name != null) {
NPC npc = NPCs.CustomNPC.FindFirstNPC(id);
if (npc != null) {
npc.GivenName = name;
}
}
}
break;
case SyncType.GENDER: {
var readId = reader.ReadInt16();
var readIsMale = reader.ReadBoolean();
if (CustomNPCNames.WaitForServerResponse) { return; }
short id = readId;
NPCs.CustomNPC.isMale[id] = readIsMale;
}
break;
case SyncType.CUSTOM_NAMES: {
var readId = reader.ReadInt16();
var readCount = reader.ReadInt32();
string[] readNames = new string[readCount];
ulong[] readIDs = new ulong[readCount];
for (int i = 0; i < readCount; i++) {
readNames[i] = reader.ReadString();
readIDs[i] = reader.ReadUInt64();
}
if (CustomNPCNames.WaitForServerResponse) { return; }
short id = readId;
int count = readCount;
while (CustomNames[id].Count < count) { CustomNames[id].Add(""); }
while (CustomNames[id].Count > count) { CustomNames[id].RemoveAt(0); }
for (int i = 0; i < count; i++) {
CustomNames[id][i] = new StringWrapper(ref readNames[i], readIDs[i]);
}
if (Main.netMode == NetmodeID.MultiplayerClient) {
updateNameList = true;
}
}
break;
case SyncType.EVERYTHING: {
var readMode = reader.ReadByte();
var readTryUnique = reader.ReadBoolean();
int[] readSize = new int[27];
StringWrapper[][] readWrappers = new StringWrapper[27][];
{
int j = 0;
foreach (KeyValuePair<short, List<StringWrapper>> i in CustomNames) {
readSize[j] = reader.ReadInt32();
readWrappers[j] = new StringWrapper[readSize[j]];
for (int k = 0; k < readSize[j]; k++) {
string name = reader.ReadString();
ulong id = reader.ReadUInt64();
readWrappers[j][k] = new StringWrapper(ref name, id);
}
j++;
}
}
bool[] readIsMale = new bool[24];
for (int i = 0; i < 24; i++) {
readIsMale[i] = reader.ReadBoolean();
}
if (CustomNPCNames.WaitForServerResponse) { return; }
mode = readMode;
tryUnique = readTryUnique;
{
int j = 0;
foreach (KeyValuePair<short, List<StringWrapper>> i in CustomNames) {
while (i.Value.Count < readSize[j]) { i.Value.Add(""); }
while (i.Value.Count > readSize[j]) { i.Value.RemoveAt(0); }
for (int k = 0; k < readSize[j]; k++) {
i.Value[k] = new StringWrapper(ref readWrappers[j][k].str, readWrappers[j][k].ID);
}
j++;
}
j = 0;
foreach (short i in CustomNPCNames.TownNPCs) {
NPCs.CustomNPC.isMale[i] = readIsMale[j++];
}
}
if (Main.netMode == NetmodeID.MultiplayerClient) {
updateNameList = true;
}
}
break;
case SyncType.BUSY_FIELDS: {
var fieldCount = reader.ReadInt32();
BusyField[] busy = new BusyField[fieldCount];
for (int i = 0; i < fieldCount; i++) {
ulong id = reader.ReadUInt64();
byte player = reader.ReadByte();
busy[i] = new BusyField(id, player);
}
if (CustomNPCNames.WaitForServerResponse) { return; }
busyFields.Clear();
busyFields.AddRange(busy);
}
break;
}
}
/// <summary>
/// Computes if any UINameFields in the SelectedNPC tab are being edited (including myPlayer).
/// </summary>
/// <returns></returns>
public static bool AnyNameFieldBusyInCurrentTab()
{
if (UI.RenameUI.IsNPCSelected) {
// Reduce time complexity by caching CustomWorld.CustomNames data
var CustomNamesIDs = new HashSet<ulong>();
foreach (StringWrapper i in CustomNames[UI.RenameUI.SelectedNPC]) {
CustomNamesIDs.Add(i.ID);
}
foreach (BusyField i in busyFields) {
if (CustomNamesIDs.Contains(i.ID)) { return true; }
}
}
return false;
}
/// <summary>
/// Computes if any UINameFields in any tab are being edited (including myPlayer).
/// </summary>
/// <returns></returns>
public static bool AnyNameFieldBusy()
{
// Reduce time complexity by caching CustomWorld.CustomNames data
var CustomNamesIDs = new HashSet<ulong>();
foreach (KeyValuePair<short, List<StringWrapper>> i in CustomNames) {
foreach (StringWrapper j in i.Value) {
CustomNamesIDs.Add(j.ID);
}
}
foreach (BusyField i in busyFields) {
if (CustomNamesIDs.Contains(i.ID)) { return true; }
}
return false;
}
/// <summary>
/// Computes if the given NPC is having its name edited by anyone (including myPlayer).
/// </summary>
/// <param name="id">The NPCID of the town NPC in question.</param>
/// <returns></returns>
public static bool IsRenamePanelBusy(short id)
{
if (id != 1000 && id != 1001 && id != 1002) {
foreach (BusyField i in busyFields) {
if (i.ID == (ulong)id) { return true; }
}
} else if (id == 1000) {
foreach (short i in CustomNPCNames.TownNPCs) {
if (NPCs.CustomNPC.isMale[i]) {
foreach (BusyField j in busyFields) {
if (j.ID == (ulong)i) { return true; }
}
}
}
} else if (id == 1001) {
foreach (short i in CustomNPCNames.TownNPCs) {
if (!NPCs.CustomNPC.isMale[i]) {
foreach (BusyField j in busyFields) {
if (j.ID == (ulong)i) { return true; }
}
}
}
} else if (id == 1002) {
foreach (short i in CustomNPCNames.TownNPCs) {
foreach (BusyField j in busyFields) {
if (j.ID == (ulong)i) { return true; }
}
}
}
return false;
}
/// <summary>
/// Searches for a BusyField matching a player indice, i.e. the BusyField being edited by that player. Returns a BusyField(0, 0) if not found.
/// </summary>
/// <param name="player">The player indice.</param>
/// <returns></returns>
public static BusyField GetBusyField(byte player)
{
foreach (BusyField i in busyFields) {
if (i.player == player) { return i; }
}
return new BusyField(0, 0);
}
/// <summary>
/// Searches for a BusyField matching an ID of either a StringWrapper or an town NPCID. Returns a BusyField(0, 0) if not found.
/// </summary>
/// <param name="player">StringWrapper.ID or town NPCID.</param>
/// <returns></returns>
public static BusyField GetBusyField(ulong id)
{
foreach (BusyField i in busyFields) {
if (i.ID == id) { return i; }
}
return new BusyField(0, 0);
}
}
/// <summary>
/// Small container for ulong ID of a StringWrapper and player indice. Used to determine which entries are occupied and by whom.
/// </summary>
public struct BusyField
{
public readonly ulong ID; // StringWrapper.ID for UINameFields, values from 1-24 for UIRenamePanel
public readonly byte player; // 255 for no one, 0-254 for player indices
public static readonly BusyField Empty = new BusyField(); // initialized with 0s
public BusyField(ulong ID, byte player)
{
this.ID = ID;
this.player = player;
}
public override bool Equals(object obj)
{
if (obj != null && GetType() == obj.GetType()) {
return ((BusyField)obj).ID == ID;
}
return false;
}
public override int GetHashCode()
{
return ID.GetHashCode();
}
}
}