Added first crafting steps, finished quest generation save and load, v1.4.0
This commit is contained in:
@@ -127,7 +127,8 @@ namespace Assets.Scripts
|
||||
string saveString = "{\r\n";
|
||||
saveString = saveString + "\"player\": {\r\n" + player.saveGame() + "\r\n},\r\n";
|
||||
saveString = saveString + "\"world\": {\r\n" + worldGenerator.saveGame() + "\r\n},\r\n";
|
||||
saveString = saveString + "\"inventory\": {\r\n" + GameObject.Find("Inventory").GetComponent<Inventory>().saveGame() + "\r\n}\r\n";
|
||||
saveString = saveString + "\"inventory\": {\r\n" + GameObject.Find("Inventory").GetComponent<Inventory>().saveGame() + "\r\n},\r\n";
|
||||
saveString = saveString + "\"questlog\": {\r\n" + GameObject.Find("QuestLog").GetComponent<QuestLog>().saveGame() + "\r\n}\r\n";
|
||||
saveString = saveString + "\r\n}";
|
||||
FileHandler.saveGame(saveString, "./save.json");
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Assets.Scripts
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
public static void loadGame(Player player, WorldGenerator worldGenerator, Inventory inventory)
|
||||
public static void loadGame(Player player, WorldGenerator worldGenerator, Inventory inventory, QuestLog questLog)
|
||||
{
|
||||
if (hasSaveFile())
|
||||
{
|
||||
@@ -36,6 +36,7 @@ namespace Assets.Scripts
|
||||
player.loadPlayer(json["player"]);
|
||||
worldGenerator.loadWorld(json["world"]);
|
||||
inventory.loadInventory(json["inventory"]);
|
||||
questLog.loadQuests(json["questlog"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -18,13 +20,14 @@ namespace Assets.Scripts
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
quests = new Dictionary<string, List<Quest>>();
|
||||
quests.Add("find", new List<Quest>());
|
||||
GameObject newQuest = Instantiate(quest);
|
||||
newQuest.transform.SetParent(content.transform, false);
|
||||
FindQuest main = new FindQuest(newQuest);
|
||||
main.generateCityQuest();
|
||||
quests["find"].Add(main);
|
||||
if (quests == null)
|
||||
{
|
||||
quests = new Dictionary<string, List<Quest>>();
|
||||
quests.Add("find", new List<Quest>());
|
||||
FindQuest main = new FindQuest(createQuestDisplay());
|
||||
main.generateCityQuest();
|
||||
quests["find"].Add(main);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -46,8 +49,7 @@ namespace Assets.Scripts
|
||||
|
||||
public void addQuest()
|
||||
{
|
||||
GameObject newQuest = Instantiate(quest);
|
||||
newQuest.transform.SetParent(content.transform, false);
|
||||
|
||||
int index = rand.Next(4);
|
||||
string type = "";
|
||||
Quest questItem;
|
||||
@@ -55,25 +57,25 @@ namespace Assets.Scripts
|
||||
{
|
||||
case 0:
|
||||
type = "collect";
|
||||
questItem = new CollectQuest(newQuest);
|
||||
questItem = new CollectQuest(createQuestDisplay());
|
||||
break;
|
||||
case 1:
|
||||
type = "kill";
|
||||
questItem = new KillQuest(newQuest);
|
||||
questItem = new KillQuest(createQuestDisplay());
|
||||
break;
|
||||
case 2:
|
||||
type = "find";
|
||||
questItem = new FindQuest(newQuest);
|
||||
questItem = new FindQuest(createQuestDisplay());
|
||||
break;
|
||||
/*case 3:
|
||||
type = "craft";
|
||||
break;*/
|
||||
case 3:
|
||||
type = "explore";
|
||||
questItem = new ExploreQuest(newQuest);
|
||||
questItem = new ExploreQuest(createQuestDisplay());
|
||||
break;
|
||||
default:
|
||||
questItem = new Quest(newQuest);
|
||||
questItem = new Quest(createQuestDisplay());
|
||||
break;
|
||||
}
|
||||
if (!quests.ContainsKey(type))
|
||||
@@ -83,6 +85,13 @@ namespace Assets.Scripts
|
||||
quests[type].Add(questItem);
|
||||
}
|
||||
|
||||
private GameObject createQuestDisplay()
|
||||
{
|
||||
GameObject newQuest = Instantiate(quest);
|
||||
newQuest.transform.SetParent(content.transform, false);
|
||||
return newQuest;
|
||||
}
|
||||
|
||||
public void showQuests()
|
||||
{
|
||||
content.GetComponent<RectTransform>().sizeDelta = new Vector2(0, 10);
|
||||
@@ -135,6 +144,81 @@ namespace Assets.Scripts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string saveGame()
|
||||
{
|
||||
string result = "";
|
||||
int counter = 0;
|
||||
int count = 0;
|
||||
foreach (string key in quests.Keys)
|
||||
{
|
||||
counter = 0;
|
||||
result = result + "\""+key+"\": {\r\n";
|
||||
foreach (Quest quest in quests[key])
|
||||
{
|
||||
result = result + "\"quest" + counter + "\": {\r\n";
|
||||
result = result + quest.saveQuest();
|
||||
result = result + "\r\n}";
|
||||
if (counter < quests[key].Count - 1)
|
||||
{
|
||||
result = result + ",\r\n";
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
result = result + "\r\n}";
|
||||
if (count < quests.Keys.Count - 1)
|
||||
{
|
||||
result = result + ",\r\n";
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void loadQuests(JToken json)
|
||||
{
|
||||
var jsonData = JObject.Parse(json.ToString()).Children();
|
||||
List<JToken> keywords = jsonData.Children().ToList();
|
||||
List<JToken> quests;
|
||||
string key = "";
|
||||
Quest questItem;
|
||||
if (this.quests == null)
|
||||
{
|
||||
this.quests = new Dictionary<string, List<Quest>>();
|
||||
}
|
||||
foreach (JToken keyword in keywords)
|
||||
{
|
||||
jsonData = JObject.Parse(keyword.ToString()).Children();
|
||||
quests = jsonData.Children().ToList();
|
||||
foreach (JToken quest in quests)
|
||||
{
|
||||
key = quest["questname"].ToString().Split(' ')[0].ToLower();
|
||||
if (!this.quests.ContainsKey(key))
|
||||
{
|
||||
this.quests.Add(key, new List<Quest>());
|
||||
}
|
||||
switch (key)
|
||||
{
|
||||
case "collect":
|
||||
questItem = new CollectQuest(quest, createQuestDisplay());
|
||||
break;
|
||||
case "kill":
|
||||
questItem = new KillQuest(quest, createQuestDisplay());
|
||||
break;
|
||||
case "find":
|
||||
questItem = new FindQuest(quest, createQuestDisplay());
|
||||
break;
|
||||
case "explore":
|
||||
questItem = new ExploreQuest(quest, createQuestDisplay());
|
||||
break;
|
||||
default:
|
||||
questItem = new Quest(quest, createQuestDisplay());
|
||||
break;
|
||||
}
|
||||
this.quests[key].Add(questItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -45,6 +46,8 @@ namespace Assets.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
public CollectQuest(JToken token, GameObject display) : base(token, display) { }
|
||||
|
||||
override
|
||||
public void update(object obj, int amount)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -15,6 +16,8 @@ namespace Assets.Scripts
|
||||
questname = "Travel to " + Mathf.Floor(coordinates.x) + "/" + Mathf.Floor(coordinates.z) + "(X/Z)";
|
||||
}
|
||||
|
||||
public ExploreQuest(JToken token, GameObject display) : base(token, display) { }
|
||||
|
||||
override
|
||||
public void update(object obj, int amount)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -37,6 +38,8 @@ namespace Assets.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
public FindQuest(JToken token, GameObject display) : base(token, display) { }
|
||||
|
||||
public void generateCityQuest()
|
||||
{
|
||||
questname = "Find all cities";
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -29,6 +30,8 @@ namespace Assets.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
public KillQuest(JToken token, GameObject display) : base(token, display) { }
|
||||
|
||||
override
|
||||
public void update(object obj, int amount)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -20,6 +21,17 @@ namespace Assets.Scripts
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public Quest(JToken token, GameObject display)
|
||||
{
|
||||
this.display = display;
|
||||
questname = token["questname"].ToString();
|
||||
keyword = token["keyword"].ToString();
|
||||
current = int.Parse(token["current"].ToString());
|
||||
goal = int.Parse(token["goal"].ToString());
|
||||
isFinished = bool.Parse(token["isFinished"].ToString());
|
||||
coordinates = new Vector3(float.Parse(token["coordinates"].ToString().Split('/')[0]), 0, float.Parse(token["coordinates"].ToString().Split('/')[1])) ;
|
||||
}
|
||||
|
||||
public virtual void update(object obj, int amount)
|
||||
{
|
||||
//empty
|
||||
@@ -61,6 +73,18 @@ namespace Assets.Scripts
|
||||
{
|
||||
GameObject.Destroy(display);
|
||||
}
|
||||
|
||||
public string saveQuest()
|
||||
{
|
||||
string result = "";
|
||||
result = result + FileHandler.generateJSON("questname", "\"" + questname + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("keyword", "\"" + keyword + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("current", current) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("goal", goal) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("isFinished", "\"" + isFinished + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("coordinates", "\"" + coordinates.x + "/" + coordinates.z + "\"") + "\r\n";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -231,9 +231,9 @@ namespace Assets.Scripts
|
||||
|
||||
public void openQuestLog()
|
||||
{
|
||||
questlog.GetComponent<QuestLog>().showQuests();
|
||||
state = UIState.QUEST;
|
||||
hideOtherElements(questlog);
|
||||
questlog.GetComponent<QuestLog>().showQuests();
|
||||
}
|
||||
|
||||
public void closeQuestLog()
|
||||
@@ -516,7 +516,7 @@ namespace Assets.Scripts
|
||||
}
|
||||
else
|
||||
{
|
||||
FileHandler.loadGame(GameObject.Find("Player").GetComponent<Player>(), GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>(), GameObject.Find("Inventory").GetComponent<Inventory>());
|
||||
FileHandler.loadGame(GameObject.Find("Player").GetComponent<Player>(), GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>(), GameObject.Find("Inventory").GetComponent<Inventory>(), GameObject.Find("QuestLog").GetComponent<QuestLog>());
|
||||
hideOtherElements(introduction);
|
||||
introduction.transform.localScale = new Vector3(0, 0, 0);
|
||||
tutorial.transform.localScale = new Vector3(0,0,0);
|
||||
|
||||
Reference in New Issue
Block a user