Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //The LootGenerator script that generates the loot
  2. switch (enemyType)
  3.         {
  4.             case "Goblin":
  5.                 for (int i = 0; i < items.Length; i++)
  6.                 {
  7.                     switch (i)
  8.                     {
  9.                         case 0:
  10.                             if (lootMultiplier > 0)
  11.                             {
  12.                                 items[i] = new Inventory.InventoryItem("Goblin Head", "goblin_head");
  13.                                 lootQuantities[i] = lootMultiplier;
  14.                             }
  15.                             break;
  16.                         case 1:
  17.                             if (goldMultiplier > 0)
  18.                             {
  19.                                 items[i] = new Inventory.InventoryItem("Gold", "gold");
  20.                                 lootQuantities[i] = goldMultiplier;
  21.                             }
  22.                             break;
  23.                         case 2:
  24.                             break;
  25.                     }
  26.                 }
  27.                 break;
  28.         }
  29.  
  30. //Later in LootGenerator the sccript will send "items" into another script where it will display the loot in the game, this script it called LootSystem
  31.  
  32. //This is the LootSystem script
  33. public void Loot()
  34.     {
  35.         for (int i = 0; i < items.Length; i++)
  36.         {
  37.             inventory.AddItem(items[i], quantities[i]);
  38.         }
  39.         Destroy(currentLootGenerator);
  40.     }
  41.  
  42.     public void LoadLoot(Inventory.InventoryItem[] lootItems, int[] amounts, GameObject lootGenerator)
  43.     {
  44.         currentLootGenerator = lootGenerator;
  45.  
  46.         items = new Inventory.InventoryItem[lootItems.Length];
  47.         items = lootItems;
  48.  
  49.         quantities = new int[amounts.Length];
  50.         quantities = amounts;
  51.  
  52.         for (int i = 0; i < items.Length; i++)
  53.         {
  54.             slotItemImage[i].sprite = Resources.Load<Sprite>("InventoryIcons/" + items[i].technicalName);
  55.             slotItemText[i].text = quantities[i].ToString();
  56.         }
  57.     }
  58.  
  59. //In the "Loot"-function the script adds the items into the invetory
  60.  
  61. //This is the Inventory script
  62. public void AddItem(InventoryItem item, int amount)
  63.     {
  64.  
  65.         if (inventoryStorage.ContainsKey(item))
  66.         {
  67.             print("?");
  68.             log.OnLooting(item.name, amount);
  69.             inventoryStorage[item] += amount;
  70.  
  71.             for (int i = 0; i < slotItemImage.Length; i++)
  72.             {
  73.                 if (slotItemImage[i].sprite.name.Contains(item.technicalName))
  74.                 {
  75.                     int quantity = inventoryStorage[item];
  76.                     slotItemQuantity[i].text = quantity.ToString();
  77.                     break;
  78.                 }
  79.             }
  80.         }
  81.         else if (!inventoryStorage.ContainsKey(item))
  82.         {
  83.             print("!");
  84.             inventoryStorage.Add(item, amount);
  85.             log.OnLooting(item.name, amount);
  86.  
  87.             for (int i = 0; i < slotItemImage.Length; i++)
  88.             {
  89.                 if (slotItemQuantity[i].text.Count() <= 0)
  90.                 {
  91.                     slotItemQuantity[i].text = amount.ToString();
  92.  
  93.                     slotItemImage[i].gameObject.SetActive(true);
  94.                     slotItemImage[i].sprite = Resources.Load<Sprite>("InventoryIcons/" + item.technicalName);
  95.                     break;
  96.                 }
  97.             }
  98.         }
  99.         GameObject.FindGameObjectWithTag("Player").GetComponent<Quests>().UpdateQuest("Fetch", item: item, amount: amount);
  100.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement