Jump to content

Sash Absorption % Calculation


Go to solution Solved by Ikarus_,

Recommended Posts

51 minutes ago, Ikarus_ said:

I've updated the code at the first message about void CPythonPlayer::__UpdateBattleStatus()

copy it again from there and let me know.

I think i ve solved both the problem you reported

It is working PERFECT!! :D 

Also:

Urx8PGm.png The rounding bug was not a bug anymore after your serverside&clientside source fix.

Thank you very very much ! 

 

One last question: 

HYgg2tR.png

I see i'm getting the server side value +.5

why is that?

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Developer
On 11/2/2020 at 12:54 AM, Ikarus_ said:

double AttBonusMax = static_cast<double>(pkItemAbsorbed->alValues[4] + pkItemAbsorbed->alValues[5]);
AttBonusMax *= acceItem->GetSocket(ACCE_ABSORPTION_SOCKET);
AttBonusMax /= 100;
AttBonusMax += 0.5;

double AttBonusMin = static_cast<double>(pkItemAbsorbed->alValues[3] + pkItemAbsorbed->alValues[5]);
AttBonusMin *= acceItem->GetSocket(ACCE_ABSORPTION_SOCKET);
AttBonusMin /= 100; 
AttBonusMin += 0.5;

 

 

check how it is calculated and you will know why.

I ve just used the identical formula on c++ (serverside and clientside) and in python so all values now should be aligned.

 

Edited by Ikarus_
  • Love 1

My youtube channel  on which you can see my works here

Link to comment
Share on other sites

5 hours ago, Ikarus_ said:

 

check how it is calculated and you will know why.

I ve just used the identical formula on c++ (serverside and clientside) and in python so all values now should be aligned.

 

I have tried with different sashes as values, also i have tried with the attBonusMin and Max -= 0.5;

Look:

ikY9Cd1.png

the values before the -.5 should be: 

20 and 27

45.03 and 52.63

^ this are The normal, calculated without round

With normal round it should be : 20 and 27 & 45 and 53

 

In Client side the round calculations are working good as i see on the sashes, but the server side are not.. There is no round in server side..

 

[EDIT]

TvjHtJZ.png

Also the char_skill part is not rounded. Can you please help me with a formula to round them? Thank you

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Developer

In my code i ve used the identical formula client-side and server-side, so the result values are equal.

Also in python the formula is identical, so why are u trying to change the formula?

 

  

16 hours ago, Shahin said:

With normal round it should be : 20 and 27 & 45 and 53

 

Also you can't define what is a 'normal round' and what isn't.

for example a number like 15.5 can be consider in many cases as 15 and in other cases as 16. Doesn't exists a standard to apply in this case, that's why we have to add a + 0.5 every where, in order to round always to the upper integer number, both python and c++.

without the +0.5 we may find different values on python rouding and on c++ rounding.

Edited by Ikarus_
  • Love 1

My youtube channel  on which you can see my works here

Link to comment
Share on other sites

7 minutes ago, Ikarus_ said:

In my code i ve used the identical formula client-side and server-side, so the result values are equal.

Also in python the formula is identical, so why are u trying to change the formula?

 

  

 

Also you can't define what is a 'normal round' and what isn't.

for example a number like 15.5 can be consider in many cases as 15 and in other cases as 16. Doesn't exists a standard to apply in this case, that's why we have to add a + 0.5 every where, in order to round always to the upper integer number, both python and c++.

without the +0.5 we may find different values on python rouding and on c++ rounding.

Ok, i understand that, but my squestion was: Why the serverside values are not rounded at all? Can you please check?

I asked this because python was good, but c++ was normal float value all of that calculation and just added + 0.5 or -0.5 at the end. No rounding after getting the final value. 

 

Before telling you about the calculation, i was doing a 20% sash with Battle sword +0 which meant 100 min att, 140 max att. In the calculation, it should be an integer at the end. 

The values should be 20% of 100 = 20 min attack; 20% of 140 = 28 max attack; The server side is showing me:

ascCSZ5.png

In which i mentioned not getting rounded at all.

 

Excuse me if i'm being insistent on this, but i am afraid of getting problems with giving damage at the end, not having a normal integer.

As you may remember, the client side in syserr was showing integer values (rounded), when we tested todebug.

 

Also: Thank you for your effort and implications ❤️

 

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Developer
double AttBonusMin = static_cast<double>(pkItemAbsorbed->alValues[3] + pkItemAbsorbed->alValues[5]);
AttBonusMin *= acceItem->GetSocket(ACCE_ABSORPTION_SOCKET);
AttBonusMin /= 100;
AttBonusMin += 0.5;

//todebug
if(ch->IsPhase(PHASE_GAME))
	ch->ChatPacket(CHAT_TYPE_INFO, "Going to add to your attack : min(%0.2f) max(%0.2f) ", AttBonusMin, AttBonusMax);

*pdamMax += static_cast<int>(AttBonusMax);
*pdamMin += static_cast<int>(AttBonusMin);

 

 

They are just rounded to integer (throught static_cast<int>) after the chat packet, that's why you are getting them as float in your chat.

but the way you may add more chat packets in this function to check step by step how it is calculating the values

Edited by Ikarus_
  • Love 3

My youtube channel  on which you can see my works here

Link to comment
Share on other sites

18 hours ago, Shahin said:

One last question: 
HYgg2tR.pngI see i'm getting the server side value +.5

why is that?

I understand now, thank you for the explanation, and also for the Implication. I couldn't do it without you :D 

Hope you have a nice evening.

 

Kind regards,

Shahin

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

I inserted everything like in your updated post and the calculation is way too high, realy strange.

 

070a6c3e6e32b255684609f1b6d249d6.png

 

battle.cpp:

Spoiler



#ifdef __SASH_SYSTEM__ //replace it with your define for sash
static void ApplySashAttackValue(LPITEM pkItem, int* pdamMin, int* pdamMax) 
{
	LPCHARACTER ch = pkItem ? pkItem->GetOwner() : NULL;
	if (!ch)
		return;

	LPITEM sashItem = ch->GetWear(WEAR_COSTUME_SASH);
	if (!sashItem)
		return;

	TItemTable* pkItemAbsorbed = ITEM_MANAGER::instance().GetTable(sashItem->GetSocket(SASH_ABSORBED_SOCKET));
	if (!pkItemAbsorbed)
		return;

	if (pkItemAbsorbed->bType != ITEM_WEAPON)
		return;

	double AttBonusMax = static_cast<double>(pkItemAbsorbed->alValues[4] + pkItemAbsorbed->alValues[5]);
	AttBonusMax *= sashItem->GetSocket(SASH_ABSORBED_SOCKET);
	AttBonusMax /= 100;
	AttBonusMax += 0.5;

	double AttBonusMin = static_cast<double>(pkItemAbsorbed->alValues[3] + pkItemAbsorbed->alValues[5]);
	AttBonusMin *= sashItem->GetSocket(SASH_ABSORBED_SOCKET);
	AttBonusMin /= 100;
	AttBonusMin += 0.5;

	//todebug
    if(ch->GetDesc()->IsPhase(PHASE_GAME))
    	ch->ChatPacket(CHAT_TYPE_INFO, "Going to add to your attack : min(%0.2f) max(%0.2f) ", AttBonusMin, AttBonusMax);
      
	*pdamMax += static_cast<int>(AttBonusMax);
	*pdamMin += static_cast<int>(AttBonusMin);
}
#endif


void Item_GetDamage(LPITEM pkItem, int* pdamMin, int* pdamMax)
{
	*pdamMin = 0;
	*pdamMax = 1;

	if (!pkItem)
		return;

	switch (pkItem->GetType())
	{
		case ITEM_ROD:
		case ITEM_PICK:
			return;
	}

	if (pkItem->GetType() != ITEM_WEAPON)
		sys_err("Item_GetDamage - !ITEM_WEAPON vnum=%d, type=%d", pkItem->GetOriginalVnum(), pkItem->GetType());

	*pdamMin = pkItem->GetValue(3);
	*pdamMax = pkItem->GetValue(4);

#ifdef __SASH_SYSTEM__ //replace it with your define for sash
	ApplySashAttackValue(pkItem, pdamMin, pdamMax);
#endif
}

 

 

Output from __UpdateBattleStatus():

 

1112 09:50:16783 :: Going to add to your points : wep(min 92.000000  max 104.000000)  mag(min 100.250000  max115.750000)
1112 09:53:16584 :: Going to add to your points : wep(min 92.000000  max 104.000000)  mag(min 100.250000  max115.750000)

 

Old calculation from item.cpp:

Spoiler


else if (pkItemAbsorbed->bType == ITEM_WEAPON)
			{
				long lAttGrade = pkItemAbsorbed->alValues[4] + long(pkItemAbsorbed->alValues[5] * 2);
				if (pkItemAbsorbed->alValues[3] > pkItemAbsorbed->alValues[4])
					lAttGrade = pkItemAbsorbed->alValues[3] + long(pkItemAbsorbed->alValues[5] * 2);
				
				double dValue = lAttGrade * GetSocket(SASH_ABSORPTION_SOCKET);
				dValue = (double)dValue / 100;
				dValue = (double)dValue + .5;
				lAttGrade = (long) dValue;
				if (((pkItemAbsorbed->alValues[3] > 0) && (lAttGrade < 1)) || ((pkItemAbsorbed->alValues[4] > 0) && (lAttGrade < 1)))
					lAttGrade += 1;
				else if ((pkItemAbsorbed->alValues[3] > 0) || (pkItemAbsorbed->alValues[4] > 0))
					lAttGrade += 1;
				
				m_pOwner->ApplyPoint(APPLY_ATT_GRADE_BONUS, bAdd ? lAttGrade : -lAttGrade);
				
				long lAttMagicGrade = pkItemAbsorbed->alValues[2] + long(pkItemAbsorbed->alValues[5] * 2);
				if (pkItemAbsorbed->alValues[1] > pkItemAbsorbed->alValues[2])
					lAttMagicGrade = pkItemAbsorbed->alValues[1] + long(pkItemAbsorbed->alValues[5] * 2);
				
				dValue = lAttMagicGrade * GetSocket(SASH_ABSORPTION_SOCKET);
				dValue = (double)dValue / 100;
				dValue = (double)dValue + .5;
				lAttMagicGrade = (long) dValue;
				if (((pkItemAbsorbed->alValues[1] > 0) && (lAttMagicGrade < 1)) || ((pkItemAbsorbed->alValues[2] > 0) && (lAttMagicGrade < 1)))
					lAttMagicGrade += 1;
				else if ((pkItemAbsorbed->alValues[1] > 0) || (pkItemAbsorbed->alValues[2] > 0))
					lAttMagicGrade += 1;
				
				m_pOwner->ApplyPoint(APPLY_MAGIC_ATT_GRADE, bAdd ? lAttMagicGrade : -lAttMagicGrade);
			}

 

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Premium

 //Basic attack value from weapon                 if (pkItemAbsorbed->alValues[3] + pkItemAbsorbed->alValues[4] > 0)

 //Basic magic attack value from weapon                 if (pkItemAbsorbed->alValues[1] + pkItemAbsorbed->alValues[2] > 0)

 

Item_proto weapons: 

VALUE0 = empty

VALUE1 = MIN MAGIC ATTACK

VALUE2 =MAX MAGIC ATTACK

VALUE3 = MIN ATTACK VALUE

VALUE4 = MAX ATTACK VALUE

VALUE5 = ADDEND TO INCREASE VALUE

 

Use brain that god gave you, thanks.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



  • Similar Content

  • Activity

    1. 0

      We are looking for a C++ and Python programmer

    2. 0

      [Quest Scheduler Request] Is there a way to make a quest run independet of player events? Lets say start quest automatically at server startup?

    3. 111

      Ulthar SF V2 (TMP4 Base)

    4. 0

      Quest function when 102.kill definition whereabouts help

    5. 5

      [M2 FILTER] Customized Client Filter

    6. 0

      [INGAME] RGB Color on chat broken

  • Recently Browsing

    • No registered users viewing this page.
×
×
  • 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.