forked from Hucaru/Valhalla
/
channel_attack.go
224 lines (172 loc) · 5.08 KB
/
channel_attack.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package server
import (
"github.com/albertojnk/Valhalla/constant/opcode"
"github.com/albertojnk/Valhalla/mnet"
"github.com/albertojnk/Valhalla/mpacket"
"github.com/albertojnk/Valhalla/server/message"
"github.com/albertojnk/Valhalla/server/player"
"github.com/albertojnk/Valhalla/server/pos"
)
func (server ChannelServer) playerMeleeSkill(conn mnet.Client, reader mpacket.Reader) {
plr, err := server.players.getFromConn(conn)
if err != nil {
conn.Send(message.PacketMessageRedText(err.Error()))
return
}
data, valid := getAttackInfo(reader, *plr, attackMelee)
if !valid {
return
}
field, ok := server.fields[plr.MapID()]
if !ok {
return
}
inst, err := field.GetInstance(plr.InstanceID())
if err != nil {
conn.Send(message.PacketMessageRedText(err.Error()))
return
}
// if player in party extract
packetSkillMelee := func(char player.Data, ad attackData) mpacket.Packet {
p := mpacket.CreateWithOpcode(opcode.SendChannelPlayerUseMeleeSkill)
p.WriteInt32(char.ID())
p.WriteByte(ad.targets*0x10 + ad.hits)
p.WriteByte(ad.skillLevel)
if ad.skillLevel != 0 {
p.WriteInt32(ad.skillID)
}
if ad.facesLeft {
p.WriteByte(ad.action | (1 << 7))
} else {
p.WriteByte(ad.action | 0)
}
p.WriteByte(ad.attackType)
p.WriteByte(char.Skills()[ad.skillID].Mastery)
p.WriteInt32(ad.projectileID)
for _, info := range ad.attackInfo {
p.WriteInt32(info.spawnID)
p.WriteByte(info.hitAction)
if ad.isMesoExplosion {
p.WriteByte(byte(len(info.damages)))
}
for _, dmg := range info.damages {
p.WriteInt32(dmg)
}
}
return p
}
inst.SendExcept(packetSkillMelee(*plr, data), conn)
for _, attack := range data.attackInfo {
inst.LifePool().MobDamaged(attack.spawnID, plr, nil, attack.damages...)
}
}
// Following logic lifted from WvsGlobal
const (
attackMelee = iota
attackRanged
attackMagic
attackSummon
)
type attackInfo struct {
spawnID int32
hitAction, foreAction, frameIndex, calcDamageStatIndex byte
facesLeft bool
hitPosition, previousMobPosition pos.Data
hitDelay int16
damages []int32
}
type attackData struct {
skillID, summonType, totalDamage, projectileID int32
isMesoExplosion, facesLeft bool
option, action, attackType byte
targets, hits, skillLevel byte
attackInfo []attackInfo
playerPos pos.Data
}
func getAttackInfo(reader mpacket.Reader, player player.Data, attackType int) (attackData, bool) {
data := attackData{}
if player.HP() == 0 {
return data, false
}
// speed hack check
if false && (reader.Time-player.LastAttackPacketTime() < 350) {
return data, false
}
player.SetLastAttackPacketTime(reader.Time)
if attackType != attackSummon {
tByte := reader.ReadByte()
skillID := reader.ReadInt32()
if _, ok := player.Skills()[skillID]; !ok && skillID != 0 {
return data, false
}
data.skillID = skillID
if data.skillID != 0 {
data.skillLevel = player.Skills()[skillID].Level
}
// if meso explosion data.IsMesoExplosion = true
data.targets = tByte / 0x10
data.hits = tByte % 0x10
data.option = reader.ReadByte()
tmp := reader.ReadByte()
data.action = tmp & 0x7F
data.facesLeft = (tmp >> 7) == 1
data.attackType = reader.ReadByte()
} else {
data.summonType = reader.ReadInt32()
data.attackType = reader.ReadByte()
data.targets = 1
data.hits = 1
}
reader.Skip(4) //checksum info?
if attackType == attackRanged {
projectileSlot := reader.ReadInt16() // star/arrow slot
if projectileSlot == 0 {
// if soul arrow is not set check for hacks
} else {
data.projectileID = -1
for _, item := range player.Use() {
if item.SlotID() == projectileSlot {
data.projectileID = item.ID()
}
}
}
reader.ReadByte() // ?
reader.ReadByte() // ?
reader.ReadByte() // ?
}
data.attackInfo = make([]attackInfo, data.targets)
for i := byte(0); i < data.targets; i++ {
attack := attackInfo{}
attack.spawnID = reader.ReadInt32()
attack.hitAction = reader.ReadByte()
tmp := reader.ReadByte()
attack.foreAction = tmp & 0x7F
attack.facesLeft = (tmp >> 7) == 1
attack.frameIndex = reader.ReadByte()
if !data.isMesoExplosion {
attack.calcDamageStatIndex = reader.ReadByte()
}
attack.hitPosition.SetX(reader.ReadInt16())
attack.hitPosition.SetY(reader.ReadInt16())
attack.previousMobPosition.SetX(reader.ReadInt16())
attack.previousMobPosition.SetY(reader.ReadInt16())
if attackType == attackSummon {
reader.Skip(1)
}
if data.isMesoExplosion {
data.hits = reader.ReadByte()
} else if attackType != attackSummon {
attack.hitDelay = reader.ReadInt16()
}
attack.damages = make([]int32, data.hits)
for j := byte(0); j < data.hits; j++ {
dmg := reader.ReadInt32()
data.totalDamage += dmg
attack.damages[j] = dmg
}
data.attackInfo[i] = attack
}
data.playerPos.SetX(reader.ReadInt16())
data.playerPos.SetY(reader.ReadInt16())
return data, true
}