Added inheritance for quests, finished quest implementation (90%), v1.4.0

This commit is contained in:
Nicola Sovic 2022-07-12 19:58:28 +02:00
parent 408339387d
commit 3f8d9c0551
18 changed files with 388 additions and 144 deletions

View File

@ -74,6 +74,7 @@ public class Fight : MonoBehaviour
player.GetComponent<Player>().enemyKilled();
player.GetComponent<Player>().gainExperience(enemy.GetComponent<Enemy>().getExperience());
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(enemy.GetComponent<Enemy>().getItem());
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("kill", enemy, 1);
}
else
{

View File

@ -85,6 +85,7 @@ namespace Assets.Scripts
if (itemAdded)
{
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("SUCCESS;You got an item!");
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("collect", item, 1);
SteamWorksHandler.getItemAchievement(item);
break;
}

View File

@ -37,10 +37,12 @@ namespace Assets.Scripts
InventorySlot toDelete = GameObject.Find("Inventory").GetComponent<Inventory>().getDrag().GetComponent<InventorySlot>();
if (toDelete.place == ItemPlace.BAG)
{
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("collect", toDelete.getItem(toDelete.getCurrentBag()), -1);
toDelete.removeItem();
}
else
{
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("collect", toDelete.getEquip(), -1);
toDelete.removeEquip();
}
GameObject.Find("Inventory").GetComponent<Inventory>().dragImage.GetComponent<RawImage>().color = new Color(0, 0, 0, 0);

View File

@ -289,6 +289,7 @@ namespace Assets.Scripts
camera.transform.Translate(new Vector3(0, bobbingDirection, 0) * Time.deltaTime / 2);
}
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("explore", gameObject, 1);
}
public void getRotation()

View File

@ -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<WorldGenerator>().getCityAmount();
}
public void update(string type)
{
}
public void show(float positionY)
{
display.transform.Find("txtName").GetComponent<Text>().text = questname;
display.transform.Find("txtAmount").GetComponent<Text>().text = current + "/" + goal;
if (isFinished)
{
display.transform.Find("imgDone").GetComponent<RawImage>().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);
}
}
}

View File

@ -22,7 +22,9 @@ namespace Assets.Scripts
quests.Add("main", new List<Quest>());
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()
{
foreach (string key in quests.Keys)
public void updateQuests(string key, object obj, int amount)
{
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<Quest>());
}
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<RectTransform>().sizeDelta = new Vector2(0, 10);
updateQuests();
float y = -37.5f;
foreach (string key in quests.Keys)
{

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 17a562a7d8c28c045b088c1dd33a6f0e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 87adb6ce71d334d41832c6e5946c8401
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<Player>().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;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bc8224ede819f4b478849d299ab24004
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<WorldGenerator>().getCityAmount();
}
override
public void update(object obj, int amount)
{
GameObject tile = (GameObject)obj;
string tilename = tile.GetComponent<Tile>().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;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9b0e62c53b5e7b84f991f4d464fe3c6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<Enemy>().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;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ab96793c0acfd754390101cc53d060bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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>().text = questname;
display.transform.Find("txtAmount").GetComponent<Text>().text = current + "/" + goal;
if (isFinished)
{
display.transform.Find("imgDone").GetComponent<RawImage>().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;
}
}
}

View File

@ -124,6 +124,7 @@ public class WorldGenerator : MonoBehaviour
newTile.GetComponent<Tile>().generateTile(pos, name);
tiles.Add(pos, newTile);
renderedTiles.Add(newTile);
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("find", newTile, 1);
}
else
{