Spawnables
This commit is contained in:
parent
6b5e768faf
commit
ea4f70f5ef
25 changed files with 4784 additions and 4436 deletions
|
|
@ -5,20 +5,40 @@ func _ready() -> void:
|
|||
Session.dynamic_objects_spawner = self
|
||||
|
||||
func request_spawn(data: Variant) -> Node:
|
||||
if data.has("scene") == false:
|
||||
if is_multiplayer_authority() == false: return
|
||||
if data.has("type") == false or data.has("spawn_name") == false:
|
||||
return Node.new()
|
||||
var node = load(data.scene).instantiate()
|
||||
if data.has("impulse"):
|
||||
if data.has_all(["ammo","remaining_ammo","slot"]):
|
||||
node.weapon.ammo = data.ammo
|
||||
node.weapon.remaining_ammo = data.remaining_ammo
|
||||
node.slot = data.slot
|
||||
|
||||
node.apply_impulse(data.impulse)
|
||||
|
||||
for key in data.keys():
|
||||
if key in ["scene","ammo","remaining_ammo","slot","position","rotation"]:
|
||||
continue
|
||||
node.set(key,data[key])
|
||||
return node
|
||||
match data.type:
|
||||
"weapon":
|
||||
var weapon: DroppableWeapon = Registry.weapons[data.spawn_name].dropped_scene.instantiate()
|
||||
weapon.apply_central_impulse(data.impulse)
|
||||
weapon.weapon.ammo = data.ammo
|
||||
weapon.weapon.remaining_ammo = data.remaining_ammo
|
||||
weapon.slot = Registry.weapons[data.spawn_name].slot
|
||||
|
||||
for key in data.keys():
|
||||
if key == "impulse" or key == "ammo" or key == "remaining_ammo":
|
||||
continue
|
||||
weapon.set(key,data[key])
|
||||
|
||||
return weapon
|
||||
"projectile":
|
||||
var projectile: RigidBody3D = Registry.spawnable_objects[data.spawn_name].instantiate()
|
||||
projectile.apply_central_impulse(data.impulse)
|
||||
|
||||
for key in data.keys():
|
||||
if key == "impulse":
|
||||
continue
|
||||
projectile.set(key,data[key])
|
||||
|
||||
return projectile
|
||||
"object":
|
||||
var object: Node3D = Registry.spawnable_objects[data.spawn_name].instantiate()
|
||||
|
||||
for key in data.keys():
|
||||
object.set(key,data[key])
|
||||
|
||||
return object
|
||||
_:
|
||||
return Node.new()
|
||||
|
||||
|
|
|
|||
11
scripts/player/input_system.gd
Normal file
11
scripts/player/input_system.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends Node
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
1
scripts/player/input_system.gd.uid
Normal file
1
scripts/player/input_system.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cg0v1nmwuuoej
|
||||
|
|
@ -66,6 +66,7 @@ func set_after_spawn(start_position: Vector3,new_team: int):
|
|||
@rpc("any_peer","call_local","reliable")
|
||||
func take_damage(damage: int):
|
||||
hp -= damage
|
||||
$DamageAudio.multiplayer_play()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
|
|
|
|||
11
scripts/registry.gd
Normal file
11
scripts/registry.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends Node
|
||||
|
||||
var spawnable_objects: Dictionary[StringName,PackedScene]
|
||||
var weapons: Dictionary[StringName,WeaponResource]
|
||||
|
||||
func _ready() -> void:
|
||||
for file in ResourceLoader.list_directory("res://weapons/"):
|
||||
weapons[file.trim_suffix(".tres")] = load("res://weapons/"+ file)
|
||||
|
||||
for file in ResourceLoader.list_directory("res://spawnables/"):
|
||||
spawnable_objects[file.trim_suffix(".tscn")] = load("res://spawnables/" + file)
|
||||
1
scripts/registry.gd.uid
Normal file
1
scripts/registry.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c7p8avavia4fp
|
||||
9
scripts/resources/weapon_resource.gd
Normal file
9
scripts/resources/weapon_resource.gd
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
extends Resource
|
||||
|
||||
class_name WeaponResource
|
||||
|
||||
@export var cost: int
|
||||
@export var preview: Texture2D
|
||||
@export var dropped_scene: PackedScene
|
||||
@export var weapon_system_scene: PackedScene
|
||||
@export var slot: StringName
|
||||
1
scripts/resources/weapon_resource.gd.uid
Normal file
1
scripts/resources/weapon_resource.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bvnn2eiwqbu7t
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
extends WeaponState
|
||||
|
||||
const active_bomb: StringName = "uid://dtbpyfdawb02b"
|
||||
|
||||
func enter():
|
||||
machine.animation_player.play(machine.animation_prefix+"plant")
|
||||
machine.animation_player.animation_finished.connect(on_animation_finished)
|
||||
|
|
@ -17,7 +15,7 @@ func on_animation_finished(animation: StringName):
|
|||
return
|
||||
if animation == machine.animation_prefix + "plant":
|
||||
|
||||
Session.spawn({"scene": 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().name})
|
||||
|
||||
machine.ammo -= 1
|
||||
return_to_previous.emit()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ extends SubStateMachine
|
|||
class_name WeaponSubStateMachine
|
||||
|
||||
@export var animation_prefix: StringName
|
||||
@export var droppable: StringName
|
||||
@export var index: StringName
|
||||
@export var visibility_target: StringName
|
||||
|
||||
@export var max_ammo: int
|
||||
|
|
|
|||
|
|
@ -103,7 +103,8 @@ func drop(weapon: WeaponSubStateMachine) -> void:
|
|||
if slots.find_key(weapon) == "knife":
|
||||
return
|
||||
var drop_data: Dictionary = {}
|
||||
drop_data.scene = weapon.droppable
|
||||
drop_data.type = "weapon"
|
||||
drop_data.spawn_name = weapon.index
|
||||
drop_data.ammo = weapon.ammo
|
||||
drop_data.remaining_ammo = weapon.remaining_ammo
|
||||
drop_data.slot = weapon.slot
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue