mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-10-16 07:03:52 -04:00
783993470e
* fixed lint error in d2app/app.go * go fmt entire project * adding doc.go for d2records * fixed lint issues in d2core/d2map * fixed lint error in d2interface/palette.go * fixed lint error in d2core/d2hero/hero_state_factory.go * adding dov.go to d2common/d2geom * fixing lint errors in d2common/d2loader * adding doc.go to d2common/d2cache * adding doc files for d2datautils, d2util, d2path * adding package doc strings for mapgen, in-geam help screen, and tcp client connection * removed all cuddling lint errors * changed stamina equality check to '<=' instead of '<'
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package d2netpacket
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
|
)
|
|
|
|
// 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.
|
|
// TODO: Need to handle being on different maps
|
|
type CastPacket struct {
|
|
SourceEntityID string `json:"sourceEntityId"`
|
|
SkillID int `json:"skillId"`
|
|
TargetX float64 `json:"targetX"`
|
|
TargetY float64 `json:"targetY"`
|
|
TargetEntityID string `json:"targetEntityId"`
|
|
}
|
|
|
|
// CreateCastPacket returns a NetPacket which declares a CastPacket with the
|
|
// given skill command.
|
|
func CreateCastPacket(entityID string, skillID int, targetX, targetY float64) NetPacket {
|
|
castPacket := CastPacket{
|
|
SourceEntityID: entityID,
|
|
SkillID: skillID,
|
|
TargetX: targetX,
|
|
TargetY: targetY,
|
|
TargetEntityID: "", // TODO implement targeting entities
|
|
}
|
|
|
|
b, err := json.Marshal(castPacket)
|
|
if err != nil {
|
|
log.Print(err)
|
|
}
|
|
|
|
return NetPacket{
|
|
PacketType: d2netpackettype.CastSkill,
|
|
PacketData: b,
|
|
}
|
|
}
|
|
|
|
func UnmarshalCast(packet []byte) (CastPacket, error) {
|
|
var p CastPacket
|
|
if err := json.Unmarshal(packet, &p); err != nil {
|
|
return p, err
|
|
}
|
|
|
|
return p, nil
|
|
}
|