Merge branch 'multiplayer-rework'

This commit is contained in:
Rendo 2025-12-07 15:54:20 +05:00
commit 2c9ef1cfe1
38 changed files with 535 additions and 288 deletions

View file

@ -5,6 +5,7 @@ class_name WeaponSystem
@export var animation_player: AnimationPlayer
@export var camera: PlayerCamera
@export var player: Player
@export var player_input: PlayerInput
var current_state: WeaponSubStateMachine
var last_slot: StringName
@ -27,6 +28,12 @@ signal ammo_updated(ammo: int, remaining_ammo: int)
func _ready() -> void:
$WeaponSpawner.spawn_function = pick_up_weapon
player_input.drop.connect(drop_current)
player_input.fire_begin.connect(use_begin)
player_input.fire_end.connect(use_end)
player_input.switch_weapon.connect(switch)
player_input.alternate_state.connect(alternate_state)
player_input.switch_firemode.connect(switch_mode)
func get_speed_modifier() -> float:
if current_state == null:
@ -64,8 +71,9 @@ func add(state: WeaponSubStateMachine, slot: StringName,ignore_parent: bool = fa
ammo_updated.emit(current_state.ammo,current_state.remaining_ammo)
state.enter.call_deferred()
@rpc("authority","call_remote","reliable")
func switch(to: StringName, exit: bool = true):
if slots.has(to) == false or slots[to] == null or slots[to] == current_state or is_multiplayer_authority() == false:
if slots.has(to) == false or slots[to] == null or slots[to] == current_state or (multiplayer.get_remote_sender_id() != 1 and is_multiplayer_authority() == false):
return
if current_state != null and exit:
current_state.exit()
@ -78,8 +86,8 @@ func switch(to: StringName, exit: bool = true):
ammo_updated.emit(current_state.ammo,current_state.remaining_ammo)
switched_to.emit(current_state)
update_remotes.rpc(to,exit)
if is_multiplayer_authority():
switch.rpc(to,exit)
func return_to_previous(exit: bool = true):
if last_slot != "":
@ -87,19 +95,12 @@ func return_to_previous(exit: bool = true):
else:
switch("knife", exit)
@rpc("authority","call_remote","reliable")
func update_remotes(to: StringName,exit: bool):
if current_state != null and exit:
current_state.exit()
current_state = slots[to]
current_state.enter()
switched_to.emit(current_state)
func drop_current():
drop(current_state)
func drop(weapon: WeaponSubStateMachine) -> void:
if not is_multiplayer_authority():
return
if slots.find_key(weapon) == "knife":
return
var drop_data: Dictionary = {}
@ -174,39 +175,14 @@ func _physics_process(delta: float) -> void:
return
current_state.physics_update(delta)
func _input(event: InputEvent) -> void:
if is_multiplayer_authority() == false or disabled: return
if current_state != null:
current_state.state_input(event)
if event.is_action_pressed("plr_ult"):
switch("ultimate")
elif event.is_action_pressed("plr_bomb"):
switch("bomb")
elif event.is_action_pressed("plr_primary"):
switch("primary")
elif event.is_action_pressed("plr_active_first"):
switch("ability_first")
elif event.is_action_pressed("plr_active_second"):
switch("ability_second")
elif event.is_action_pressed("plr_active_third"):
switch("ability_third")
elif event.is_action_pressed("plr_secondary"):
switch("secondary")
elif event.is_action_pressed("plr_knife"):
switch("knife")
if not Session.round_state == Session.ROUND_STATES.BUY and not player.passived:
if event.is_action_pressed("plr_fire"):
current_state.use_begin.rpc()
if event.is_action_released("plr_fire"):
current_state.use_end.rpc()
if event.is_action_pressed("plr_scope"):
current_state.alternate_state()
if event.is_action_pressed("plr_firemode"):
current_state.switch_mode()
if event.is_action_pressed("plr_drop"):
drop_current()
func use_begin() -> void:
current_state.use_begin.rpc()
func use_end() -> void:
current_state.use_end.rpc()
func alternate_state() -> void:
current_state.alternate_state()
func switch_mode() -> void:
current_state.switch_mode()