// ----------------------------------------------------------------------------------- // Hit // ----------------------------------------------------------------------------------- public void Hit(HitInfo hitInfo) { if (health <= 0) { return; } Character source = null; if (hitInfo.source is Player) { source = Obj.GetPlayer; } DamageResult damageResult = Utl.DamageFormula(hitInfo.damage, defence, source); health -= damageResult.amount; SoundController.Play(hitSound, transform.position); if (hitInfo.isShowEffect && damageResult.amount > 0) { if (hitEffectObject != null) { GameObject hitEffect = Instantiate(hitEffectObject, hitInfo.point, Quaternion.identity) as GameObject; Destroy(hitEffect, 3); } } if (health <= 0) { Death(); } }
// ----------------------------------------------------------------------------------- // Hit // ----------------------------------------------------------------------------------- public override void Hit(HitInfo hitInfo) { if (statistics.Health <= 0) { return; } DamageResult damageResult = Utl.DamageFormula(hitInfo.damage, resistances.resistances, hitInfo.source, this, hitInfo.baseAmount); hitInfo.amount = damageResult.amount; base.Hit(hitInfo); inventory.DamageEquipment((int)Mathf.Round(hitInfo.amount * hitInfo.damage.equipmentDamage)); }
// ----------------------------------------------------------------------------------- // Hit // ----------------------------------------------------------------------------------- public override void Hit(HitInfo hitInfo) { DamageResult damageResult = Utl.DamageFormula(hitInfo.damage, resistances.resistances, hitInfo.source, this, hitInfo.baseAmount); hitInfo.amount = damageResult.amount; base.Hit(hitInfo); StartShake(); if (hitInfo.source is Player) { Obj.GetPlayer.AdjustProperty(rewardStatisticBoost); } if (hitInfo.isShowEffect && hitEffectObject != null) { GameObject hitEffect = Instantiate(hitEffectObject, hitInfo.point, Quaternion.identity) as GameObject; Destroy(hitEffect, 3); } }
// =================================================================================== // DAMAGE // =================================================================================== // ----------------------------------------------------------------------------------- // DamageFormula // ----------------------------------------------------------------------------------- public static DamageResult DamageFormula(DamageTemplate damage, List <Element> defence, Character source = null, Character target = null, float baseDamage = 0) { DamageResult damageResult = new DamageResult(); int index; float bonus_damage = 0; float bonus_probability = 0; float element_damage = 0; float bonus_critical; float total_damage = baseDamage; // -- summarize all bonus damage if (source != null) { bonus_damage += source.CalculateProperties(damage.attackModifiers, PropertyTypes.TotalValue); } // -- summarize all base damage and base defence foreach (Element element1 in damage.elements) { element_damage = (element1.TotalValue + bonus_damage) * 4; // factor ? // -- randomize damage by variance element_damage = randomizeDamage(element_damage, damage.damageVariance); index = defence.FindIndex(e => e.template == element1.template); if (index != -1) { element_damage -= (defence[index].TotalValue * 2); // factor ? } total_damage += element_damage; } // -- check for critical or glancing hit if (source != null) { bonus_probability = source.CalculateProperties(damage.probabilityModifiers, PropertyTypes.TotalValue); } if (Random.value <= damage.criticalProbability + bonus_probability) { bonus_critical = damage.criticalPower; if (source != null) { bonus_critical += source.CalculateProperties(damage.powerModifiers, PropertyTypes.TotalValue); } total_damage *= bonus_critical; damageResult.type = DamageTypes.Critical; } //damageResult.type = DamageTypes.Glancing; // -- Target Dodge??? damageResult.amount = (int)total_damage; return(damageResult); }