Defuse win
This commit is contained in:
parent
215598c63b
commit
8535dba9cd
10 changed files with 151 additions and 21 deletions
30
scripts/interaction_system/interactible.gd
Normal file
30
scripts/interaction_system/interactible.gd
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
class_name Interactible
|
||||
|
||||
signal interacted(with: int)
|
||||
signal stopped_interacting(with: int)
|
||||
|
||||
var interacted_id: int = -1
|
||||
|
||||
func _ready() -> void:
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
Session.player_stopped_interacting.connect(player_stopped_interacting)
|
||||
|
||||
func interaction_start(player_id: int):
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
interacted.emit(player_id)
|
||||
|
||||
interacted_id = player_id
|
||||
|
||||
func player_stopped_interacting(id: int):
|
||||
if interacted_id == id:
|
||||
interaction_end()
|
||||
|
||||
func interaction_end():
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
stopped_interacting.emit(interacted_id)
|
||||
interacted_id = -1
|
||||
1
scripts/interaction_system/interactible.gd.uid
Normal file
1
scripts/interaction_system/interactible.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d1c4u4aul8oc1
|
||||
|
|
@ -21,6 +21,7 @@ const DEFENCE_LAYER: int = 0b100000
|
|||
|
||||
signal round_started
|
||||
signal round_state_changed(state: int)
|
||||
signal player_stopped_interacting(id: int)
|
||||
|
||||
var player_nodes: Dictionary[int,Player] = {}
|
||||
var object_containers: Array[ObjectContainer]
|
||||
|
|
@ -59,7 +60,7 @@ func _ready() -> void:
|
|||
round_timer.timeout.connect(end_round.bind(TEAMS.DEFENCE))
|
||||
|
||||
buy_timer = Timer.new()
|
||||
buy_timer.wait_time = 15
|
||||
buy_timer.wait_time = 1
|
||||
buy_timer.one_shot = true
|
||||
buy_timer.timeout.connect(begin_main_stage)
|
||||
|
||||
|
|
@ -170,6 +171,12 @@ func begin_bomb_stage() -> void:
|
|||
round_state = ROUND_STATES.AFTER_PLANT
|
||||
round_state_changed.emit(round_state)
|
||||
|
||||
func defuse_win() -> void:
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
bomb_timer.stop()
|
||||
end_round(TEAMS.DEFENCE)
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func add_dead(team: int):
|
||||
if multiplayer.is_server() == false:
|
||||
|
|
@ -250,6 +257,43 @@ func shoot_internal(id:int , damage: int) -> void:
|
|||
if collision != {} and collision["collider"] is Player:
|
||||
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")
|
||||
func interact_internal(id:int) -> void:
|
||||
if multiplayer.is_server() == false:
|
||||
return
|
||||
|
||||
var player: Player = player_nodes[id]
|
||||
var player_camera: Camera3D = player.get_node("Camera3D")
|
||||
var space: PhysicsDirectSpaceState3D = player.get_world_3d().direct_space_state
|
||||
var endpoint: Vector3 = player_camera.global_position - player_camera.global_basis.z * 3
|
||||
|
||||
var ray = PhysicsRayQueryParameters3D.create(player_camera.global_position,endpoint,1)
|
||||
ray.exclude = [player.get_rid()]
|
||||
ray.collide_with_areas = false
|
||||
ray.collision_mask |= 64
|
||||
|
||||
var collision = space.intersect_ray(ray)
|
||||
if collision != {} and collision["collider"] is Interactible:
|
||||
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")
|
||||
func stop_interact_internal(id: int) -> void:
|
||||
if multiplayer.is_server() == false:
|
||||
return
|
||||
player_stopped_interacting.emit(id)
|
||||
|
||||
func is_on_site() -> bool:
|
||||
for plant in plants:
|
||||
if plant.is_player_on_site(multiplayer.get_unique_id()):
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ class_name Player
|
|||
@export var team: Session.TEAMS
|
||||
@export var weapon_models: Dictionary[StringName,Node3D]
|
||||
|
||||
var passived: bool = false
|
||||
|
||||
signal spawned
|
||||
signal health_changed(to: int)
|
||||
signal died
|
||||
|
|
@ -38,6 +40,15 @@ func die() -> void:
|
|||
return
|
||||
Session.add_dead.rpc(team)
|
||||
died.emit()
|
||||
passived = true
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func passive() -> void:
|
||||
passived = true
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func depassive() -> void:
|
||||
passived = false
|
||||
|
||||
@rpc("any_peer","call_local","reliable")
|
||||
func kill_request() -> void:
|
||||
|
|
@ -55,3 +66,11 @@ func set_after_spawn(start_position: Vector3,new_team: int):
|
|||
@rpc("any_peer","call_local","reliable")
|
||||
func take_damage(damage: int):
|
||||
hp -= damage
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if event.is_action_pressed("plr_interact"):
|
||||
Session.interact()
|
||||
if event.is_action_released("plr_interact"):
|
||||
Session.stop_interact()
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ extends Node
|
|||
class_name PlayerMovement
|
||||
|
||||
@export var player: Player
|
||||
var disabled: bool
|
||||
|
||||
func process_movement(max_speed: float,acceleration: float,deceleration: float,delta: float) -> void:
|
||||
if is_multiplayer_authority() == false:
|
||||
return
|
||||
if Session.round_state == Session.ROUND_STATES.BUY:
|
||||
if Session.round_state == Session.ROUND_STATES.BUY or disabled or player.passived:
|
||||
player.velocity.x = 0
|
||||
player.velocity.z = 0
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
extends Node3D
|
||||
extends Interactible
|
||||
|
||||
var plant: StringName
|
||||
@onready var defuse_timer: Timer = $DefuseTimer
|
||||
|
||||
func _ready() -> void:
|
||||
super()
|
||||
if multiplayer.is_server():
|
||||
Session.bomb_timer.timeout.connect(on_timeout)
|
||||
Session.begin_bomb_stage()
|
||||
|
|
@ -12,3 +14,19 @@ func on_timeout():
|
|||
return
|
||||
|
||||
Session.kill_site(plant)
|
||||
|
||||
func on_defuse_timeout():
|
||||
Session.defuse_win()
|
||||
|
||||
func interaction_start(player_id: int):
|
||||
if Session.player_nodes[player_id].team != Session.TEAMS.DEFENCE:
|
||||
return
|
||||
super(player_id)
|
||||
defuse_timer.start()
|
||||
Session.player_nodes[player_id].passive.rpc_id(player_id)
|
||||
|
||||
func interaction_end():
|
||||
Session.player_nodes[interacted_id].depassive.rpc_id(interacted_id)
|
||||
|
||||
super()
|
||||
defuse_timer.stop()
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ func _physics_process(delta: float) -> void:
|
|||
current_state.physics_update(delta)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if is_multiplayer_authority() == false or disabled or Session.round_state == Session.ROUND_STATES.BUY: return
|
||||
if is_multiplayer_authority() == false or disabled: return
|
||||
|
||||
if current_state != null:
|
||||
current_state.state_input(event)
|
||||
|
|
@ -196,14 +196,15 @@ func _input(event: InputEvent) -> void:
|
|||
elif event.is_action_pressed("plr_knife"):
|
||||
switch("knife")
|
||||
|
||||
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 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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue