示例#1
0
 public Boo(Level l, Point position, Sprite hideState, Sprite chaseState) : base(l, position, hideState, null)
 {
     Stompable        = false;
     BoundingBox      = new Bounds(this, Color.Red, new Vector2(3, 3), new Vector2(13, 13));
     this.chaseState  = new ChaseState(this, chaseState);
     this.hiddenState = new HideState(this, hideState);
     currentstate     = hiddenState;
     Speed            = 1;
 }
示例#2
0
    private void ConstructFSM()
    {
        PatrolState patrol = new PatrolState(this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.GotBored, FSMStateID.Bored);
        patrol.AddTransition(Transition.WantsTimeOff, FSMStateID.OffDuty);
        patrol.AddTransition(Transition.Hurt, FSMStateID.Repairing);
        patrol.AddTransition(Transition.WantsToHide, FSMStateID.Hiding);

        ChaseState chase = new ChaseState(this);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        chase.AddTransition(Transition.Hurt, FSMStateID.Repairing);

        AttackState attack = new AttackState(this);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        attack.AddTransition(Transition.Hurt, FSMStateID.Repairing);

        OffDutyState offduty = new OffDutyState(rigidbody.transform, this);

        offduty.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        offduty.AddTransition(Transition.RestedLongEnough, FSMStateID.Patrolling);
        offduty.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        offduty.AddTransition(Transition.WantsToHide, FSMStateID.Hiding);

        RepairState repair = new RepairState(this);

        repair.AddTransition(Transition.Healed, FSMStateID.Patrolling);
        repair.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        HideState hide = new HideState(this);

        hide.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        hide.AddTransition(Transition.RestedLongEnough, FSMStateID.Patrolling);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);


        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(offduty);
        AddFSMState(repair);
        AddFSMState(hide);
        AddFSMState(dead);
    }
        public AutoHideWindowBehavior()
        {
            _lockTimer      = false;
            _hideStatus     = HideState.None;
            _autoHideFactor = 10;
            var autoHideTimer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(100)
            };

            autoHideTimer.Tick += AutoHideTimer_Tick;
            autoHideTimer.Start();
        }
示例#4
0
        static void Main(string[] args)
        {
            //Primero, creas los estados que tendra tu maquina

            State hide   = new HideState();
            State attack = new AttackState();
            State flee   = new FleeState();
            State dance  = new DanceState();

            // Luego, mapeamos cada estado y le damos etiquetas

            hide.setMap(new Dictionary <string, State> {
                { "notice_sempai", dance }
            });

            attack.setMap(new Dictionary <string, State> {
                { "afraid", flee }
            });

            flee.setMap(new Dictionary <string, State> {
                { "not_afraid", dance }
            });

            dance.setMap(new Dictionary <string, State> {
                { "not_afraid", attack },
                { "afraid", flee }
            });

            // Creamos nuestro state machine, dandole un estado inicial

            ObjectStateMachine sm = new ObjectStateMachine(hide);

            if (sm.getState() is HideState)
            {
                Console.WriteLine("Se escondio");
            }

            // Ahora le damos un input

            Dictionary <string, bool> input = new Dictionary <string, bool> {
                { "notice_sempai", true }
            };

            sm.updateState(input);

            if (sm.getState() is DanceState)
            {
                Console.WriteLine("Te noticeo");
            }
        }
示例#5
0
        protected void InitForHiding()
        {
            //enable and prep for exit
            m_HiddenAmount     = 0.0f;
            m_CurrentHideState = HideState.Hiding;
            gameObject.SetActive(true);

            // TODO: See if we still need m_TargetMainPointer.
            //
            // Originally, doing an undo while pointing at a panel (presumably when you press the Undo
            // button on the tools panel) would cause the stroke to disappear into the stroke's end
            // point. But now that we allow the undo / redo shortcuts to work even when focused on a panel,
            // it seemed more logical to always disappear to the pointer position.
            //m_TargetMainPointer = !SketchControlsScript.m_Instance.IsUserInteractingWithUI();
            m_TargetMainPointer = true;
        }
示例#6
0
 void Update()
 {
     if (m_CurrentHideState == HideState.Hiding)
     {
         m_HiddenAmount += (Time.deltaTime * m_HideSpeed);
         if (m_HiddenAmount >= 1.0f)
         {
             m_HiddenAmount = 1.0f;
             gameObject.SetActive(false);
             m_CurrentHideState = HideState.Hidden;
             if (m_DestroyOnHide)
             {
                 Destroy(gameObject);
             }
         }
         AnimateHiding();
     }
 }
示例#7
0
 protected void OnAwake()
 {
     //cache renderer and disable ourselves
     m_CurrentHideState = HideState.Hidden;
     gameObject.SetActive(false);
 }
    private void ConstructFSM()
    {
        pointList = GameObject.FindGameObjectsWithTag("WayPoint");
        //
        //Creating a wapoint transform array for each state
        //
        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }
        //
        //Create States
        //
        HideState   hide   = new HideState(waypoints);
        AttackState attack = new AttackState(waypoints);


        //Create the Dead state
        DeadState dead = new DeadState(waypoints);
        //there are no transitions out of the dead state

        PatrolState patrol = new PatrolState(waypoints);
        FleeState   flee   = new FleeState(waypoints);

        //add transitions OUT of the attack state
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        if (AI1)
        {
            attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
            attack.AddTransition(Transition.LowHealth, FSMStateID.Fleeing);
        }

        if (AI2)
        {
            attack.AddTransition(Transition.LostPlayer, FSMStateID.Hiding);
        }

        attack.AddTransition(Transition.LowHealth, FSMStateID.Fleeing);

        //add transitions OUT of the hide state
        hide.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);
        hide.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //add transitions OUT of the patrol state
        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //add transitions OUT of the flee state
        if (AI1)
        {
            flee.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        }
        if (AI2)
        {
            flee.AddTransition(Transition.LostPlayer, FSMStateID.Hiding);
        }
        flee.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        //Add state to the state list
        if (AI1)
        {
            AddFSMState(patrol);
        }

        if (AI2)
        {
            AddFSMState(hide);
        }

        AddFSMState(attack);
        AddFSMState(dead);
    }
        public void Show()
        {
            if (_hideStatus != HideState.None)
            {
                _lockTimer = true;
                switch (_hideStatus)
                {
                case HideState.PreviewTopHidden:
                    _cacheTranslateTransform.Y = _autoHideFactor + 1;
                    _hideStatus = HideState.None;
                    _lockTimer  = false;
                    break;

                case HideState.TopHidden:
                    AnimationTranslate(MoveDirection.Bottom, AssociatedObject.ActualHeight + _autoHideFactor, () =>
                    {
                        _cacheTranslateTransform.Y = _autoHideFactor + 1;
                        _hideStatus = HideState.None;
                        _lockTimer  = false;
                    });
                    break;

                case HideState.PreviewRightHidden:
                    _cacheTranslateTransform.X = SystemParameters.VirtualScreenWidth - AssociatedObject.ActualWidth - _autoHideFactor - 1;
                    _hideStatus = HideState.None;
                    _lockTimer  = false;
                    break;

                case HideState.RightHidden:
                    AnimationTranslate(MoveDirection.Left, AssociatedObject.ActualWidth + _autoHideFactor, () =>
                    {
                        _cacheTranslateTransform.X = SystemParameters.VirtualScreenWidth - AssociatedObject.ActualWidth - _autoHideFactor - 1;
                        _hideStatus = HideState.None;
                        _lockTimer  = false;
                    });
                    break;

                case HideState.PreviewBottomHidden:
                    _cacheTranslateTransform.Y = SystemParameters.VirtualScreenHeight - AssociatedObject.ActualHeight - _autoHideFactor - 1;
                    _hideStatus = HideState.None;
                    _lockTimer  = false;
                    break;

                case HideState.BottomHidden:
                    AnimationTranslate(MoveDirection.Top, AssociatedObject.ActualHeight + _autoHideFactor, () =>
                    {
                        _cacheTranslateTransform.Y = SystemParameters.VirtualScreenHeight - AssociatedObject.ActualHeight - _autoHideFactor - 1;
                        _hideStatus = HideState.None;
                        _lockTimer  = false;
                    });
                    break;

                case HideState.PreviewLeftHidden:
                    _cacheTranslateTransform.X = _autoHideFactor + 1;
                    _hideStatus = HideState.None;
                    _lockTimer  = false;
                    break;

                case HideState.LeftHidden:
                    AnimationTranslate(MoveDirection.Right, AssociatedObject.ActualWidth + _autoHideFactor, () =>
                    {
                        _cacheTranslateTransform.X = _autoHideFactor + 1;
                        _hideStatus = HideState.None;
                        _lockTimer  = false;
                    });
                    break;
                }
            }
        }
        private void AutoHideTimer_Tick(object sender, EventArgs e)
        {
            if (!_lockTimer)
            {
                _lockTimer = true;
                if (Win32.GetCursorPos(out _curPosition))
                {
                    switch (_hideStatus)
                    {
                    case HideState.None:
                        if (AssociatedObject.Top <= _autoHideFactor)
                        {
                            _hideStatus = HideState.PreviewTopHidden;
                        }
                        else if (AssociatedObject.Left + AssociatedObject.ActualWidth >= SystemParameters.VirtualScreenWidth - _autoHideFactor)
                        {
                            _hideStatus = HideState.PreviewRightHidden;
                        }
                        else if (AssociatedObject.Top + AssociatedObject.ActualHeight >= SystemParameters.VirtualScreenHeight - _autoHideFactor)
                        {
                            _hideStatus = HideState.PreviewBottomHidden;
                        }
                        else if (AssociatedObject.Left <= _autoHideFactor)
                        {
                            _hideStatus = HideState.PreviewLeftHidden;
                        }
                        _lockTimer = false;
                        break;

                    case HideState.PreviewTopHidden:
                        if (AssociatedObject.Top <= _autoHideFactor)
                        {
                            if (_curPosition.X < AssociatedObject.Left ||
                                _curPosition.X > AssociatedObject.Left + AssociatedObject.ActualWidth ||
                                _curPosition.Y > AssociatedObject.Top + AssociatedObject.ActualHeight)
                            {
                                AnimationTranslate(MoveDirection.Top, AssociatedObject.ActualHeight + _autoHideFactor, () =>
                                {
                                    AssociatedObject.Top = -(AssociatedObject.ActualHeight + _autoHideFactor);
                                    _hideStatus          = HideState.TopHidden;
                                    _lockTimer           = false;
                                });
                            }
                            else
                            {
                                _lockTimer = false;
                            }
                        }
                        else
                        {
                            _hideStatus = HideState.None;
                            _lockTimer  = false;
                        }
                        break;

                    case HideState.TopHidden:
                        if (_curPosition.Y <= _autoHideFactor &&
                            _curPosition.X >= AssociatedObject.Left &&
                            _curPosition.X <= AssociatedObject.Left + AssociatedObject.ActualWidth)
                        {
                            AnimationTranslate(MoveDirection.Bottom, AssociatedObject.ActualHeight + _autoHideFactor, () =>
                            {
                                AssociatedObject.Top = 0;
                                _hideStatus          = HideState.PreviewTopHidden;
                                _lockTimer           = false;
                            });
                        }
                        else
                        {
                            _lockTimer = false;
                        }
                        break;

                    case HideState.PreviewRightHidden:
                        if (AssociatedObject.Left + AssociatedObject.ActualWidth >= SystemParameters.VirtualScreenWidth - _autoHideFactor)
                        {
                            if (_curPosition.X < AssociatedObject.Left ||
                                _curPosition.Y < AssociatedObject.Top ||
                                _curPosition.Y > AssociatedObject.Top + AssociatedObject.ActualHeight)
                            {
                                AnimationTranslate(MoveDirection.Right, AssociatedObject.ActualHeight + _autoHideFactor, () =>
                                {
                                    AssociatedObject.Left = (SystemParameters.VirtualScreenWidth + _autoHideFactor);
                                    _hideStatus           = HideState.RightHidden;
                                    _lockTimer            = false;
                                });
                            }
                            else
                            {
                                _lockTimer = false;
                            }
                        }
                        else
                        {
                            _hideStatus = HideState.None;
                            _lockTimer  = false;
                        }
                        break;

                    case HideState.RightHidden:
                        if (_curPosition.X >= SystemParameters.VirtualScreenWidth - _autoHideFactor &&
                            _curPosition.Y >= AssociatedObject.Top &&
                            _curPosition.Y <= AssociatedObject.Top + AssociatedObject.ActualHeight)
                        {
                            AnimationTranslate(MoveDirection.Left, AssociatedObject.ActualWidth + _autoHideFactor, () =>
                            {
                                AssociatedObject.Left = SystemParameters.VirtualScreenWidth - AssociatedObject.ActualWidth;
                                _hideStatus           = HideState.PreviewRightHidden;
                                _lockTimer            = false;
                            });
                        }
                        else
                        {
                            _lockTimer = false;
                        }
                        break;

                    case HideState.PreviewBottomHidden:
                        if (AssociatedObject.Top + AssociatedObject.ActualHeight >= SystemParameters.VirtualScreenHeight - _autoHideFactor)
                        {
                            if (_curPosition.Y < AssociatedObject.Top ||
                                _curPosition.X < AssociatedObject.Left ||
                                _curPosition.X > AssociatedObject.Left + AssociatedObject.ActualWidth)
                            {
                                AnimationTranslate(MoveDirection.Bottom, AssociatedObject.ActualHeight + _autoHideFactor, () =>
                                {
                                    AssociatedObject.Top = (SystemParameters.VirtualScreenHeight + _autoHideFactor);
                                    _hideStatus          = HideState.BottomHidden;
                                    _lockTimer           = false;
                                });
                            }
                            else
                            {
                                _lockTimer = false;
                            }
                        }
                        else
                        {
                            _hideStatus = HideState.None;
                            _lockTimer  = false;
                        }
                        break;

                    case HideState.BottomHidden:
                        if (_curPosition.Y >= SystemParameters.VirtualScreenHeight - _autoHideFactor &&
                            _curPosition.X >= AssociatedObject.Left &&
                            _curPosition.X <= AssociatedObject.Left + AssociatedObject.ActualWidth)
                        {
                            AnimationTranslate(MoveDirection.Top, AssociatedObject.ActualHeight + _autoHideFactor, () =>
                            {
                                AssociatedObject.Top = SystemParameters.VirtualScreenHeight - AssociatedObject.ActualHeight;
                                _hideStatus          = HideState.PreviewBottomHidden;
                                _lockTimer           = false;
                            });
                        }
                        else
                        {
                            _lockTimer = false;
                        }
                        break;

                    case HideState.PreviewLeftHidden:
                        if (AssociatedObject.Left <= _autoHideFactor)
                        {
                            if (_curPosition.X > AssociatedObject.Left + AssociatedObject.ActualWidth ||
                                _curPosition.Y < AssociatedObject.Top ||
                                _curPosition.Y > AssociatedObject.Top + AssociatedObject.ActualHeight)
                            {
                                AnimationTranslate(MoveDirection.Left, AssociatedObject.ActualWidth + _autoHideFactor, () =>
                                {
                                    AssociatedObject.Left = -(AssociatedObject.ActualWidth + _autoHideFactor);
                                    _hideStatus           = HideState.LeftHidden;
                                    _lockTimer            = false;
                                });
                            }
                            else
                            {
                                _lockTimer = false;
                            }
                        }
                        else
                        {
                            _hideStatus = HideState.None;
                            _lockTimer  = false;
                        }
                        break;

                    case HideState.LeftHidden:
                        if (_curPosition.X <= _autoHideFactor &&
                            _curPosition.Y >= AssociatedObject.Top &&
                            _curPosition.Y <= AssociatedObject.Top + AssociatedObject.ActualHeight)
                        {
                            AnimationTranslate(MoveDirection.Right, AssociatedObject.ActualWidth + _autoHideFactor, () =>
                            {
                                AssociatedObject.Left = 0;
                                _hideStatus           = HideState.PreviewLeftHidden;
                                _lockTimer            = false;
                            });
                        }
                        else
                        {
                            _lockTimer = false;
                        }
                        break;
                    }
                }
                else
                {
                    _lockTimer = false;
                }
            }
        }
示例#11
0
    public override void Init()
    {
        base.Init();
        wanderState     = new WanderState(this);
        hideState       = new HideState(this);
        retreatState    = new Retreat(this, enemyObj.health.maxHealth);
        refillAmmoState = new RefifllAmmo(this);
        stunnedState    = new StunnedState(this);

        hideState.AddTransition(() =>
        {
            if (hideState.doneHiding)
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Ok, done hiding");
                return(true);
            }
            return(false);
        }, wanderState);

        //Will look for healthpack if health is not at max
        wanderState.AddTransition(() =>
        {
            if (enemyObj.health.GetHealth() < enemyObj.health.maxHealth)
            {
                var packs = GameManager.Instance.GetAvailableHealthPacks();
                if (packs.Count > 0)
                {
                    if (stateMachine.GetCurrentState() != retreatState)
                    {
                        retreatState.allPacks = packs.ToArray();

                        Diagnostic.Instance.AddLog(enemyObj.gameObject, "Low health, got nothing to do, going to get some");
                        return(true);
                    }
                }
            }
            return(false);
        }, retreatState);

        //Will look for healthpack if health is not at max
        wanderState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo < enemyObj.rifle.MaxAmmo)
            {
                var packs = GameManager.Instance.GetAvailableAmmoPacks();
                if (packs.Count > 0)
                {
                    if (stateMachine.GetCurrentState() != refillAmmoState)
                    {
                        refillAmmoState.allPacks = packs.ToArray();

                        Diagnostic.Instance.AddLog(enemyObj.gameObject, "Low ammo, got nothing to do, going to get some");
                        return(true);
                    }
                }
            }
            return(false);
        }, refillAmmoState);

        retreatState.AddTransition(() =>
        {
            var packs = GameManager.Instance.GetAvailableHealthPacks();
            //If the health was restored, or no packs available  go back wandering
            if (enemyObj.health.GetHealth() >= enemyObj.health.maxHealth ||
                enemyObj.health.GetHealth() < enemyObj.health.maxHealth && packs.Count == 0)
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, going to stroll around...");
                return(true);
            }

            return(false);
        }, wanderState);

        refillAmmoState.AddTransition(() =>
        {
            var packs = GameManager.Instance.GetAvailableAmmoPacks();
            //If the health was restored, or no packs available  go back wandering
            if (enemyObj.rifle.Ammo >= enemyObj.rifle.MaxAmmo ||
                enemyObj.rifle.Ammo < enemyObj.rifle.MaxAmmo && packs.Count == 0)
            {
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, going to stroll around...");
                return(true);
            }

            return(false);
        }, wanderState);

        stunnedState.AddTransition(() =>
        {
            if (!stunnedState.isStunned)
            {
                return(true);
            }

            return(false);
        },
                                   hideState);

        stateMachine.SetState(wanderState);
    }
示例#12
0
 void OnHideScreen(string screenId, HideState state)
 {
     OnHide?.Invoke(new HideEv {
         ScreenId = screenId, State = state
     });
 }
示例#13
0
    public override void Init()
    {
        base.Init();
        wanderState        = new WanderState(this);
        shootState         = new ShootState(this, enemyObj.shootRate);
        investigationState = new InvestigateState(this);
        retreatState       = new Retreat(this, minHealthForRetreat);
        hideState          = new HideState(this);
        bombAvoidState     = new BombAvoid(this);
        refillAmmoState    = new RefifllAmmo(this);
        stunnedState       = new StunnedState(this);

        shootState.AddTransition(() =>
        {
            if (!enemyObj.enemySight.IsPlayerInSight())
            {
                investigationState.waitBeforeGoingToPoint = 0;
                investigationState.investigationPoint     = Player.Instance.transform.position;
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Lost sight of player, going to check last known position");

                return(true);
            }
            return(false);
        }, investigationState);

        shootState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo <= 0)
            {
                var allPacks = GameManager.Instance.GetAvailableAmmoPacks();
                if (allPacks.Count == 0)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Out of ammo, no packs around, going to hide!");
                    return(true);
                }
            }
            return(false);
        }, hideState);

        shootState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo <= 0)
            {
                var allPacks = GameManager.Instance.GetAvailableAmmoPacks();
                if (allPacks.Count > 0)
                {
                    refillAmmoState.allPacks = allPacks.ToArray();
                    refillAmmoState.playerLastKnowsPosition = Player.Instance.transform.position;
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Out of ammo, going to refill!");
                    return(true);
                }
            }
            return(false);
        }, refillAmmoState);

        investigationState.AddTransition(() => {
            return(investigationState.done);
        }, wanderState);

        refillAmmoState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo <= 0)
            {
                var allPacks = GameManager.Instance.GetAvailableAmmoPacks();
                if (allPacks.Count == 0)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "No ammo boxe available, will hide!");

                    return(true);
                }
            }

            return(false);
        }, hideState);

        refillAmmoState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo > 0)
            {
                if (refillAmmoState.playerLastKnowsPosition != null)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Go ammo, going to check last player known position");

                    investigationState.investigationPoint = refillAmmoState.playerLastKnowsPosition.Value;
                    return(true);
                }
            }

            return(false);
        }, investigationState);

        refillAmmoState.AddTransition(() =>
        {
            if (enemyObj.rifle.Ammo > 0)
            {
                if (refillAmmoState.playerLastKnowsPosition == null)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Go ammo, don't know where player is, will wander around");

                    return(true);
                }
            }

            return(false);
        }, wanderState);

        //If health is ok and retreat has a player known pos, go investigate
        retreatState.AddTransition(() => {
            if (enemyObj.health.GetHealth() >= minHealthForRetreat)
            {
                if (retreatState.playerLastKnowsPosition != null)
                {
                    investigationState.investigationPoint = retreatState.playerLastKnowsPosition.Value;
                }

                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, go to check last investigation point");

                return(true);
            }

            return(false);
        }, investigationState);

        //If health is ok and retreat has no player known pos, go patrol

        retreatState.AddTransition(() => {
            if (enemyObj.health.GetHealth() >= minHealthForRetreat)
            {
                if (retreatState.playerLastKnowsPosition == null)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Feeling better, go to back to wander");
                    return(true);
                }
            }

            return(false);
        }, wanderState);

        retreatState.AddTransition(() =>
        {
            if (enemyObj.health.GetHealth() < minHealthForRetreat)
            {
                var packs = GameManager.Instance.GetAvailableHealthPacks();

                if (packs.Count == 0 && !hideState.isHiding)
                {
                    Diagnostic.Instance.AddLog(enemyObj.gameObject, "Go a healthpack, but still feel crap, will go hide");
                }

                return(packs.Count == 0 && !hideState.isHiding);
            }
            return(false);
        }, hideState);


        //Will come out of hiding only when a health pack is available again
        hideState.AddTransition(() => {
            var packs = GameManager.Instance.GetAvailableHealthPacks();

            if (packs.Count > 0 && enemyObj.health.GetHealth() < retreatState.minHealthForRetreat)
            {
                retreatState.allPacks = packs.ToArray();
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Healthpack is available, going to get it!");

                return(true);
            }

            return(false);
        }, retreatState);

        //Will come out of hiding only when a ammo pack is available again
        hideState.AddTransition(() => {
            var packs = GameManager.Instance.GetAvailableAmmoPacks();
            if (packs.Count > 0 && enemyObj.health.GetHealth() >= retreatState.minHealthForRetreat)
            {
                refillAmmoState.allPacks = packs.ToArray();
                Diagnostic.Instance.AddLog(enemyObj.gameObject, "Ammo box is available, going to get it!");

                return(true);
            }

            return(false);
        }, refillAmmoState);

        bombAvoidState.AddTransitionDynamicState(() =>
        {
            return(bombAvoidState.readyToGo);
        },
                                                 () => { return(stateMachine.previousState); });

        stunnedState.AddTransition(() =>
        {
            if (!stunnedState.isStunned)
            {
                investigationState.investigationPoint = enemyObj.transform.position;

                return(true);
            }

            return(false);
        },
                                   investigationState);

        //Soldier will respond to alarm
        Enemy.OnAlarmSent += GoInvestigateSOS;
        stateMachine.SetState(wanderState);
    }
示例#14
0
        public IEnumerator GoToPosition(Vector3 startPosition, Vector3 endPosition, float t, HideState state) //Makes the log rotate around the axis for x degrees over t seconds
        {
            float     step            = 0f;                                                                   //raw step
            float     smoothStep      = 0f;                                                                   //current smooth step
            float     lastStep        = 0f;                                                                   //previous smooth step
            Transform lizardTransform = _lizard.transform;

            while (step < 1f)                                // until we're done
            {
                step      += Time.deltaTime / t;             // for t seconds
                smoothStep = Mathf.SmoothStep(0f, 1f, step); // finding smooth step

                //Do Smooth Translation to position
                lizardTransform.position = Vector3.Lerp(startPosition, endPosition, smoothStep);

                lastStep = smoothStep;                 //get previous last step
                yield return(null);
            }
            //once mouvement is over, Tell the state
            state.isSafe = true;
        }