This commit is contained in:
2025-03-17 20:34:59 -07:00
parent 79bf3d598b
commit 5e863dfd81
221 changed files with 4610 additions and 634 deletions

View File

@@ -1,4 +1,4 @@
using Chickensoft.AutoInject;
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using System;
@@ -22,39 +22,39 @@ public partial class NavigationAgentClient : Node3D, INavigationAgentClient
public void Setup()
{
NavAgent.VelocityComputed += NavAgent_VelocityComputed;
NavAgent.TargetReached += NavAgent_TargetReached;
NavAgent.VelocityComputed += NavAgent_VelocityComputed;
NavAgent.TargetReached += NavAgent_TargetReached;
var rng = new RandomNumberGenerator();
rng.Randomize();
_patrolTimer.Timeout += OnPatrolTimeout;
_patrolTimer.WaitTime = rng.RandfRange(7.0f, 15.0f);
var rng = new RandomNumberGenerator();
rng.Randomize();
_patrolTimer.Timeout += OnPatrolTimeout;
_patrolTimer.WaitTime = rng.RandfRange(7.0f, 15.0f);
_thinkTimer = new Timer
{
WaitTime = 0.4f
};
AddChild(_thinkTimer);
_thinkTimer.Timeout += NavAgent_TargetReached;
_thinkTimer.Start();
_thinkTimer = new Timer
{
WaitTime = 0.4f
};
AddChild(_thinkTimer);
_thinkTimer.Timeout += NavAgent_TargetReached;
_thinkTimer.Start();
}
private void NavAgent_VelocityComputed(Vector3 safeVelocity)
{
if (!_canMove)
return;
if (!_canMove)
return;
var enemy = GetOwner() as IEnemy;
enemy.Move(safeVelocity);
var enemy = GetOwner() as IEnemy;
enemy.Move(safeVelocity);
}
public void CalculateVelocity(Vector3 currentPosition, bool canMove)
{
_canMove = canMove;
var nextPathPosition = NavAgent.GetNextPathPosition();
_canMove = canMove;
var nextPathPosition = NavAgent.GetNextPathPosition();
var newVelocity = currentPosition.DirectionTo(nextPathPosition) * 2f;
NavAgent.Velocity = newVelocity;
var newVelocity = currentPosition.DirectionTo(nextPathPosition) * 2f;
NavAgent.Velocity = newVelocity;
}
public void SetTarget(Vector3 target) => Task.Delay(TimeSpan.FromSeconds(0.4)).ContinueWith(_ => _currentTarget = new Vector3(target.X, -1.75f, target.Z));
@@ -63,15 +63,15 @@ public partial class NavigationAgentClient : Node3D, INavigationAgentClient
private void NavAgent_TargetReached()
{
NavAgent.TargetPosition = _currentTarget;
NavAgent.TargetPosition = _currentTarget;
}
private void OnPatrolTimeout()
{
var rng = new RandomNumberGenerator();
rng.Randomize();
_patrolTimer.WaitTime = rng.RandfRange(5.0f, 10.0f);
var enemy = GetOwner() as ICanPatrol;
enemy.Patrol();
var rng = new RandomNumberGenerator();
rng.Randomize();
_patrolTimer.WaitTime = rng.RandfRange(5.0f, 10.0f);
var enemy = GetOwner() as ICanPatrol;
enemy.Patrol();
}
}