Пример #1
0
 //If an MP Energy component is slotted, subtract from the current value
 public void DecrementMP(int amount)
 {
     if (mp != null)
     {
         mp.Decrement(amount);
     }
 }
Пример #2
0
        //If an HP Energy component is attached, this lowers its value by the amount damaged. Also does processing to ensure the player CAN be damaged first (i.e. that it isn't currently invincible) and determines if knockback should be applied.
        public int Damage(int amount, bool willCauseKnockback = true, BattleEnums.DamageType damageType = BattleEnums.DamageType.Regular, Collider2D col = null)
        {
            int damageTaken = 0;

            if (!WillProcessDamageFromObject(col) || DetermineIfInvincible() || isDead)
            {
                return(0);
            }

            if (hp != null)
            {
                hp.Decrement(amount);
                damageTaken = hp.previous - hp.current;
            }

            if (damagedProperties.willShowDamagedNumber)
            {
                float yPosition = (slots.collider != null) ? slots.collider.bounds.max.y : transform.position.y;
                DamageNumberManager.Instance.ShowNumber(amount, new Vector2(transform.position.x, yPosition));
            }

            Direction.Horizontal knockbackDirection = Direction.Horizontal.Right;

            if (damageType != BattleEnums.DamageType.Poison)
            {
                if (damagedProperties.willFlash)
                {
                    Flash();
                }
            }

            if (hp == null)
            {
                return(0);
            }

            if (hp.current <= 0)
            {
                SetDeathParameters();
            }
            else
            {
                if (damageType != BattleEnums.DamageType.Poison)
                {
                    if (damagedProperties.willShakeScreen)
                    {
                        ScreenShake.Instance.Shake();
                    }

                    if (willCauseKnockback)
                    {
                        if (col != null)
                        {
                            knockbackDirection = (col.transform.position.x < transform.position.x) ? Direction.Horizontal.Right : Direction.Horizontal.Left;
                        }
                        else
                        {
                            knockbackDirection = (slots.controller && slots.controller.direction.horizontal == Direction.Horizontal.Left) ? Direction.Horizontal.Right : Direction.Horizontal.Left;
                        }

                        if (currentAttack != null)
                        {
                            if (currentAttack.canceledBy.onKnockback)
                            {
                                currentAttack.Cancel();
                            }
                            else
                            {
                                willCauseKnockback = false;
                            }
                        }
                    }

                    bool didChangeController = false;
                    if (damagedProperties.damagedControllers.damagedController && hp.current <= damagedProperties.damagedControllers.hpThreshold)
                    {
                        SetController(damagedProperties.damagedControllers.damagedController);
                        didChangeController = true;
                    }

                    StartDamageInvincibility();

                    if (!(currentAttack != null && !currentAttack.canceledBy.onKnockback) && willCauseKnockback)
                    {
                        if (slots.controller && !didChangeController)
                        {
                            slots.controller.Knockback(knockbackDirection);
                        }
                    }
                }
            }

            if (col != null && damageType != BattleEnums.DamageType.Poison)
            {
                HitSparkManager.Instance.CreateHitSpark(GetComponent <BoxCollider2D>(), col.GetComponent <BoxCollider2D>(), (damageTaken > 0), hp.current);
                OnHit(damageTaken, col);
                if (col.GetComponent <RexActor>() != null)
                {
                    //col.GetComponent<RexActor>().StartContactDelay();
                }

                if (GetComponent <Jitter>())
                {
                    GetComponent <Jitter>().Play();
                }
            }

            return(damageTaken);
        }