-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockPlayer.cs
More file actions
103 lines (98 loc) · 3.84 KB
/
LockPlayer.cs
File metadata and controls
103 lines (98 loc) · 3.84 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.Audio;
using Terraria.GameContent.Drawing;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Terraria.UI;
namespace LoadoutLock
{
public class LockPlayer : ModPlayer
{
public bool[] LockAccessory = new bool[10];
public int[] OriginalIndex = new int[10];
public override void Load()
{
On_Player.TrySwitchingLoadout += On_Player_TrySwitchingLoadout;
base.Load();
}
public override void Initialize()
{
OriginalIndex = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
base.Initialize();
}
private void On_Player_TrySwitchingLoadout(On_Player.orig_TrySwitchingLoadout orig, Player self, int loadoutIndex)
{
if (ModContent.GetInstance<LoadoutLockConfig>().SwitchItem)
{
var lockAcc = self.GetModPlayer<LockPlayer>().LockAccessory;
var oriIndex = self.GetModPlayer<LockPlayer>().OriginalIndex;
bool flag = self.itemTime > 0 || self.itemAnimation > 0;
if ((self.whoAmI != Main.myPlayer || (!flag && !self.CCed && !self.dead)) && loadoutIndex != self.CurrentLoadoutIndex && loadoutIndex >= 0 && loadoutIndex < self.Loadouts.Length)
{
self.Loadouts[self.CurrentLoadoutIndex].Swap(self);
self.Loadouts[loadoutIndex].Swap(self);
for(int i = 0; i < 10; i++)
{
if (lockAcc[i] && oriIndex[i] != -1)
{
self.Loadouts[self.CurrentLoadoutIndex].SwapCertainSlotWith(self.Loadouts[oriIndex[i]], i);
self.Loadouts[oriIndex[i]].SwapCertainSlotWith(self.Loadouts[loadoutIndex], i);
}
}
self.CurrentLoadoutIndex = loadoutIndex;
if (self.whoAmI == Main.myPlayer)
{
self.CloneLoadOuts(Main.clientPlayer);
Main.mouseLeftRelease = false;
ItemSlot.RecordLoadoutChange();
SoundEngine.PlaySound(SoundID.MenuTick);
NetMessage.TrySendData(147, -1, -1, null, self.whoAmI, loadoutIndex);
ParticleOrchestrator.RequestParticleSpawn(clientOnly: false, ParticleOrchestraType.LoadoutChange, new ParticleOrchestraSettings
{
PositionInWorld = self.Center,
UniqueInfoPiece = loadoutIndex
}, self.whoAmI);
}
}
return;
}
orig(self, loadoutIndex);
}
public override void Unload()
{
On_Player.TrySwitchingLoadout -= On_Player_TrySwitchingLoadout;
base.Unload();
}
public override void LoadData(TagCompound tag)
{
for (int i = 0; i < 10; i++)
{
if (tag.TryGet<bool>($"LockAccessory{i}", out bool value))
{
LockAccessory[i] = value;
}
if(tag.TryGet<int>($"OriginalIndex{i}",out int index))
{
OriginalIndex[i] = index;
}
}
base.LoadData(tag);
}
public override void SaveData(TagCompound tag)
{
for (int i = 0; i < 10; i++)
{
tag[$"LockAccessory{i}"] = LockAccessory[i];
tag[$"OriginalIndex{i}"] = OriginalIndex[i];
}
base.SaveData(tag);
}
}
}