-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneral.js
More file actions
180 lines (154 loc) · 6.37 KB
/
General.js
File metadata and controls
180 lines (154 loc) · 6.37 KB
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
let PARENT = parent;
const CHARACTER_NAME = parent.character.name;
const IS_ELECTRON = is_electron();
var fs;
var path;
if (IS_ELECTRON) {
fs = require('fs');
path = require('path');
}
function flog(message) {
if (!IS_ELECTRON)
return;
var now = new Date();
var full_message = "[" + now.toISOString() + "] " + message;
var filePath = path.join("D:/Users/Max/Documents/AdventureLand/Logs/", CHARACTER_NAME + ".log");
fs.appendFileSync(filePath, full_message + "\n", (err) => {});
};
function flog_alt(message) {
if (!IS_ELECTRON)
return;
var now = new Date();
var full_message = "[" + now.toISOString() + "] " + message;
var filePath = path.join("D:/Users/Max/Documents/AdventureLand/Logs/", CHARACTER_NAME + ".alt.log");
fs.appendFileSync(filePath, full_message + "\n", (err) => {});
};
function chest_log(message) {
if (!IS_ELECTRON)
return;
var now = new Date();
var full_message = "[" + now.toISOString() + "] " + message;
var filePath = path.join("D:/Users/Max/Documents/AdventureLand/Logs/", CHARACTER_NAME + ".chests.log");
fs.appendFileSync(filePath, full_message + "\n", (err) => {});
};
function upgrade_log(message) {
if (!IS_ELECTRON)
return;
var now = new Date();
var full_message = "[" + now.toISOString() + "] " + message;
var filePath = path.join("D:/Users/Max/Documents/AdventureLand/Logs/", CHARACTER_NAME + ".upgrade.log");
fs.appendFileSync(filePath, full_message + "\n", (err) => {});
game_log("U: " + message);
};
// Wishlist:
// - is traveling (moving for extended period)
function sort_by(arr, f) {
return arr.sort((e1, e2) => (fe1 = f(e1), fe2 = f(e2), (fe1 < fe2 ? -1 : (fe1 > fe2 ? 1 : 0))));
}
let assertCount = 0;
function assert(condition, ...params) {
if (!condition)
{
let str = "[ASSERT] ASSERTION FAILURE, CHECK CONSOLE";
if (assertCount < 10)
show_json({"assert": str, "counter": assertCount});
game_log(str);
flog(str);
++assertCount;
console.assert(condition, ...params);
}
}
function isPvP()
{
return (parent.is_pvp || G.maps[character.map].pvp);
}
function use_hp_or_mp_fixed() {
if (safeties && mssince(last_potion) < min(200, character.ping * 3)) return;
var used = false;
// On cooldown?
if (new Date() < parent.next_skill.use_hp) return;
// In dire need of mana?
if (character.mp / character.max_mp < 0.1) use('use_mp'), used = true;
// Potion use justified?
else if (character.hp < character.max_hp - 400) use('use_hp'), used = true;
else if (character.mp < character.max_mp - 500) use('use_mp'), used = true;
// Anything to regen without wasting?
// Prefer MP as HP is less effective.
else if (character.mp < character.max_mp - 100) use('regen_mp'), used = true;
else if (character.hp < character.max_hp - 50) use('regen_hp'), used = true;
// Anything to regen at all?
else if (character.hp < character.max_hp) use('regen_hp'), used = true;
else if (character.mp < character.max_mp) use('regen_mp'), used = true;
if (used) last_potion = new Date();
}
function for_nearby_monsters(f)
{
for (id in parent.entities) {
var current = parent.entities[id];
if (current.type != "monster" || !current.visible || current.dead) continue;
if (current.target && current.target === character.name) targeting_me++;
if (args.type && current.mtype != args.type) continue;
if (args.min_xp && current.xp < args.min_xp) continue;
if (args.max_att && current.attack > args.max_att) continue;
if (args.target && current.target != args.target) continue;
if (args.no_target && current.target && current.target != character.name) continue;
if (args.exclusive_target && current.target && current.target === character.name) continue;
if (args.path_check && !can_move_to(current)) continue;
var c_dist = parent.distance(character, current);
if (c_dist < min_d) min_d = c_dist, target = current;
}
}
// Extended version of get_nearest_monster
function getNearestMonster(args)
{
//args:
// max_att - max attack
// min_xp - min XP
// target: Only return monsters that target this "name" or player object
// no_target: Only pick monsters that don't have any target
// path_check: Checks if the character can move to the target
// type: Type of the monsters, for example "goo", can be referenced from `show_json(G.monsters)` [08/02/17]
var min_d=999999,target=null;
if(!args) args={};
if(args && args.target && args.target.name) args.target=args.target.name;
if(args && args.type=="monster") game_log("get_nearest_monster: you used monster.type, which is always 'monster', use monster.mtype instead");
if(args && args.mtype) game_log("get_nearest_monster: you used 'mtype', you should use 'type'");
for(id in parent.entities)
{
var current=parent.entities[id];
if(current.type!="monster" || !current.visible || current.dead) continue;
if(args.type && current.mtype!=args.type) continue;
if(args.min_xp && current.xp<args.min_xp) continue;
if(args.max_att && current.attack>args.max_att) continue;
if(args.min_att && current.attack<args.min_att) continue;
if(args.target && current.target!=args.target) continue;
if(args.no_target && current.target && current.target!=character.name) continue;
if(args.exclusive_target && current.target && current.target===character.name) continue;
if(args.path_check && !can_move_to(current)) continue;
var c_dist=parent.distance(character,current);
if(c_dist<min_d) min_d=c_dist,target=current;
}
return target;
}
function getMonstersWhere(f)
{
let ret = [];
// Yes, you could filter or map or whatever. If I had type safety I would.
for (let id in parent.entities)
{
let e = parent.entities[id];
if (e.type != "monster" || !e.visible || e.dead)
continue;
if (f(e))
ret.push(e);
}
return ret;
}
function haveEmptySlot() {
return character.items.findIndex(i => !i) != -1;
}
function ms_until(a, b)
{
b || (b = new Date);
return a.getTime() - b.getTime()
}