Added network skill usage
This commit is contained in:
@ -32,6 +32,7 @@ func NewRouter(game *Game) *Router {
|
||||
router.Get(Login, game.Login)
|
||||
router.Get(PlayerMove, game.Move)
|
||||
router.Get(PlayerJump, game.Jump)
|
||||
router.Get(PlayerUseSkill, game.UseSkill)
|
||||
router.Get(Chat, game.Chat)
|
||||
return router
|
||||
}
|
||||
|
@ -6,15 +6,15 @@ import (
|
||||
|
||||
// Byte prefixes to indicate the packet type.
|
||||
const (
|
||||
Ping = 1
|
||||
Login = 2
|
||||
Logout = 3
|
||||
PlayerAdd = 10
|
||||
PlayerRemove = 11
|
||||
PlayerMove = 12
|
||||
PlayerJump = 13
|
||||
PlayerAttack = 14
|
||||
Chat = 20
|
||||
Ping = 1
|
||||
Login = 2
|
||||
Logout = 3
|
||||
PlayerAdd = 10
|
||||
PlayerRemove = 11
|
||||
PlayerMove = 12
|
||||
PlayerJump = 13
|
||||
PlayerUseSkill = 14
|
||||
Chat = 20
|
||||
)
|
||||
|
||||
// Packet represents a single UDP datagram.
|
||||
|
30
server/game/UseSkill.go
Normal file
30
server/game/UseSkill.go
Normal file
@ -0,0 +1,30 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidPacketLength = errors.New("invalid packet length")
|
||||
)
|
||||
|
||||
// UseSkill tries to use a player skill.
|
||||
func (game *Game) UseSkill(data []byte, address *net.UDPAddr) error {
|
||||
player := game.players.ByAddress(address)
|
||||
|
||||
if player == nil {
|
||||
return ErrUnknownAddress
|
||||
}
|
||||
|
||||
if len(data) != 1 {
|
||||
return ErrInvalidPacketLength
|
||||
}
|
||||
|
||||
slot := data[0]
|
||||
broadcast := []byte(player.ID)
|
||||
broadcast = append(broadcast, slot)
|
||||
|
||||
game.BroadcastOthers(PlayerUseSkill, broadcast, player)
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user