forked from UnrealMultiple/TShockPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
37 lines (32 loc) · 1.5 KB
/
Utils.cs
File metadata and controls
37 lines (32 loc) · 1.5 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
using Terraria;
using Terraria.DataStructures;
using TShockAPI;
namespace CaiRewardChest;
public static class Utils
{
public static void GiveItem(RewardChest chest, GetDataHandlers.ChestOpenEventArgs args)
{
var chestType = WorldGen.GetChestItemDrop(chest.X, chest.Y, Main.tile[chest.X, chest.Y].type);
foreach (var i in chest.Chest.item)
{
GiveItemByDrop(args.Player, i.netID, i.stack, i.prefix);
}
var itemsReceived = chest.Chest.item
.Where(i => i != null && i.netID != 0 && i.stack != 0)
.Select(i => TShock.Utils.ItemTag(i)).ToList();
itemsReceived.Add(TShock.Utils.ItemTag(new Item { netID = chestType, stack = 1 }));
GiveItemByDrop(args.Player, chestType, 1, 0);
args.Player.SendSuccessMessage(GetString($"[i:{chestType}]你打开了一个奖励箱: ") +
"" + string.Join(", ", itemsReceived));
chest.HasOpenPlayer.Add(args.Player.Account.ID);
RewardChest.UpdateChest(chest);
}
private static void GiveItemByDrop(TSPlayer plr, int type, int stack, int prefix)
{
var number = Item.NewItem(new EntitySource_DebugCommand(), (int) plr.X, (int) plr.Y, plr.TPlayer.width,
plr.TPlayer.height, type, stack, true, prefix, true);
Main.item[number].playerIndexTheItemIsReservedFor = plr.Index;
plr.SendData(PacketTypes.ItemDrop, number: number, number2: 1f);
plr.SendData(PacketTypes.ItemOwner, null, number);
}
}