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
|
package combat
import "math/rand"
func EffectiveRoll(level int, styleBonus int, equipBonus int) int {
effective := level + styleBonus + 8
return effective * (equipBonus + 64)
}
func HitChance(attackRoll, defenseRoll int) float64 {
a := float64(attackRoll)
d := float64(defenseRoll)
if a > d {
return 1.0 - (d+2.0)/(2.0*(a+1.0))
}
return a / (2.0 * (d + 1.0))
}
func HitCheck(attackRoll, defenseRoll int) bool {
chance := HitChance(attackRoll, defenseRoll)
return rand.Float64() < chance
}
func MaxHit(level int, styleBonus int, equipBonus int) int {
effective := level + styleBonus + 8
hit := (effective * (equipBonus + 64)) / 512
if hit < 1 {
hit = 1
}
return hit
}
func RollDamage(maxHit int) int {
if maxHit <= 0 {
return 0
}
return 1 + rand.Intn(maxHit)
}
func AttackStyleBonus(style string) (attack, strength, defense int) {
switch style {
case "accurate":
return 3, 0, 0
case "aggressive":
return 0, 3, 0
case "defensive":
return 0, 0, 3
case "balanced":
return 1, 1, 1
default:
return 0, 0, 0
}
}
func RangedStyleBonus(style string) (ranged, defense int) {
switch style {
case "accurate":
return 3, 0
case "aggressive":
return 3, 0
case "defensive":
return 0, 3
case "balanced":
return 1, 1
default:
return 0, 0
}
}
func SelectBonus(attackType string, stab, slash, crush, science, ranged int) int {
switch attackType {
case "stab":
return stab
case "slash":
return slash
case "crush":
return crush
case "science":
return science
case "ranged":
return ranged
default:
return crush
}
}
|