90 lines
3.1 KiB
C#
90 lines
3.1 KiB
C#
using Newtonsoft.Json.Linq;
|
|
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 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
|
|
}
|
|
|
|
public void show(float positionY)
|
|
{
|
|
display.transform.Find("txtName").GetComponent<Text>().text = TextHandler.translate(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);
|
|
}
|
|
else
|
|
{
|
|
display.transform.Find("imgDone").GetComponent<RawImage>().color = new Color(255, 255, 255, 0);
|
|
}
|
|
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;
|
|
}
|
|
|
|
public bool isFinishedQuest()
|
|
{
|
|
return isFinished;
|
|
}
|
|
|
|
public void delete()
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
} |