using System;
using Goap.Agent.Core;
using Goap.Core;
using UnityEngine;
namespace Goap.Runtime
{
public abstract class LocalTargetSensorBase : ILocalTargetSensor
{
public ITargetKey Key => this.Config.Key;
public ITargetSensorConfig Config { get; private set; }
public virtual ISensorTimer Timer => SensorTimer.Always;
public void SetConfig(ITargetSensorConfig config) => this.Config = config;
public abstract void Created();
public abstract void Update();
public Type[] GetKeys() => new[] { TypeReSolveHelper.ResolveType(this.Key) };
///
/// Senses the world data using this sensor. Don't override this method, override the other Sense method instead.
///
/// The world data.
/// The action receiver.
/// The component references.
public void Sense(IWorldData worldData, IActionReceiver agent, IComponentReference references)
{
var tmp_WorldKey = TypeReSolveHelper.ResolveType(this.Key);
var state = worldData.GetTargetState(tmp_WorldKey);
if (!this.Timer.ShouldSense(state?.Timer))
return;
var tmp_Target = this.Sense(agent, references, state?.Value);
worldData.SetTarget(tmp_WorldKey, tmp_Target);
}
///
/// Senses the world data using the specified action receiver, component references, and existing target.
///
/// The action receiver.
/// Use this to get cached component references on the agent.
/// The existing target. (The previously returned instance by this sensor).
/// The sensed target.
public abstract ITarget Sense(IActionReceiver agent, IComponentReference references, ITarget existingTarget);
[Obsolete("This should not be used anymore! Use 'Sense(IActionReceiver agent, IComponentReference references, ITarget existingTarget) instead'")]
public virtual ITarget Sense(IActionReceiver agent, IComponentReference references)
{
throw new GoapException("This should not be called anymore!");
}
[Obsolete("This should not be used anymore! Use 'Sense(IActionReceiver agent, IComponentReference references)'")]
public virtual ITarget Sense(IMonoAgent agent, IComponentReference references)
{
throw new GoapException("This should not be called anymore!");
}
}
}