-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathrc_utils.js
75 lines (61 loc) · 1.79 KB
/
rc_utils.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
const dungeon_health = 10
const dungeon_damage = 2
const dungeon_to_hit = 3
const dungeon_armor_class = 2
const health_by_class = [12, 6, 8, 8, 10, 8, 10, 8, 6, 4, 4]
const base_attack_bonus_by_class = [4, 3, 3, 3, 4, 3, 4, 4, 3, 2, 3]
function modifier_for_attribute(_attr) {
if (_attr == 9) return -1
return Math.floor((_attr - 10) / 2)
}
function health_by_class_and_level(_class, level, _const) {
let _base_health = health_by_class[_class - 1] + modifier_for_attribute(_const)
if (_base_health <= 0) {
_base_health = 1
}
return _base_health * level
}
function base_attack_bonus_by_class_and_level(_class, level) {
return Math.floor(level * base_attack_bonus_by_class[_class - 1] / 4)
}
function attack_bonus(_class, _str, level) {
return base_attack_bonus_by_class_and_level(_class, level) + modifier_for_attribute(_str)
}
function to_hit_ac(_attack_bonus) {
return _attack_bonus > dungeon_armor_class
}
function damage(_str) {
let _mod = modifier_for_attribute(_str)
if (_mod <= 1) return 1
return _mod
}
function armor_class(_dex) {
return modifier_for_attribute(_dex)
}
function scout(_class, level, _str, _dex, _const) {
let _health = health_by_class_and_level(_class, level, _const)
let _dungeon_health = dungeon_health
let _damage = damage(_str)
let _attack_bonus = attack_bonus(_class, _str, level)
let _to_hit_ac = to_hit_ac(_attack_bonus)
let _hit_ac = armor_class(_dex) < dungeon_to_hit
if (_to_hit_ac) {
for (reward = 10; reward >= 0; reward--) {
_dungeon_health -= _damage
if (_dungeon_health <= 0) break
if (_hit_ac) {
_health -= dungeon_damage
}
if (_health <= 0) return 0
}
return reward
}
return 0
}
module.exports = {
scout,
health_by_class_and_level,
damage,
armor_class,
attack_bonus,
}