public void AttackCommand(int index) { currentAction = BtAction.Attack; // uiController.showIndicator(true, targetIndices); // uiController.EnemyTargetActive(true); uiController.SetActionText(currentPlayerIndex, "Attack"); }
protected override int OnUpdate(BtWorkingData workData) { BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData); int runningState = BtRunningStatus.FINISHED; if (thisContext._currentSelectedIndex != thisContext._lastSelectedIndex) { if (IsIndexValid(thisContext._lastSelectedIndex)) { BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex); node.Transition(workData); } thisContext._lastSelectedIndex = thisContext._currentSelectedIndex; } if (IsIndexValid(thisContext._lastSelectedIndex)) { BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex); runningState = node.Update(workData); if (BtRunningStatus.IsFinished(runningState)) { thisContext._lastSelectedIndex = -1; } } return(runningState); }
public override void ExecuteTactic(ImpAi imp) { if (_impAi == null) { _impAi = imp; } if (_impCombatBehaviour == null) { _impCombatBehaviour = _impAi.GetComponent <ImpCombatBehaviour>(); } if (_attackInstance == null) { _attackInstance = data.TacticAttack.GetAttack(); } if (_tacticBehaviourTree == null) { BtCondition isFacingTarget = new BtCondition(IsFacingTarget); BtCondition inAttackRange = new BtCondition(InAttackRange); BtAction attack = new BtAction(Attack); BtSequence meleeAttack = new BtSequence(new IBtTask[] { isFacingTarget, inAttackRange, attack }); _tacticBehaviourTree = new BehaviourTree(meleeAttack); } _tacticBehaviourTree.Run(); }
public override void ExecuteTactic(ImpAi imp) { if (_imp == null) { _imp = imp; //_contextGroupFormation = imp.GetComponent<ContextGroupFormation>(); _impRecruitBehaviour = imp.GetComponent <ImpRecruitBehaviour>(); BtAction startRecruit = new BtAction(StartRecruit); BtAction stopRecruit = new BtAction(StopRecruit); //BtCondition inPositionCondition = new BtCondition(InPosition); BtCondition isRecruiting = new BtCondition(() => _isRecruiting); BtCondition isNotRecruiting = new BtCondition(() => !_isRecruiting); BtSelector startRecruitSelector = new BtSelector(new IBtTask[] { isRecruiting, startRecruit }); BtSelector stopRecruitSelector = new BtSelector(new IBtTask[] { isNotRecruiting, stopRecruit }); BtSequence startRecruitSequence = new BtSequence(new IBtTask[] { startRecruitSelector }); BtSelector recruitTree = new BtSelector(new IBtTask[] { startRecruitSequence, stopRecruitSelector }); _recruitBehaviourTree = new BehaviourTree(recruitTree); } _recruitBehaviourTree.Run(); }
protected override int OnUpdate(BtWorkingData workData) { BtActionSequenceContext thisContext = GetContext <BtActionSequenceContext>(workData); int runningStatus = BtRunningStatus.FINISHED; BtAction node = GetChild <BtAction>(thisContext.current_selected_index); runningStatus = node.Update(workData); if (_continueIfErrorOccors == false && BtRunningStatus.IsError(runningStatus)) { thisContext.current_selected_index = -1; return(runningStatus); } if (BtRunningStatus.IsFinished(runningStatus)) { thisContext.current_selected_index++; if (IsIndexValid(thisContext.current_selected_index)) { runningStatus = BtRunningStatus.EXECUTING; } else { thisContext.current_selected_index = -1; } } return(runningStatus); }
private void Start() { BtAction executeTactic = new BtAction(ExecuteTactic); BtAction ability = new BtAction(() => _activeAbility != null); BtAction allInPosition = new BtAction(() => !_activeAbility.GetData().InPositionBeforeActivation || _groupManager.Imps.All(pair => pair.Key.GetComponent <ContextGroupFormation>().InPosition())); BtAction doAbility = new BtAction(ExecuteAbility); BtSequence combatSequence = new BtSequence(new IBtTask[] { executeTactic, ability, allInPosition, doAbility }); FSMState outOfCombat = new FSMState(); FSMState inCombat = new FSMState(); FSMTransition battleEnter = new FSMTransition(() => _inBattle); FSMTransition battleExit = new FSMTransition(() => !_inBattle); outOfCombat.AddTransition(battleEnter, inCombat); inCombat.AddTransition(battleExit, outOfCombat); inCombat.enterActions.Add(() => OnTacticChanged?.Invoke(_activeTactic)); inCombat.stayActions.Add(() => combatSequence.Run()); outOfCombat.stayActions.Add(SetPlayer); FSM groupFsm = new FSM(outOfCombat); StartCoroutine(FsmStayAlive(groupFsm)); }
void resetActionData() { uiController.resetAllIndicator(); currentPlayerIndex = -1; targetIndices = new int[1] { targetPicker(true) }; curActionIndex = -1; currentAction = BtAction.NULL; uiController.CommandPanelActive(false); }
protected override void OnTransition(BtWorkingData workData) { BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData); BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex); if (node != null) { node.Transition(workData); } thisContext._lastSelectedIndex = -1; }
protected override void OnTransition(BtWorkingData workData) { BtActionSequenceContext this_context = GetContext <BtActionSequenceContext>(workData); BtAction node = GetChild <BtAction>(this_context.current_selected_index); if (node != null) { node.Transition(workData); } this_context.current_selected_index = -1; }
public void RunCommand(int index) { currentAction = BattleManager.BtAction.Run; uiController.SetActionText(currentPlayerIndex, "Run"); uiController.showIndicator(false); uiController.EnemyTargetActive(false); uiController.CommandPanelActive(false); targetIndices = null; makeBattleAction(); resetActionData(); }
protected override bool OnEvaluate(BtWorkingData workData) { BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData); //check last node first if (IsIndexValid(thisContext._currentSelectedIndex)) { BtAction node = GetChild <BtAction>(thisContext._currentSelectedIndex); if (node.Evaluate(workData)) { return(true); } } return(base.OnEvaluate(workData)); }
protected override bool OnEvaluate(BtWorkingData workData) { BtActionSequenceContext thisContext = GetContext <BtActionSequenceContext>(workData); int checkedNodeIndex = IsIndexValid(thisContext.current_selected_index) ? thisContext.current_selected_index : 0; if (IsIndexValid(checkedNodeIndex)) { BtAction node = GetChild <BtAction>(checkedNodeIndex); if (node.Evaluate(workData)) { thisContext.current_selected_index = checkedNodeIndex; return(true); } } return(false); }
protected override bool OnEvaluate(BtWorkingData workData) { BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData); thisContext._currentSelectedIndex = -1; int childCount = GetChildCount(); for (int i = 0; i < childCount; i++) { BtAction node = GetChild <BtAction>(i); if (node.Evaluate(workData)) { thisContext._currentSelectedIndex = i; return(true); } } return(false); }
public void SkillCommand(int index) { int skillIndex = userPartyData[currentPlayerIndex].skill; curActionIndex = skillIndex; currentAction = BattleManager.BtAction.Skill; SkillBase curSkill = DataManager.GetInstance().GetSkillData(skillIndex); uiController.SetActionText(currentPlayerIndex, curSkill.name); switch (curSkill.targetType) { case TargetType.SingleEnemy: uiController.showIndicator(true, targetIndices); uiController.EnemyTargetActive(true); break; case TargetType.AllEnemy: targetIndices = new int[enemyPartyData.Length]; for (int i = 0; i < enemyPartyData.Length; i++) { targetIndices[i] = i + 5; } uiController.CommandPanelActive(false); makeBattleAction(); resetActionData(); break; case TargetType.SingleAlli: targetIndices = new int[1] { 0 }; break; case TargetType.AllAlli: break; } }
public BtAction(int maxChildCount) : base(maxChildCount) { _uniqueKey = BtAction.GenUniqueKey(); }
private void Start() { foreach(GameObject group in GroupsManager.Instance.Groups.Values) { _groupAggros.Add(group.GetComponent<GroupAggro>()); } #region Behaviour tree #region Target selection BtCondition isTargetStillValid = new BtCondition(() => _currentTargetStillValid); BtAction tryChooseByAggro = new BtAction(TryChooseByAggro); BtSequence byAggroSequence = new BtSequence(new IBtTask[] { tryChooseByAggro }); BtSelector targetSelection = new BtSelector(new IBtTask[] { isTargetStillValid, byAggroSequence }); #endregion #region Attack BtCondition lastAttackDone = new BtCondition(() => _lastAttackDone); BtCondition isFacingTarget = new BtCondition(IsFacingTarget); BtCondition inAttackRange = new BtCondition(InAttackRange); BtAction chooseAttack = new BtAction(ChooseAttack); BtAction attack = new BtAction(Attack); BtSequence attackSequence = new BtSequence(new IBtTask[] { lastAttackDone, isFacingTarget, inAttackRange, chooseAttack, attack }); #endregion BtSequence combatSequence = new BtSequence(new IBtTask[] { targetSelection, attackSequence }); #endregion #region FSM FSMState idle = new FSMState(); FSMState combat = new FSMState(); combat.enterActions.Add(StartCombat); FSMTransition battleEnter = new FSMTransition(() => _inCombat); idle.AddTransition(battleEnter, combat); #endregion _combatBehaviourTree = new BehaviourTree(combatSequence); _bossFsm = new FSM(idle); _runFsmCoroutine = StartCoroutine(BossFsmUpdate()); }
public void FormationCommand(int index) { currentAction = BattleManager.BtAction.Formation; uiController.EnemyTargetActive(true); uiController.SetActionText(currentPlayerIndex, "Formation"); }
public void ItemCommand(int index) { currentAction = BattleManager.BtAction.Item; uiController.EnemyTargetActive(true); uiController.SetActionText(currentPlayerIndex, "Item"); }