public AttackInfo(Unit sUnit, Unit tUnit, bool useAOE = true) { srcUnit = sUnit; tgtUnit = tUnit; damageMin = srcUnit.GetDamageMin(); damageMax = srcUnit.GetDamageMax(); aoeRange = useAOE ? srcUnit.GetAOERange() : 0; critChance = srcUnit.GetCritChance(); critMultiplier = tUnit.GetImmunedToCrit() ? 0 : srcUnit.GetCritMultiplier(); //~ useEffect=srcUnit.UseEffectOnHit(); //~ if(useEffect) effect=srcUnit.GetEffectOnHit().Clone(); if (Random.value < srcUnit.GetEffectOnHitChance()) { effect = srcUnit.GetEffectOnHit(); } critical = Random.value < critChance; damage = Mathf.Round(Random.Range(damageMin, damageMax)) * (critical ? critMultiplier : 1); //Debug.Log(damageMin+" "+damageMax+" "+damage); damage *= DamageTable.GetModifier(tgtUnit.GetArmorType(), srcUnit.GetDamageType()); damage *= (1 - tUnit.GetDmgReduction()); if (Random.value < srcUnit.GetHit() - tgtUnit.GetDodge()) { hit = true; } }
//stats processing for attack from unit (tower/creep) public void Process_SrcUnit() { if (srcUnit.GetHit() <= 0) { Debug.LogWarning("Attacking unit (" + srcUnit.unitName + ") has default hitChance of 0%, is this intended?", srcUnit); } float hitChance = Mathf.Clamp(srcUnit.GetHit() - tgtUnit.GetDodge(), 0, 1); if (Random.Range(0f, 1f) > hitChance) { missed = true; return; } if (srcUnit.GetInstantKill().IsApplicable(tgtUnit.HP, tgtUnit.fullHP)) { damage = tgtUnit.HP; damageHP = tgtUnit.HP; instantKill = true; destroy = true; return; } damage = Random.Range(srcUnit.GetDamageMin(), srcUnit.GetDamageMax()); damage /= (float)srcUnit.GetShootPointCount(); //divide the damage by number of shootPoint float critChance = srcUnit.GetCritChance(); if (tgtUnit.immuneToCrit) { critChance = -1f; } if (Random.Range(0f, 1f) < critChance) { critical = true; damage *= srcUnit.GetCritMultiplier(); //new TextOverlay(impactPoint, "Critical", new Color(1f, .6f, 0f, 1f)); } float dmgModifier = DamageTable.GetModifier(tgtUnit.armorType, srcUnit.damageType); damage *= dmgModifier; if (damage >= tgtUnit.shield) { damageShield = tgtUnit.shield; damageHP = damage - tgtUnit.shield; } else { damageShield = damage; damageHP = 0; } if (Random.Range(0f, 1f) < srcUnit.GetShieldPierce() && damageShield > 0) { damageHP += damageShield; damageShield = 0; pierceShield = true; //new TextOverlay(impactPoint,"Shield Pierced", new Color(0f, 1f, 1f, 1f)); } if (srcUnit.DamageShieldOnly()) { damageHP = 0; } if (damageHP >= tgtUnit.HP) { destroy = true; return; } if (Random.Range(0f, 1f) < srcUnit.GetShieldBreak() && tgtUnit.fullShield > 0) { breakShield = true; } stunned = srcUnit.GetStun().IsApplicable(); if (tgtUnit.immuneToStun) { stunned = false; } slowed = srcUnit.GetSlow().IsValid(); if (tgtUnit.immuneToSlow) { slowed = false; } if (srcUnit.GetDot().GetTotalDamage() > 0) { dotted = true; } if (stunned) { stun = srcUnit.GetStun().Clone(); } if (slowed) { slow = srcUnit.GetSlow().Clone(); } if (dotted) { dot = srcUnit.GetDot().Clone(); } }