diff --git a/Assets/Scripts/Fight.cs b/Assets/Scripts/Fight.cs index a053372..ac89ea0 100644 --- a/Assets/Scripts/Fight.cs +++ b/Assets/Scripts/Fight.cs @@ -74,6 +74,7 @@ public class Fight : MonoBehaviour player.GetComponent().enemyKilled(); player.GetComponent().gainExperience(enemy.GetComponent().getExperience()); GameObject.Find("Inventory").GetComponent().addItem(enemy.GetComponent().getItem()); + GameObject.Find("QuestLog").GetComponent().updateQuests("kill", enemy, 1); } else { diff --git a/Assets/Scripts/Inventory.cs b/Assets/Scripts/Inventory.cs index a597461..93cc469 100644 --- a/Assets/Scripts/Inventory.cs +++ b/Assets/Scripts/Inventory.cs @@ -85,6 +85,7 @@ namespace Assets.Scripts if (itemAdded) { GameObject.Find("UIHandler").GetComponent().showMessage("SUCCESS;You got an item!"); + GameObject.Find("QuestLog").GetComponent().updateQuests("collect", item, 1); SteamWorksHandler.getItemAchievement(item); break; } diff --git a/Assets/Scripts/InventoryTrash.cs b/Assets/Scripts/InventoryTrash.cs index de6b7d7..597f31f 100644 --- a/Assets/Scripts/InventoryTrash.cs +++ b/Assets/Scripts/InventoryTrash.cs @@ -37,10 +37,12 @@ namespace Assets.Scripts InventorySlot toDelete = GameObject.Find("Inventory").GetComponent().getDrag().GetComponent(); if (toDelete.place == ItemPlace.BAG) { + GameObject.Find("QuestLog").GetComponent().updateQuests("collect", toDelete.getItem(toDelete.getCurrentBag()), -1); toDelete.removeItem(); } else { + GameObject.Find("QuestLog").GetComponent().updateQuests("collect", toDelete.getEquip(), -1); toDelete.removeEquip(); } GameObject.Find("Inventory").GetComponent().dragImage.GetComponent().color = new Color(0, 0, 0, 0); diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 1866843..36efb58 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -289,6 +289,7 @@ namespace Assets.Scripts camera.transform.Translate(new Vector3(0, bobbingDirection, 0) * Time.deltaTime / 2); } + GameObject.Find("QuestLog").GetComponent().updateQuests("explore", gameObject, 1); } public void getRotation() diff --git a/Assets/Scripts/Quest.cs b/Assets/Scripts/Quest.cs deleted file mode 100644 index 6d9883b..0000000 --- a/Assets/Scripts/Quest.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -namespace Assets.Scripts -{ - public class Quest - { - string questname; - string keyword; - int current; - int goal; - bool isFinished = false; - Vector3 coordinates; - System.Random rand = new System.Random(); - GameObject display; - - public Quest(string type, GameObject display) - { - switch (type) - { - case "collect": - generateCollectQuest(); - break; - case "find": - generateFindQuest(); - break; - case "kill": - generateKillQuest(); - break; - case "craft": - generateCraftQuest(); - break; - case "explore": - generateExploreQuest(); - break; - case "main": - generateCityQuest(); - break; - } - this.display = display; - } - - public void generateCollectQuest() - { - current = 0; - goal = rand.Next(10) + 1; - questname = "Collect " + goal + " "; - int index = rand.Next(7); - switch (index) - { - case 0: - questname = questname + "slimeballs"; - keyword = "Slimeball"; - break; - case 1: - questname = questname + "stones"; - keyword = "Stone"; - break; - case 2: - questname = questname + "wood"; - keyword = "Wood"; - break; - case 3: - questname = questname + "common items"; - keyword = "Common"; - break; - case 4: - questname = questname + "rare items"; - keyword = "Rare"; - break; - case 5: - questname = questname + "epic items"; - keyword = "Epic"; - break; - case 6: - questname = questname + "legendary items"; - keyword = "Legendary"; - break; - } - } - - public void generateFindQuest() - { - - } - - public void generateKillQuest() - { - - } - - public void generateCraftQuest() - { - - } - - public void generateExploreQuest() - { - - } - - public void generateCityQuest() - { - questname = "Find all cities"; - current = 0; - goal = GameObject.Find("WorldGenerator").GetComponent().getCityAmount(); - } - - public void update(string type) - { - - } - - public void show(float positionY) - { - display.transform.Find("txtName").GetComponent().text = questname; - display.transform.Find("txtAmount").GetComponent().text = current + "/" + goal; - if (isFinished) - { - display.transform.Find("imgDone").GetComponent().color = new Color(255,255,255,255); - } - float x = display.transform.localPosition.x; - float z = display.transform.localPosition.z; - display.transform.localPosition = new Vector3(x, positionY, z); - } - } - -} \ No newline at end of file diff --git a/Assets/Scripts/QuestLog.cs b/Assets/Scripts/QuestLog.cs index a983c01..1c576a4 100644 --- a/Assets/Scripts/QuestLog.cs +++ b/Assets/Scripts/QuestLog.cs @@ -22,7 +22,9 @@ namespace Assets.Scripts quests.Add("main", new List()); GameObject newQuest = Instantiate(quest); newQuest.transform.SetParent(content.transform, false); - quests["main"].Add(new Quest("main", newQuest)); + FindQuest main = new FindQuest(newQuest); + main.generateCityQuest(); + quests["main"].Add(main); for (int i = 0; i < 20; i++) { addQuest(); @@ -35,49 +37,56 @@ namespace Assets.Scripts } - public void updateQuests() + public void updateQuests(string key, object obj, int amount) { - foreach (string key in quests.Keys) + foreach (Quest quest in quests[key]) { - foreach (Quest quest in quests[key]) - { - quest.update(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 = "find"; + type = "kill"; + questItem = new KillQuest(newQuest); break; case 2: - type = "kill"; + type = "find"; + questItem = new FindQuest(newQuest); break; - case 3: + /*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()); } - GameObject newQuest = Instantiate(quest); - newQuest.transform.SetParent(content.transform, false); - quests[type].Add(new Quest(type, newQuest)); + quests[type].Add(questItem); } public void showQuests() { content.GetComponent().sizeDelta = new Vector2(0, 10); - updateQuests(); float y = -37.5f; foreach (string key in quests.Keys) { diff --git a/Assets/Scripts/Quests.meta b/Assets/Scripts/Quests.meta new file mode 100644 index 0000000..e2b205f --- /dev/null +++ b/Assets/Scripts/Quests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 17a562a7d8c28c045b088c1dd33a6f0e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Quests/CollectQuest.cs b/Assets/Scripts/Quests/CollectQuest.cs new file mode 100644 index 0000000..0874ec9 --- /dev/null +++ b/Assets/Scripts/Quests/CollectQuest.cs @@ -0,0 +1,87 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Assets.Scripts +{ + public class CollectQuest : Quest + { + public CollectQuest(GameObject display) : base(display) + { + current = 0; + goal = getRandomNumber(10) + 1; + questname = "Collect " + goal + " "; + int index = getRandomNumber(7); + switch (index) + { + case 0: + questname = questname + "slimeballs"; + keyword = "Slimeball"; + break; + case 1: + questname = questname + "stones"; + keyword = "Stone"; + break; + case 2: + questname = questname + "wood"; + keyword = "Wood"; + break; + case 3: + questname = questname + "common items"; + keyword = "Common"; + break; + case 4: + questname = questname + "rare items"; + keyword = "Rare"; + break; + case 5: + questname = questname + "epic items"; + keyword = "Epic"; + break; + case 6: + questname = questname + "legendary items"; + keyword = "Legendary"; + break; + } + } + + override + public void update(object obj, int amount) + { + Item item = (Item)obj; + if (keyword == "Slimeball" && item.getName().ToLower().Contains("slimeball")) + { + current = current + amount; + } + if (keyword == "Stone" && item.getName().ToLower().Contains("stone")) + { + current = current + amount; + } + if (keyword == "Wood" && item.getName().ToLower().Contains("wood")) + { + current = current + amount; + } + if (keyword == "Common" && item.getName().ToLower().Contains("common")) + { + current = current + amount; + } + if (keyword == "Rare" && item.getName().ToLower().Contains("rare")) + { + current = current + amount; + } + if (keyword == "Epic" && item.getName().ToLower().Contains("epic")) + { + current = current + amount; + } + if (keyword == "Legendary" && item.getName().ToLower().Contains("legendary")) + { + current = current + amount; + } + if (current >= goal) + { + isFinished = true; + } + } + } + +} diff --git a/Assets/Scripts/Quests/CollectQuest.cs.meta b/Assets/Scripts/Quests/CollectQuest.cs.meta new file mode 100644 index 0000000..d55f1cb --- /dev/null +++ b/Assets/Scripts/Quests/CollectQuest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 87adb6ce71d334d41832c6e5946c8401 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Quests/ExploreQuest.cs b/Assets/Scripts/Quests/ExploreQuest.cs new file mode 100644 index 0000000..aadaf26 --- /dev/null +++ b/Assets/Scripts/Quests/ExploreQuest.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Assets.Scripts +{ + public class ExploreQuest : Quest + { + public ExploreQuest(GameObject display) : base(display) + { + Vector3 playerPos = GameObject.Find("Player").GetComponent().transform.position; + float coordX = getRandomNumber(20) - 10; + float coordZ = getRandomNumber(20) - 10; + coordinates = new Vector3(playerPos.x + coordX, 0, playerPos.z + coordZ); + questname = "Travel to " + coordinates.x + "/" + coordinates.z + "(X/Z)"; + } + + override + public void update(object obj, int amount) + { + Vector3 player = ((GameObject)obj).transform.position; + if (player.x - 5 >= coordinates.x && player.x + 5 <= coordinates.x && player.z - 5 >= coordinates.z && player.z + 5 <= coordinates.z) + { + isFinished = true; + } + } + } +} + diff --git a/Assets/Scripts/Quests/ExploreQuest.cs.meta b/Assets/Scripts/Quests/ExploreQuest.cs.meta new file mode 100644 index 0000000..628ff9b --- /dev/null +++ b/Assets/Scripts/Quests/ExploreQuest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bc8224ede819f4b478849d299ab24004 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Quests/FindQuest.cs b/Assets/Scripts/Quests/FindQuest.cs new file mode 100644 index 0000000..db0b6ab --- /dev/null +++ b/Assets/Scripts/Quests/FindQuest.cs @@ -0,0 +1,83 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Assets.Scripts +{ + public class FindQuest : Quest + { + public FindQuest(GameObject display) : base(display) + { + current = 0; + goal = getRandomNumber(10) + 1; + questname = "Find " + goal + " "; + int index = getRandomNumber(5); + switch (index) + { + case 0: + questname = questname + "planes"; + keyword = "Plane"; + break; + case 1: + questname = questname + "mountains"; + keyword = "Mountain"; + break; + case 2: + questname = questname + "forests"; + keyword = "Forest"; + break; + case 3: + questname = questname + "rivers"; + keyword = "River"; + break; + case 4: + questname = questname + "lakes"; + keyword = "Lake"; + break; + } + } + + public void generateCityQuest() + { + questname = "Find all cities"; + keyword = "City"; + current = 0; + goal = GameObject.Find("WorldGenerator").GetComponent().getCityAmount(); + } + + override + public void update(object obj, int amount) + { + GameObject tile = (GameObject)obj; + string tilename = tile.GetComponent().getTileType(); + if (keyword == "Forest" && tilename.ToLower().Contains("forest")) + { + current++; + } + if (keyword == "Plane" && tilename.ToLower().Contains("plane")) + { + current++; + } + if (keyword == "Mountain" && tilename.ToLower().Contains("mountain")) + { + current++; + } + if (keyword == "River" && tilename.ToLower().Contains("river")) + { + current++; + } + if (keyword == "Lake" && tilename.ToLower().Contains("lake")) + { + current++; + } + if (keyword == "City" && tilename.ToLower().Contains("city")) + { + current++; + } + if (current >= goal) + { + isFinished = true; + } + } + } +} diff --git a/Assets/Scripts/Quests/FindQuest.cs.meta b/Assets/Scripts/Quests/FindQuest.cs.meta new file mode 100644 index 0000000..3010941 --- /dev/null +++ b/Assets/Scripts/Quests/FindQuest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9b0e62c53b5e7b84f991f4d464fe3c6e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Quests/KillQuest.cs b/Assets/Scripts/Quests/KillQuest.cs new file mode 100644 index 0000000..01e1116 --- /dev/null +++ b/Assets/Scripts/Quests/KillQuest.cs @@ -0,0 +1,56 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Assets.Scripts +{ + public class KillQuest : Quest + { + public KillQuest(GameObject display) : base(display) + { + current = 0; + goal = getRandomNumber(20) + 1; + questname = "Kill " + goal + " "; + int index = getRandomNumber(3); + switch (index) + { + case 0: + questname = questname + "slimes"; + keyword = "slime"; + break; + case 1: + questname = questname + "boss slimes"; + keyword = "boss"; + break; + case 2: + questname = questname + "mini boss slimes"; + keyword = "miniboss"; + break; + } + } + + override + public void update(object obj, int amount) + { + GameObject enemy = (GameObject)obj; + string enemyname = enemy.GetComponent().getEnemyName(); + if (keyword == "miniboss" && enemyname.ToLower().Contains("miniboss")) + { + current++; + } + if (keyword == "boss" && enemyname.ToLower().Contains("boss")) + { + current++; + } + if (keyword == "slime") + { + current++; + } + if (current >= goal) + { + isFinished = true; + } + } + } +} + diff --git a/Assets/Scripts/Quests/KillQuest.cs.meta b/Assets/Scripts/Quests/KillQuest.cs.meta new file mode 100644 index 0000000..dc6d945 --- /dev/null +++ b/Assets/Scripts/Quests/KillQuest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ab96793c0acfd754390101cc53d060bb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Quests/Quest.cs b/Assets/Scripts/Quests/Quest.cs new file mode 100644 index 0000000..7421c4e --- /dev/null +++ b/Assets/Scripts/Quests/Quest.cs @@ -0,0 +1,52 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace Assets.Scripts +{ + public class Quest + { + protected string questname; + protected string keyword; + protected int current; + protected int goal; + protected bool isFinished = false; + protected Vector3 coordinates; + protected GameObject display; + + public Quest(GameObject display) + { + this.display = display; + } + + public virtual void update(object obj, int amount) + { + //empty + } + + public void show(float positionY) + { + display.transform.Find("txtName").GetComponent().text = questname; + display.transform.Find("txtAmount").GetComponent().text = current + "/" + goal; + if (isFinished) + { + display.transform.Find("imgDone").GetComponent().color = new Color(255,255,255,255); + } + float x = display.transform.localPosition.x; + float z = display.transform.localPosition.z; + display.transform.localPosition = new Vector3(x, positionY, z); + } + + public int getRandomNumber(int max) + { + int result = 0; + for (int i = 0; i < 50; i++) + { + result = Random.Range(0,max); + } + return result; + } + } + +} \ No newline at end of file diff --git a/Assets/Scripts/Quest.cs.meta b/Assets/Scripts/Quests/Quest.cs.meta similarity index 100% rename from Assets/Scripts/Quest.cs.meta rename to Assets/Scripts/Quests/Quest.cs.meta diff --git a/Assets/Scripts/WorldGenerator.cs b/Assets/Scripts/WorldGenerator.cs index 8fa2611..d21a3e2 100644 --- a/Assets/Scripts/WorldGenerator.cs +++ b/Assets/Scripts/WorldGenerator.cs @@ -124,6 +124,7 @@ public class WorldGenerator : MonoBehaviour newTile.GetComponent().generateTile(pos, name); tiles.Add(pos, newTile); renderedTiles.Add(newTile); + GameObject.Find("QuestLog").GetComponent().updateQuests("find", newTile, 1); } else {