int32_t WeaponMelee::getWeaponDamage(const Player* player, const Creature*, const Item* item, bool maxDamage /*= false*/) const
{
int32_t attackSkill = player->getWeaponSkill(item), attackValue = std::max((int32_t)0,
(int32_t(item->getAttack() + item->getExtraAttack()) - item->getElementDamage()));
float attackFactor = player->getAttackFactor();
double maxValue = Weapons::getMaxWeaponDamage(player->getLevel(), attackSkill, attackValue, attackFactor);
if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
{
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);
}