Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool waiting = false;
- bool finishedwaiting = false;
- IEnumerator Wait(float dif)
- {
- waiting = true;
- yield return new WaitForSeconds(dif);
- waiting = false;
- finishedwaiting = true;
- }
- //get's called every frame
- public void ReadAIScript()
- {
- //starts at the beginning of the tree
- BoxingNode currentNode = AITree.Nodes[AITree.FirstNodeIndex];
- do
- {
- //don't do the rest of the tree if we're waiting
- if (waiting == false)
- {
- switch (currentNode.type)
- {
- //if the node is an equation
- case BoxingNode.NodeType.Equation:
- //what kind of value we're checking
- string ValueType = "";
- //both equation nodes
- for (int i = 0; i < 2; i++)
- {
- //the different situations. there will be more, i just don't need them yet
- switch (currentNode.EqNodes[i].Vchoice)
- {
- case BoxingNode.EquationNodeButton.ValueChoices.enemyAttacking:
- currentNode.EqNodes[i].InputBool = enemy.StartedPunching;
- ValueType = "Bool";
- break;
- case BoxingNode.EquationNodeButton.ValueChoices.EnemyWeaving:
- currentNode.EqNodes[i].InputBool = enemy.weavingL || enemy.weavingR;
- ValueType = "Bool";
- break;
- case BoxingNode.EquationNodeButton.ValueChoices.SelfWeaving:
- currentNode.EqNodes[i].InputBool = owner.weavingL || owner.weavingR;
- ValueType = "Bool";
- break;
- case BoxingNode.EquationNodeButton.ValueChoices.enemyAttackDirection:
- currentNode.EqNodes[i].InputAttackDirection = enemy.currentPunch.LimbIndex;
- ValueType = "Direction";
- break;
- case BoxingNode.EquationNodeButton.ValueChoices.DistanceToEnemy:
- currentNode.EqNodes[i].InputDouble = Vector3.Distance(owner.nav.transform.position, enemy.nav.transform.position);
- ValueType = "Double";
- break;
- }
- }
- //see the result of the equation node
- switch (ValueType)
- {
- case "Bool":
- currentNode.EquationValue = currentNode.EqNodes[0].InputBool == currentNode.EqNodes[1].InputBool;
- break;
- case "Direction":
- currentNode.EquationValue = currentNode.EqNodes[0].InputAttackDirection == currentNode.EqNodes[1].InputAttackDirection;
- break;
- case "Double":
- switch (currentNode.typ)
- {
- case BoxingNode.EquationType.Equal:
- currentNode.EquationValue = currentNode.EqNodes[0].InputDouble == currentNode.EqNodes[1].InputDouble;
- break;
- case BoxingNode.EquationType.Less:
- currentNode.EquationValue = currentNode.EqNodes[0].InputDouble < currentNode.EqNodes[1].InputDouble;
- break;
- case BoxingNode.EquationType.Greater:
- currentNode.EquationValue = currentNode.EqNodes[0].InputDouble > currentNode.EqNodes[1].InputDouble;
- break;
- }
- break;
- }
- //set the correct next step depending on the result
- if (currentNode.EquationValue == true)
- {
- currentNode.NextStep = currentNode.connections[0];
- }
- else
- {
- currentNode.NextStep = currentNode.connections[1];
- }
- break;
- //follow the enemy
- case BoxingNode.NodeType.FollowEnemy:
- owner.nav.destination = enemy.nav.transform.position;
- break;
- //perform a specific move
- case BoxingNode.NodeType.Move:
- if (owner.Energy >= currentNode.move.energy)
- owner.anim.SetTrigger(currentNode.move.name);
- break;
- //do nothing
- case BoxingNode.NodeType.StandStill:
- owner.nav.destination = owner.nav.transform.position;
- break;
- //do a random punch
- case BoxingNode.NodeType.RandomMove:
- RandomPunch(currentNode.RandomPunches);
- break;
- //wait randomly between x and y seconds
- case BoxingNode.NodeType.WaitBetween:
- if (finishedwaiting == false)//this means that we haven't started waiting at all
- {//start waiting
- StartCoroutine(Wait(Random.Range((float)currentNode.EqNodes[0].InputDouble*10,(float)currentNode.EqNodes[1].InputDouble*10)/10));
- }
- else
- {//otherwise we'ev finished waiting
- finishedwaiting = false;
- }
- //if finishedwaiting is true, then the rest of the do while loop will continue, rather than entering an infinite loop of Wait coroutines
- break;
- }
- }
- //if this isn't an equation node or anything special, just tell it to keep going with it's first connected node
- if (currentNode.NextStep == null)
- {
- if (currentNode.connections.Count > 0)
- {
- currentNode.NextStep = currentNode.connections[0];
- }
- }
- //proceed
- currentNode = currentNode.NextStep;
- }
- while (currentNode != null);
- Rotate();
- }
Add Comment
Please, Sign In to add comment