• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Defense Formula

Yngwie

Member
Joined
May 16, 2008
Messages
155
Reaction score
14
Hi, was wondering if anyone could point me in direction,

Where (In the source) is the calculations for armor and defense (shield)

For both players and monsters.
 
Do you mean:

LUA:
Full - 100/0 -- 100% Attack
Balance - 50/50 -- 50% Defense, 50% Attack
Defense - 0/100 -- 100% Defense

Curious :huh:
 
No, I meant the actual calculation in the source,

The damage calculation for example is in weapons.cpp line 147

Code:
int32_t Weapons::getMaxWeaponDamage(int32_t level, int32_t attackSkill, int32_t attackValue, float attackFactor)
{
	return (int32_t)std::ceil((2 * attackValue * (attackSkill + 5.8) / 25 + (level - 1) / 10.) / attackFactor);
}
 
Maybe this is what you are looking for?

Code:
int32_t Player::getDefense() const
{
	int32_t baseDefense = 5;
	int32_t defenseValue = 0;
	int32_t defenseSkill = 0;
	int32_t extraDefense = 0;
	float defenseFactor = getDefenseFactor();
	const Item* weapon = NULL;
	const Item* shield = NULL;
	getShieldAndWeapon(shield, weapon);

	if(weapon)
	{
		defenseValue = baseDefense + weapon->getDefense();
		extraDefense = weapon->getExtraDefense();
		defenseSkill = getWeaponSkill(weapon);
	}

	if(shield && shield->getDefense() >= defenseValue)
	{
		defenseValue = baseDefense + shield->getDefense() + extraDefense;
		defenseSkill = getSkill(SKILL_SHIELD, SKILL_LEVEL);
	}

	if(vocation->defenseMultipler != 1.0)
		defenseValue = int32_t(defenseValue * vocation->defenseMultipler);

	return ((int32_t)std::ceil(((float)(defenseSkill * (defenseValue * 0.015)) + (defenseValue * 0.1)) * defenseFactor));
}

But when I do: ((((21 * (55 * 0.015)) + (55 * 0.1)) * 1)) I get 22.825 and I made a monster to hit 30s constantly, and he sometimes hits 1s 2s etc. Shouldn't he not be able to?
 
Last edited:
There's a seperate armor calculation which might be blocking the last 6-7 points

Oh cool, thanks.

I found this, but it makes the value lower:

Code:
		if(checkArmor)
		{
			int32_t armorValue = getArmor();
			int32_t minArmorReduction = 0;
			int32_t maxArmorReduction = 0;
			if(armorValue > 1)
			{
				minArmorReduction = (int32_t)std::ceil(armorValue * 0.475);
				maxArmorReduction = (int32_t)std::ceil(((armorValue * 0.475) - 1) + minArmorReduction);
			}
			else if(armorValue == 1)
			{
				minArmorReduction = 1;
				maxArmorReduction = 1;
			}

			damage -= random_range(minArmorReduction, maxArmorReduction);
			if(damage <= 0)
			{
				damage = 0;
				blockType = BLOCK_ARMOR;
			}
		}

I checked both afformentioned formulas and they're not 100% accurate. I have a shield (nothing else) with 14 defence and 21 shielding = 6.225 (6) damage resistance and I'm getting hit 22... when the monster should hit 30 max all the time. So that's 2 off.
 
Last edited:
Back
Top