-
Notifications
You must be signed in to change notification settings - Fork 0
/
Combat.js
113 lines (100 loc) · 2.57 KB
/
Combat.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
updateCombatState = () => {
if (hasEnoughPotions()) {
try {
let useHealthPotionThreshold = getUseHealthPotionThreshold() * character.max_hp;
let useManaPotionThreshold = getUseManaPotionThreshold() * character.max_mp;
useHealthPotion(useHealthPotionThreshold);
useManaPotion(useManaPotionThreshold);
loot();
findCombatTarget();
moveToCombatTarget();
autoAttack();
} catch (e) {
game_log(`Error during Combat: ${e}`);
combatTarget = null;
}
} else {
setState(STATES.MOVING_TO_POTIONS);
}
}
autoAttack = () => {
if (canAttack()) {
attack(combatTarget);
}
}
canAttack = () => {
return (character.rip || is_moving(character) || !combatTarget || can_attack(combatTarget));
}
moveToCombatTarget = () => {
if (!combatTarget) {
return;
}
if (!in_attack_range(combatTarget)) {
let newX = character.x + (combatTarget.x - character.x) / 2;
let newY = character.y + (combatTarget.y - character.y) / 2;
if (can_move_to(newX, newY)){
move(newX, newY);
} else {
smart_move(combatTarget.real_x, combatTarget.real_y);
}
}
}
useHealthPotion = (healthPotionThreshold) => {
if (character.hp <= healthPotionThreshold) {
game_log("Restoring HP");
use("use_hp");
}
}
useManaPotion = (manaPotionThreshhold) => {
if (character.mp <= manaPotionThreshhold) {
game_log("Restoring MP");
use("use_mp");
}
}
moveToEnemies = () => {
if (!is_moving(character)) {
smart_move(getEnemyToKill(), () => { setState(STATES.ATTACKING) });
}
}
requestHealing = (requestThreshold) => {
if (new Date() > nextValidHealRequestDate) {
if (character.hp < requestThreshold) {
safeSay(`${HEALER}, I need healing!`);
send_cm(HEALER, new Command(COMMAND_TYPES.HEAL_REQUEST, ""));
var newDate = new Date();
newDate.setSeconds(newDate.getSeconds() + getHealRequestDelayInSeconds());
nextValidHealRequestDate = newDate;
}
}
}
findCombatTarget = () => {
if (!combatTarget || combatTarget.dead) {
combatTarget = get_nearest_monster({ min_xp: 100, max_att: 120, type: getEnemyToKill() });
if (combatTarget) {
useCombatBuffAbility();
change_target(combatTarget);
if (character.ctype == "warrior") {
sendCommandtoParty(new Command(COMMAND_TYPES.SET_TARGET, combatTarget.id));
}
}
}
}
setCombatTarget = (id) => {
let newTarget = getTargetEntityFromId(id);
if (newTarget !== null) {
combatTarget = newTarget;
change_target(combatTarget);
}
}
useCombatBuffAbility = () => {
switch (character.ctype) {
case "rogue":
if (can_use("invis")) {
game_log("Using Assassins Smoke");
use("invis");
}
break;
default:
break;
}
}