public override bool Update(GameTime gameTime, float percent)
        {
            bool retVal = State.Action(percent, gameTime);

            if (Visible)
            {
                retVal |= base.Update(gameTime, percent);
            }
            return(retVal);
        }
Example #2
0
    public void Action()
    {
        if (_current != null)
        {
            _current.Action();
            _current = _current.Next();

            //Generic transitions
            if (_animal != null && !_isDead && (_animal.animal.happiness == 0 || _animal.animal.hunger == 100))
            {
                _isDead  = true;
                _current = new StateDead(this);
            }
        }
    }
Example #3
0
        private void Update()
        {
            if (state == TankAIState.waiting)
            {
                return;
            }

            if (Time.time - lastCheckTime > configs.checkInterval)
            {
                sensoringSimulator.FindEnemyTanksWithinDistance(
                    transform.position, configs.findingDistance, ObservedEnemyTanks, tank.seatID);
                sensoringSimulator.LoseEnemyTanksWithoutDistance(
                    transform.position, configs.findingDistance, ObservedEnemyTanks);
                if (ObservedEnemyTanks.Contains(TargetTank) && TryIfShootable(TargetTank.transform.position) && (targetTank.transform.position - transform.position).magnitude > keepingDistance)
                {
                    if (currentMotionState == MotionStates[(int)MotionStateIndices.going])
                    {
                        currentMotionState = MotionStates[(int)MotionStateIndices.stopping];
                        currentMotionState.Start();
                    }
                }
                else if (ObservedEnemyTanks.Contains(TargetTank) &&
                         (!TryIfShootable(TargetTank.transform.position) || (targetTank.transform.position - transform.position).magnitude > keepingDistance))
                {
                    DestinationPosition = TargetTank.transform.position;
                    currentMotionState  = MotionStates[(int)MotionStateIndices.going];
                    currentMotionState.Start();
                }
                else
                {
                    for (int i = 0; i < ObservedEnemyTanks.Count; i++)
                    {
                        if (TryIfShootable(ObservedEnemyTanks[i].transform.position))
                        {
                            TargetTank           = ObservedEnemyTanks[i];
                            currentShootingState = ShootingStates[(int)ShootingStateIndices.shooting];
                            currentShootingState.Start();
                            break;
                        }
                    }
                }
                lastCheckTime = Time.time;
            }

            currentMotionState.Action();
            State nextState = currentMotionState.Decide();

            if (nextState != currentMotionState)
            {
                tankStateInfo_motion.lastState = currentMotionState;
                currentMotionState             = nextState;
                currentMotionState.Start();
            }
            currentShootingState.Action();
            nextState = currentShootingState.Decide();
            if (nextState != currentShootingState)
            {
                currentShootingState = nextState;
                currentShootingState.Start();
            }
        }
Example #4
0
 public void Action(ButtonPayload payload)
 {
     State.Action(payload);
 }
Example #5
0
 public override bool Update(GameTime gameTime, float percent)
 {
     base.Update(gameTime, percent);
     return(State.Action(percent, gameTime));
 }
Example #6
0
 private void Update()
 {
     _currentState.Action();
     _currentState.Reaction();
 }
Example #7
0
 private void Update()
 {
     _state.Action();
 }
Example #8
0
 public int Action(int index, Menu m, GameObject guiTextLink)
 {
     return(State.Action(index, m, guiTextLink));
 }
Example #9
0
 /// <summary>
 /// Update FSM and check for a new state.
 /// </summary>
 public void Update()
 {
     currentState.Action();
     currentState = currentState.GetNextState();
 }
Example #10
0
    public bool ToState(int name)
    {
        if (!stateMap.ContainsKey(name))
            return false;

        if (crtState != null && name == crtState.GetStateName())
            return false;

        if (crtState != null)
        {
            crtState.Action(StateState.LEAVE);
        }

        crtState = stateMap[name];
        crtState.Action(StateState.ENTER);
        return true;
    }