-
Notifications
You must be signed in to change notification settings - Fork 0
/
town.js
186 lines (165 loc) · 5.81 KB
/
town.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
"use strict";
const TUTORIALIS = 12;
const BEGINNERSVILLE = 0;
const FORESTPATH = 1;
const MERCHANTON = 2;
const MTOLYMPUS = 3;
const VALHALLA = 4;
const STARTINGTOWN = 5;
const JUNGLEPATH = 6;
const COMMERCEVILLE = 7;
const VLOLYMPUS = 8;
const SANCTUARY = 9;
const CURSEDOCEAN = 11;
const CHRONOSLAIR = 10;
const arrow = {
none: 0,
right: 1,
right_alt : 2,
left: 3,
letf_alt : 4,
alt: 5
};
const zoneOrder = [
[SANCTUARY],
[BEGINNERSVILLE],
[FORESTPATH],
[MERCHANTON],
[MTOLYMPUS, CURSEDOCEAN],
[VALHALLA],
[STARTINGTOWN],
[JUNGLEPATH],
[COMMERCEVILLE],
[VLOLYMPUS],
[CHRONOSLAIR]
];
function Town(index) {
this.index = index;
this.varNames = [];
this.progressVars = [];
this.totalActionList = [];
this.unlocked = function() {
return townsUnlocked.includes(this.index);
};
this.expFromLevel = function(level) {
return level * (level + 1) * 50;
};
this.getLevel = function(varName) {
if (varName === "Survey") varName = varName + "Z" + this.index;
return Math.floor((Math.sqrt(8 * this[`exp${varName}`] / 100 + 1) - 1) / 2);
};
this.restart = function() {
for (let i = 0; i < this.varNames.length; i++) {
const varName = this.varNames[i];
this[`goodTemp${varName}`] = this[`good${varName}`];
this[`lootFrom${varName}`] = 0;
view.updateRegular(varName, this.index);
}
};
this.finishProgress = function(varName, expGain) {
// return if capped, for performance
if (this[`exp${varName}`] === 505000) return;
const prevLevel = this.getLevel(varName);
if (this[`exp${varName}`] + expGain >= 505000) {
this[`exp${varName}`] = 505000;
if(options.pauseOnExplorationComplete){
shouldRestart = true;
stopOnExplorationComplete = true;
}
} else {
this[`exp${varName}`] += expGain;
}
const level = this.getLevel(varName);
if (level !== prevLevel) {
view.updateLockedHidden();
adjustAll();
view.adjustTooltip(findAction(varName));
for (const action of totalActionList) {
if (towns[action.townNum].varNames.indexOf(action.varName) !== -1) {
view.updateRegular(action.varName, action.townNum);
}
}
}
view.updateProgressAction(varName, towns[curTown]);
for(const action of totalActionList){
if(action.tooltipRefresh && action.tooltipRefresh.includes(varName)){
view.adjustTooltip(action);
}
}
if(this[`exp${varName}`] >= 505000){
view.updateCompletedProgress(varName);
if(varName === "Met") view.updateCompletedProgress("ThrowParty");
}
};
this.getPrcToNext = function(varName) {
const level = this.getLevel(varName);
const expOfCurLevel = this.expFromLevel(level);
const curLevelProgress = this[`exp${varName}`] - expOfCurLevel;
const nextLevelNeeds = this.expFromLevel(level + 1) - expOfCurLevel;
return Math.floor(curLevelProgress / nextLevelNeeds * 100 * 10) / 10;
};
// finishes actions that have checkable aspects
this.finishRegular = function(varName, rewardRatio, rewardFunc) {
// error state, negative numbers.
if (this[`total${varName}`] - this[`checked${varName}`] < 0) {
this[`checked${varName}`] = this[`total${varName}`];
this[`good${varName}`] = Math.floor(this[`total${varName}`] / rewardRatio);
this[`goodTemp${varName}`] = this[`good${varName}`];
console.log("Error state fixed");
}
// only checks unchecked items
// IF there are unchecked items
// AND the user has not disabled checking unchecked items OR there are no checked items left
const searchToggler = document.getElementById(`searchToggler${varName}`);
if (this[`total${varName}`] - this[`checked${varName}`] > 0 && ((searchToggler && !searchToggler.checked) || this[`goodTemp${varName}`] <= 0)) {
this[`checked${varName}`]++;
if (this[`checked${varName}`] % rewardRatio === 0) {
this[`lootFrom${varName}`] += rewardFunc();
this[`good${varName}`]++;
}
} else if (this[`goodTemp${varName}`] > 0) {
this[`goodTemp${varName}`]--;
this[`lootFrom${varName}`] += rewardFunc();
}
view.updateRegular(varName, this.index);
};
this.createVars = function(varName) {
if (this[`checked${varName}`] === undefined) {
this[`checked${varName}`] = 0;
}
if (this[`goodTemp${varName}`] === undefined) {
this[`goodTemp${varName}`] = 0;
}
if (this[`good${varName}`] === undefined) {
this[`good${varName}`] = 0;
}
if (this[`lootFrom${varName}`] === undefined) {
this[`lootFrom${varName}`] = 0;
}
if (this[`total${varName}`] === undefined) {
this[`total${varName}`] = 0;
}
if (this.varNames.indexOf(varName) === -1) {
this.varNames.push(varName);
}
};
this.createProgressVars = function(varName) {
if (this[`exp${varName}`] === undefined) {
this[`exp${varName}`] = 0;
}
if (this.progressVars.indexOf(varName) === -1) {
this.progressVars.push(varName);
}
};
for (const action of totalActionList) {
if (this.index === action.townNum) {
this.totalActionList.push(action);
if (action.type === "limited") this.createVars(action.varName);
if (action.type === "progress") this.createProgressVars(action.varName);
if (action.type === "multipart") {
this[action.varName] = 0;
this[`${action.varName}LoopCounter`] = 0;
}
}
}
}