-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInvTweaksPlayer.cs
198 lines (183 loc) · 7.33 KB
/
InvTweaksPlayer.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
using System.Linq;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace InvTweaks
{
public class InvTweaksPlayer : ModPlayer
{
public Item extraSlotItem;
public override void Initialize()
{
extraSlotItem = new Item();
extraSlotItem.SetDefaults();
extraSlotItem.TurnToAir();
}
public override void LoadData(TagCompound tag)
{
// legacy load
int type = tag.GetInt("extraSlotItem_Type");
if (type != 0)
extraSlotItem.SetDefaults(type);
if (tag.GetCompound("extraSlotItem") is TagCompound item
&& item != new TagCompound())
{
extraSlotItem = ItemIO.Load(item);
}
}
private int originalSelectedItem;
private bool autoRevertSelectedItem;
public void PlaceTree()
{
for (int i = 0; i < Player.inventory.Length; i++)
{
Item item = Player.inventory[i];
if (item.type == ItemID.Acorn)
{
originalSelectedItem = Player.selectedItem;
autoRevertSelectedItem = true;
Player.selectedItem = i;
Player.controlUseItem = true;
Player.ItemCheck(Main.myPlayer);
return;
}
}
}
public override void SaveData(TagCompound tag)
{
tag.Add("extraSlotItem", ItemIO.Save(extraSlotItem));
}
public override void PostUpdateBuffs()
{
if (ClientConfig.Instance.AutoBuff)
{
for (int queryBuff = 0; queryBuff < Player.buffTime.Length; queryBuff++)
{
if (Player.buffTime[queryBuff] == 1)
{
for (int queryItem = 0; queryItem < Player.inventory.Length - 5; queryItem++)
{
if (Player.inventory[queryItem].buffType == Player.buffType[queryBuff])
{
ItemLoader.UseItem(Player.inventory[queryItem], Player);
Player.buffTime[queryBuff] = Player.inventory[queryItem].buffTime;
//the swapping of cursorFill is unconventional,
//but prevents items from randomly teleporting thru the inv
bool cursorFill = ClientConfig.Instance.CursorFill;
ClientConfig.Instance.CursorFill = false;
if (ItemLoader.ConsumeItem(Player.inventory[queryItem], Player))
{
if (--Player.inventory[queryItem].stack <= 0)
Player.inventory[queryItem].TurnToAir();
}
ClientConfig.Instance.CursorFill = cursorFill;
Recipe.FindRecipes();
}
}
}
}
}
}
public override void PostUpdate()
{
if (autoRevertSelectedItem)
{
if (Player.itemTime == 0 && Player.itemAnimation == 0)
{
Player.selectedItem = originalSelectedItem;
autoRevertSelectedItem = false;
}
}
}
public override void PostHurt(bool pvp, bool quiet, double damage, int hitDirection, bool crit)
{
if (ClientConfig.Instance.AutoHeal
&& Player.statLife < Player.statLifeMax2 * (ClientConfig.Instance.AutoHealThreshold * .01))
{
if (Player.noItems)
return;
if (Player.potionDelay > 0)
return;
if (!(Player.QuickHeal_GetItemToUse() is Item item))
return;
SoundEngine.PlaySound(item.UseSound, Player.position);
if (item.potion)
{
if (item.type == ItemID.RestorationPotion)
{
Player.AddBuff(21, Player.potionDelay = Player.restorationDelayTime, true);
}
else
{
Player.AddBuff(21, Player.potionDelay = Player.potionDelayTime, true);
}
}
ItemLoader.UseItem(item, Player);
int healLife = Player.GetHealLife(item, true);
Player.statLife += healLife;
if (Player.statLife > Player.statLifeMax2)
{
Player.statLife = Player.statLifeMax2;
}
if (Player.statMana > Player.statManaMax2)
{
Player.statMana = Player.statManaMax2;
}
if (healLife > 0 && Main.myPlayer == Player.whoAmI)
{
Player.HealEffect(healLife, true);
}
bool cursorFill = ClientConfig.Instance.CursorFill;
ClientConfig.Instance.CursorFill = false;
if (ItemLoader.ConsumeItem(item, Player))
{
if (--item.stack <= 0)
item.TurnToAir();
}
ClientConfig.Instance.CursorFill = cursorFill;
Recipe.FindRecipes();
}
}
public override void PostBuyItem(NPC vendor, Item[] shopInventory, Item item)
{
Item shopItem = shopInventory.FirstOrDefault(x => x.type == item.type);
if (ShopStackUI.visible
&& !Terraria.UI.ItemSlot.ShiftInUse
&& PlayerLoader.CanBuyItem(Player, Main.npc[Player.talkNPC], shopInventory, shopItem)
&& (Main.mouseItem.stack < Main.mouseItem.maxStack)
&& (Main.mouseItem.stack < InvTweaksGuiSystem.Instance.shopStackState.ShopStack)
&& Player.BuyItem(shopItem.GetStoreValue(), shopItem.shopSpecialCurrency))
{
Main.mouseItem.stack++;
if (Main.stackSplit == 0)
{
Main.stackSplit = 15;
}
else
{
Main.stackSplit = Main.stackDelay;
}
if (shopItem.buyOnce && --shopItem.stack <= 0)
{
shopItem.SetDefaults(0, false);
}
PlayerLoader.PostBuyItem(Player, Main.npc[Player.talkNPC], shopInventory, Main.mouseItem);
}
}
public override bool CanBuyItem(NPC vendor, Item[] shopInventory, Item item)
{
if (ClientConfig.Instance.ShopClick && Terraria.UI.ItemSlot.ShiftInUse)
{
var gui = InvTweaksGuiSystem.Instance;
var state = new ShopStackUI();
state.Activate();
state.ShopStack = item.maxStack;
ShopStackUI.visible = true;
gui.userInterface.SetState(gui.shopStackState = state);
}
return true;
}
}
}