forked from bladecoding/Terraria-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemHelper.cs
102 lines (87 loc) · 2.81 KB
/
ItemHelper.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
using Terraria;
using TerrariaAPI;
namespace ItemPlugin
{
public static class ItemHelper
{
private static Player me
{
get { return Main.player[Main.myPlayer]; }
}
public static Item CreateItem(string itemName, int stack = 0)
{
Item item = new Item();
item.RealSetDefaults(itemName);
if (stack > 0) item.stack = stack;
return item;
}
public static Item GiveItem(string itemName, int stack = 0)
{
Item item = ItemHelper.CreateItem(itemName, stack);
return me.GetItem(Main.myPlayer, item);
}
public static bool RemoveItem(Item item)
{
if (item != null && item.active)
{
item.active = false;
for (int i = 0; i < me.inventory.Length; i++)
{
if (me.inventory[i] == item)
{
me.inventory[i] = new Item();
Main.PlaySound(7, (int)me.position.X, (int)me.position.Y, 1);
return true;
}
}
}
return false;
}
public static Item ThrowItem(string itemName, int stack = 0)
{
Item item = CreateItem(itemName, stack);
item.position.X = me.position.X + me.width / 2f - item.width / 2f;
item.position.Y = me.position.Y + me.height / 2f - item.height / 2f;
item.wet = Collision.WetCollision(item.position, item.width, item.height);
item.velocity.Y = -2f;
item.velocity.X = 4f * me.direction + me.velocity.X;
item.spawnTime = 0;
if (Main.netMode == 0)
{
item.owner = Main.myPlayer;
item.noGrabDelay = 100;
}
int num = 200;
Main.item[num] = new Item();
if (Main.netMode != 1)
{
for (int i = 0; i < 200; i++)
{
if (!Main.item[i].active)
{
num = i;
break;
}
}
}
if (num == 200 && Main.netMode != 1)
{
int num2 = 0;
for (int j = 0; j < 200; j++)
{
if (Main.item[j].spawnTime > num2)
{
num2 = Main.item[j].spawnTime;
num = j;
}
}
}
Main.item[num] = item;
if (Main.netMode == 1)
{
NetMessage.SendData((int)PacketTypes.ItemDrop, -1, -1, "", num, 0f, 0f, 0f);
}
return item;
}
}
}