2020-06-26 20:03:00 -04:00
|
|
|
package d2netpacket
|
|
|
|
|
2020-08-09 20:32:47 -04:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-09-23 13:30:54 -04:00
|
|
|
"log"
|
2020-09-12 16:25:09 -04:00
|
|
|
|
2020-08-09 20:32:47 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
|
|
|
)
|
2020-06-26 20:03:00 -04:00
|
|
|
|
2020-06-29 17:01:26 -04:00
|
|
|
// CastPacket contains a cast command for an entity. It is sent by the server
|
|
|
|
// and instructs the client to trigger the use of the given skill on the given
|
|
|
|
// entity.
|
2020-06-26 20:03:00 -04:00
|
|
|
type CastPacket struct {
|
|
|
|
SourceEntityID string `json:"sourceEntityId"`
|
|
|
|
SkillID int `json:"skillId"`
|
|
|
|
TargetX float64 `json:"targetX"`
|
|
|
|
TargetY float64 `json:"targetY"`
|
|
|
|
TargetEntityID string `json:"targetEntityId"`
|
|
|
|
}
|
|
|
|
|
2020-06-29 17:01:26 -04:00
|
|
|
// CreateCastPacket returns a NetPacket which declares a CastPacket with the
|
|
|
|
// given skill command.
|
2020-06-26 20:03:00 -04:00
|
|
|
func CreateCastPacket(entityID string, skillID int, targetX, targetY float64) NetPacket {
|
2020-08-09 20:32:47 -04:00
|
|
|
castPacket := CastPacket{
|
|
|
|
SourceEntityID: entityID,
|
|
|
|
SkillID: skillID,
|
|
|
|
TargetX: targetX,
|
|
|
|
TargetY: targetY,
|
2020-10-25 18:36:12 -04:00
|
|
|
TargetEntityID: "", // https://github.com/OpenDiablo2/OpenDiablo2/issues/826
|
2020-08-09 20:32:47 -04:00
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-09-23 13:30:54 -04:00
|
|
|
b, err := json.Marshal(castPacket)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
2020-08-09 20:32:47 -04:00
|
|
|
|
2020-06-26 20:03:00 -04:00
|
|
|
return NetPacket{
|
|
|
|
PacketType: d2netpackettype.CastSkill,
|
2020-08-09 20:32:47 -04:00
|
|
|
PacketData: b,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// UnmarshalCast unmarshals the given data to a CastPacket struct
|
2020-08-09 20:32:47 -04:00
|
|
|
func UnmarshalCast(packet []byte) (CastPacket, error) {
|
|
|
|
var p CastPacket
|
|
|
|
if err := json.Unmarshal(packet, &p); err != nil {
|
|
|
|
return p, err
|
2020-06-26 20:03:00 -04:00
|
|
|
}
|
2020-08-09 20:32:47 -04:00
|
|
|
|
|
|
|
return p, nil
|
2020-06-26 20:03:00 -04:00
|
|
|
}
|