SHADE_Y3/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AlertState.cs

83 lines
1.7 KiB
C#
Raw Normal View History

using SHADE;
2023-03-24 13:26:18 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-03-26 13:27:42 +08:00
using SHADE_Scripting.Audio;
2023-03-24 13:26:18 +08:00
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
2023-03-26 13:27:42 +08:00
public class AlertState : AIBaseState
{
const float alertDuration = 16.0f / 30.0f + 1.0f;
float alertTimer = alertDuration;
bool firstDetection;
2023-03-26 13:27:42 +08:00
public AlertState(StateMachine machine) : base(machine)
{
stateName = "Alert";
AudioHandler.audioClipHandlers["raccoondetected"] = SHADE.Audio.CreateAudioClip("event:/Raccoon/raccoon_detected");
firstDetection = true;
2023-03-26 13:27:42 +08:00
}
public override void OnEnter()
{
alertTimer = alertDuration;
if (animator)
{
animator.PlayOneShot(ai.alertAnim);
}
if(firstDetection)
{
SHADE.Audio.SetParameterWithLabel("HomeownerBark", "DetectFirst");
AudioHandler.audioClipHandlers["HO_bark"].Play();
firstDetection = false;
}
else
{
PlayerController pc = ai.player.GetScript<PlayerController>();
if (pc && pc.holdItem)
{
SHADE.Audio.SetParameterWithLabel("HomeownerBark", "DetectFood");
AudioHandler.audioClipHandlers["HO_bark"].Play();
}
else
{
SHADE.Audio.SetParameterWithLabel("HomeownerBark", "DetectAgain");
AudioHandler.audioClipHandlers["HO_bark"].Play();
}
}
}
2023-03-26 13:27:42 +08:00
public override void OnExit()
{
animator.Stop();
}
public override void update()
2023-03-24 13:26:18 +08:00
{
2023-03-26 13:27:42 +08:00
alertTimer -= Time.DeltaTimeF;
if (alertTimer <= 0.0f)
{
machine.SetState(typeof(ChaseState));
}
2023-03-24 13:26:18 +08:00
}
2023-03-26 13:27:42 +08:00
public override void fixedUpdate()
{
}
}
2023-03-24 13:26:18 +08:00
}