public static void ApplyDrop(Player player, World world, Vector2 pos, int item, float amount, bool fromPlayer) { if (fromPlayer) { if (!player.Inventory.Find(item, out var count)) { return; } if (count < amount) { return; } player.Inventory.Remove(item, (int)amount); player.Inventory.Modify(); } Random rand = new Random(); if (rand.Next(0, 2) == 0) { pos.X += rand.Next(0, 8); } else { pos.X -= rand.Next(0, 8); } if (rand.Next(0, 2) == 0) { pos.Y -= rand.Next(0, 5); } TankPacket packet = new TankPacket() { Type = 0xe, NetId = -1, Tile = item, Pos = pos }; byte[] data = packet.Pack(); Buffer.BlockCopy(BitConverter.GetBytes(amount), 0, data, 20, 4); player.Send(data); DroppedItem drop = new DroppedItem() { ItemId = item, Amount = (int)amount, Pos = pos }; world.DroppedItems.Add(world.DropId++, drop); world.Save(); }
private static void SerializeItemDatabase() { SerializedItemData = File.ReadAllBytes("items.dat"); TankPacket tank = new TankPacket() { Type = 0x10, NetId = -1, State = 0x8, Size = SerializedItemData.Length, Data = SerializedItemData }; ItemData = tank.Pack(); ItemDataHash = HashData(SerializedItemData); }
public void Send(TankPacket tank) => Send(tank.Pack());