Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The LootGenerator script that generates the loot
- switch (enemyType)
- {
- case "Goblin":
- for (int i = 0; i < items.Length; i++)
- {
- switch (i)
- {
- case 0:
- if (lootMultiplier > 0)
- {
- items[i] = new Inventory.InventoryItem("Goblin Head", "goblin_head");
- lootQuantities[i] = lootMultiplier;
- }
- break;
- case 1:
- if (goldMultiplier > 0)
- {
- items[i] = new Inventory.InventoryItem("Gold", "gold");
- lootQuantities[i] = goldMultiplier;
- }
- break;
- case 2:
- break;
- }
- }
- break;
- }
- //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
- //This is the LootSystem script
- public void Loot()
- {
- for (int i = 0; i < items.Length; i++)
- {
- inventory.AddItem(items[i], quantities[i]);
- }
- Destroy(currentLootGenerator);
- }
- public void LoadLoot(Inventory.InventoryItem[] lootItems, int[] amounts, GameObject lootGenerator)
- {
- currentLootGenerator = lootGenerator;
- items = new Inventory.InventoryItem[lootItems.Length];
- items = lootItems;
- quantities = new int[amounts.Length];
- quantities = amounts;
- for (int i = 0; i < items.Length; i++)
- {
- slotItemImage[i].sprite = Resources.Load<Sprite>("InventoryIcons/" + items[i].technicalName);
- slotItemText[i].text = quantities[i].ToString();
- }
- }
- //In the "Loot"-function the script adds the items into the invetory
- //This is the Inventory script
- public void AddItem(InventoryItem item, int amount)
- {
- if (inventoryStorage.ContainsKey(item))
- {
- print("?");
- log.OnLooting(item.name, amount);
- inventoryStorage[item] += amount;
- for (int i = 0; i < slotItemImage.Length; i++)
- {
- if (slotItemImage[i].sprite.name.Contains(item.technicalName))
- {
- int quantity = inventoryStorage[item];
- slotItemQuantity[i].text = quantity.ToString();
- break;
- }
- }
- }
- else if (!inventoryStorage.ContainsKey(item))
- {
- print("!");
- inventoryStorage.Add(item, amount);
- log.OnLooting(item.name, amount);
- for (int i = 0; i < slotItemImage.Length; i++)
- {
- if (slotItemQuantity[i].text.Count() <= 0)
- {
- slotItemQuantity[i].text = amount.ToString();
- slotItemImage[i].gameObject.SetActive(true);
- slotItemImage[i].sprite = Resources.Load<Sprite>("InventoryIcons/" + item.technicalName);
- break;
- }
- }
- }
- GameObject.FindGameObjectWithTag("Player").GetComponent<Quests>().UpdateQuest("Fetch", item: item, amount: amount);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement