-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
52 lines (42 loc) · 858 Bytes
/
action.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
package ospokemon
import (
"time"
"github.com/ospokemon/ospokemon/event"
"taylz.io/types"
)
const PARTaction = "action"
type Action struct {
Spell *Spell
*Timer
Parts
}
func MakeAction() *Action {
return &Action{
Parts: make(Parts),
}
}
func BuildAction(spell *Spell) *Action {
action := MakeAction()
action.Spell = spell
action.AddPart(BuildImaging(spell.Animations))
return action
}
func (a *Action) Part() string {
return PARTaction
}
func (parts Parts) GetAction() *Action {
action, _ := parts[PARTaction].(*Action)
return action
}
func (a *Action) Update(universe *Universe, entity *Entity, d time.Duration) {
if a.Timer == nil {
event.Fire(event.ActionCast, universe, entity, a)
entity.RemovePart(a)
}
}
func (a *Action) Json() types.Dict {
return types.Dict{
"timer": a.Timer.Fmt(),
"spell": a.Spell.Json(),
}
}