示例#1
0
        public override void ProcessAbility()
        {
            base.ProcessAbility();
            if (!AbilityPermitted)
            {
                return;
            }

            if (isClimbing && isNearWall)
            {
                _controller.SetVerticalForce(10.0f);
                float val = _Stamina.spendStamina(StaminaCost);
                if (val == 0)
                {
                    StopWallClimb();
                    _movement.ChangeState(CharacterStates.MovementStates.Jumping);
                    _Jump.JumpStart();
                }
            }
            else if (isClimbing && !isNearWall)
            {
                StopWallClimb();
                _movement.ChangeState(CharacterStates.MovementStates.pWallClimbFinish);
            }
        }
示例#2
0
        /// <summary>
        /// Causes the character to start shooting
        /// </summary>
        public virtual void ShootStart()
        {
            if (!atackingPermited)
            {
                return;
            }

            // if the Shoot action is enabled in the permissions, we continue, if not we do nothing.  If the player is dead we do nothing.
            if (!AbilityPermitted ||
                (_condition.CurrentState != CharacterStates.CharacterConditions.Normal) ||
                (_movement.CurrentState == CharacterStates.MovementStates.LadderClimbing))
            {
                return;
            }

            attacking = true;

            if (gameObject.tag == "Player")
            {
                _characterStamina.spendStamina(5.0f);
            }
        }
示例#3
0
        /// <summary>
        /// Called when the object takes damage
        /// </summary>
        /// <param name="damage">The amount of health points that will get lost.</param>
        /// <param name="instigator">The object that caused the damage.</param>
        /// <param name="flickerDuration">The time (in seconds) the object should flicker after taking the damage.</param>
        /// <param name="invincibilityDuration">The duration of the short invincibility following the hit.</param>
        public virtual void Damage(int damage, GameObject instigator, float flickerDuration, float invincibilityDuration, bool ignoreArmor = false)
        {
            // if the object is invulnerable, we do nothing and exit
            if (Invulnerable)
            {
                return;
            }

            // if we're already below zero, we do nothing and exit
            if ((CurrentHealth <= 0) && (InitialHealth != 0))
            {
                return;
            }

            if (isBlocking)
            {
                PlaySound(blockSound);
                DamageDisabled();
                StartCoroutine(DamageEnabled(invincibilityDuration));
                Vector2 knockbackForce = new Vector2(3.0f, 0.0f);
                if (_character.IsFacingRight)
                {
                    knockbackForce.x *= -1;
                }
                _controller.SetForce(knockbackForce);
                _stamina.spendStamina(blockStaminaSpend);
                gotHitCooldown = 5.0f;
                return;
            }
            gotHitCooldown = 5.0f;
            // we decrease the character's health by the damage
            float previousHealth = CurrentHealth;
            float rng            = Random.Range(0.0f, 1.0f);

            ignoreArmor    = (rng > 0.75f) ? true : ignoreArmor;
            CurrentHealth -= (ignoreArmor) ? damage : (damage - Armor);
            PlaySound(damageSound);
            if (OnHit != null)
            {
                OnHit();
            }

            if (CurrentHealth < 0)
            {
                CurrentHealth = 0;
            }

            // we prevent the character from colliding with Projectiles, Player and Enemies
            if (invincibilityDuration > 0)
            {
                DamageDisabled();
                StartCoroutine(DamageEnabled(invincibilityDuration));
            }

            // we trigger a damage taken event
            // TODO:: Event Manager will do something
            //MMEventManager.TriggerEvent(new MMDamageTakenEvent(_character, instigator, CurrentHealth, damage, previousHealth));

            if (_animator != null)
            {
                _animator.SetTrigger("Damage");
            }

            // we play the sound the player makes when it gets hit
            PlayHitSfx();

            // When the character takes damage, we create an auto destroy hurt particle system
            if (DamageEffect != null)
            {
                Instantiate(DamageEffect, transform.position, transform.rotation);
            }

            if (FlickerSpriteOnHit && !isBlocking)
            {
                // We make the character's sprite flicker
                if (_renderer != null)
                {
                    StartCoroutine(Blink(flickerDuration, 0.05f, 0.05f));
                }
            }

            //CharacterStates.CharacterTypes.AI
            if (_character.CharacterType == CharacterStates.CharacterTypes.Player)
            {
                UpdateHealthBar(true);
            }

            // if health has reached zero
            if (CurrentHealth <= 0)
            {
                // we set its health to zero (useful for the healthbar)
                CurrentHealth = 0;
                if (_character != null)
                {
                    //Debug.Log("Character's Health is " + CurrentHealth);

                    //if (_character.CharacterType == Character.CharacterTypes.Player)
                    //{
                    //	LevelManager.Instance.KillPlayer(_character);
                    //	return;
                    //}
                }

                Kill();
            }
        }