Untitled

 avatar
unknown
c_cpp
2 years ago
2.4 kB
5
Indexable
bool Combat::getMinMaxValues(Creature* creature, Creature* target, CombatParams& _params, int32_t& min, int32_t& max) const
{
	if(creature)
	{
		if(creature->getCombatValues(min, max))
			return true;

		if(Player* player = creature->getPlayer())
		{
			if(params.valueCallback)
			{
				params.valueCallback->getMinMaxValues(player, _params, min, max);
				return true;
			}

			std::string value;
			player->getStorage("72345", value);
			int32_t rebirths = (int32_t)(atoi(value.c_str()));
 
			min = max = 0;
			switch(formulaType)
			{
				case FORMULA_LEVELMAGIC:
				{
					min = (int32_t)((700000 + (rebirths * 10) / minl + player->getMagicLevel() * minm) * 1. * mina + minb);
					max = (int32_t)((700000 + (rebirths * 10) / maxl + player->getMagicLevel() * maxm) * 1. * maxa + maxb);
					if(minc && std::abs(min) < std::abs(minc))
						min = minc;

					if(maxc && std::abs(max) < std::abs(maxc))
						max = maxc;

					player->increaseCombatValues(min, max, params.useCharges, true);
					return true;
				}

				case FORMULA_SKILL:
				{
					bool crit = false;
					Item* item = player->getWeapon(false);
					if(const Weapon* weapon = g_weapons->getWeapon(item))
					{
						_params.element.type = item->getElementType();
						if(_params.element.type != COMBAT_NONE)
						{
							_params.element.damage = weapon->getWeaponElementDamage(player, item, true);
							_params.element.damage = random_range((int32_t)0, (int32_t)(_params.element.damage * maxa + maxb), DISTRO_NORMAL);
						}

						max = (int32_t)(weapon->getWeaponDamage(player, target, item, crit, true) * maxa + maxb);
						if(params.useCharges && item->hasCharges() && g_config.getBool(ConfigManager::REMOVE_WEAPON_CHARGES))
							g_game.transformItem(item, item->getID(), std::max((int32_t)0, ((int32_t)item->getCharges()) - 1));
					}
					else
						max = (int32_t)maxb;

					if(crit)
						min = max;
					else
						min = (int32_t)minb;

					if(maxc && std::abs(max) < std::abs(maxc))
						max = maxc;

					return true;
				}

				case FORMULA_VALUE:
				{
					min = (int32_t)minb;
					max = (int32_t)maxb;
					return true;
				}

				default:
					break;
			}

			return false;
		}
	}

	if(formulaType != FORMULA_VALUE)
		return false;

	min = (int32_t)mina;
	max = (int32_t)maxa;
	return true;
}
Editor is loading...