Added CaughtRaccoon State.

This commit is contained in:
maverickdgg 2023-03-30 15:26:15 +08:00
parent 5ab7cbe5f3
commit c6faeeb282
8 changed files with 117 additions and 31 deletions

View File

@ -5911,6 +5911,7 @@
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAI - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAI
Enabled: true Enabled: true
idleDuration: 1 idleDuration: 1
caughtDuration: 2
timeoutDuration: 2 timeoutDuration: 2
patrolPointParent: 166 patrolPointParent: 166
patrolSpeed: 1 patrolSpeed: 1
@ -17271,3 +17272,4 @@
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAttackHitbox - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAttackHitbox
Enabled: true Enabled: true
aiGO: 158 aiGO: 158
raccoonFound: false

View File

@ -10,6 +10,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
public class HomeOwnerAI : Script public class HomeOwnerAI : Script
{ {
public float idleDuration = 1.0f; public float idleDuration = 1.0f;
public float caughtDuration = 2.0f;
public float timeoutDuration = 2.0f; public float timeoutDuration = 2.0f;
public GameObject patrolPointParent; public GameObject patrolPointParent;
@ -41,6 +42,9 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
private Transform transform; private Transform transform;
[NonSerialized]
public HomeOwnerAttackHitbox hitboxScript;
public void Reset() public void Reset()
{ {
StateMachine machine = GetScript<StateMachine>(); StateMachine machine = GetScript<StateMachine>();
@ -65,6 +69,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
dictionary.Add(typeof(ChaseState), new ChaseState(machine)); dictionary.Add(typeof(ChaseState), new ChaseState(machine));
dictionary.Add(typeof(AlertState), new AlertState(machine)); dictionary.Add(typeof(AlertState), new AlertState(machine));
dictionary.Add(typeof(AttackState), new AttackState(machine)); dictionary.Add(typeof(AttackState), new AttackState(machine));
dictionary.Add(typeof(CaughtRaccoonState), new CaughtRaccoonState(machine));
machine.InitStateMachine(dictionary); machine.InitStateMachine(dictionary);
} }
@ -84,6 +89,11 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
//attackHitbox.SetActive(false); //attackHitbox.SetActive(false);
if (pppList != null) if (pppList != null)
startPos = pppList[0].LocalPosition; startPos = pppList[0].LocalPosition;
if (attackHitbox)
hitboxScript = attackHitbox.GetScript<HomeOwnerAttackHitbox>();
} }

View File

@ -13,11 +13,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{ {
public GameObject aiGO; public GameObject aiGO;
private bool raccoonFound = false; public bool raccoonFound = false;
Transform transform; Transform transform;
Transform aiTransform; Transform aiTransform;
private PlayerController pc; [NonSerialized]
public PlayerController pc;
private HomeOwnerAI ai; private HomeOwnerAI ai;
protected override void start() protected override void start()
@ -39,20 +40,18 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
if (raccoonFound && pc && ai) if (raccoonFound && pc && ai)
{ {
pc.currentState = RaccoonStates.CAUGHT; if (!ai.atk)
if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState))) raccoonFound = false;
pc.stateMachine.SetState(typeof(PlayerCaughtState));
pc.GotCaught();
ai.Reset();
raccoonFound = false;
} }
} }
protected override void onTriggerStay(CollisionInfo info) protected override void onTriggerStay(CollisionInfo info)
{ {
pc = info.GameObject.GetScript<PlayerController>(); if(info.GameObject.GetScript<PlayerController>())
pc = info.GameObject.GetScript<PlayerController>();
if (ai && ai.atk && pc) if (ai && ai.atk && pc)
{ {
raccoonFound = true; raccoonFound = true;

View File

@ -37,23 +37,23 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{ {
lookOffset = 0.0f; lookOffset = 0.0f;
} }
else //else
{ //{
if(left ) // if(left )
{ // {
if (lookOffset > -lookAroundAngle) // if (lookOffset > -lookAroundAngle)
lookOffset -= rotationPerSecond * Time.DeltaTimeF; // lookOffset -= rotationPerSecond * Time.DeltaTimeF;
else // else
left = false; // left = false;
} // }
if (!left) // if (!left)
{ // {
if (lookOffset < lookAroundAngle) // if (lookOffset < lookAroundAngle)
lookOffset += rotationPerSecond * Time.DeltaTimeF; // lookOffset += rotationPerSecond * Time.DeltaTimeF;
else // else
left = false; // left = false;
} // }
} //}
@ -75,7 +75,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
if(vel.GetMagnitude() > 0.01f) if(vel.GetMagnitude() > 0.01f)
{ {
Quaternion currentRotation = transform.LocalRotation; Quaternion currentRotation = transform.LocalRotation;
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 0.0f); Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 0.0f);
transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.DeltaTimeF); transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.DeltaTimeF);
} }
} }

View File

@ -26,7 +26,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public AttackState(StateMachine machine) : base(machine) public AttackState(StateMachine machine) : base(machine)
{ {
stateName = "Attack";
} }
@ -68,7 +68,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnExit() public override void OnExit()
{ {
animator.Stop();
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>(); RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if (rotate) if (rotate)
{ {
@ -84,6 +84,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void update() public override void update()
{ {
if (ai.hitboxScript.raccoonFound)
{
machine.SetState(typeof(CaughtRaccoonState));
}
timer -= Time.DeltaTimeF; timer -= Time.DeltaTimeF;
if (windUp) if (windUp)
{ {
@ -141,9 +147,13 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
machine.SetState(typeof(TimeoutState)); machine.SetState(typeof(TimeoutState));
} }
} }
} }
} }
public override void fixedUpdate() public override void fixedUpdate()

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SHADE;
using static PlayerController;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
public class CaughtRaccoonState: AIBaseState
{
private float timer = 0.0f;
private PlayerController pc;
public CaughtRaccoonState(StateMachine machine):base(machine)
{
stateName = "Caught Raccoon";
}
public override void OnEnter()
{
if(ai.hitboxScript)
pc = ai.hitboxScript.pc;
timer = ai.caughtDuration;
}
public override void OnExit()
{
animator.Stop();
}
public override void update()
{
timer -= Time.DeltaTimeF;
if(timer <= 0.0f)
{
if (pc)
{
pc.currentState = RaccoonStates.CAUGHT;
if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState)))
pc.stateMachine.SetState(typeof(PlayerCaughtState));
pc.GotCaught();
}
ai.Reset();
}
}
public override void fixedUpdate()
{
}
}
}

View File

@ -0,0 +1,3 @@
Name: CaughtRaccoonState
ID: 153010954
Type: 9

View File

@ -14,7 +14,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
float giveUpDuration = 10.0f; float giveUpDuration = 10.0f;
float giveUpTimer = 0.0f; float giveUpTimer = 0.0f;
float atkDistance = 2.0f; float atkDistance = 1.0f;
bool run = true; bool run = true;