Dancer_A

Discard Item edit

Dec 8th, 2023 (edited)
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.81 KB | None | 0 0
  1. // Event_Processor_Commands.cs
  2.         // Discard Item
  3.         private bool command_item_discard()
  4.         {
  5.             // Value[0] = id is for a unit, or for an actor
  6.             // Value[1] = id
  7.             // Value[2] = item index  (-1 for discard everything, -2 to discard a specific item)
  8.             // Value[3] = item type
  9.             // Value[4] = item id
  10.             Game_Actor actor;
  11.             get_actor(command.Value[0], command.Value[1], out actor);
  12.             int item_index = process_number(command.Value[2]);
  13.             if (actor != null)
  14.             {
  15.                 if (item_index == -1)
  16.                 {
  17.                     // Discard all items
  18.                     while (actor.num_items > 0)
  19.                         actor.discard_item(0);
  20.                 }
  21.                 else if (item_index == -2) // Skitty
  22.                 {
  23.                     {
  24.                         int result = 0;
  25.                         var itemData = new Item_Data(process_number(command.Value[3]),
  26.                             process_number(command.Value[4]));
  27.                         result = actor.FindItem(itemData);
  28.                         if (result != -1)
  29.                             actor.discard_item(result);
  30.                         //else
  31.                         //    Print.message(
  32.                         //    "Item not found in inventory.\n" +
  33.                         //    "Check to make sure you have the\n" +
  34.                         //    "correct item/weapon id.");
  35.                     }
  36.                 }
  37.  
  38.                 else
  39.                     actor.discard_item(item_index);
  40.             }
  41.             Index++;
  42.             return true;
  43.         }
  44.  
  45. // Game_Actor.cs
  46.         public bool HasItem(Item_Data itemData)
  47.         {
  48.             Maybe<int> index;
  49.             return HasItem(itemData, out index);
  50.         }
  51.         private bool HasItem(Item_Data itemData, out Maybe<int> index)
  52.         {
  53.             index = Maybe<int>.Nothing;
  54.             for (int i = 0; i < Items.Count; i++)
  55.             {
  56.                 if (itemData.same_item(Items[i]) && !Items[i].out_of_uses)
  57.                 {
  58.                     index = i;
  59.                     return true;
  60.                 }
  61.             }
  62.             return false;
  63.         }
  64.  
  65.         public int FindItem(Item_Data itemData)
  66.         {
  67.             Maybe<int> index;
  68.             return FindItem(itemData, out index);
  69.         }
  70.         private int FindItem(Item_Data itemData, out Maybe<int> index)
  71.         {
  72.             index = Maybe<int>.Nothing;
  73.             for (int i = 0; i < Items.Count; i++)
  74.             {
  75.                 if (itemData.same_item(Items[i]) && !Items[i].out_of_uses)
  76.                 {
  77.                     return i;
  78.                 }
  79.             }
  80.             return -1;
  81.         }
  82.  
  83. // placed above discard_item(int)
Advertisement
Add Comment
Please, Sign In to add comment