Advertisement
KidaCoding

Untitled

Jul 4th, 2024 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | Source Code | 0 0
  1. case "@rui":
  2. {
  3.     if (line.Length != 3)
  4.     {
  5.         Console.WriteLine("Usage: @rui <playerUID> <itemID>", ConsoleColor.Red);
  6.         break;
  7.     }
  8.  
  9.     uint playerUID;
  10.     if (!uint.TryParse(line[1], out playerUID))
  11.     {
  12.         Console.WriteLine("Invalid player UID", ConsoleColor.Red);
  13.         break;
  14.     }
  15.  
  16.     uint itemID;
  17.     if (!uint.TryParse(line[2], out itemID))
  18.     {
  19.         Console.WriteLine("Invalid item ID", ConsoleColor.Red);
  20.         break;
  21.     }
  22.  
  23.     WindowsAPI.BinaryFile binary = new WindowsAPI.BinaryFile();
  24.  
  25.     string filePath = Program.ServerConfig.DbLocation + "\\PlayersItems\\" + playerUID + ".bin";
  26.  
  27.     if (!System.IO.File.Exists(filePath))
  28.     {
  29.         Console.WriteLine("Player file not found", ConsoleColor.Red);
  30.         break;
  31.     }
  32.  
  33.     uint clientUID = uint.Parse(System.IO.Path.GetFileName(filePath).Replace(".bin", ""));
  34.     Client.GameClient client = new Client.GameClient(null);
  35.     client.Player.UID = clientUID;
  36.     client.Inventory = new Role.Instance.Inventory(client);
  37.     client.Equipment = new Role.Instance.Equip(client);
  38.     client.Warehouse = new Role.Instance.Warehouse(client);
  39.     Database.ServerDatabase.LoadClientItems(client);
  40.  
  41.     List<Task> tasks = new List<Task>();
  42.  
  43.     tasks.Add(Task.Run(() =>
  44.     {
  45.         var list = client.Equipment.ClientItems.Values.ToList();
  46.         foreach (var item in list)
  47.         {
  48.             if (item.ITEM_ID == itemID)
  49.             {
  50.                 client.Equipment.ClientItems.Remove(item.UID);
  51.                 Console.WriteLine($"Item {item.ITEM_ID} removed from equipment", ConsoleColor.Green);
  52.             }
  53.         }
  54.     }));
  55.  
  56.     tasks.Add(Task.Run(() =>
  57.     {
  58.         foreach (var a in client.Warehouse.ClientItems)
  59.         {
  60.             foreach (var b in a.Value.Values)
  61.             {
  62.                 if (b.ITEM_ID == itemID)
  63.                 {
  64.                     client.Warehouse.ClientItems[a.Key].Remove(b.UID);
  65.                     Console.WriteLine($"Item {b.ITEM_ID} removed from warehouse", ConsoleColor.Green);
  66.                 }
  67.             }
  68.         }
  69.     }));
  70.  
  71.     tasks.Add(Task.Run(() =>
  72.     {
  73.         var list = client.Inventory.ClientItems.Values.ToList();
  74.         foreach (var item in list)
  75.         {
  76.             if (item.ITEM_ID == itemID)
  77.             {
  78.                 client.Inventory.ClientItems.Remove(item.UID);
  79.                 Console.WriteLine($"Item {item.ITEM_ID} removed from inventory", ConsoleColor.Green);
  80.             }
  81.         }
  82.     }));
  83.  
  84.     Task.WaitAll(tasks.ToArray());
  85.  
  86.     Database.ServerDatabase.SaveClientItems(client);
  87.     Console.WriteLine("Done processing player items", ConsoleColor.DarkRed);
  88.  
  89.     break;
  90. }
Tags: MS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement