Crouch, walking and scoping support, deleted unnecessary Session rpcs
This commit is contained in:
parent
76647fc2fc
commit
d79db8a8d8
6 changed files with 4513 additions and 4456 deletions
8810
scenes/molikman.tscn
8810
scenes/molikman.tscn
File diff suppressed because one or more lines are too long
|
|
@ -2,3 +2,6 @@ extends Node
|
||||||
|
|
||||||
|
|
||||||
var SENSITIVITY: float = 0.02
|
var SENSITIVITY: float = 0.02
|
||||||
|
var TOGGLE_CROUCH: bool = false
|
||||||
|
var TOGGLE_SCOPE: bool = false
|
||||||
|
var TOGGLE_WALK: bool = false
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
extends MultiplayerSynchronizer
|
extends MultiplayerSynchronizer
|
||||||
|
|
||||||
|
#region SYNC
|
||||||
var direction: Vector2
|
var direction: Vector2
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
var crouching: bool = false
|
||||||
|
var scoping: bool = false
|
||||||
|
var walking: bool = false
|
||||||
|
|
||||||
signal drop
|
signal drop
|
||||||
signal switch_weapon(to_slot: StringName)
|
signal switch_weapon(to_slot: StringName)
|
||||||
|
|
@ -8,6 +14,16 @@ signal fire_begin
|
||||||
signal fire_end
|
signal fire_end
|
||||||
signal alternate_state
|
signal alternate_state
|
||||||
signal switch_firemode
|
signal switch_firemode
|
||||||
|
signal reload
|
||||||
|
signal scope_begin
|
||||||
|
signal scope_end
|
||||||
|
signal crouch_begin
|
||||||
|
signal crouch_end
|
||||||
|
signal walk_begin
|
||||||
|
signal walk_end
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
set_multiplayer_authority(int(get_parent().name))
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if not is_multiplayer_authority(): return
|
if not is_multiplayer_authority(): return
|
||||||
|
|
@ -41,6 +57,40 @@ func _input(event: InputEvent) -> void:
|
||||||
|
|
||||||
if event.is_action_pressed("plr_drop"):
|
if event.is_action_pressed("plr_drop"):
|
||||||
drop_on_server.rpc_id(1)
|
drop_on_server.rpc_id(1)
|
||||||
|
|
||||||
|
if event.is_action_pressed("plr_crouch"):
|
||||||
|
if ClientSettings.TOGGLE_CROUCH:
|
||||||
|
crouch_on_server(crouching)
|
||||||
|
crouching = not crouching
|
||||||
|
elif not crouching:
|
||||||
|
crouching = true
|
||||||
|
crouch_on_server(false)
|
||||||
|
if event.is_action_released("plr_crouch") and not ClientSettings.TOGGLE_CROUCH and crouching:
|
||||||
|
crouching = false
|
||||||
|
crouch_on_server(false)
|
||||||
|
|
||||||
|
if event.is_action_pressed("plr_walk"):
|
||||||
|
if ClientSettings.TOGGLE_WALK:
|
||||||
|
walk_on_server(walking)
|
||||||
|
walking = not walking
|
||||||
|
elif not walking:
|
||||||
|
walking = true
|
||||||
|
walk_on_server(false)
|
||||||
|
if event.is_action_released("plr_walk") and not ClientSettings.TOGGLE_WALK and walking:
|
||||||
|
walking = false
|
||||||
|
walk_on_server(false)
|
||||||
|
|
||||||
|
if event.is_action_pressed("plr_scope"):
|
||||||
|
if ClientSettings.TOGGLE_SCOPE:
|
||||||
|
scope_on_server(scoping)
|
||||||
|
scoping = not scoping
|
||||||
|
elif not scoping:
|
||||||
|
scoping = true
|
||||||
|
scope_on_server(false)
|
||||||
|
if event.is_action_released("plr_scope") and not ClientSettings.TOGGLE_SCOPE and scoping:
|
||||||
|
scoping = false
|
||||||
|
scope_on_server(false)
|
||||||
|
|
||||||
|
|
||||||
@rpc("authority","call_local","reliable")
|
@rpc("authority","call_local","reliable")
|
||||||
func switch_on_server(slot: StringName) -> void:
|
func switch_on_server(slot: StringName) -> void:
|
||||||
|
|
@ -69,4 +119,32 @@ func alternate_state_on_server() -> void:
|
||||||
func switch_firemode_on_server() -> void:
|
func switch_firemode_on_server() -> void:
|
||||||
if not multiplayer.is_server(): return
|
if not multiplayer.is_server(): return
|
||||||
switch_firemode.emit()
|
switch_firemode.emit()
|
||||||
|
|
||||||
|
@rpc("authority","call_local","reliable")
|
||||||
|
func crouch_on_server(end: bool) -> void:
|
||||||
|
if not multiplayer.is_server(): return
|
||||||
|
if end:
|
||||||
|
crouch_end.emit()
|
||||||
|
else:
|
||||||
|
crouch_begin.emit()
|
||||||
|
|
||||||
|
@rpc("authority","call_local","reliable")
|
||||||
|
func walk_on_server(end: bool) -> void:
|
||||||
|
if not multiplayer.is_server(): return
|
||||||
|
if end:
|
||||||
|
walk_end.emit()
|
||||||
|
else:
|
||||||
|
walk_begin.emit()
|
||||||
|
|
||||||
|
@rpc("authority","call_local","reliable")
|
||||||
|
func scope_on_server(end: bool) -> void:
|
||||||
|
if not multiplayer.is_server(): return
|
||||||
|
if end:
|
||||||
|
scope_end.emit()
|
||||||
|
else:
|
||||||
|
scope_begin.emit()
|
||||||
|
|
||||||
|
@rpc("authority","call_local","reliable")
|
||||||
|
func reload_on_server() -> void:
|
||||||
|
if not multiplayer.is_server(): return
|
||||||
|
reload.emit()
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ func _process(_delta: float) -> void:
|
||||||
func update_clock(time: float):
|
func update_clock(time: float):
|
||||||
reference_round_time = time
|
reference_round_time = time
|
||||||
|
|
||||||
@rpc("any_peer","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func start_session() -> void:
|
func start_session() -> void:
|
||||||
if not is_server_request():
|
if not is_server_request():
|
||||||
return
|
return
|
||||||
|
|
@ -100,7 +100,7 @@ func start_session() -> void:
|
||||||
|
|
||||||
start_round()
|
start_round()
|
||||||
|
|
||||||
@rpc("any_peer","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func end_session() -> void:
|
func end_session() -> void:
|
||||||
if not is_server_request():
|
if not is_server_request():
|
||||||
return
|
return
|
||||||
|
|
@ -114,7 +114,7 @@ func end_session() -> void:
|
||||||
|
|
||||||
session_started = false
|
session_started = false
|
||||||
|
|
||||||
@rpc("any_peer","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func start_round() -> void:
|
func start_round() -> void:
|
||||||
if not is_server_request():
|
if not is_server_request():
|
||||||
return
|
return
|
||||||
|
|
@ -134,7 +134,7 @@ func start_round() -> void:
|
||||||
round_state = ROUND_STATES.BUY
|
round_state = ROUND_STATES.BUY
|
||||||
round_state_changed.emit.call_deferred(round_state)
|
round_state_changed.emit.call_deferred(round_state)
|
||||||
|
|
||||||
@rpc("any_peer","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func end_round(win_team: int) -> void:
|
func end_round(win_team: int) -> void:
|
||||||
if not is_server_request():
|
if not is_server_request():
|
||||||
return
|
return
|
||||||
|
|
@ -150,7 +150,7 @@ func end_round(win_team: int) -> void:
|
||||||
round_state = ROUND_STATES.AFTER_ROUND
|
round_state = ROUND_STATES.AFTER_ROUND
|
||||||
round_state_changed.emit(round_state)
|
round_state_changed.emit(round_state)
|
||||||
|
|
||||||
@rpc("any_peer","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func begin_main_stage() -> void:
|
func begin_main_stage() -> void:
|
||||||
if not is_server_request():
|
if not is_server_request():
|
||||||
return
|
return
|
||||||
|
|
@ -161,7 +161,7 @@ func begin_main_stage() -> void:
|
||||||
round_state = ROUND_STATES.ROUND
|
round_state = ROUND_STATES.ROUND
|
||||||
round_state_changed.emit(round_state)
|
round_state_changed.emit(round_state)
|
||||||
|
|
||||||
@rpc("any_peer","call_remote","reliable")
|
@rpc("authority","call_remote","reliable")
|
||||||
func begin_bomb_stage() -> void:
|
func begin_bomb_stage() -> void:
|
||||||
if not is_server_request():
|
if not is_server_request():
|
||||||
return
|
return
|
||||||
|
|
@ -179,7 +179,6 @@ func defuse_win() -> void:
|
||||||
bomb_timer.stop()
|
bomb_timer.stop()
|
||||||
end_round(TEAMS.DEFENCE)
|
end_round(TEAMS.DEFENCE)
|
||||||
|
|
||||||
@rpc("any_peer","call_local","reliable")
|
|
||||||
func add_dead(team: int):
|
func add_dead(team: int):
|
||||||
if multiplayer.is_server() == false:
|
if multiplayer.is_server() == false:
|
||||||
return
|
return
|
||||||
|
|
@ -204,12 +203,7 @@ func is_server_request() -> bool:
|
||||||
## ammo, remaining_ammo, slot - data for dropped weapon [br]
|
## ammo, remaining_ammo, slot - data for dropped weapon [br]
|
||||||
## for more, see dyn_objects_spawner.gd
|
## for more, see dyn_objects_spawner.gd
|
||||||
func spawn(data: Dictionary) -> void:
|
func spawn(data: Dictionary) -> void:
|
||||||
spawn_internal.rpc_id(1,data)
|
|
||||||
|
|
||||||
@rpc("any_peer","call_local","reliable")
|
|
||||||
func spawn_internal(data: Dictionary) -> void:
|
|
||||||
if multiplayer.is_server() == false:
|
if multiplayer.is_server() == false:
|
||||||
printerr(str(multiplayer.get_remote_sender_id())+" tried to spawn internally on "+str(multiplayer.get_unique_id()))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var object = dynamic_objects_spawner.spawn(data)
|
var object = dynamic_objects_spawner.spawn(data)
|
||||||
|
|
@ -217,25 +211,14 @@ func spawn_internal(data: Dictionary) -> void:
|
||||||
if data.has("position"):
|
if data.has("position"):
|
||||||
object.global_position = data.position
|
object.global_position = data.position
|
||||||
|
|
||||||
func despawn(path: NodePath):
|
func despawn(path: NodePath) -> void:
|
||||||
despawn_internal.rpc_id(1,path)
|
|
||||||
|
|
||||||
@rpc("any_peer","call_local","reliable")
|
|
||||||
func despawn_internal(path: NodePath) -> void:
|
|
||||||
if multiplayer.is_server() == false:
|
if multiplayer.is_server() == false:
|
||||||
printerr(str(multiplayer.get_remote_sender_id())+" tried to despawn internally on "+str(multiplayer.get_unique_id()))
|
printerr(str(multiplayer.get_remote_sender_id())+" tried to despawn internally on "+str(multiplayer.get_unique_id()))
|
||||||
return
|
return
|
||||||
|
|
||||||
get_node(path).queue_free()
|
get_node(path).queue_free()
|
||||||
|
|
||||||
func shoot(damage: int,distance: float = 100) -> void:
|
func shoot(id:int , damage: int, distance: float) -> void:
|
||||||
if multiplayer.get_unique_id() == 1:
|
|
||||||
shoot_internal(1,damage,distance)
|
|
||||||
else:
|
|
||||||
shoot_internal.rpc_id(1,multiplayer.get_unique_id(),damage,distance)
|
|
||||||
|
|
||||||
@rpc("any_peer","call_local","reliable")
|
|
||||||
func shoot_internal(id:int , damage: int, distance: float) -> void:
|
|
||||||
if multiplayer.is_server() == false:
|
if multiplayer.is_server() == false:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -260,16 +243,12 @@ func shoot_internal(id:int , damage: int, distance: float) -> void:
|
||||||
if collision != {} and collision["collider"] is Player:
|
if collision != {} and collision["collider"] is Player:
|
||||||
collision["collider"].take_damage.rpc_id(int(collision["collider"].name),damage)
|
collision["collider"].take_damage.rpc_id(int(collision["collider"].name),damage)
|
||||||
|
|
||||||
func interact() -> void:
|
|
||||||
if multiplayer.get_unique_id() == 1:
|
|
||||||
interact_internal(1)
|
|
||||||
else:
|
|
||||||
interact_internal.rpc_id(1,multiplayer.get_unique_id())
|
|
||||||
|
|
||||||
@rpc("any_peer","call_local","reliable")
|
@rpc("any_peer","call_local","reliable")
|
||||||
func interact_internal(id:int) -> void:
|
func interact() -> void:
|
||||||
if multiplayer.is_server() == false:
|
if multiplayer.is_server() == false:
|
||||||
return
|
return
|
||||||
|
var id = multiplayer.get_remote_sender_id()
|
||||||
|
|
||||||
var player: Player = player_nodes[id]
|
var player: Player = player_nodes[id]
|
||||||
var player_camera: Camera3D = player.get_node("Camera3D")
|
var player_camera: Camera3D = player.get_node("Camera3D")
|
||||||
|
|
@ -285,16 +264,11 @@ func interact_internal(id:int) -> void:
|
||||||
if collision != {} and collision["collider"] is Interactible:
|
if collision != {} and collision["collider"] is Interactible:
|
||||||
collision["collider"].interaction_start(id)
|
collision["collider"].interaction_start(id)
|
||||||
|
|
||||||
func stop_interact():
|
|
||||||
if multiplayer.get_unique_id() == 1:
|
|
||||||
stop_interact_internal(1)
|
|
||||||
else:
|
|
||||||
stop_interact_internal.rpc_id(1,multiplayer.get_unique_id())
|
|
||||||
|
|
||||||
@rpc("any_peer","call_local","reliable")
|
@rpc("any_peer","call_local","reliable")
|
||||||
func stop_interact_internal(id: int) -> void:
|
func stop_interact() -> void:
|
||||||
if multiplayer.is_server() == false:
|
if multiplayer.is_server() == false:
|
||||||
return
|
return
|
||||||
|
var id = multiplayer.get_remote_sender_id()
|
||||||
player_stopped_interacting.emit(id)
|
player_stopped_interacting.emit(id)
|
||||||
|
|
||||||
func is_on_site() -> bool:
|
func is_on_site() -> bool:
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ func _exit_tree() -> void:
|
||||||
Session.round_started.disconnect(spawn)
|
Session.round_started.disconnect(spawn)
|
||||||
|
|
||||||
func spawn():
|
func spawn():
|
||||||
|
if not multiplayer.is_server():
|
||||||
|
return
|
||||||
match team:
|
match team:
|
||||||
Session.TEAMS.ATTACK:
|
Session.TEAMS.ATTACK:
|
||||||
for attacker in Lobby.attack_team:
|
for attacker in Lobby.attack_team:
|
||||||
|
|
@ -36,18 +38,21 @@ func spawn_player(id: int) -> void:
|
||||||
elif team == Session.TEAMS.ATTACK:
|
elif team == Session.TEAMS.ATTACK:
|
||||||
Session.attackers_alive += 1
|
Session.attackers_alive += 1
|
||||||
|
|
||||||
deferred_setup.bind(inst,team).call_deferred()
|
var distance = randf_range(0,spawn_radius)
|
||||||
|
var angle = randf_range(0,TAU)
|
||||||
|
var new_position = global_position + Vector3.RIGHT.rotated(Vector3.UP,angle) * distance
|
||||||
|
get_parent().add_child(inst)
|
||||||
|
inst.global_position = new_position
|
||||||
|
inst.team = team
|
||||||
|
|
||||||
func spawn_spectator(id: int) -> void:
|
func spawn_spectator(id: int) -> void:
|
||||||
var spectator: PackedScene = load("res://scenes/spectator.tscn")
|
var spectator: PackedScene = load("res://scenes/spectator.tscn")
|
||||||
var inst = spectator.instantiate()
|
var inst = spectator.instantiate()
|
||||||
|
|
||||||
inst.name = str(id)
|
inst.name = str(id)
|
||||||
deferred_setup.bind(inst,Session.TEAMS.SPECTATE).call_deferred()
|
|
||||||
|
|
||||||
func deferred_setup(what: Node3D, new_team: Session.TEAMS):
|
|
||||||
get_parent().add_child(what,true)
|
|
||||||
var distance = randf_range(0,spawn_radius)
|
var distance = randf_range(0,spawn_radius)
|
||||||
var angle = randf_range(0,TAU)
|
var angle = randf_range(0,TAU)
|
||||||
var new_position = global_position + Vector3.RIGHT.rotated(Vector3.UP,angle) * distance
|
var new_position = global_position + Vector3.RIGHT.rotated(Vector3.UP,angle) * distance
|
||||||
what.set_after_spawn.rpc_id(int(what.name),new_position,new_team)
|
get_parent().add_child(inst)
|
||||||
|
inst.global_position = new_position
|
||||||
|
inst.team = team
|
||||||
|
|
|
||||||
|
|
@ -26,19 +26,16 @@ const MAX_HP = 100
|
||||||
get:
|
get:
|
||||||
return hp
|
return hp
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
|
||||||
set_multiplayer_authority(str(name).to_int())
|
|
||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
if not is_multiplayer_authority():
|
if not multiplayer.is_server():
|
||||||
return
|
return
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
func die() -> void:
|
func die() -> void:
|
||||||
if (not is_multiplayer_authority()):
|
if (not multiplayer.is_server()):
|
||||||
return
|
return
|
||||||
Session.add_dead.rpc(team)
|
Session.add_dead(team)
|
||||||
died.emit()
|
died.emit()
|
||||||
passived = true
|
passived = true
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue