2020-07-30 15:04:05 -04:00
|
|
|
package d2netpacket
|
|
|
|
|
|
|
|
import (
|
2020-08-09 20:32:47 -04:00
|
|
|
"encoding/json"
|
2020-09-12 16:25:09 -04:00
|
|
|
|
2020-07-30 15:04:05 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
|
|
|
)
|
|
|
|
|
2020-09-12 16:25:09 -04:00
|
|
|
// SpawnItemPacket contains the data required to create a Item entity
|
2020-07-30 15:04:05 -04:00
|
|
|
type SpawnItemPacket struct {
|
|
|
|
X int `json:"x"`
|
|
|
|
Y int `json:"y"`
|
|
|
|
Codes []string `json:"codes"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSpawnItemPacket returns a NetPacket which declares a
|
|
|
|
// SpawnItemPacket with the data in given parameters.
|
|
|
|
func CreateSpawnItemPacket(x, y int, codes ...string) NetPacket {
|
2020-08-09 20:32:47 -04:00
|
|
|
spawnItemPacket := SpawnItemPacket{
|
|
|
|
X: x,
|
|
|
|
Y: y,
|
|
|
|
Codes: codes,
|
|
|
|
}
|
|
|
|
b, _ := json.Marshal(spawnItemPacket)
|
|
|
|
|
2020-07-30 15:04:05 -04:00
|
|
|
return NetPacket{
|
|
|
|
PacketType: d2netpackettype.SpawnItem,
|
2020-08-09 20:32:47 -04:00
|
|
|
PacketData: b,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnmarshalSpawnItem(packet []byte) (SpawnItemPacket, error) {
|
|
|
|
var p SpawnItemPacket
|
|
|
|
if err := json.Unmarshal(packet, &p); err != nil {
|
|
|
|
return p, err
|
2020-07-30 15:04:05 -04:00
|
|
|
}
|
2020-08-09 20:32:47 -04:00
|
|
|
|
|
|
|
return p, nil
|
2020-07-30 15:04:05 -04:00
|
|
|
}
|