reorganizing stuff
This commit is contained in:
23
components/damage/CDamageable.cs
Normal file
23
components/damage/CDamageable.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class CDamageable : Node, IDamageable
|
||||
{
|
||||
public event Action<IDamageable, DamageRecord> DamageTaken;
|
||||
|
||||
[Export]
|
||||
public RDamageModifier[] DamageModifiers { get; set; }
|
||||
|
||||
|
||||
public DamageRecord TakeDamage(DamageRecord damageRecord)
|
||||
{
|
||||
var finalDamage = 0f;
|
||||
foreach (var damageable in DamageModifiers.ToIDamageables())
|
||||
finalDamage += damageable.TakeDamage(damageRecord).Damage.DamageDealt;
|
||||
var finalDamageRecord = damageRecord with { Damage = new RDamage(finalDamage, damageRecord.Damage.DamageType) };
|
||||
DamageTaken?.Invoke(this, finalDamageRecord);
|
||||
return finalDamageRecord;
|
||||
}
|
||||
}
|
||||
1
components/damage/CDamageable.cs.uid
Normal file
1
components/damage/CDamageable.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b0u23nkpaimyc
|
||||
6
components/damage/CDamageable.tscn
Normal file
6
components/damage/CDamageable.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://hpsg4fqwrx1u"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b0u23nkpaimyc" path="res://components/damage/CDamageable.cs" id="1_qp8bd"]
|
||||
|
||||
[node name="CDamageable" type="Node"]
|
||||
script = ExtResource("1_qp8bd")
|
||||
24
components/damage/RDamage.cs
Normal file
24
components/damage/RDamage.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.systems.damage;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RDamage : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float DamageDealt = 1.0f;
|
||||
|
||||
[Export]
|
||||
public EDamageTypes DamageType = EDamageTypes.Normal;
|
||||
|
||||
public RDamage()
|
||||
{
|
||||
DamageDealt = 1.0f;
|
||||
DamageType = EDamageTypes.Normal;
|
||||
}
|
||||
public RDamage(float damageDealt, EDamageTypes damageType)
|
||||
{
|
||||
DamageDealt = damageDealt;
|
||||
DamageType = damageType;
|
||||
}
|
||||
}
|
||||
1
components/damage/RDamage.cs.uid
Normal file
1
components/damage/RDamage.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://jitubgv6judn
|
||||
37
components/damage/RDamageModifier.cs
Normal file
37
components/damage/RDamageModifier.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.systems.damage;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RDamageModifier : Resource, IDamageable
|
||||
{
|
||||
public event Action<IDamageable, DamageRecord> DamageTaken;
|
||||
|
||||
[Export]
|
||||
public EDamageTypes DamageType = EDamageTypes.Normal;
|
||||
[Export]
|
||||
public float Modifier = 1.0f;
|
||||
|
||||
public RDamageModifier()
|
||||
{
|
||||
Modifier = 1.0f;
|
||||
DamageType = EDamageTypes.Normal;
|
||||
}
|
||||
public RDamageModifier(EDamageTypes damageType, float modifier)
|
||||
{
|
||||
Modifier = modifier;
|
||||
DamageType = damageType;
|
||||
}
|
||||
|
||||
public DamageRecord TakeDamage(DamageRecord damageRecord)
|
||||
{
|
||||
if (damageRecord.Damage.DamageType != DamageType)
|
||||
return damageRecord with { Damage = new RDamage(0, damageRecord.Damage.DamageType) };
|
||||
|
||||
var finalDamage = damageRecord.Damage.DamageDealt * Modifier;
|
||||
var finalDamageRecord = damageRecord with { Damage = new RDamage(finalDamage, damageRecord.Damage.DamageType) };
|
||||
DamageTaken?.Invoke(this, finalDamageRecord);
|
||||
return finalDamageRecord;
|
||||
}
|
||||
}
|
||||
1
components/damage/RDamageModifier.cs.uid
Normal file
1
components/damage/RDamageModifier.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b6y3ugfydvch0
|
||||
33
components/health/CHealth.cs
Normal file
33
components/health/CHealth.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class CHealth : Node, IHealthable
|
||||
{
|
||||
public event Action<IHealthable, float> HealthChanged;
|
||||
public event Action<IHealthable> HealthDepleted;
|
||||
|
||||
[Export]
|
||||
public RHealth RHealth { get; set; }
|
||||
|
||||
public float CurrentHealth { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CurrentHealth = RHealth.StartingHealth;
|
||||
}
|
||||
|
||||
public void ReduceHealth(IDamageable source, DamageRecord damageRecord)
|
||||
{
|
||||
GD.Print(CurrentHealth);
|
||||
CurrentHealth -= damageRecord.Damage.DamageDealt;
|
||||
HealthChanged?.Invoke(this, CurrentHealth);
|
||||
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
CurrentHealth = 0;
|
||||
HealthDepleted?.Invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
components/health/CHealth.cs.uid
Normal file
1
components/health/CHealth.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bjwrpv3jpsc1e
|
||||
6
components/health/CHealth.tscn
Normal file
6
components/health/CHealth.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://c4ikbhojckpnc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bjwrpv3jpsc1e" path="res://components/health/CHealth.cs" id="1_75uyt"]
|
||||
|
||||
[node name="CHealth" type="Node"]
|
||||
script = ExtResource("1_75uyt")
|
||||
12
components/health/RDeathEffect.cs
Normal file
12
components/health/RDeathEffect.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RDeathEffect : Resource, IKillable
|
||||
{
|
||||
public void Kill(IHealthable source)
|
||||
{
|
||||
GD.Print($"Death Effect triggered on {source}");
|
||||
}
|
||||
}
|
||||
1
components/health/RDeathEffect.cs.uid
Normal file
1
components/health/RDeathEffect.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b4cwruitopcee
|
||||
20
components/health/RHealth.cs
Normal file
20
components/health/RHealth.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RHealth : Resource
|
||||
{
|
||||
[Export]
|
||||
public float StartingHealth = 100.0f;
|
||||
|
||||
public RHealth()
|
||||
{
|
||||
StartingHealth = 100.0f;
|
||||
}
|
||||
|
||||
public RHealth(float startingHealth)
|
||||
{
|
||||
StartingHealth = startingHealth;
|
||||
}
|
||||
}
|
||||
1
components/health/RHealth.cs.uid
Normal file
1
components/health/RHealth.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://baiapod3csndf
|
||||
25
components/knockback/CKnockback.cs
Normal file
25
components/knockback/CKnockback.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class CKnockback : Node3D, IKnockbackable
|
||||
{
|
||||
[Export] public RKnockback RKnockback { get; set;}
|
||||
|
||||
private DamageRecord _damageRecord = null;
|
||||
|
||||
public void RegisterKnockback(IDamageable source, DamageRecord damageRecord)
|
||||
{
|
||||
_damageRecord = damageRecord;
|
||||
}
|
||||
|
||||
public Vector3 ComputeKnockback()
|
||||
{
|
||||
if (_damageRecord == null) return Vector3.Zero;
|
||||
|
||||
var knockbackDirection = GlobalPosition - _damageRecord.Source.GlobalPosition;
|
||||
_damageRecord = null;
|
||||
return knockbackDirection.Normalized() * RKnockback.Modifier;
|
||||
}
|
||||
}
|
||||
1
components/knockback/CKnockback.cs.uid
Normal file
1
components/knockback/CKnockback.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b8dprpcjeac7e
|
||||
12
components/knockback/CKnockback.tscn
Normal file
12
components/knockback/CKnockback.tscn
Normal file
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bctpe34ddamg5"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b8dprpcjeac7e" path="res://components/knockback/CKnockback.cs" id="1_ix2yg"]
|
||||
[ext_resource type="Script" uid="uid://b44cse62qru7j" path="res://components/knockback/RKnockback.cs" id="2_uqiml"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_gbu2d"]
|
||||
script = ExtResource("2_uqiml")
|
||||
metadata/_custom_type_script = "uid://b44cse62qru7j"
|
||||
|
||||
[node name="CKnockback" type="Node3D"]
|
||||
script = ExtResource("1_ix2yg")
|
||||
RKnockback = SubResource("Resource_gbu2d")
|
||||
19
components/knockback/RKnockback.cs
Normal file
19
components/knockback/RKnockback.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RKnockback : Resource
|
||||
{
|
||||
[Export]
|
||||
public float Modifier = 1.0f;
|
||||
|
||||
public RKnockback()
|
||||
{
|
||||
Modifier = 1.0f;
|
||||
}
|
||||
public RKnockback(float modifier)
|
||||
{
|
||||
Modifier = modifier;
|
||||
}
|
||||
}
|
||||
1
components/knockback/RKnockback.cs.uid
Normal file
1
components/knockback/RKnockback.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b44cse62qru7j
|
||||
61
components/movement/CFlyingMovement.cs
Normal file
61
components/movement/CFlyingMovement.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Godot;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
namespace Movementtests.scenes.movement;
|
||||
|
||||
public partial class CFlyingMovement : Node3D, IMoveable
|
||||
{
|
||||
[Export] public RMovement RMovement { get; set; }
|
||||
|
||||
[Export(PropertyHint.Layers3DPhysics)]
|
||||
public uint TerrainCollision { get; set; } = 1;
|
||||
|
||||
private bool _movingToDesiredHeight = true;
|
||||
private Vector3 _randomDirection;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
|
||||
public Vector3 ComputeVelocity(MovementInputs inputs)
|
||||
{
|
||||
var velocity = inputs.Velocity;
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var target = inputs.TargetLocation;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
// Check if we have a direct line of sight to the player
|
||||
if (!_movingToDesiredHeight)
|
||||
{
|
||||
velocity = velocity.Lerp(direction * RMovement.Speed, (float) inputs.delta * RMovement.Acceleration);
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, TerrainCollision);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count > 0)
|
||||
{
|
||||
_movingToDesiredHeight = true;
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = velocity.Lerp(_randomDirection * RMovement.Speed, (float) inputs.delta * RMovement.Acceleration);
|
||||
|
||||
var groundQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition, GlobalPosition+Vector3.Down*RMovement.TargetHeight, TerrainCollision);
|
||||
var groundResult = spaceState.IntersectRay(groundQuery);
|
||||
if (groundResult.Count == 0)
|
||||
{
|
||||
velocity.Y = 0;
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, TerrainCollision);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count == 0)
|
||||
{
|
||||
_movingToDesiredHeight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
}
|
||||
1
components/movement/CFlyingMovement.cs.uid
Normal file
1
components/movement/CFlyingMovement.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cps1rbkxs3nvq
|
||||
7
components/movement/CFlyingMovement.tscn
Normal file
7
components/movement/CFlyingMovement.tscn
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dmw5ibwrb483f"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cps1rbkxs3nvq" path="res://components/movement/CFlyingMovement.cs" id="1_i26q2"]
|
||||
|
||||
[node name="CFlyingMovement" type="Node3D"]
|
||||
script = ExtResource("1_i26q2")
|
||||
CollisionMask = 256
|
||||
34
components/movement/CGroundedMovement.cs
Normal file
34
components/movement/CGroundedMovement.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Godot;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
namespace Movementtests.scenes.movement;
|
||||
|
||||
public partial class CGroundedMovement : Node3D, IMoveable
|
||||
{
|
||||
[Export] public RMovement RMovement { get; set; }
|
||||
|
||||
[Export]
|
||||
public RayCast3D WallInFrontRayCast { get; set; }
|
||||
|
||||
|
||||
public Vector3 ComputeVelocity(MovementInputs inputs)
|
||||
{
|
||||
var velocity = inputs.Velocity;
|
||||
var target = inputs.TargetLocation;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
|
||||
var targetPlane = new Vector3(target.X, GlobalPosition.Y, target.Z);
|
||||
LookAt(targetPlane);
|
||||
float xAcc = (float) Mathf.Lerp(velocity.X, direction.X * RMovement.Speed, inputs.delta * RMovement.Acceleration);
|
||||
float zAcc = (float) Mathf.Lerp(velocity.Z, direction.Z * RMovement.Speed, inputs.delta * RMovement.Acceleration);
|
||||
velocity.X = xAcc;
|
||||
velocity.Z = zAcc;
|
||||
|
||||
if (WallInFrontRayCast.IsColliding())
|
||||
velocity.Y = RMovement.Speed;
|
||||
else if (!inputs.isOnFloor)
|
||||
velocity += inputs.gravity * (float)inputs.delta * RMovement.GravityModifier;
|
||||
|
||||
return velocity;
|
||||
}
|
||||
}
|
||||
1
components/movement/CGroundedMovement.cs.uid
Normal file
1
components/movement/CGroundedMovement.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bdag2eeixw2lt
|
||||
6
components/movement/CGroundedMovement.tscn
Normal file
6
components/movement/CGroundedMovement.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dbr7ioio158ew"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bdag2eeixw2lt" path="res://components/movement/CGroundedMovement.cs" id="1_e0agf"]
|
||||
|
||||
[node name="CGroundedMovement" type="Node3D"]
|
||||
script = ExtResource("1_e0agf")
|
||||
31
components/movement/RMovement.cs
Normal file
31
components/movement/RMovement.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RMovement : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed { get; set;}
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Acceleration { get; set;}
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float GravityModifier { get; set;}
|
||||
|
||||
[Export(PropertyHint.Range, "0,20,1,or_greater")]
|
||||
public float TargetHeight { get; set;}
|
||||
|
||||
public RMovement()
|
||||
{
|
||||
Speed = 3.0f;
|
||||
Acceleration = 1.0f;
|
||||
GravityModifier = 1.0f;
|
||||
TargetHeight = 10.0f;
|
||||
}
|
||||
public RMovement(float speed, float acceleration, float gravityModifier, float targetHeight)
|
||||
{
|
||||
Speed = speed;
|
||||
Acceleration = acceleration;
|
||||
GravityModifier = gravityModifier;
|
||||
TargetHeight = targetHeight;
|
||||
}
|
||||
}
|
||||
1
components/movement/RMovement.cs.uid
Normal file
1
components/movement/RMovement.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dtpxijlnb2c5
|
||||
Reference in New Issue
Block a user