Exemple #1
0
    private IEnumerator ShowBloodSplash(SNWeapon.AttackClass attack, SNCharacter dealer)
    {
        if (bloodSplashPrefab != null)
        {
            if (attack.bloodSplahIndexes.Length > 0)
            {
                int index = attack.bloodSplahIndexes [Random.Range(0, attack.bloodSplahIndexes.Length)];

                GameObject gob = Instantiate(bloodSplashPrefab, characterTransform.position, Quaternion.identity);
                if (dealer)
                {
                    float direction = transform.position.x - dealer.transform.position.x;
                    if (direction > 0)
                    {
                        gob.GetComponent <SpriteRenderer> ().flipX = true;
                    }
                }
                Debug.Log("Show blood splash with index " + index);
                gob.GetComponent <SpriteRenderer> ().color = bloodColor;
                gob.GetComponent <Animator> ().Play("Splash" + index);
                yield return(new WaitForSeconds(1));

                gob.GetComponent <SpriteRenderer> ().sortingOrder = -1;
                //yield return new WaitForSeconds (1);
                gob.GetComponent <Animator> ().Play("Hide" + index);
                yield return(new WaitForSeconds(5));

                Destroy(gob);
            }
        }
    }
Exemple #2
0
    public void HitBlock(SNWeapon.AttackClass attack, Transform dealer, float duration, float force)
    {
        if (movementController != null)
        {
            Vector2 dir = dealer.position - this.characterTransform.position;
            //bool criticalHit = false;
            int   damage = Random.Range(attack.attackDamageMin, attack.attackDamageMax);
            float crit   = Random.Range(0.01f, 1f);

            if (crit <= attack.criticalDamageRatio)
            {
                //criticalHit = true;
                damage *= 2;
            }
            ShowHitSpark(2, (dealer.position + this.characterTransform.position) / 2);
            if (weapon != null)
            {
                weapon.blockPower -= damage;
            }
            if (weapon.blockPower > 0)
            {
                movementController.Knockback(-dir, attack.enemyPushForce, attack.enemyPushDuration);
            }
            else
            {
                ParryKnockback(dealer, duration, force);
            }
        }
    }
Exemple #3
0
 private void ShowHitSpark(SNWeapon.AttackClass attack)
 {
     if (hitSparkPrefab != null)
     {
         if (attack.hitSparkIndexes.Length > 0)
         {
             int index = attack.hitSparkIndexes [Random.Range(0, attack.hitSparkIndexes.Length)];
             ShowHitSpark(index, characterTransform.position);
         }
     }
 }
Exemple #4
0
    public void TakeDamage(SNWeapon.AttackClass attack, SNCharacter dealer)
    {
        if (!dead)
        {
            bool  criticalHit = false;
            int   damage      = Random.Range(attack.attackDamageMin, attack.attackDamageMax);
            float crit        = Random.Range(0.01f, 1f);

            if (crit <= attack.criticalDamageRatio)
            {
                criticalHit = true;
                damage     *= 2;
            }
            ShowHit();
            if ((attack.shakeDuration > 0) && (attack.shakeStrengh > 0))
            {
                Camera.main.GetComponent <CameraFollow> ().Shake(attack.shakeDuration, attack.shakeStrengh);
            }
            health -= damage;
            if (healthBar != null)
            {
                healthBar.RefreshHealth(health);
            }
            if (damageIndicatorPrefab != null)
            {
                GameObject gob = Instantiate(damageIndicatorPrefab, transform.GetChild(0).position, Quaternion.identity);
                gob.GetComponent <DamageIndicator> ().ShowDamage(damage, criticalHit);
                gob.GetComponent <Animator> ().Play("dmg_indicator_show" + Random.Range(1, 4));
                Destroy(gob, 5);
            }
            StartCoroutine(ShowBloodSplash(attack, dealer));
            ShowHitSpark(attack);
            if (!immune)
            {
                Vector2 dir = dealer.transform.position - this.transform.position;
                movementController.Hurt(dir, attack.enemyPushDuration);
                movementController.Knockback(-dir, attack.enemyPushForce, attack.enemyPushDuration);
            }

            if (health <= 0 && !dead)
            {
                Death();
            }
        }
    }