// this function goes thorugh the tree testing differnt decsisions until it reaches a leaf node public void TraverseTree(TheNode TheCurrentNode, RealBattleUIScript TheUI, MonsterScript TheMonster) { if (TheCurrentNode.LeafNode) { CurrentNode.ExecuteAction(TheUI); } else { CurrentNode = TheCurrentNode.MakeDecision(TheMonster); // the function does not do anything yet //CurrentNode = TheCurrentNode.MakeDecision(); TraverseTree(CurrentNode, TheUI, TheMonster); } }
// this is what will use the skill depending on the circumstances public override void ExecuteAction(RealBattleUIScript TheUI) { if (TheActionName == "SkillOne") { TheAction.UseMonsterSkillOne(TheUI); } else if (TheActionName == "SkillTwo") { TheAction.UseMonsterSkillTwo(TheUI); } else if (TheActionName == "SkillThree") { TheAction.UseMonsterSkillThree(TheUI); } }
// this funcion starts the decision tree public void Execute(RealBattleUIScript TheUI, MonsterScript CurrentMonster) { TraverseTree(TheRootNode, TheUI, CurrentMonster); }
// the node needs the ability to execute actions and made a decsision depending on the type of node public virtual void ExecuteAction(RealBattleUIScript TheUI) { }
public void UseMonsterSkillThree(RealBattleUIScript TheBattleUI) { TheBattleUI.UseSkillThreeAI(); }