2023-11-08 14:28:55 +11:00
|
|
|
extends CharacterBody3D
|
|
|
|
class_name Hero
|
|
|
|
|
|
|
|
signal ready_state_changed(state)
|
|
|
|
signal spawned
|
|
|
|
signal died
|
|
|
|
|
|
|
|
@export var hero_class: HeroClass
|
|
|
|
@export var camera : Camera3D
|
2023-11-13 19:36:35 +11:00
|
|
|
@export var gun_camera : Camera3D
|
2023-11-08 14:28:55 +11:00
|
|
|
@export var left_hand : Node3D
|
|
|
|
@export var right_hand : Node3D
|
|
|
|
@export var right_hand_animator : AnimationPlayer
|
|
|
|
@export var edit_tool : EditTool
|
|
|
|
@export var gauntlet_sprite : Sprite3D
|
|
|
|
@export var sprite : EightDirectionSprite3D
|
|
|
|
@export var interaction_raycast : RayCast3D
|
|
|
|
@export var inventory : Inventory
|
|
|
|
@export var card : CardInHand
|
|
|
|
@export var pause_menu_scene : PackedScene
|
|
|
|
@export var hud : HUD
|
|
|
|
@export var movement : PlayerMovement
|
2023-11-13 19:36:35 +11:00
|
|
|
@export var sprint_zoom_speed := 0.2
|
2023-11-16 00:07:41 +11:00
|
|
|
@export var player_name_tag : Label
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
var equipped_card : Card
|
2023-11-15 15:19:40 +11:00
|
|
|
var weapon : Weapon
|
2023-11-08 14:28:55 +11:00
|
|
|
var paused := false
|
|
|
|
var editing_mode := true
|
2023-11-16 00:07:41 +11:00
|
|
|
var profile : PlayerProfile
|
2023-11-13 19:36:35 +11:00
|
|
|
var ready_state := false :
|
2023-11-08 14:28:55 +11:00
|
|
|
set(value):
|
|
|
|
ready_state = value
|
2023-11-13 19:36:35 +11:00
|
|
|
ready_state_changed.emit(value)
|
2023-11-08 14:28:55 +11:00
|
|
|
var currency := 0 :
|
|
|
|
set(value):
|
|
|
|
currency = value
|
|
|
|
hud.set_currency_count(value)
|
|
|
|
get:
|
|
|
|
return currency
|
|
|
|
|
|
|
|
|
2023-11-09 17:56:08 +11:00
|
|
|
func set_zoom_factor(value):
|
|
|
|
movement.zoom_factor = value
|
|
|
|
|
|
|
|
|
2023-11-08 14:28:55 +11:00
|
|
|
func _ready() -> void:
|
|
|
|
if is_multiplayer_authority():
|
|
|
|
right_hand_animator.play("weapon_sway")
|
|
|
|
right_hand_animator.speed_scale = 0
|
|
|
|
camera.make_current()
|
|
|
|
sprite.queue_free()
|
2023-11-16 00:07:41 +11:00
|
|
|
player_name_tag.queue_free()
|
2023-11-08 14:28:55 +11:00
|
|
|
else:
|
|
|
|
camera.set_visible(false)
|
2023-11-13 19:36:35 +11:00
|
|
|
gun_camera.set_visible(false)
|
|
|
|
hud.set_visible(false)
|
2023-11-08 14:28:55 +11:00
|
|
|
if weapon != null:
|
|
|
|
weapon.set_raycast_origin(camera)
|
|
|
|
inventory.contents.append_array(hero_class.deck)
|
2023-11-16 00:07:41 +11:00
|
|
|
sprite.texture.atlas = hero_class.texture
|
2023-11-08 14:28:55 +11:00
|
|
|
check_left_hand_valid()
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
|
|
|
|
|
2023-11-13 19:36:35 +11:00
|
|
|
func _physics_process(_delta: float) -> void:
|
2023-11-08 14:28:55 +11:00
|
|
|
if !is_multiplayer_authority() or paused:
|
|
|
|
return
|
|
|
|
if movement.input_vector == Vector2.ZERO:
|
|
|
|
right_hand_animator.speed_scale = 0
|
|
|
|
elif movement.sprinting:
|
|
|
|
right_hand_animator.speed_scale = 1
|
|
|
|
else:
|
|
|
|
right_hand_animator.speed_scale = 0.6
|
|
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
if !is_multiplayer_authority() or paused:
|
|
|
|
return
|
|
|
|
if !movement.sprinting:
|
|
|
|
movement.zoom_factor += sprint_zoom_speed * 2.0 * delta
|
|
|
|
if movement.zoom_factor > 1.0:
|
|
|
|
movement.zoom_factor = 1.0
|
|
|
|
|
|
|
|
if editing_mode:
|
2023-11-09 20:37:12 +11:00
|
|
|
if interaction_raycast.is_colliding() and interaction_raycast.get_collider() is InteractButton:
|
|
|
|
hud.set_hover_text(interaction_raycast.get_collider().hover_text)
|
|
|
|
else:
|
|
|
|
hud.unset_hover_text()
|
|
|
|
|
2023-11-08 14:28:55 +11:00
|
|
|
if edit_tool.is_looking_at_tower_base:
|
|
|
|
card.view_tower()
|
|
|
|
else:
|
|
|
|
card.view_weapon()
|
|
|
|
if Input.is_action_just_pressed("Interact"):
|
|
|
|
edit_tool.interact()
|
|
|
|
if interaction_raycast.get_collider() is InteractButton:
|
|
|
|
var button = interaction_raycast.get_collider() as InteractButton
|
|
|
|
if currency >= button.press_cost:
|
|
|
|
button.press()
|
|
|
|
currency -= button.press_cost
|
|
|
|
if interaction_raycast.get_collider() is ItemCard:
|
|
|
|
inventory.add(interaction_raycast.get_collider().pick_up())
|
|
|
|
if Input.is_action_just_pressed("Equip In Gauntlet"):
|
|
|
|
equip_weapon()
|
|
|
|
if Input.is_action_just_pressed("Select Next Card"):
|
|
|
|
inventory.increment_selected()
|
|
|
|
if Input.is_action_just_pressed("Select Previous Card"):
|
|
|
|
inventory.decrement_selected()
|
|
|
|
|
|
|
|
if Input.is_action_just_pressed("Primary Fire"):
|
|
|
|
edit_tool.interact_key_held = true
|
|
|
|
if Input.is_action_just_released("Primary Fire"):
|
|
|
|
edit_tool.interact_key_held = false
|
|
|
|
if weapon != null:
|
|
|
|
weapon.release_trigger()
|
|
|
|
weapon.release_second_trigger()
|
|
|
|
else:
|
|
|
|
if weapon != null and Input.is_action_just_pressed("Primary Fire"):
|
|
|
|
weapon.hold_trigger()
|
|
|
|
if weapon != null and Input.is_action_just_released("Primary Fire"):
|
|
|
|
weapon.release_trigger()
|
|
|
|
if weapon != null and Input.is_action_pressed("Secondary Fire"):
|
|
|
|
weapon.hold_second_trigger()
|
|
|
|
if weapon != null and Input.is_action_just_released("Secondary Fire"):
|
|
|
|
weapon.release_second_trigger()
|
|
|
|
if weapon != null and Input.is_action_pressed("Primary Fire"):
|
|
|
|
movement.can_sprint = false
|
|
|
|
if weapon != null and Input.is_action_pressed("Secondary Fire"):
|
|
|
|
movement.can_sprint = false
|
|
|
|
|
|
|
|
if movement.sprinting:
|
|
|
|
movement.zoom_factor -= sprint_zoom_speed * delta
|
|
|
|
if movement.zoom_factor <= 1.0 - movement.sprint_zoom_factor:
|
|
|
|
movement.zoom_factor = 1.0 - movement.sprint_zoom_factor
|
2023-11-17 20:49:38 +11:00
|
|
|
camera.fov = Data.graphics.hfov * (1.0 / movement.zoom_factor)
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
if Input.is_action_just_pressed("View Map"):
|
|
|
|
hud.maximise_minimap(Game.level)
|
|
|
|
#Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
if Input.is_action_just_released("View Map"):
|
|
|
|
hud.minimize_minimap(self)
|
|
|
|
#Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
check_left_hand_valid()
|
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
|
|
if !is_multiplayer_authority() or paused:
|
|
|
|
return
|
|
|
|
if editing_mode and event.is_action_pressed("Ready"):
|
|
|
|
edit_tool.interact_key_held = false
|
2023-11-13 19:36:35 +11:00
|
|
|
if !ready_state:
|
|
|
|
ready_state = true
|
|
|
|
networked_set_ready_state.rpc(ready_state)
|
2023-11-08 14:28:55 +11:00
|
|
|
if event.is_action_pressed("Pause"):
|
|
|
|
var menu = pause_menu_scene.instantiate() as PauseMenu
|
|
|
|
pause()
|
|
|
|
menu.closed.connect(unpause)
|
|
|
|
hud.add_child(menu)
|
|
|
|
|
|
|
|
|
|
|
|
func unpause():
|
|
|
|
paused = false
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
2023-11-09 17:56:08 +11:00
|
|
|
movement.set_process(true)
|
|
|
|
movement.set_physics_process(true)
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
|
|
|
|
func pause():
|
|
|
|
paused = true
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
2023-11-09 17:56:08 +11:00
|
|
|
movement.set_process(false)
|
|
|
|
movement.set_physics_process(false)
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
|
|
|
|
func enter_editing_mode(value):
|
|
|
|
hud.set_wave_count(value + 1)
|
|
|
|
editing_mode = true
|
|
|
|
edit_tool.enabled = true
|
|
|
|
check_left_hand_valid()
|
|
|
|
if weapon != null:
|
|
|
|
weapon.release_trigger()
|
|
|
|
|
|
|
|
|
|
|
|
func exit_editing_mode(value):
|
|
|
|
hud.set_wave_count(value)
|
|
|
|
edit_tool.enabled = false
|
2023-11-09 20:37:12 +11:00
|
|
|
edit_tool.delete_tower_preview()
|
2023-11-08 14:28:55 +11:00
|
|
|
left_hand.set_visible(false)
|
|
|
|
editing_mode = false
|
|
|
|
|
|
|
|
|
|
|
|
func check_left_hand_valid():
|
2023-11-09 20:37:12 +11:00
|
|
|
if !editing_mode:
|
|
|
|
return
|
2023-11-08 14:28:55 +11:00
|
|
|
if inventory.contents.size() == 0:
|
|
|
|
left_hand.set_visible(false)
|
|
|
|
#gauntlet.texture.region = Rect2(64, 0, 64, 64)
|
|
|
|
else:
|
|
|
|
left_hand.set_visible(true)
|
|
|
|
#gauntlet.texture.region = Rect2(0, 0, 64, 64)
|
|
|
|
card.set_card(inventory.selected_item)
|
|
|
|
|
|
|
|
|
|
|
|
func equip_weapon():
|
|
|
|
if weapon != null:
|
|
|
|
unequip_weapon()
|
|
|
|
return
|
|
|
|
if inventory.contents.size() > 0:
|
|
|
|
equipped_card = inventory.remove()
|
2023-11-15 15:19:40 +11:00
|
|
|
networked_equip_weapon.rpc(Data.cards.find(equipped_card))
|
|
|
|
weapon = equipped_card.weapon_scene.instantiate()
|
2023-11-13 19:36:35 +11:00
|
|
|
weapon.name = "weapon"
|
|
|
|
weapon.set_multiplayer_authority(multiplayer.get_unique_id())
|
2023-11-08 14:28:55 +11:00
|
|
|
gauntlet_sprite.set_visible(false)
|
|
|
|
weapon.set_hero(self)
|
2023-11-15 15:19:40 +11:00
|
|
|
right_hand.add_child(weapon)
|
2023-11-08 14:28:55 +11:00
|
|
|
check_left_hand_valid()
|
|
|
|
|
|
|
|
|
|
|
|
func unequip_weapon():
|
2023-11-13 19:36:35 +11:00
|
|
|
networked_unequip_weapon.rpc()
|
2023-11-08 14:28:55 +11:00
|
|
|
gauntlet_sprite.set_visible(true)
|
|
|
|
weapon.queue_free()
|
|
|
|
inventory.add(equipped_card)
|
|
|
|
equipped_card = null
|
|
|
|
check_left_hand_valid()
|
|
|
|
|
|
|
|
|
|
|
|
#MULTIPLAYER NETWORKED FUNCTIONS
|
|
|
|
@rpc("reliable")
|
|
|
|
func networked_set_ready_state(state: bool):
|
|
|
|
ready_state = state
|
2023-11-13 19:36:35 +11:00
|
|
|
|
|
|
|
|
|
|
|
@rpc("reliable")
|
2023-11-15 15:19:40 +11:00
|
|
|
func networked_equip_weapon(card_index):
|
|
|
|
equipped_card = Data.cards[card_index]
|
|
|
|
weapon = equipped_card.weapon_scene.instantiate()
|
2023-11-13 19:36:35 +11:00
|
|
|
weapon.set_multiplayer_authority(multiplayer.get_remote_sender_id())
|
|
|
|
weapon.name = "weapon"
|
|
|
|
weapon.set_hero(self)
|
2023-11-15 15:19:40 +11:00
|
|
|
right_hand.add_child(weapon)
|
2023-11-13 19:36:35 +11:00
|
|
|
|
|
|
|
|
|
|
|
@rpc("reliable")
|
|
|
|
func networked_unequip_weapon():
|
|
|
|
weapon.queue_free()
|
|
|
|
inventory.add(equipped_card)
|
|
|
|
equipped_card = null
|