Added first steps to new questing system, v1.4.0

This commit is contained in:
Nicola Sovic
2022-07-12 14:33:21 +02:00
parent d898a1c5fd
commit 408339387d
15 changed files with 1150 additions and 127 deletions

View File

@@ -375,11 +375,6 @@ namespace Assets.Scripts
return result;
}
public void updateKillcount(GameObject gameObject)
{
gameObject.GetComponent<Text>().text = "Slimes: " + killcount + "/" + (30 * (difficulty + 1));
}
public int castSkill(int index)
{
int damage = 0;
@@ -470,7 +465,7 @@ namespace Assets.Scripts
public void gameFinished()
{
if (killcount >= 30 * (difficulty + 1) && GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().gameWon())
if (GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().gameWon())
{
uihandler.showMessage("SUCCESS;You won the game!");
switch (difficulty)

130
Assets/Scripts/Quest.cs Normal file
View File

@@ -0,0 +1,130 @@
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

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

View File

@@ -0,0 +1,96 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts
{
public class QuestLog : MonoBehaviour
{
public Dictionary<string, List<Quest>> 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<string, List<Quest>>();
quests.Add("main", new List<Quest>());
GameObject newQuest = Instantiate(quest);
newQuest.transform.SetParent(content.transform, false);
quests["main"].Add(new Quest("main", newQuest));
for (int i = 0; i < 20; i++)
{
addQuest();
}
}
// Update is called once per frame
void Update()
{
}
public void updateQuests()
{
foreach (string key in quests.Keys)
{
foreach (Quest quest in quests[key])
{
quest.update(key);
}
}
}
public void addQuest()
{
int index = rand.Next(4);
string type = "";
switch (index)
{
case 0:
type = "collect";
break;
case 1:
type = "find";
break;
case 2:
type = "kill";
break;
case 3:
type = "craft";
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));
}
public void showQuests()
{
content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, 10);
updateQuests();
float y = -37.5f;
foreach (string key in quests.Keys)
{
foreach (Quest quest in quests[key])
{
quest.show(y);
y = y - 75;
content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, content.GetComponent<RectTransform>().sizeDelta.y + 75);
}
}
scrollBar.value = 0;
content.transform.localPosition = new Vector3(0,0,0);
}
}
}

View File

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

View File

@@ -233,8 +233,7 @@ namespace Assets.Scripts
{
state = UIState.QUEST;
hideOtherElements(questlog);
GameObject.Find("Player").GetComponent<Player>().updateKillcount(GameObject.Find("txtSlimesKilled"));
GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().updateCityCount(GameObject.Find("txtCitiesFound"));
questlog.GetComponent<QuestLog>().showQuests();
}
public void closeQuestLog()

View File

@@ -183,11 +183,6 @@ public class WorldGenerator : MonoBehaviour
return currentTile;
}
public void updateCityCount(GameObject gameObject)
{
gameObject.GetComponent<Text>().text = "Cities: " + (maxCityAmount - cityAmount) + "/" + maxCityAmount;
}
public string saveGame()
{
string result = "";
@@ -257,4 +252,9 @@ public class WorldGenerator : MonoBehaviour
Vector3 position = new Vector3(currentTile.transform.position.x, 5, currentTile.transform.position.z);
player.transform.SetPositionAndRotation(position, player.transform.rotation);
}
public int getCityAmount()
{
return maxCityAmount;
}
}