Esempio n. 1
0
 //... HP CALCULATION
 public void Hit(float damage, Vector3 position)
 {
     if (!(_state is Dead))
     {
         sound.clip = hurt;
         sound.Play();
         currHP -= damage;
         _lastRelativeHitPosition =
             position - gameObject.transform.position; //Vector from enemy center to hit position!
         if (currHP <= 0)
         {
             IsDying();
             _state = new Dead(2.5f);
         }
         else
         {
             _lastSeenPlayerPosition = Player.transform.position;
             currentSenseState       = SenseStates.attackedByPlayer; //SenseStates.playerSpotted;
             _state = new Search();
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Converts which sense states are enabled based on which values are true.
        /// Converts into medtronic api format based on the true values input as parameters
        /// </summary>
        /// <param name="TimeDomain">True if enabled and false if disabled</param>
        /// <param name="FFT">True if enabled and false if disabled</param>
        /// <param name="Power">True if enabled and false if disabled</param>
        /// <param name="LD0">True if enabled and false if disabled</param>
        /// <param name="LD1">True if enabled and false if disabled</param>
        /// <param name="AdaptiveState">True if enabled and false if disabled</param>
        /// <param name="LoopRecording">True if enabled and false if disabled</param>
        /// <param name="Unused">True if enabled and false if disabled</param>
        /// <returns>SenseStates for all the true values that were input as parameter. SenseStates.None if there were not any true values. If there was an error, a message is displayed and program terminated</returns>
        public static SenseStates TDSenseStatesConvert(bool TimeDomain, bool FFT, bool Power, bool LD0, bool LD1, bool AdaptiveState, bool LoopRecording, bool Unused)
        {
            SenseStates state = SenseStates.None;

            try
            {
                if (TimeDomain)
                {
                    state = SenseStates.LfpSense;
                }
                if (FFT)
                {
                    if (state.Equals(SenseStates.None))
                    {
                        state = SenseStates.Fft;
                    }
                    else
                    {
                        state = state | SenseStates.Fft;
                    }
                }
                if (Power)
                {
                    if (state.Equals(SenseStates.None))
                    {
                        state = SenseStates.Power;
                    }
                    else
                    {
                        state = state | SenseStates.Power;
                    }
                }
                if (LD0)
                {
                    if (state.Equals(SenseStates.None))
                    {
                        state = SenseStates.DetectionLd0;
                    }
                    else
                    {
                        state = state | SenseStates.DetectionLd0;
                    }
                }
                if (LD1)
                {
                    if (state.Equals(SenseStates.None))
                    {
                        state = SenseStates.DetectionLd1;
                    }
                    else
                    {
                        state = state | SenseStates.DetectionLd1;
                    }
                }
                if (AdaptiveState)
                {
                    if (state.Equals(SenseStates.None))
                    {
                        state = SenseStates.AdaptiveStim;
                    }
                    else
                    {
                        state = state | SenseStates.AdaptiveStim;
                    }
                }
                if (LoopRecording)
                {
                    if (state.Equals(SenseStates.None))
                    {
                        state = SenseStates.LoopRecording;
                    }
                    else
                    {
                        state = state | SenseStates.LoopRecording;
                    }
                }
                if (Unused)
                {
                    if (state.Equals(SenseStates.None))
                    {
                        state = SenseStates.Unused08;
                    }
                    else
                    {
                        state = state | SenseStates.Unused08;
                    }
                }
            }
            catch
            {
                DisplayErrorMessageAndClose("Error converting Sense States.");
            }
            return(state);
        }
Esempio n. 3
0
        private void FixedUpdate()
        {
            //Debug.Log(currHP);
            //==============================================================================================================
            if (!(_state is Dead))
            {
                ActionState newState = NotDead();
                _state = (newState != null) ? newState : _state;
                if (currentSenseState != SenseStates.neverSeenPlayer)
                {
                    if (hasAlzheimer)
                    {
                        if (alzheimerTimer >= 0)
                        {
                            alzheimerTimer -= Time.deltaTime;
                        }
                        else
                        {
                            alzheimerTimer    = patience;
                            currentSenseState = SenseStates.neverSeenPlayer;
                            _state            = new Idle(20f);
                        }
                    }
                }


                var     playerPosition = Player.transform.position;
                Vector3 vectorToPlayer = eyes.transform.position - playerPosition;

                float distanceFromPlayer = vectorToPlayer.magnitude;
                float angel = Vector3.Angle(-transform.forward, vectorToPlayer);

                //Debug.Log("distanceFromPlayer: " +distanceFromPlayer);
                if (distanceFromPlayer > 35)
                {
                    SwitchEnemyColliderState(false); //Improve performance
                }
                else
                {
                    SwitchEnemyColliderState(true);
                    if (
                        distanceFromPlayer <= 1.95 &&
                        !Physics.Linecast(eyes.position, Player.transform.position, searchMask) ||
                        (distanceFromPlayer <= sightDistance &&
                         angel <= sightAngle &&
                         !Physics.Linecast(eyes.position, Player.transform.position, searchMask))
                        )
                    {
                        if (Mathf.Abs(eyes.position.y - playerPosition.y) < 3f) //Vertical distance is narrowed.
                        {
                            //...only when player is on the same level attacking makes sense!
                            _lastSeenPlayerPosition = Player.transform.position;
                            if (!(_state is Attack))
                            {
                                _state            = new Chase(patience);
                                currentSenseState = SenseStates.playerSpotted;
                            }
                        }
                    }
                }
            }

            _state = _state.update(this, Time.deltaTime);
            _DrawPath();
        }