using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Assets.Scripts { public class QuestLog : MonoBehaviour { public Dictionary> quests; public GameObject content; public Scrollbar scrollBar; System.Random rand = new System.Random(); public GameObject quest; public Texture finished; public GameObject uiHandler; // Start is called before the first frame update void Start() { quests = new Dictionary>(); quests.Add("find", new List()); GameObject newQuest = Instantiate(quest); newQuest.transform.SetParent(content.transform, false); FindQuest main = new FindQuest(newQuest); main.generateCityQuest(); quests["find"].Add(main); } // Update is called once per frame void Update() { } public void updateQuests(string key, object obj, int amount) { if (quests.ContainsKey(key)) { foreach (Quest quest in quests[key]) { quest.update(obj, amount); } } } public void addQuest() { GameObject newQuest = Instantiate(quest); newQuest.transform.SetParent(content.transform, false); int index = rand.Next(4); string type = ""; Quest questItem; switch (index) { case 0: type = "collect"; questItem = new CollectQuest(newQuest); break; case 1: type = "kill"; questItem = new KillQuest(newQuest); break; case 2: type = "find"; questItem = new FindQuest(newQuest); break; /*case 3: type = "craft"; break;*/ case 3: type = "explore"; questItem = new ExploreQuest(newQuest); break; default: questItem = new Quest(newQuest); break; } if (!quests.ContainsKey(type)) { quests.Add(type, new List()); } quests[type].Add(questItem); } public void showQuests() { content.GetComponent().sizeDelta = new Vector2(0, 10); float y = -37.5f; foreach (string key in quests.Keys) { foreach (Quest quest in quests[key]) { quest.show(y); y = y - 75; content.GetComponent().sizeDelta = new Vector2(0, content.GetComponent().sizeDelta.y + 75); } } scrollBar.value = 0; content.transform.localPosition = new Vector3(0,0,0); } public void removeQuests() { Inventory inventory = GameObject.Find("Inventory").GetComponent(); int luck = GameObject.Find("Player").GetComponent().getLuck(); luck = luck + inventory.getEquipmentBonus()["LCK"]; Dictionary> toDelete = new Dictionary>(); foreach (string key in quests.Keys) { foreach (Quest quest in quests[key]) { if (quest.isFinishedQuest()) { if (!toDelete.ContainsKey(key)) { toDelete.Add(key, new List()); } toDelete[key].Add(quest); } } } foreach (string key in toDelete.Keys) { foreach (Quest quest in toDelete[key]) { if (quest is CollectQuest) { ((CollectQuest)quest).removeItems(inventory); } quest.delete(); quests[key].Remove(quest); inventory.addItem(new Item(luck)); } } } } }