2022-01-02 20:52:31 +00:00
|
|
|
using SanAndreasUnity.Behaviours.Peds.States;
|
2022-01-02 19:31:57 +00:00
|
|
|
using SanAndreasUnity.Importing.Items.Definitions;
|
2021-09-19 20:04:06 +00:00
|
|
|
using SanAndreasUnity.Importing.Paths;
|
|
|
|
using SanAndreasUnity.Utilities;
|
2022-01-02 19:31:57 +00:00
|
|
|
using System.Collections.Generic;
|
2021-09-19 20:04:06 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Behaviours.Peds.AI
|
|
|
|
{
|
2021-09-26 18:26:56 +00:00
|
|
|
public class WalkAroundState : BaseState, IPathMovementState
|
2021-09-19 20:04:06 +00:00
|
|
|
{
|
|
|
|
private readonly PathMovementData _pathMovementData = new PathMovementData();
|
2021-09-26 18:26:56 +00:00
|
|
|
public PathMovementData PathMovementData => _pathMovementData;
|
2021-09-19 20:04:06 +00:00
|
|
|
|
2021-10-17 16:36:30 +00:00
|
|
|
private ChaseState _chaseState;
|
|
|
|
|
2022-01-02 19:31:57 +00:00
|
|
|
private float _timeWhenStartedSurrendering = 0f;
|
|
|
|
public float TimeSinceStartedSurrendering => Time.time - _timeWhenStartedSurrendering;
|
|
|
|
public bool IsSurrendering => this.TimeSinceStartedSurrendering < 4f;
|
|
|
|
|
2021-10-17 16:36:30 +00:00
|
|
|
|
|
|
|
protected internal override void OnAwake(PedAI pedAI)
|
|
|
|
{
|
|
|
|
base.OnAwake(pedAI);
|
|
|
|
|
|
|
|
_chaseState = _pedAI.StateContainer.GetStateOrThrow<ChaseState>();
|
|
|
|
}
|
2021-09-19 20:04:06 +00:00
|
|
|
|
2021-09-19 22:44:31 +00:00
|
|
|
public override void OnBecameActive()
|
|
|
|
{
|
|
|
|
base.OnBecameActive();
|
|
|
|
|
|
|
|
if (this.ParameterForEnteringState is PathNode pathNode)
|
|
|
|
{
|
|
|
|
_pathMovementData.currentNode = _pathMovementData.destinationNode = pathNode;
|
|
|
|
_pathMovementData.moveDestination = PedAI.GetMoveDestinationBasedOnTargetNode(pathNode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_pathMovementData.Cleanup();
|
|
|
|
}
|
|
|
|
|
2021-09-19 20:04:06 +00:00
|
|
|
public override void UpdateState()
|
|
|
|
{
|
|
|
|
if (this.MyPed.IsInVehicleSeat)
|
|
|
|
{
|
|
|
|
// exit vehicle
|
|
|
|
this.MyPed.OnSubmitPressed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.MyPed.IsInVehicle) // wait until we exit vehicle
|
|
|
|
return;
|
|
|
|
|
|
|
|
// check if we gained some enemies
|
|
|
|
_enemyPeds.RemoveDeadObjectsIfNotEmpty();
|
2021-10-17 16:36:30 +00:00
|
|
|
if (_enemyPeds.Count > 0 && _chaseState.CanStartChasing())
|
2021-09-19 20:04:06 +00:00
|
|
|
{
|
|
|
|
_pedAI.StartChasing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-02 19:31:57 +00:00
|
|
|
if (this.IsSurrendering)
|
|
|
|
{
|
2022-01-02 20:52:31 +00:00
|
|
|
// make sure ped is surrendering
|
|
|
|
if (!_ped.IsSurrendering())
|
|
|
|
_ped.OnSurrenderButtonPressed();
|
2022-01-02 19:31:57 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-19 20:04:06 +00:00
|
|
|
if (PedAI.ArrivedAtDestinationNode(_pathMovementData, _ped.transform))
|
|
|
|
PedAI.OnArrivedToDestinationNode(_pathMovementData);
|
|
|
|
|
|
|
|
if (!_pathMovementData.destinationNode.HasValue)
|
|
|
|
{
|
2021-09-19 20:33:51 +00:00
|
|
|
PedAI.FindClosestWalkableNode(_pathMovementData, _ped.transform.position);
|
2021-09-19 20:04:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.MyPed.IsWalkOn = true;
|
|
|
|
this.MyPed.Movement = (_pathMovementData.moveDestination - this.MyPed.transform.position).normalized;
|
|
|
|
this.MyPed.Heading = this.MyPed.Movement;
|
|
|
|
}
|
2021-09-19 23:06:45 +00:00
|
|
|
|
|
|
|
protected internal override void OnMyPedDamaged(DamageInfo dmgInfo, Ped.DamageResult dmgResult)
|
|
|
|
{
|
|
|
|
_pedAI.StateContainer.GetStateOrThrow<IdleState>().HandleOnMyPedDamaged(dmgInfo, dmgResult);
|
|
|
|
}
|
2021-09-26 18:02:17 +00:00
|
|
|
|
2021-12-31 23:37:00 +00:00
|
|
|
protected internal override void OnWeaponConductedAttack(Weapon.AttackConductedEventData data)
|
|
|
|
{
|
|
|
|
_pedAI.StateContainer.GetStateOrThrow<IdleState>().HandleOnWeaponConductedAttack(data);
|
|
|
|
}
|
|
|
|
|
2022-01-02 19:31:57 +00:00
|
|
|
protected internal override void OnUnderAim(IReadOnlyList<Ped.UnderAimInfo> underAimInfos)
|
|
|
|
{
|
|
|
|
if (_pedAI.PedestrianType.IsGangMember())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// find those peds that are visible by our ped
|
|
|
|
|
|
|
|
List<Ped.UnderAimInfo> visibleList = null;
|
|
|
|
|
|
|
|
for (int i = 0; i < underAimInfos.Count; i++)
|
|
|
|
{
|
|
|
|
if (PedAI.PedSeesHeadOfAnotherPed(_ped, underAimInfos[i].ped))
|
|
|
|
{
|
|
|
|
if (null == visibleList)
|
|
|
|
visibleList = new List<Ped.UnderAimInfo>();
|
|
|
|
visibleList.Add(underAimInfos[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibleList != null)
|
|
|
|
{
|
|
|
|
if (_pedAI.PedestrianType.IsCop())
|
|
|
|
{
|
|
|
|
visibleList.ForEach(_ => _enemyPeds.AddIfNotPresent(_.ped));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_timeWhenStartedSurrendering = Time.time;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-26 18:02:17 +00:00
|
|
|
protected internal override void OnRecruit(Ped recruiterPed)
|
|
|
|
{
|
|
|
|
_pedAI.StateContainer.GetStateOrThrow<IdleState>().HandleOnRecruit(recruiterPed);
|
|
|
|
}
|
2021-09-26 18:17:17 +00:00
|
|
|
|
|
|
|
protected internal override void OnDrawGizmosSelected()
|
|
|
|
{
|
|
|
|
PedAI.OnDrawGizmosSelected(_pathMovementData);
|
|
|
|
}
|
2021-09-19 20:04:06 +00:00
|
|
|
}
|
|
|
|
}
|