inching towards better class inheritence and multiplayer compatibility
This commit is contained in:
37
Scripts/Weapons/hitscan_weapon.gd
Normal file
37
Scripts/Weapons/hitscan_weapon.gd
Normal file
@ -0,0 +1,37 @@
|
||||
extends Weapon
|
||||
class_name HitscanWeapon
|
||||
|
||||
@export var raycast : RayCast3D
|
||||
@export var range_debug_indicator : CSGSphere3D
|
||||
|
||||
var attack_range := 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
attack_range = stats.get_attribute("Range")
|
||||
raycast.target_position = Vector3(0, 0, -attack_range)
|
||||
range_debug_indicator.radius = attack_range
|
||||
raycast.global_position = hero.camera.global_position
|
||||
|
||||
|
||||
func shoot():
|
||||
super.shoot()
|
||||
if raycast.is_colliding():
|
||||
var target = raycast.get_collider()
|
||||
if target != null:
|
||||
var target_hitbox = target.shape_owner_get_owner(raycast.get_collider_shape())
|
||||
if target_hitbox is Hitbox:
|
||||
hit(target, target_hitbox)
|
||||
networked_hit.rpc(get_tree().root.get_path_to(target), get_tree().root.get_path_to(target_hitbox))
|
||||
|
||||
|
||||
func hit(_target, target_hitbox : Hitbox):
|
||||
target_hitbox.damage(damage)
|
||||
|
||||
|
||||
@rpc("reliable")
|
||||
func networked_hit(target_path : String, target_hitbox_path : String):
|
||||
var target = get_tree().root.get_node(target_path)
|
||||
var target_hitbox = get_tree().root.get_node(target_hitbox_path) as Hitbox
|
||||
hit(target, target_hitbox)
|
25
Scripts/Weapons/projectile_weapon.gd
Normal file
25
Scripts/Weapons/projectile_weapon.gd
Normal file
@ -0,0 +1,25 @@
|
||||
extends Weapon
|
||||
class_name ProjectileWeapon
|
||||
|
||||
@export var projectile_scene : PackedScene
|
||||
|
||||
var force := 2.0
|
||||
var projectile_id := 0
|
||||
|
||||
|
||||
func shoot():
|
||||
super.shoot()
|
||||
var projectile = projectile_scene.instantiate() as Projectile
|
||||
projectile.position = global_position
|
||||
projectile.damage = damage
|
||||
projectile.direction = -global_transform.basis.z
|
||||
projectile.force = force
|
||||
projectile.name = str(multiplayer.get_unique_id()) + str(projectile_id)
|
||||
get_tree().root.add_child(projectile)
|
||||
projectile_id += 1
|
||||
|
||||
|
||||
@rpc("reliable")
|
||||
func networked_shoot():
|
||||
super.networked_shoot()
|
||||
shoot()
|
15
Scripts/Weapons/status_applying_weapon.gd
Normal file
15
Scripts/Weapons/status_applying_weapon.gd
Normal file
@ -0,0 +1,15 @@
|
||||
extends HitscanWeapon
|
||||
class_name StatusApplyingWeapon
|
||||
|
||||
@export var status_stats : StatusStats
|
||||
|
||||
|
||||
func hit(target, target_hitbox : Hitbox):
|
||||
super.hit(target, target_hitbox)
|
||||
target.status_manager.add_effect(build_status_object())
|
||||
|
||||
|
||||
func build_status_object() -> StatusEffect:
|
||||
var status = StatusEffect.new()
|
||||
status.stats = status_stats
|
||||
return status
|
58
Scripts/Weapons/weapon.gd
Normal file
58
Scripts/Weapons/weapon.gd
Normal file
@ -0,0 +1,58 @@
|
||||
extends Node3D
|
||||
class_name Weapon
|
||||
|
||||
@export var stats : CardText
|
||||
@export var animator : AnimationPlayer
|
||||
|
||||
var hero : Hero
|
||||
var trigger_held := false
|
||||
var second_trigger_held := false
|
||||
var time_since_firing := 0.0
|
||||
var time_between_shots := 0.0
|
||||
var damage := 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
time_between_shots = stats.get_attribute("Fire Delay")
|
||||
damage = stats.get_attribute("Damage")
|
||||
|
||||
|
||||
func set_hero(value):
|
||||
hero = value
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if time_since_firing < time_between_shots:
|
||||
time_since_firing += delta
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if trigger_held and time_since_firing >= time_between_shots:
|
||||
time_since_firing -= time_between_shots
|
||||
shoot()
|
||||
networked_shoot.rpc()
|
||||
|
||||
|
||||
func hold_trigger():
|
||||
trigger_held = true
|
||||
|
||||
|
||||
func release_trigger():
|
||||
trigger_held = false
|
||||
|
||||
|
||||
func hold_second_trigger():
|
||||
second_trigger_held = true
|
||||
|
||||
|
||||
func release_second_trigger():
|
||||
second_trigger_held = false
|
||||
|
||||
|
||||
func shoot():
|
||||
animator.play("shoot")
|
||||
|
||||
|
||||
@rpc
|
||||
func networked_shoot():
|
||||
animator.play("shoot")
|
Reference in New Issue
Block a user