-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_quests.js
220 lines (211 loc) · 7.59 KB
/
main_quests.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Quests
function updateQuests(){
let quests_ = document.getElementById(`quests`);
let questsHTML = `<p>Quests</p>`;
quests_.innerHTML = questsHTML;
ActiveQuests.sort(function(a,b){ return getQuestProgress(b)-getQuestProgress(a); });
if(ActiveQuests.length > 0){
for (var i = 0; i < ActiveQuests.length; i++) {
let q_ = document.createElement(`button`);
let id = ActiveQuests[i].name;
let aq = getQuestFromName(id);
q_.className = `button`;
q_.id = id;
q_.innerHTML = `<span><w>${id}</w></span> <span style="float:right">${getQuestProgress(aq)}%</span><br>`;
q_.style.fontSize = `14px`;
q_.style.fontWeight = `normal`;
q_.style.width = `100%`;
q_.style.marginLeft = `0px`;
q_.style.textAlign = `left`;
q_.onclick = function(){ toggleQuestDisplay(id); };
quests_.appendChild(q_);
}
} else {
let q_ = document.createElement(`button`);
q_.className = `button`;
q_.id = `not-a-quest`;
q_.innerHTML = `You currently have no active quests.`;
q_.style.fontSize = `14px`;
q_.style.fontWeight = `normal`;
q_.style.marginLeft = `0px`;
q_.style.textAlign = `left`;
q_.style.width = `100%`;
quests_.appendChild(q_);
}
}
function toggleQuestDisplay(id){
let q = document.getElementById(id);
let aq = getQuestFromName(id);
q.innerHTML = `<span><w>${id}</w></span> <span style="float:right">${getQuestProgress(aq)}%</span><br>`;
if(q.style.height == `90px`){
q.style.height = `auto`;
} else if(aq != null){
q.style.height = `90px`;
let d_ = getQuestDescription(aq);
let desc = `<span style="font-size:${Math.max(Math.round(14-(d_.length/15)),11)}px;">${d_}</span>`;
q.innerHTML += `${desc}`;
}
}
function getQuestFromName(name){
for (var i = 0; i < quests.length; i++) {
if(quests[i].name == name){
return quests[i];
}
}
return null;
}
function addQuest(quest){
if(ActiveQuests.indexOf(quest) > -1){
return;
}
ActiveQuests.push(quest);
important(`<w>Quest Started</w>: ${quest.name}.`);
updateQuests();
}
function isQuestComplete(quest){
let p = getQuestProgress(quest);
if(p >= 100){
return true;
}
return false;
}
function isQuestProgressChanged(quest){
if(quest == null){
return;
}
let p = getQuestProgress(quest);
let prev_p = document.getElementById(quest.name).innerHTML.split(/(\d+)%/gmi)[1];
if(prev_p != p){
return true;
}
return false;
}
function getQuestProgress(quest){
if(quest == null){
return;
}
let qr = quest.requirements;
let tasks_done = 0;
let tasks_required = 0;
for (var i = 0; i < qr.length; i++) {
if( qr[i].reachLevel != null ){
tasks_required += qr[i].reachLevel;
if(Level > qr[i].reachLevel){
tasks_done += Level - (Level - qr[i].reachLevel);
} else {
tasks_done += Level;
}
} else if( qr[i].discover != null ){
tasks_required += 1;
if(Discovered.indexOf(getLocationByName(qr[i].discover)) > -1){
tasks_done++;
}
} else if( qr[i].haveItemMat != null ){
tasks_required += 1;
let items_ = Inventory.filter(function(a){ if(a != null && a.baseMaterial.name == qr[i].haveItemMat){ return a; } });
if( items_.length > 0 ){
if(qr[i].count == null){
tasks_done++;
} else {
let items_count = items_.reduce(function(total,num){ return total.count + num.count; });
if(items_.length == 1){ items_count = items_[0].count; }
tasks_required += qr[i].count-1;
tasks_done += items_count;
}
}
} else if( qr[i].haveItemType != null ){
tasks_required += 1;
let items_ = Inventory.filter(function(a){ if(a != null && a.itemType == qr[i].haveItemType){ return a; } });
if( items_.length > 0 ){
if(qr[i].count == null){
tasks_done++;
} else {
let items_count = items_.reduce(function(total,num){ return total.count + num.count; });
if(items_.length == 1){ items_count = items_[0].count; }
tasks_required += qr[i].count-1;
tasks_done += items_count;
}
}
} else if( qr[i].haveBronze != null ){
tasks_required += qr[i].haveBronze;
tasks_done += Bronze + (Silver * 100) + (Gold * 10000);
} else if( qr[i].haveSilver != null ){
tasks_required += qr[i].haveSilver * 100;
tasks_done += Bronze + (Silver * 100) + (Gold * 10000);
} else if( qr[i].haveGold != null ){
tasks_required += qr[i].haveGold * 10000;
tasks_done += Bronze + (Silver * 100) + (Gold * 10000);
}
}
//console.log(tasks_done,tasks_required);
return Math.min(Math.round((tasks_done/tasks_required)*100),100);
}
function getQuestDescription(quest){
let qrq = quest.requirements;
let desc = ``;
if(qrq != null){
desc += `Requirements: `;
for (var i = 0; i < qrq.length; i++) {
if(i > 0 && i < qrq.length-1){
desc += `, `;
}
if(qrq[i].reachLevel != null){
desc += `Reach <w>Level ${qrq[i].reachLevel}</w>`;
}
if(qrq[i].discover != null){
desc += `Discover <w>${getLocationByName(qrq[i].discover).displayName}</w>`;
}
if(qrq[i].haveItemMat != null){
if(qrq[i].count == null){
desc += `Have any <w>${qrq[i].haveItemMat}</w> item`;
} else {
desc += `Have <w>${qrq[i].count} ${qrq[i].haveItemMat}</w> items`;
}
}
if(qrq[i].haveItemType != null){
if(qrq[i].count == null){
desc += `Have any <w>${qrq[i].haveItemType}</w> item`;
} else {
desc += `Have <w>${qrq[i].count} ${qrq[i].haveItemType}</w> items`;
}
}
if(qrq[i].haveBronze != null){
desc += `Have <w>${qrq[i].haveBronze} Bronze</w>`;
}
if(qrq[i].haveSilver != null){
desc += `Have <w>${qrq[i].haveSilver} Silver</w>`;
}
if(qrq[i].haveGold != null){
desc += `Have <w>${qrq[i].haveGold} Gold</w>`;
}
if(i == qrq.length-2){
desc += `, and `;
}
}
}
return `${desc}.`;
}
function completeQuest(quest){
//console.dir(quest);
quest.completed = true;
ActiveQuests.splice(ActiveQuests.indexOf(quest),1);
important(`<w>Quest Completed</w>: ${quest.name}.`);
for (var i = 0; i < quest.rewards.length; i++) {
addItem(quest.rewards[i]);
}
if(quest.xp != null){ changeExperience(quest.xp); }
if(quest.currency != null){ setCurrencyToTotal( (Bronze + (Silver * 100) + (Gold * 10000)) + quest.currency ); }
if(quest.next != null){
for (var i = 0; i < quest.next.length; i++) {
let a = getQuestFromName(quest.next[i]);
addQuest(a);
}
}
updateQuests();
}
function hasCompletedQuest(quest){
if(quest.completed){
return true;
}
return false;
}