Jump to content

Recommended Posts

I implemented a pet system. To calculate the pet's buffs, I'm retrieving the DEF and STR values using GetPoint().

However, the retrieved values do not match the values displayed in the character (C) window.

The reason is that the buff function uses GetPoint(POINT_DEF_GRADE) and GetPoint(POINT_ATT_GRADE). This is also how many existing public pet systems are implemented.

Instead, you could implement the same calculation logic used in CPythonPlayer::__GetTotalAtk from the client source on the server side. This would allow the server to calculate the actual STR (Attack) value correctly and use it when applying pet buffs, ensuring the values match those shown in the character window.

Anyone who wants to use it can adapt it to their own pet system.

 

void CNewPet::GiveBuff()
{
	if (!m_pkChar || !m_petItem)
		return;

	m_pkOwner->RemoveAffect(EPetConstants::PET_AFFECT_TYPE);

	// ---- ATTACK (like client) ----
	LPITEM weapon = m_pkOwner->GetWear(WEAR_WEAPON);
	int weaponMin = 0, weaponMax = 0, weaponBonus = 0;
	if (weapon && weapon->GetType() == ITEM_WEAPON)
	{
		weaponMin = weapon->GetValue(3);
		weaponMax = weapon->GetValue(4);
		weaponBonus = weapon->GetValue(5);
	}

	int raceStat = 0;
	switch (m_pkOwner->GetJob())
	{
		case JOB_WARRIOR:
		case JOB_SURA:
			raceStat = m_pkOwner->GetPoint(POINT_ST);
			break;
		case JOB_ASSASSIN:
			raceStat = m_pkOwner->GetPoint(POINT_DX);
			break;
		case JOB_SHAMAN:
			raceStat = m_pkOwner->GetPoint(POINT_IQ);
			break;
#ifdef ENABLE_WOLFMAN_CHARACTER
		case JOB_WOLFMAN:
			raceStat = m_pkOwner->GetPoint(POINT_DX);
			break;
#endif
		default:
			raceStat = m_pkOwner->GetPoint(POINT_ST);
			break;
	}

	int levelAtk = m_pkOwner->GetLevel() * 2;
	int statAtk = (4 * m_pkOwner->GetPoint(POINT_ST) + 2 * raceStat) / 3;
	int hitRateSrc = (m_pkOwner->GetPoint(POINT_DX) * 4 + m_pkOwner->GetLevel() * 2) / 6;
	int hitRate = 100 * (MIN(90, hitRateSrc) + 210) / 300;
	int weaponAtk = (((weaponMin + weaponMax) / 2) + weaponBonus) * 2;
	int attValue = levelAtk + (statAtk + weaponAtk) * hitRate / 100;

	attValue += m_pkOwner->GetPoint(POINT_ATT_GRADE_BONUS);

	// -----------------------------------------------

	int baseValues[3] =
	{
		m_pkOwner->GetMaxHP(),
		m_pkOwner->GetPoint(POINT_CLIENT_DEF_GRADE),
		attValue
	};

//	m_pkOwner->ChatPacket(CHAT_TYPE_INFO, "MaxHP:%d ,Def:%d, Str:%d", baseValues[0], baseValues[1], baseValues[2]);
//	m_pkOwner->ChatPacket(CHAT_TYPE_INFO, "MaxHP:%d ,Def:%d, Str:%d", m_pkOwner->GetMaxHP(), m_pkOwner->GetPoint(POINT_DEF_GRADE), m_pkOwner->GetPoint(POINT_ATT_GRADE));

	for (int i = 0; i < 3; ++i)
	{
		m_pkOwner->AddAffect(
			EPetConstants::PET_AFFECT_TYPE,
			aApplyInfo[petBonusType[i]].bPointType,
			static_cast<int>(baseValues[i] * m_bonus[i] / 1000),
			0,
			INFINITE_AFFECT_DURATION,
			0,
			false
		);
	}
}

 

Link to comment
https://metin2.dev/topic/34656-growth-pet-system-str-fix/
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.