示例#1
0
    /// <summary>
    /// 对敌人造成伤害
    /// </summary>
    /// <param name="enemy">敌人对象</param>
    /// <param name="baseDamage">基础伤害</param>
    /// <param name="direction">伤害方向</param>
    /// <param name="extraDamage">额外伤害</param>
    public void Damage(GameObject enemy, float baseDamage, float direction, float extraDamage = 0)
    {
        var enemyMovement = enemy.GetComponent <EnemyMovement>();

        if (!enemyMovement.canGetDamage())
        {
            return;
        }
        int type = 1;

        baseDamage += property.GetAttack();
        if (property.HaveEquipment("SkullSword"))
        {
            baseDamage += property.GetCoinNumber() / 20 * 2;
        }
        if (property.HaveEquipment("WizardSword") && Random.Range(0, 1f) < 0.05f)
        {
            property.SetShield(1);
        }
        if (property.HaveEquipment("ThiefMask") && Random.Range(0, 1f) < 0.1f)
        {
            GameObject coin = Resources.Load <GameObject>("Prefabs/Item/SilverCoin");
            Instantiate(coin).GetComponent <Item>().Emit(enemy.transform.position, false);
        }
        if (property.HaveEquipment("SamuraiSoul") && Random.Range(0, 1f) < 0.3f)
        {
            baseDamage *= 2;
            type       += 2;
        }
        if (extraDamage > 0)
        {
            type++;
        }
        if (property.HaveEquipment("ShadowBlade") && direction * enemy.transform.localScale.x > 0)
        {
            extraDamage += 10;
            if (type != 2 && type != 4)
            {
                type++;
            }
        }
        if (property.HaveEquipment("EnergyDrink"))
        {
            if (Random.Range(0, 1f) < 0.35f)
            {
                extraDamage += Random.Range(10, 51);
                if (type != 2 && type != 4)
                {
                    type++;
                }
            }
        }
        if (property.HaveEquipment("BloodyFangs"))
        {
            if (!enemy.TryGetComponent(out BloodyFangs bloodyFangs))
            {
                bloodyFangs = enemy.AddComponent <BloodyFangs>();
            }
            bloodyFangs.AddHurtNumber();
            extraDamage += bloodyFangs.GetExtraDamage();
            if (extraDamage > 0 && type != 2 && type != 4)
            {
                type++;
            }
        }
        float damage = baseDamage + extraDamage;

        enemyMovement.getDamage(damage, (int)direction);
        PoolManager.GetInstance().GetDamageText(enemy.transform.position, damage, type);
    }