forked from MadYeling/Fargowiltas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFargoPlayer.cs
444 lines (366 loc) · 13.6 KB
/
FargoPlayer.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
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.GameInput;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using Fargowiltas.NPCs;
using System;
using System.Linq;
using Terraria.ModLoader.IO;
using Fargowiltas.Projectiles;
using Fargowiltas.Items;
using Terraria.GameContent.Events;
////using Fargowiltas.Toggler;
namespace Fargowiltas
{
public class FargoPlayer : ModPlayer
{
// //public ToggleBackend Toggler = new ToggleBackend();
// public Dictionary<string, bool> TogglesToSync = new Dictionary<string, bool>();
public bool extractSpeed;
public bool HasDrawnDebuffLayer;
internal bool BattleCry;
internal bool CalmingCry;
internal int originalSelectedItem;
internal bool autoRevertSelectedItem;
public float luckPotionBoost;
public float ElementalAssemblerNearby;
public float StatSheetMaxAscentMultiplier;
public float StatSheetWingSpeed;
public bool? CanHover = null;
internal Dictionary<string, bool> FirstDyeIngredients = new Dictionary<string, bool>();
private readonly string[] tags = new string[]
{
"RedHusk",
"OrangeBloodroot",
"YellowMarigold",
"LimeKelp",
"GreenMushroom",
"TealMushroom",
"CyanHusk",
"SkyBlueFlower",
"BlueBerries",
"PurpleMucos",
"VioletHusk",
"PinkPricklyPear",
"BlackInk"
};
public override void SaveData(TagCompound tag)
{
string name = "FargoDyes" + Player.name;
List<string> dyes = new List<string>();
foreach (string tagString in tags)
{
bool value;
if (FirstDyeIngredients.TryGetValue(tagString, out value))
{
dyes.AddWithCondition(tagString, FirstDyeIngredients[tagString]);
}
else
{
dyes.AddWithCondition(tagString, false);
}
}
tag.Add(name, dyes);
if (BattleCry)
tag.Add($"FargoBattleCry{Player.name}", true);
if (CalmingCry)
tag.Add($"FargoCalmingCry{Player.name}", true);
}
// public override void Initialize()
// {
// //Toggler.Load(this);
// }
public override void LoadData(TagCompound tag)
{
string name = "FargoDyes" + Player.name;
IList<string> dyes = tag.GetList<string>(name);
foreach (string downedTag in tags)
{
FirstDyeIngredients[downedTag] = dyes.Contains(downedTag);
}
BattleCry = tag.ContainsKey($"FargoBattleCry{Player.name}");
CalmingCry = tag.ContainsKey($"FargoCalmingCry{Player.name}");
}
public override void ModifyStartingInventory(IReadOnlyDictionary<string, List<Item>> itemsByMod, bool mediumCoreDeath)
{
foreach (string tag in tags)
{
FirstDyeIngredients[tag] = false;
}
}
public override void ResetEffects()
{
extractSpeed = false;
HasDrawnDebuffLayer = false;
}
public override void ProcessTriggers(TriggersSet triggersSet)
{
if (Fargowiltas.CustomKey.JustPressed)
{
QuickUseItemAt(40);
}
if (Fargowiltas.RodKey.JustPressed)
{
AutoUseRod();
}
if (Fargowiltas.HomeKey.JustPressed)
{
AutoUseMirror();
}
if (Fargowiltas.StatKey.JustPressed)
{
Fargowiltas.UserInterfaceManager.ToggleStatSheet();
}
}
public override void PostUpdateBuffs()
{
if (GetInstance<FargoConfig>().UnlimitedPotionBuffsOn120)
{
foreach (Item item in Player.bank.item)
{
FargoGlobalItem.TryUnlimBuff(item, Player);
}
foreach (Item item in Player.bank2.item)
{
FargoGlobalItem.TryUnlimBuff(item, Player);
}
}
if (GetInstance<FargoConfig>().PiggyBankAcc)
{
foreach (Item item in Player.bank.item)
{
FargoGlobalItem.TryPiggyBankAcc(item, Player);
}
foreach (Item item in Player.bank2.item)
{
FargoGlobalItem.TryPiggyBankAcc(item, Player);
}
}
}
public override void PostUpdateEquips()
{
if (Fargowiltas.SwarmActive)
{
Player.buffImmune[BuffID.Horrified] = true;
}
}
public override void PostUpdateMiscEffects()
{
if (ElementalAssemblerNearby > 0)
{
ElementalAssemblerNearby -= 1;
Player.alchemyTable = true;
}
if (Player.equippedWings == null)
ResetStatSheetWings();
ForceBiomes();
}
public void ResetStatSheetWings()
{
StatSheetMaxAscentMultiplier = 0;
StatSheetWingSpeed = 0;
CanHover = null;
}
private void ForceBiomes()
{
if (FargoGlobalNPC.SpecificBossIsAlive(ref FargoGlobalNPC.eaterBoss, NPCID.EaterofWorldsHead)
&& Player.Distance(Main.npc[FargoGlobalNPC.eaterBoss].Center) < 3000)
{
Player.ZoneCorrupt = true;
}
if (FargoGlobalNPC.SpecificBossIsAlive(ref FargoGlobalNPC.brainBoss, NPCID.BrainofCthulhu)
&& Player.Distance(Main.npc[FargoGlobalNPC.brainBoss].Center) < 3000)
{
Player.ZoneCrimson = true;
}
if (FargoGlobalNPC.SpecificBossIsAlive(ref FargoGlobalNPC.plantBoss, NPCID.Plantera)
&& Player.Distance(Main.npc[FargoGlobalNPC.plantBoss].Center) < 3000)
{
Player.ZoneJungle = true;
}
if (GetInstance<FargoConfig>().Fountains)
{
switch (Main.SceneMetrics.ActiveFountainColor)
{
case -1: //no fountain active
goto default;
case 0: //pure water, ocean
Player.ZoneBeach = true;
break;
case 2: //corrupt
Player.ZoneCorrupt = true;
break;
case 3: //jungle
Player.ZoneJungle = true;
break;
case 4: //hallow
if (Main.hardMode)
Player.ZoneHallow = true;
break;
case 5: //ice
Player.ZoneSnow = true;
break;
case 6: //oasis
goto case 12;
case 8: //cavern
goto default;
case 9: //blood fountain
goto default;
case 10: //crimson
Player.ZoneCrimson = true;
break;
case 12: //desert fountain
Player.ZoneDesert = true;
if (Player.Center.Y > 3200f)
Player.ZoneUndergroundDesert = true;
break;
default:
break;
}
}
}
public override void PostUpdate()
{
if (autoRevertSelectedItem)
{
if (Player.itemTime == 0 && Player.itemAnimation == 0)
{
Player.selectedItem = originalSelectedItem;
autoRevertSelectedItem = false;
}
}
if (FargoWorld.OverloadedSlimeRain && Main.rand.Next(20) == 0)
{
SlimeRainSpawns();
}
}
public void SlimeRainSpawns()
{
int type = NPCID.GreenSlime;
int[] slimes = { NPCID.SlimeSpiked, NPCID.SandSlime, NPCID.IceSlime, NPCID.SpikedIceSlime, NPCID.MotherSlime, NPCID.SpikedJungleSlime, NPCID.DungeonSlime, NPCID.UmbrellaSlime, NPCID.ToxicSludge, NPCID.CorruptSlime, NPCID.Crimslime, NPCID.IlluminantSlime };
int rand = Main.rand.Next(50);
if (rand == 0)
{
type = NPCID.Pinky;
}
else if (rand < 20)
{
type = slimes[Main.rand.Next(slimes.Length)];
}
Vector2 pos = new Vector2((int)Player.position.X + Main.rand.Next(-800, 800), (int)Player.position.Y + Main.rand.Next(-800, -250));
//Projectile.NewProjectile( pos, Vector2.Zero, ModContent.ProjectileType<SpawnProj>(), 0, 0, Main.myPlayer, type);
}
public override bool PreModifyLuck(ref float luck)
{
if (FargoWorld.Matsuri && !Main.IsItRaining && !Main.IsItStorming)
{
LanternNight.GenuineLanterns = true;
LanternNight.ManualLanterns = false;
}
return base.PreModifyLuck(ref luck);
}
public override void ModifyLuck(ref float luck)
{
luck += luckPotionBoost;
luckPotionBoost = 0; //look nowhere else works ok
}
public void AutoUseMirror()
{
int potionofReturn = -1;
int recallPotion = -1;
int magicMirror = -1;
for (int i = 0; i < Player.inventory.Length; i++)
{
switch (Player.inventory[i].type)
{
case ItemID.PotionOfReturn:
potionofReturn = i;
break;
case ItemID.RecallPotion:
recallPotion = i;
break;
case ItemID.MagicMirror:
case ItemID.IceMirror:
case ItemID.CellPhone:
magicMirror = i;
break;
}
}
if (potionofReturn != -1)
QuickUseItemAt(potionofReturn);
else if (recallPotion != -1)
QuickUseItemAt(recallPotion);
else if (magicMirror != -1)
QuickUseItemAt(magicMirror);
}
public void AutoUseRod()
{
for (int i = 0; i < Player.inventory.Length; i++)
{
if (Player.inventory[i].type == ItemID.RodofDiscord)
{
QuickUseItemAt(i);
break;
}
}
}
public void QuickUseItemAt(int index, bool use = true)
{
if (!autoRevertSelectedItem && Player.selectedItem != index && Player.inventory[index].type != 0)
{
originalSelectedItem = Player.selectedItem;
autoRevertSelectedItem = true;
Player.selectedItem = index;
Player.controlUseItem = true;
if (use)
{
Player.ItemCheck(Main.myPlayer);
}
}
}
// /*public override void clientClone(ModPlayer clientClone)
// {
// FargoPlayer modPlayer = clientClone as FargoPlayer;
// modPlayer.Toggler = Toggler;
// }*/
// /*public void SyncToggle(string key)
// {
// if (!TogglesToSync.ContainsKey(key))
// TogglesToSync.Add(key, player.GetToggle(key).ToggleBool);
// }*/
// public override void SyncPlayer(int toWho, int fromWho, bool newPlayer)
// {
// foreach (KeyValuePair<string, bool> toggle in TogglesToSync)
// {
// ModPacket packet = mod.GetPacket();
// packet.Write((byte)80);
// packet.Write((byte)player.whoAmI);
// packet.Write(toggle.Key);
// packet.Write(toggle.Value);
// packet.Send(toWho, fromWho);
// }
// TogglesToSync.Clear();
// }
// /*public override void SendClientChanges(ModPlayer clientPlayer)
// {
// FargoPlayer modPlayer = clientPlayer as FargoPlayer;
// if (modPlayer.Toggler.Toggles != Toggler.Toggles)
// {
// ModPacket packet = mod.GetPacket();
// packet.Write((byte)79);
// packet.Write((byte)player.whoAmI);
// packet.Write((byte)Toggler.Toggles.Count);
// for (int i = 0; i < Toggler.Toggles.Count; i++)
// {
// packet.Write(Toggler.Toggles.Values.ElementAt(i).ToggleBool);
// }
// packet.Send();
// }
// }*/
}
}