-
Notifications
You must be signed in to change notification settings - Fork 0
/
combatroutine.go
54 lines (48 loc) · 1.27 KB
/
combatroutine.go
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
package main
import (
"fmt"
"math/rand"
)
// how opp bot will do during combat
type CombatRoutine interface {
Execute(cs *CombatScene, ls *CombatLogSubstate)
}
type AttackRandomly struct {
atkDamage GetAtkDamage
}
func NewAttackRandomly(a GetAtkDamage) CombatRoutine {
return &AttackRandomly{atkDamage: a}
}
func (a *AttackRandomly) Execute(cs *CombatScene, ls *CombatLogSubstate) {
damage := a.atkDamage()
target := rand.Int() % len(cs.Characters)
character := cs.Characters[target]
for true {
if character.HP == 0 {
target = rand.Int() % len(cs.Characters)
character = cs.Characters[target]
} else {
break
}
}
// damage := character.AtkDamage()
cplx_anim := &ComplexAnim{cs: cs, doneFunc: func(cs *CombatScene) {
// cs.OppTakeDamage(damage)
cs.PlayerTakeDamage(character, damage)
DoneAnim(cs)
}, animations: []CombatAnimation{
&MoveAttackAnim{cs: cs, PosX: float64(PLAYER_POS_X_START + target*170), PosY: float64(PLAYER_POS_Y_START - 30)},
&AttackAnim{cs: cs},
// &BlinkAnim{cs: cs, blinkCount: 5},
},
}
cs.attackAnim.Done = func() {
if cplx_anim.idx < len(cplx_anim.animations) {
cplx_anim.idx += 1
}
}
go func() {
cs.animationQueue <- cplx_anim
}()
ls.BattleLog = fmt.Sprintf("opponent deals %d of damage to %s", damage, character.Name)
}