private void CreatePerformState() { _performState = (fsm, fsmGameObject) => { // all actions done, plan over... if (_plan.Count == 0) { _dataProvider.PlanFinished(); fsm.PopState(); fsm.PushState(_idleState); return; } // if action done (in other words, has exited) var action = _plan.Peek(); if (action.IsDone()) { _plan.Pop(); return; } // action go! if (!action.Go(this)) { _dataProvider.PlanAborted(action); fsm.PopState(); fsm.PushState(_idleState); } }; }
private void CreateIdleState() { _idleState = (fsm, fsmGameObject) => { // reset data content ResetActionData(); HashSet <KeyValuePair <string, object> > worldStates = _dataProvider.GetWorldStates(); HashSet <KeyValuePair <string, object> > goals = _dataProvider.GetGoals(); // planning _plan = _planner.Plan(this, _actions, worldStates, goals); // if has no plan... if (_plan == null) { _dataProvider.PlanFailed(goals); } else { _dataProvider.PlanFound(goals, _plan); fsm.PopState(); fsm.PushState(_performState); } }; }
private void CreateHarvestState() { _harvestState = (fsm, fsmGameObject) => { // target herb is null... if (Target == null) { Herb herb = FindObjectOfType <Herb>(); if (herb == null) { fsm.PopState(); fsm.PushState(_idleState); return; } Target = herb.gameObject; } // target too far... if ((Target.transform.position - transform.position).magnitude > MaxTargetRange) { fsm.PushState(_moveState); } else { Destroy(Target); BackPack++; fsm.PopState(); fsm.PushState(_idleState); } }; }
private void CreateUnLoadState() { _unloadState = (fsm, fsmGameObject) => { // target bonfire is null... if (Target == null) { Bonfire bonfire = FindObjectOfType <Bonfire>(); if (bonfire == null) { fsm.PopState(); fsm.PushState(_idleState); return; } Target = bonfire.gameObject; } // target too far... if ((Target.transform.position - transform.position).magnitude > MaxTargetRange) { fsm.PushState(_moveState); } else { BackPack = 0; fsm.PopState(); fsm.PushState(_idleState); } }; }
private void CreateIdleState() { _idleState = (fsm, fsmGameObject) => { Target = null; fsm.PopState(); fsm.PushState(BackPack < MaxBackPack ? _harvestState : _unloadState); }; }
private void CreateMoveState() { _moveState = (fsm, fsmGameObject) => { if (MoveTo(Target.transform.position, MoveSpeed)) { fsm.PopState(); } }; }