public static async Task SendRandomItems(ENetPeer peer, int x, int y, int items, World world) { try { Random r = new Random(); int rarity = ItemsData[items].Rarity / 3; int a = x / 32, b = y / 32; if (rarity <= 5) { rarity = 3; } int gems = r.Next(0, rarity); int rand = r.Next(0, 20); if (rand > 10) { await SendGems(peer, x, y, 0, gems, world); } else if (rand > 4 && rand <= 10) { DroppedItem drop = new DroppedItem { ItemID = items + 1, ItemCount = 1, ItemName = "" }; world.Items[a + b * world.Width].DroppedItems.Add(drop); await peer.SendDrop(-1, x, y, items + 1, 1, 0); } else { DroppedItem drop = new DroppedItem { ItemID = items, ItemCount = 1, ItemName = ItemsData[items + 1].Name }; world.Items[a + b * world.Width].DroppedItems.Add(drop); await peer.SendDrop(-1, x, y, items, 1, 0); } } catch (Exception e) { Console.WriteLine("RandomItems error : " + e.Message); } }
public static async Task SendGems(ENetPeer peer, int x, int y, byte se, int gemsCount, World world) { try { int a = x / 32, b = y / 32; while (gemsCount != 0) { if (gemsCount >= 100) { DroppedItem drop = new DroppedItem { ItemID = 112, ItemCount = 100, ItemName = ItemsData[112].Name }; world.Items[a + b * world.Width].DroppedItems.Add(drop); await peer.SendDrop(-1, x, y, 112, 100, se); gemsCount -= 100; } else if (gemsCount >= 50) { DroppedItem drop = new DroppedItem { ItemID = 112, ItemCount = 50, ItemName = ItemsData[112].Name }; world.Items[a + b * world.Width].DroppedItems.Add(drop); await peer.SendDrop(-1, x, y, 112, 50, se); gemsCount -= 50; } else if (gemsCount >= 10) { DroppedItem drop = new DroppedItem { ItemID = 112, ItemCount = 10, ItemName = ItemsData[112].Name }; world.Items[a + b * world.Width].DroppedItems.Add(drop); await peer.SendDrop(-1, x, y, 112, 10, se); gemsCount -= 10; } else if (gemsCount >= 5) { DroppedItem drop = new DroppedItem { ItemID = 112, ItemCount = 5, ItemName = ItemsData[112].Name }; world.Items[a + b * world.Width].DroppedItems.Add(drop); await peer.SendDrop(-1, x, y, 112, 5, se); gemsCount -= 5; } else if (gemsCount >= 1) { DroppedItem drop = new DroppedItem { ItemID = 112, ItemCount = 1, ItemName = ItemsData[112].Name }; world.Items[a + b * world.Width].DroppedItems.Add(drop); await peer.SendDrop(-1, x, y, 112, 1, se); gemsCount -= 1; } } } catch (Exception e) { Console.WriteLine("Sendgems error : " + e.Message); } }