/
ce_special_steal.go
184 lines (152 loc) · 4.4 KB
/
ce_special_steal.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package game_map
import (
"fmt"
"github.com/faiface/pixel"
"github.com/steelx/go-rpg-cgm/combat"
"github.com/steelx/go-rpg-cgm/world"
"reflect"
)
type CESteal struct {
mOwner *combat.Actor
mName string
mCountDown float64
mIsFinished, Success bool
SpecialItem world.SpecialItem
Targets []*combat.Actor
Scene *CombatState
Character *Character
Storyboard *Storyboard
AttackEntityDef EntityDefinition
DefaultTargeter func(state *CombatState) []*combat.Actor
OriginalPos pixel.Vec
}
func CEStealCreate(scene *CombatState, owner *combat.Actor, targets []*combat.Actor, specialI interface{}) CombatEvent {
special := reflect.ValueOf(specialI).Interface().(world.SpecialItem)
c := &CESteal{
mOwner: owner,
mName: fmt.Sprintf("%s is using Steal: %s", owner.Name, special.Name),
SpecialItem: special,
Targets: targets,
Scene: scene,
Character: scene.ActorCharMap[owner],
}
c.OriginalPos = pixel.V(c.Character.Entity.X, c.Character.Entity.Y)
c.Character.Controller.Change(csRunanim, csProne, true)
c.DefaultTargeter = CombatSelector.WeakestEnemy
c.AttackEntityDef = Entities["slash"]
storyboardEvents := []interface{}{
RunFunction(c.ShowNotice),
Wait(0.5),
RunState(c.Character.Controller, csMove, CSMoveParams{Dir: 3}),
RunState(c.Character.Controller, csRunanim, "steal_1", false),
RunFunction(c.TeleportOut),
RunState(c.Character.Controller, csRunanim, "steal_2", false),
Wait(1.2),
RunFunction(c.DoSteal),
RunState(c.Character.Controller, csRunanim, "steal_3", false),
RunFunction(c.TeleportIn),
RunState(c.Character.Controller, csRunanim, "steal_4", false),
RunFunction(c.ShowResult),
Wait(1.0),
RunFunction(c.HideNotice),
Wait(0.5),
RunState(c.Character.Controller, csRunanim, csStandby, false),
RunFunction(c.OnFinish),
}
c.Storyboard = StoryboardCreate(scene.InternalStack, scene.win, storyboardEvents, false)
return c
}
func (c *CESteal) Name() string {
return c.mName
}
func (c *CESteal) CountDown() float64 {
return c.mCountDown
}
func (c *CESteal) CountDownSet(t float64) {
c.mCountDown = t
}
func (c *CESteal) Owner() *combat.Actor {
return c.mOwner
}
func (c *CESteal) Update() {
}
func (c *CESteal) IsFinished() bool {
return c.mIsFinished
}
func (c *CESteal) OnFinish() {
c.mIsFinished = true
}
func (c *CESteal) Execute(queue *EventQueue) {
c.Scene.InternalStack.Push(c.Storyboard)
for i := len(c.Targets) - 1; i >= 0; i-- {
v := c.Targets[i]
hp := v.Stats.Get("HpNow")
if hp <= 0 {
c.Targets = removeActorAtIndex(c.Targets, i)
}
}
if len(c.Targets) == 0 {
//Find another enemy
c.Targets = c.DefaultTargeter(c.Scene)
}
}
func (c *CESteal) TimePoints(queue *EventQueue) float64 {
speed := c.mOwner.Stats.Get("Speed")
return queue.SpeedToTimePoints(speed)
}
func (c *CESteal) HideNotice() {
c.Scene.HideNotice()
}
func (c *CESteal) ShowNotice() {
c.Scene.ShowNotice(c.SpecialItem.Name)
}
func (c *CESteal) TeleportOut() {
target := c.Targets[0]
entity := c.Scene.ActorCharMap[target].Entity
width := entity.Texture.Bounds().W()
height := entity.Texture.Bounds().H()
pos := entity.GetSelectPosition()
c.Character.Entity.X = pos.X - width/2
c.Character.Entity.Y = pos.Y - height/2
}
func (c *CESteal) TeleportIn() {
c.Character.Entity.X = c.OriginalPos.X
c.Character.Entity.Y = c.OriginalPos.Y
}
func (c *CESteal) ShowResult() {
animId := "steal_failure"
if c.Success {
animId = "steal_success"
}
c.Character.Controller.Change(csRunanim, animId, false)
}
func (c *CESteal) DoSteal() {
target := c.Targets[0]
c.Scene.HideNotice()
if target.StealItem == 0 {
c.Scene.ShowNotice("Nothing to steal")
return
}
c.Success = c.StealFrom(target)
if c.Success {
id := target.StealItem
def := world.ItemsDB[id]
gWorld := reflect.ValueOf(c.Scene.GameState.Globals["world"]).Interface().(*combat.WorldExtended)
gWorld.AddItem(id, 1)
target.StealItem = 0 //remove StealItem from enemy
notice := fmt.Sprintf("Stolen: %s", def.Name)
c.Scene.ShowNotice(notice)
} else {
c.Scene.ShowNotice("Steal failed !")
}
}
func (c *CESteal) StealFrom(target *combat.Actor) bool {
success := Formula.Steal(c.Scene, c.mOwner, target)
entity := c.Scene.ActorCharMap[target].Entity
pos := entity.GetSelectPosition()
x := pos.X
y := pos.Y
effect := AnimEntityFxCreate(x, y, c.AttackEntityDef, c.AttackEntityDef.Frames)
c.Scene.AddEffect(effect)
return success
}