some damage interfacing
This commit is contained in:
9
interfaces/IDamageMaker.cs
Normal file
9
interfaces/IDamageMaker.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Godot;
|
||||
|
||||
namespace Movementtests.interfaces;
|
||||
|
||||
public interface IDamageMaker
|
||||
{
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
}
|
||||
1
interfaces/IDamageMaker.cs.uid
Normal file
1
interfaces/IDamageMaker.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://wdqo51131g5
|
||||
@@ -2,5 +2,5 @@ namespace Movementtests.interfaces;
|
||||
|
||||
public interface IDamageable
|
||||
{
|
||||
void TakeDamage();
|
||||
void TakeDamage(RDamage damage);
|
||||
}
|
||||
@@ -1,11 +1,19 @@
|
||||
[gd_scene load_steps=15 format=3 uid="uid://q7uc1h2jpbd2"]
|
||||
[gd_scene load_steps=19 format=3 uid="uid://q7uc1h2jpbd2"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bei4nhkf8lwdo" path="res://player_controller/PlayerController.tscn" id="1_62kkh"]
|
||||
[ext_resource type="Material" uid="uid://31aulub2nqov" path="res://assets/greybox/m_greybox.tres" id="2_3uydm"]
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="2_sysok"]
|
||||
[ext_resource type="PackedScene" uid="uid://dxt0e2ugmttqq" path="res://scenes/enemies/first_enemy.tscn" id="3_3uydm"]
|
||||
[ext_resource type="Script" uid="uid://b2vdwkiqauhk3" path="res://scenes/enemies/EnemyInitInputs.cs" id="4_nd7vd"]
|
||||
[ext_resource type="PackedScene" uid="uid://cmlud1hwkd6sv" path="res://scenes/enemies/flying_enemy.tscn" id="5_8fd2t"]
|
||||
[ext_resource type="Script" uid="uid://do0dic4r3ri0s" path="res://scenes/enemies/FlyingEnemyInputs.cs" id="6_7m3bq"]
|
||||
[ext_resource type="Resource" uid="uid://otfc2snh8umc" path="res://scenes/enemies/first_enemy_damage.tres" id="6_dmw1t"]
|
||||
[ext_resource type="Resource" uid="uid://dgo65k2ceqfvy" path="res://scenes/enemies/flying_enemy_damage.tres" id="9_gp7s3"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_gp7s3"]
|
||||
script = ExtResource("2_sysok")
|
||||
DamageDealt = 3.0
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_0xm2m"]
|
||||
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
|
||||
@@ -61,6 +69,7 @@ metadata/_custom_type_script = "uid://do0dic4r3ri0s"
|
||||
[node name="Player" parent="." instance=ExtResource("1_62kkh")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 7.5)
|
||||
TutorialDone = true
|
||||
GetDamageDealt = SubResource("Resource_gp7s3")
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_1bvp3")
|
||||
@@ -126,23 +135,28 @@ material = ExtResource("2_3uydm")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_8fd2t")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="Enemy2" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("3_3uydm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_7m3bq")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="Enemy3" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("3_3uydm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.5, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_sysok")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="FlyingEnemy" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("5_8fd2t")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8, 7, -16)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_caohq")
|
||||
GetDamageDealt = ExtResource("9_gp7s3")
|
||||
|
||||
[node name="FlyingEnemy2" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("5_8fd2t")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 7, -16)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_dmw1t")
|
||||
GetDamageDealt = ExtResource("9_gp7s3")
|
||||
|
||||
@@ -7,7 +7,7 @@ using Movementtests.systems;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
using RustyOptions;
|
||||
|
||||
public partial class PlayerController : CharacterBody3D, IDamageable, IKnockbackable
|
||||
public partial class PlayerController : CharacterBody3D, IDamageable, IKnockbackable, IDamageMaker
|
||||
{
|
||||
// Enums
|
||||
public enum AllowedInputs
|
||||
@@ -59,6 +59,11 @@ public partial class PlayerController : CharacterBody3D, IDamageable, IKnockback
|
||||
[Export] public Marker3D TutorialWeaponTarget;
|
||||
[Export] public bool TutorialDone { get; set; }
|
||||
|
||||
[ExportCategory("Combat")]
|
||||
[ExportGroup("Damage")]
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
|
||||
[ExportCategory("Movement")]
|
||||
[ExportGroup("Ground")]
|
||||
[Export(PropertyHint.Range, "0,20,0.1,or_greater")]
|
||||
@@ -1571,26 +1576,6 @@ public partial class PlayerController : CharacterBody3D, IDamageable, IKnockback
|
||||
DashIndicatorMesh.Visible = false;
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Hit Management ///////
|
||||
///////////////////////////
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
if (_aiming.Active && WeaponSystem.InHandState.Active)
|
||||
{
|
||||
ThrowWeapon();
|
||||
}
|
||||
|
||||
if (!WeaponSystem.InHandState.Active) return;
|
||||
|
||||
var bodies = WeaponHitbox.GetOverlappingBodies();
|
||||
foreach (var body in bodies)
|
||||
{
|
||||
if(body is IDamageable spawnable)
|
||||
spawnable.TakeDamage();
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Parry Management ///////
|
||||
///////////////////////////
|
||||
@@ -1741,9 +1726,29 @@ public partial class PlayerController : CharacterBody3D, IDamageable, IKnockback
|
||||
DashIndicatorNode.LookAt(WeaponSystem.GlobalPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage()
|
||||
|
||||
public void TakeDamage(RDamage damage)
|
||||
{
|
||||
GD.Print("Ouch!");
|
||||
GD.Print("Ouch", damage.DamageDealt);
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Hit Management ///////
|
||||
///////////////////////////
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
if (_aiming.Active && WeaponSystem.InHandState.Active)
|
||||
{
|
||||
ThrowWeapon();
|
||||
}
|
||||
|
||||
if (!WeaponSystem.InHandState.Active) return;
|
||||
|
||||
var bodies = WeaponHitbox.GetOverlappingBodies();
|
||||
foreach (var body in bodies)
|
||||
{
|
||||
if(body is IDamageable spawnable)
|
||||
spawnable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
resource_definitions/RDamage.cs
Normal file
18
resource_definitions/RDamage.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RDamage : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float DamageDealt;
|
||||
|
||||
public RDamage()
|
||||
{
|
||||
DamageDealt = 1.0f;
|
||||
}
|
||||
public RDamage(float damageDealt)
|
||||
{
|
||||
DamageDealt = damageDealt;
|
||||
}
|
||||
}
|
||||
1
resource_definitions/RDamage.cs.uid
Normal file
1
resource_definitions/RDamage.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://jitubgv6judn
|
||||
@@ -5,7 +5,7 @@ using System;
|
||||
public partial class EnemyInitInputs : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed = 5.0f;
|
||||
public float Speed;
|
||||
|
||||
public EnemyInitInputs()
|
||||
{
|
||||
|
||||
@@ -4,13 +4,16 @@ using Movementtests.interfaces;
|
||||
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FirstEnemy : CharacterBody3D, IDamageable, IKillable, IKnockbackable
|
||||
public partial class FirstEnemy : CharacterBody3D, IDamageable, IKillable, IKnockbackable, IDamageMaker
|
||||
{
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
public EnemyInitInputs Inputs;
|
||||
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
|
||||
private RayCast3D _wallInFrontRayCast;
|
||||
private Area3D _damageBox;
|
||||
@@ -22,11 +25,6 @@ public partial class FirstEnemy : CharacterBody3D, IDamageable, IKillable, IKnoc
|
||||
_damageBox.BodyEntered += OnDamageBoxTriggered;
|
||||
}
|
||||
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
if(body is IDamageable damageable) damageable.TakeDamage();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var target = Target.GlobalPosition;
|
||||
@@ -48,8 +46,13 @@ public partial class FirstEnemy : CharacterBody3D, IDamageable, IKillable, IKnoc
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public void TakeDamage()
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
GD.Print("Emotional daaamaaage!");
|
||||
if(body is IDamageable damageable) damageable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
|
||||
public void TakeDamage(RDamage damage)
|
||||
{
|
||||
GD.Print("Emotional daaamaaage!", damage.DamageDealt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,16 @@ using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKnockbackable
|
||||
public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKnockbackable, IDamageMaker
|
||||
{
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
public FlyingEnemyInputs Inputs;
|
||||
public FlyingEnemyInputs Inputs { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
|
||||
private RayCast3D _groundDistanceRaycast;
|
||||
private Area3D _damageBox;
|
||||
@@ -20,7 +23,7 @@ public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKno
|
||||
public override void _Ready()
|
||||
{
|
||||
_groundDistanceRaycast = GetNode<RayCast3D>("GroundDistance");
|
||||
_groundDistanceRaycast.TargetPosition = new Vector3(0, -Inputs.TargetHeight, 0);
|
||||
_groundDistanceRaycast.TargetPosition = new Vector3(0, 0, 0);
|
||||
|
||||
_damageBox = GetNode<Area3D>("DamageBox");
|
||||
_damageBox.BodyEntered += OnDamageBoxTriggered;
|
||||
@@ -28,26 +31,20 @@ public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKno
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
if(body is IDamageable damageable) damageable.TakeDamage();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var target = Target.GlobalPosition;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
Vector3 velocity = Velocity;
|
||||
|
||||
var targetPlane = new Vector3(target.X, GlobalPosition.Y, target.Z);
|
||||
LookAt(targetPlane);
|
||||
LookAt(target);
|
||||
|
||||
// Check if we have a direct line of sight to the player
|
||||
if (!_movingToDesiredHeight)
|
||||
{
|
||||
velocity = direction * Inputs.Speed;
|
||||
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count > 0)
|
||||
@@ -60,11 +57,12 @@ public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKno
|
||||
{
|
||||
velocity = _randomDirection * Inputs.Speed;
|
||||
|
||||
if (!_groundDistanceRaycast.IsColliding())
|
||||
var groundQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition, GlobalPosition+Vector3.Down*Inputs.TargetHeight, _groundDistanceRaycast.CollisionMask);
|
||||
var groundResult = spaceState.IntersectRay(groundQuery);
|
||||
if (groundResult.Count == 0)
|
||||
{
|
||||
velocity.Y = 0;
|
||||
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count == 0)
|
||||
@@ -78,8 +76,13 @@ public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKno
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public void TakeDamage()
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
GD.Print("Oh no I'm falling");
|
||||
if(body is IDamageable damageable) damageable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
|
||||
public void TakeDamage(RDamage damage)
|
||||
{
|
||||
GD.Print("Oh no I'm falling!", damage.DamageDealt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ using System;
|
||||
public partial class FlyingEnemyInputs : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed = 5.0f;
|
||||
public float Speed;
|
||||
|
||||
[Export(PropertyHint.Range, "0,100,1,or_greater")]
|
||||
public float TargetHeight = 50.0f;
|
||||
public float TargetHeight;
|
||||
|
||||
public FlyingEnemyInputs()
|
||||
{
|
||||
|
||||
8
scenes/enemies/first_enemy_damage.tres
Normal file
8
scenes/enemies/first_enemy_damage.tres
Normal file
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="RDamage" load_steps=2 format=3 uid="uid://otfc2snh8umc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="1_y415a"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_y415a")
|
||||
DamageDealt = 2.0
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
8
scenes/enemies/flying_enemy_damage.tres
Normal file
8
scenes/enemies/flying_enemy_damage.tres
Normal file
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="RDamage" load_steps=2 format=3 uid="uid://dgo65k2ceqfvy"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="1_h6law"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_h6law")
|
||||
DamageDealt = 1.0
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
Reference in New Issue
Block a user