示例#1
0
    public void TakeDamage(Damage damage)
    {
        TakedDamage?.Invoke(damage);

        float initialDamage              = damage.Amount;
        CharacterAttribute energySheild  = attributes.dynamicAttributes[DynamicAttributeType.EnergyShieldAmount];
        CharacterAttribute health        = attributes.dynamicAttributes[DynamicAttributeType.HealthAmount];
        CharacterAttribute armour        = attributes.scalableAttributes[ScalableAttributeType.ArmourAmount];
        CharacterAttribute armourQuality = attributes.scalableAttributes[ScalableAttributeType.ArmourQuality];

        float damageWithConsumedEnergyShield = initialDamage;

        if (damage.Amount <= energySheild.Amount)
        {
            energySheild.Amount           -= initialDamage;
            damageWithConsumedEnergyShield = 0;
        }
        else
        {
            damageWithConsumedEnergyShield -= energySheild.Amount;
            energySheild.Amount             = 0;
        }

        float damageWithArmourReduction = damageWithConsumedEnergyShield * 0.7f;
        float damageAvoidedArmour       = damageWithConsumedEnergyShield * 0.3f;

        if (damageWithArmourReduction >= armour.Amount * armourQuality.Amount)
        {
            damageWithArmourReduction -= armour.Amount * armourQuality.Amount;
        }
        else
        {
            damageWithArmourReduction = 0;
        }

        float totalDamage = damageWithArmourReduction + damageAvoidedArmour;

        if (initialDamage > 0)
        {
            health.Amount -= totalDamage;
        }
        Debug.Log("Damage " + totalDamage.ToString());
    }
        /// <summary>
        /// ダメージを受ける
        /// </summary>
        public void TakeDamage(DamageResult damageResult)
        {
            // すでに死亡していたら何もしない
            if (this.status.HitPoint.Value <= 0)
            {
                return;
            }

            this.status.HitPoint.Value -= damageResult.Damage;
            this.owner.Broker.Publish(TakedDamage.Get(damageResult));

            // 与えた側にも通知する
            damageResult.Attacker?.Broker.Publish(GivedDamage.Get(damageResult));

            // 死亡したら通知する
            if (this.status.HitPoint.Value <= 0)
            {
                this.owner.Broker.Publish(Died.Get(damageResult.Attacker));
            }
        }