-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestManager.cs
109 lines (97 loc) · 4.4 KB
/
QuestManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QuestManager : MonoBehaviour {
[SerializeField]
protected List<Quest> quests = new List<Quest>();
public InventoryObject inventory;
public void AddQuest(Quest quest) {
quests.Add(quest);
UpdateQuests();
}
public void RemoveQuest(Guid questID) {
quests.Remove(quests.Find(x => x.id == questID));
Destroy(GameObject.Find(questID.ToString()).gameObject);
}
public void CompleteQuest(Quest quest) {
RemoveQuest(quest.id);
Destroy(GameObject.Find(quest.id.ToString()).gameObject);
InventoryObject inventory = this.GetComponentInParent<Pick_Items>().inventory;
var counter = 0;
for (var i = 0; i < inventory.Container.Items.Length; i++) {
if (inventory.Container.Items[i].ID == -1) continue;
if (quest.type == QuestType.Collect) {
if (inventory.Container.Items[i].item.Name == quest.objectName) {
inventory.Container.Items[i].amount -= quest.countNeeded;
if (inventory.Container.Items[i].amount <= 0) {
inventory.RemoveItem(inventory.Container.Items[i].item);
}
break;
}
} else if (quest.type == QuestType.Photo) {
try {
for (var j = 0; j < (inventory.Container.Items[i].item as PhotoItem).Animals.Count; j++) {
if ((inventory.Container.Items[i].item as PhotoItem).Animals[j] == quest.objectName) {
inventory.RemoveItem(inventory.Container.Items[i].item);
counter++;
}
}
if (counter == quest.countNeeded) {
break;
}
} catch (Exception) {
}
}
}
inventory.AddItem(new EquipmentItem(quest.reward), 1);
GameObject.Find("InfoBox").GetComponent<InfoBox>().ShowBox("Kaptál egy " + quest.reward.name + "-t!", true);
}
public void UpdateQuests() {
foreach (var quest in quests) {
int count = 0;
if (quest.type == QuestType.Collect) {
for (var i = 0; i < inventory.Container.Items.Length; i++) {
if (inventory.Container.Items[i].ID == -1) {
continue;
} else {
if (quest.objectName == inventory.Container.Items[i].item.Name) {
count += inventory.Container.Items[i].amount;
}
}
}
} else if (quest.type == QuestType.Photo) {
for (var i = 0; i < inventory.Container.Items.Length; i++) {
if (inventory.Container.Items[i].ID == -1 || inventory.Container.Items[i].item.Type != ItemType.Photo) {
continue;
} else {
for (var j = 0; j < (inventory.Container.Items[i].item as PhotoItem).Animals.Count; j++) {
if ((inventory.Container.Items[i].item as PhotoItem).Animals[j].Contains(quest.objectName)) {
if (quest.options == "fromblind") {
if ((inventory.Container.Items[i].item as PhotoItem).IsOnBlind) {
count++;
}
} else {
count++;
}
}
}
}
}
}
quest.count = count;
CheckState(quest);
}
}
public void CheckState(Quest quest) {
if (quest.count >= quest.countNeeded) {
quest.questDone = true;
//GameObject.Find(quest.id.ToString()).GetComponent<TMPro.TextMeshProUGUI>().overrideColorTags = true;
GameObject.Find(quest.id.ToString()).GetComponent<TMPro.TextMeshProUGUI>().color = Color.yellow;
} else {
quest.questDone = false;
GameObject.Find(quest.id.ToString()).GetComponent<TMPro.TextMeshProUGUI>().color = Color.gray;
}
quest.questGiver.GetComponent<QuestGiver>().QuestState(quest);
}
}