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
|
package combat
import "math/rand"
func AttackRoll(attackLevel int, styleBonus int, equipBonus int) int {
return (attackLevel + styleBonus + 8) * (equipBonus + 64)
}
func DefenseRoll(defenseLevel int, styleBonus int, equipBonus int) int {
return (defenseLevel + styleBonus + 8) * (equipBonus + 64)
}
func HitCheck(attackRoll, defenseRoll int) bool {
if attackRoll > defenseRoll {
return true
}
if attackRoll < defenseRoll {
return false
}
return rand.Intn(2) == 1
}
func MaxHit(strengthLevel int, styleBonus int, equipBonus int) int {
effective := (strengthLevel + styleBonus + 8) * (equipBonus + 64)
hit := effective / 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
}
}
|