Added CaughtRaccoon state to AI FSM #449

Merged
maverickdgg merged 5 commits from Navigation into main 2023-03-31 17:05:28 +08:00
10 changed files with 120 additions and 31 deletions
Showing only changes of commit 8c5bf82aa5 - Show all commits

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,19 +40,17 @@ 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)))
pc.stateMachine.SetState(typeof(PlayerCaughtState));
pc.GotCaught();
ai.Reset();
raccoonFound = false; raccoonFound = false;
} }
} }
protected override void onTriggerStay(CollisionInfo info) protected override void onTriggerStay(CollisionInfo info)
{ {
if(info.GameObject.GetScript<PlayerController>())
pc = info.GameObject.GetScript<PlayerController>(); pc = info.GameObject.GetScript<PlayerController>();
if (ai && ai.atk && pc) if (ai && ai.atk && pc)
{ {

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;
} // }
} //}

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;

View File

@ -8,6 +8,7 @@ struct MatPropData
int textureIndex; int textureIndex;
float alpha; float alpha;
float sliderThreshold; float sliderThreshold;
float borderThickness;
vec4 sliderStartColor; vec4 sliderStartColor;
vec4 sliderEndColor; vec4 sliderEndColor;
vec4 sliderBarColor; vec4 sliderBarColor;
@ -43,6 +44,8 @@ void main()
{ {
//fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv); //fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
if (In.uv.x > MatProp.data[In2.materialIndex].sliderThreshold) if (In.uv.x > MatProp.data[In2.materialIndex].sliderThreshold)
fragColor = MatProp.data[In2.materialIndex].sliderBarColor; fragColor = MatProp.data[In2.materialIndex].sliderBarColor;
else else