🐛 Refactored AreaDamageComponent to be an ExplosiveDamageComponent

This commit is contained in:
Squinty 2024-04-14 21:20:02 +00:00
parent dc7896a591
commit 49a59e8c31
12 changed files with 1331 additions and 1340 deletions

View file

@ -1,4 +0,0 @@
extends Area3D
class_name AreaDamageComponent
@export var damage : int = 100

View file

@ -1,7 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://ds1hekx1dq1bg"]
[ext_resource type="Script" path="res://components/area_damage_component.gd" id="1_hn2e3"]
[node name="AreaDamage" type="Area3D"]
collision_layer = 4
script = ExtResource("1_hn2e3")

View file

@ -0,0 +1,16 @@
class_name ExplosiveDamageComponent extends Area3D
@export var damage : int = 100
@export var impulse_force : int = 1000
func _physics_process(_delta):
for body in get_overlapping_bodies():
if body is RigidBody3D:
var direction = (body.global_position - global_position).normalized()
body.apply_central_impulse(direction * impulse_force)
for area in get_overlapping_areas():
if area is HealthComponent and is_multiplayer_authority():
area.damage.rpc(damage)
set_physics_process(false)

View file

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://ds1hekx1dq1bg"]
[ext_resource type="Script" path="res://components/explosive_damage_component.gd" id="1_2uehk"]
[node name="ExplosiveDamage" type="Area3D"]
collision_layer = 0
collision_mask = 5
monitorable = false
script = ExtResource("1_2uehk")

View file

@ -12,10 +12,9 @@ signal health_changed(value : int)
func _ready():
heal_full()
area_entered.connect(_on_area_entered)
@rpc("call_local")
func _damage(amount : int) -> void:
func damage(amount : int) -> void:
health = clampf(health - amount, 0.0, max_health)
if health == 0.0:
health_zeroed.emit()
@ -29,10 +28,3 @@ func heal_full():
return
_heal.rpc(max_health)
func _on_area_entered(area : Area3D):
if not is_multiplayer_authority():
return
if area is AreaDamageComponent:
_damage.rpc(area.damage)

View file

@ -4,8 +4,8 @@
[ext_resource type="Shape3D" uid="uid://dkwljsgaflf31" path="res://entities/player/collision_shape.res" id="2_sgbmt"]
[node name="HealthComponent" type="Area3D"]
collision_layer = 0
collision_mask = 4
collision_layer = 4
collision_mask = 0
script = ExtResource("1_00xis")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]