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

@ -40,10 +40,10 @@ func interaction_start(player_id: int):
super(player_id)
defuse_timer.start()
$DefuseAudio.multiplayer_play()
Session.player_nodes[player_id].passive.rpc_id(player_id)
Session.player_nodes[player_id].passive()
func interaction_end():
Session.player_nodes[interacted_id].depassive.rpc_id(interacted_id)
Session.player_nodes[interacted_id].depassive()
super()
defuse_timer.stop()

View file

@ -7,6 +7,6 @@ func enter() -> void:
func exit() -> void:
pass
func state_input(event: InputEvent) -> void:
if event.is_action("plr_bomb") and Session.is_on_site():
func use_begin() -> void:
if Session.is_on_site(machine.player.player_id):
transition.emit("Plant")

View file

@ -3,8 +3,9 @@ extends WeaponState
func enter():
machine.animation_player.play(machine.animation_prefix+"plant")
machine.animation_player.animation_finished.connect(on_animation_finished)
machine.speed_modifier = 0.0
machine.player.get_node("PlantAudio").multiplayer_play()
if is_multiplayer_authority():
machine.speed_modifier = 0.0
machine.player.get_node("PlantAudio").multiplayer_play()
func exit():
machine.animation_player.animation_finished.disconnect(on_animation_finished)
@ -14,15 +15,13 @@ func on_animation_finished(animation: StringName):
if is_multiplayer_authority() == false:
return
if animation == machine.animation_prefix + "plant":
Session.spawn({"type": "object","spawn_name": "active_bomb", "position": machine.player_camera.get_parent().global_position,"plant": Session.get_site().name})
Session.spawn({"type": "object","spawn_name": "active_bomb", "position": machine.player_camera.get_parent().global_position,"plant": Session.get_site(machine.player.player_id).name})
machine.ammo -= 1
return_to_previous.emit()
func state_input(event: InputEvent) -> void:
func use_end() -> void:
if is_multiplayer_authority() == false:
return
if event.is_action_released("plr_bomb"):
transition.emit("Idle")
machine.player.get_node("PlantAudio").multiplayer_stop()
transition.emit("Idle")
machine.player.get_node("PlantAudio").multiplayer_stop()

View file

@ -4,15 +4,10 @@ extends WeaponState
func enter() -> void:
machine.animation_player.play(with_morphems("idle"))
machine.player.get_node("PlayerInput").reload.connect(init_reload)
func exit() -> void:
pass
func state_input(event: InputEvent) -> void:
if not machine.is_multiplayer_authority() or Input.mouse_mode != Input.MouseMode.MOUSE_MODE_CAPTURED: return
if event.is_action_pressed("plr_reload"):
init_reload.rpc()
machine.player.get_node("PlayerInput").reload.disconnect(init_reload)
func use_begin() -> void:
if machine.ammo > 0:

View file

@ -31,7 +31,6 @@ func use_begin() -> void:
func fire() -> void:
if machine.ammo == 0 or fire_timer.time_left > 0:
return
machine.player.get_node("ShootAudio").multiplayer_play()
machine.ammo -= 1
bullets_shot += 1
@ -39,7 +38,8 @@ func fire() -> void:
machine.animation_player.play(with_morphems("shoot"))
if is_multiplayer_authority():
Session.shoot(damage,shoot_distance)
Session.shoot(int(machine.player.name),damage,shoot_distance)
machine.player.get_node("ShootAudio").multiplayer_play()
fire_timer.start()
machine.player_camera.recoil(horizontal_curve.sample(bullets_shot),vertical_curve.sample(bullets_shot))

View file

@ -14,7 +14,7 @@ func exit() -> void:
func attack() -> void:
if is_multiplayer_authority():
Session.shoot(damage,1.5)
Session.shoot(int(machine.player.name),damage,1.5)
func on_animation_finished(animation):
if animation == machine.animation_prefix + "attack":

View file

@ -12,7 +12,7 @@ func exit() -> void:
func attack() -> void:
if is_multiplayer_authority():
Session.shoot(damage,1.5)
Session.shoot(int(machine.player.name),damage,1.5)
func on_animation_finished(animation):
if animation == machine.animation_prefix + "heavy_attack":

View file

@ -64,6 +64,7 @@ func exit() -> void:
@rpc("authority","call_local","reliable")
func use_begin() -> void:
current_state.use_begin()
@rpc("authority","call_local","reliable")
func use_end() -> void:
current_state.use_end()

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()