64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
/*********************************************************************
|
|
* \file LeafAttack.cs
|
|
* \author Ryan Wang Nian Jing
|
|
* \brief Leaf node implementation for AI attacking the player
|
|
* when the AI is close enough after chasing
|
|
*
|
|
*
|
|
* \copyright Copyright (c) 2022 DigiPen Institute of Technology. Reproduction
|
|
or disclosure of this file or its contents without the prior written
|
|
consent of DigiPen Institute of Technology is prohibited.
|
|
*********************************************************************/
|
|
|
|
using SHADE;
|
|
using SHADE_Scripting.AIBehaviour.BehaviourTree;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
//VARIABLES
|
|
public partial class LeafAttack : BehaviourTreeNode
|
|
{
|
|
//Holds the player game object
|
|
private GameObject player;
|
|
}
|
|
|
|
//FUNCTIONS
|
|
public partial class LeafAttack : BehaviourTreeNode
|
|
{
|
|
public LeafAttack(string name, GameObject p) : base (name)
|
|
{
|
|
player = p;
|
|
}
|
|
|
|
public override BehaviourTreeNodeStatus Evaluate()
|
|
{
|
|
//Debug.LogWarning("LeafAttack");
|
|
//Fail if no target in blackboard?
|
|
|
|
onEnter(BehaviourTreeNodeStatus.RUNNING);
|
|
|
|
//Succeed when stand in hurt box for long enough
|
|
float captureTime = (float)GetNodeData("captureTimeLeft");
|
|
captureTime -= Time.DeltaTimeF;
|
|
SetNodeData("captureTimeLeft", captureTime);
|
|
//Debug.Log(captureTime.ToString());
|
|
if (captureTime <= 0.0f)
|
|
{
|
|
//Catch player when in range for long enough
|
|
player.GetScript<PlayerController>().currentState = PlayerController.RaccoonStates.CAUGHT;
|
|
status = BehaviourTreeNodeStatus.SUCCESS;
|
|
onExit(BehaviourTreeNodeStatus.SUCCESS);
|
|
return status;
|
|
}
|
|
|
|
//Return running if not success
|
|
|
|
//Debug.Log("Success: Caught");
|
|
status = BehaviourTreeNodeStatus.RUNNING;
|
|
onExit(BehaviourTreeNodeStatus.RUNNING);
|
|
return status;
|
|
}
|
|
} |