34 lines
946 B
GDScript3
Raw Normal View History

2024-02-16 14:51:23 +00:00
extends PacketHandler
func _ready():
%PlayerAdd.main_player_spawned.connect(on_main_player_spawned)
func on_main_player_spawned(player: Player):
2024-02-24 14:30:41 +00:00
player.controlled.connect(on_main_player_controlled)
func on_main_player_controlled(controller: Controller):
controller.used_skill.connect(on_skill_used)
2024-02-16 14:51:23 +00:00
func on_skill_used(slot: int):
var buffer := StreamPeerBuffer.new()
buffer.put_u8(PacketHandler.Packet.PLAYER_USE_SKILL)
buffer.put_u8(slot)
%Client.send(buffer.data_array)
func handle_packet(data: PackedByteArray):
var buffer := StreamPeerBuffer.new()
buffer.data_array = data
var player_id_length := buffer.get_size() - 1
var player_id := buffer.get_string(player_id_length)
var slot := buffer.get_u8()
var player := Global.players.get_player(player_id)
2024-02-28 12:23:17 +00:00
if !player || !player.controller:
return
emit.call_deferred(player.controller, slot)
func emit(controller: Controller, slot: int):
controller.used_skill.emit(slot)