Files
Gen_Hack-and-Slash-Roguelit…/Client/Assets/Scripts/AI/JobBase.cs
2025-08-27 13:56:22 +08:00

97 lines
2.2 KiB
C#

using System.Collections.Generic;
using Base;
using Data;
using Managers;
using Prefab;
using Unity.VisualScripting;
using UnityEngine;
namespace AI
{
public abstract class JobBase
{
public Entity.Entity entity;
protected int timeoutTicks = 300;
public bool Running => timeoutTicks > 0;
protected abstract void UpdateJob();
public virtual void StartJob(Entity.Entity target)
{
entity = target;
}
public bool Update()
{
if (!Running)
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);
Vector3 move = new(Random.Range(-10, 10), Random.Range(-10, 10));
var targetPosition = entity.transform.position + move;
entity.SetTarget(targetPosition);
entity.IsChase = false;
}
protected override void UpdateJob()
{
entity.TryMove();
}
override public void StopJob()
{
base.StopJob();
entity.IsChase = true;
}
}
public class IdleJob : JobBase
{
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();
}
}
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;
}
}
}