int32_t WeaponMelee::getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage /*= false*/) const
{
int32_t attackSkill = player->getWeaponSkill(item);
int32_t attackValue = std::max((int32_t)0, (int32_t(item->getAttack() + item->getExtraAttack()) - elementDamage));
float attackFactor = player->getAttackFactor();
double maxValue = Weapons::getMaxWeaponDamage(player->getLevel(), attackSkill, attackValue, attackFactor);
if(random_range(1, 100) <= g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE))
{
maxValue = std::pow(maxValue, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
player->sendCritical();
}
Vocation* vocation = player->getVocation();
if(vocation && vocation->getMultiplier(MULTIPLIER_MELEE) != 1.0)
maxValue *= vocation->getMultiplier(MULTIPLIER_MELEE);
int32_t ret = (int32_t)std::floor(maxValue);
if(maxDamage)
return -ret;
return -random_range(0, ret, DISTRO_NORMAL);
}