2025-08-07 16:44:43 +08:00
|
|
|
using System.Collections.Generic;
|
2025-07-21 13:58:58 +08:00
|
|
|
using Base;
|
2025-08-27 13:56:22 +08:00
|
|
|
using Data;
|
|
|
|
using Managers;
|
2025-08-07 16:44:43 +08:00
|
|
|
using Prefab;
|
2025-07-21 13:58:58 +08:00
|
|
|
using Unity.VisualScripting;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace AI
|
|
|
|
{
|
|
|
|
public abstract class JobBase
|
|
|
|
{
|
|
|
|
public Entity.Entity entity;
|
2025-07-25 19:16:58 +08:00
|
|
|
protected int timeoutTicks = 300;
|
2025-08-07 16:44:43 +08:00
|
|
|
public bool Running => timeoutTicks > 0;
|
2025-07-21 13:58:58 +08:00
|
|
|
|
2025-08-07 16:44:43 +08:00
|
|
|
protected abstract void UpdateJob();
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void StartJob(Entity.Entity target)
|
2025-07-21 13:58:58 +08:00
|
|
|
{
|
|
|
|
entity = target;
|
|
|
|
}
|
|
|
|
public bool Update()
|
|
|
|
{
|
2025-08-07 16:44:43 +08:00
|
|
|
if (!Running)
|
2025-07-21 13:58:58 +08:00
|
|
|
return false;
|
|
|
|
UpdateJob();
|
|
|
|
timeoutTicks--;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
public virtual void StopJob()
|
|
|
|
{
|
|
|
|
timeoutTicks = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public class WanderJob : JobBase
|
|
|
|
{
|
|
|
|
public override void StartJob(Entity.Entity target)
|
|
|
|
{
|
|
|
|
base.StartJob(target);
|
2025-08-07 16:44:43 +08:00
|
|
|
Vector3 move = new(Random.Range(-10, 10), Random.Range(-10, 10));
|
|
|
|
var targetPosition = entity.transform.position + move;
|
2025-07-21 13:58:58 +08:00
|
|
|
entity.SetTarget(targetPosition);
|
|
|
|
entity.IsChase = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateJob()
|
|
|
|
{
|
|
|
|
entity.TryMove();
|
|
|
|
}
|
|
|
|
|
|
|
|
override public void StopJob()
|
|
|
|
{
|
|
|
|
base.StopJob();
|
|
|
|
entity.IsChase = true;
|
|
|
|
}
|
2025-08-07 16:44:43 +08:00
|
|
|
|
2025-07-21 13:58:58 +08:00
|
|
|
}
|
2025-08-07 16:44:43 +08:00
|
|
|
public class IdleJob : JobBase
|
2025-07-25 19:16:58 +08:00
|
|
|
{
|
|
|
|
override public void StartJob(Entity.Entity target)
|
|
|
|
{
|
|
|
|
base.StartJob(target);
|
|
|
|
timeoutTicks = 500;
|
|
|
|
}
|
|
|
|
protected override void UpdateJob()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public class MoveJob : JobBase
|
|
|
|
{
|
|
|
|
protected override void UpdateJob()
|
|
|
|
{
|
|
|
|
entity.TryMove();
|
|
|
|
}
|
|
|
|
}
|
2025-08-07 16:44:43 +08:00
|
|
|
|
2025-08-27 13:56:22 +08:00
|
|
|
public class AttackJob : JobBase
|
|
|
|
{
|
|
|
|
private Entity.Entity attackTarget;
|
|
|
|
protected override void UpdateJob()
|
|
|
|
{
|
|
|
|
entity.TryMove();
|
|
|
|
}
|
|
|
|
|
|
|
|
override public void StartJob(Entity.Entity target)
|
|
|
|
{
|
|
|
|
base.StartJob(target);
|
|
|
|
attackTarget =
|
|
|
|
EntityManage.Instance
|
|
|
|
.FindNearestEntityByRelation(target.currentDimensionId, target.entityPrefab, Relation.Hostile)
|
|
|
|
?.entity;
|
|
|
|
}
|
|
|
|
}
|
2025-08-25 18:24:12 +08:00
|
|
|
|
2025-07-21 13:58:58 +08:00
|
|
|
}
|