PDA

View Full Version : I need to fix this folks


KingMort
03-03-2013, 11:11 PM
This Code is stock :

// Note: The client calculates exp separately, we cant change this function
// Add: You can set the values you want now, client will be always sync :) - Merkur
uint32 Client::GetEXPForLevel(uint16 check_level)
{

uint16 check_levelm1 = check_level-1;
float mod;
if (check_level < 31)
mod = 1.0;
else if (check_level < 36)
mod = 1.1;
else if (check_level < 41)
mod = 1.2;
else if (check_level < 46)
mod = 1.3;
else if (check_level < 52)
mod = 1.4;
else if (check_level < 53)
mod = 1.5;
else if (check_level < 54)
mod = 1.6;
else if (check_level < 55)
mod = 1.7;
else if (check_level < 56)
mod = 1.9;
else if (check_level < 57)
mod = 2.1;
else if (check_level < 58)
mod = 2.3;
else if (check_level < 59)
mod = 2.5;
else if (check_level < 60)
mod = 2.7;
else if (check_level < 61)
mod = 3.0;
else
mod = 3.1;

float base = (check_levelm1)*(check_levelm1)*(check_levelm1);

mod *= 1000;

return(uint32(base * mod));
}

Alright well on raid Addicts we used some other code.. which didn't appear to me to be DRASTICALLY different, another GM I had made this code since we couldn't go past level 87.. Now when I am trying to remove this code and go with what you guys wrote, I can't keep any character on my server to what they were originally .. Max level on my server is 100, and they all revert to level 1.. I set them to 100 either by #setexp, or #level, and they just all revert BACK to level 1..

Please Help ! I want to go with what you guys wrote and not some weirdness but it seems my database is stuck on it's old ways.. Is there some way I can repair this issue?

At the top it says // Add: You can set the values you want now, client will be always sync :) - Merkur

but that's not ringing true right now , no offense :(

Morty

KingMort
03-03-2013, 11:59 PM
I know i'm a total n00b by the way and please forgive me devs for even allowing my change to go in in the first place..

I have changed the code to this for now, and it seems to have fixed my problem however I still desire a vender recommended solution please :)


// Note: The client calculates exp separately, we cant change this function
// Add: You can set the values you want now, client will be always sync :) - Merkur
uint32 Client::GetEXPForLevel(uint16 check_level)
{

uint16 check_levelm1 = check_level-1;
float mod;
if (check_level < 101)
mod = 1.0;
else if (check_level < 36)
mod = 1.1;
else if (check_level < 41)
mod = 1.2;
else if (check_level < 46)
mod = 1.3;
else if (check_level < 52)
mod = 1.4;
else if (check_level < 53)
mod = 1.5;
else if (check_level < 54)
mod = 1.6;
else if (check_level < 55)
mod = 1.7;
else if (check_level < 56)
mod = 1.9;
else if (check_level < 57)
mod = 2.1;
else if (check_level < 58)
mod = 2.3;
else if (check_level < 59)
mod = 2.5;
else if (check_level < 60)
mod = 2.7;
else if (check_level < 101)
mod = 3.0;
else
mod = 3.1;

float base = (check_levelm1)*(check_levelm1)*(check_levelm1);

mod *= 1000;

return(uint32(base * mod));
}

Drajor
03-04-2013, 12:36 AM
I suggest checking if the value returned by GetEXPForLevel is being cast to a signed int anywhere. 3000(98^3) would be wrapping if that is the case (where going from lvl 99 to 100).

KingMort
03-04-2013, 01:01 AM
Look dude, I don't speak dev that's why I've never posted in here :) Can you please send that in English? Love ya guys!

lerxst2112
03-04-2013, 02:42 AM
Look dude, I don't speak dev

And this is why you fail.

KingMort
03-04-2013, 12:06 PM
Yes I understand I "FAIL" because that is why I posted this so that I can get help with this and not "FAIL" ..

Please help me to understand how I can check the value returned by "GetEXPForLevel" ??

orionsun
03-04-2013, 02:19 PM
You are the least technical network whatever you claim to be. Its basic stuff like this that undermines all the boasting you do lol.

Lets break this down...

Your code:
else if (check_level < 101)
mod = 3.0;


The equation:
float base = (check_levelm1)*(check_levelm1)*(check_levelm1);
mod *= 1000;
return(uint32(base * mod))

Basic math time...

check_levelm1 = 100 <-- Character level(lets test max)
mod = 3.0 <-- This is the modifier a level 100 char has

base = 100 * 100 * 100 = 1,000,000
mod = 3.0 * 1000 = 3,000

return val = 1,000,000, * 3,000 = 3,000,000,000

The max value a uint32 can hold is ~2.14 billion.

A monkey could figure out where to go from here... good luck.

lerxst2112
03-04-2013, 03:59 PM
The maximum value of a uint32 is 4,294,967,295. It's possible that is it being converted to a signed value somewhere along the way which would make anything over 2,147,483,647 become negative.

Drajor
03-04-2013, 05:24 PM
Thanks guys for explaining this. I didn't have the patience yesterday.

wolfwalkereci
03-04-2013, 07:17 PM
And this is why you fail.
You are the least technical network whatever you claim to be. Its basic stuff like this that undermines all the boasting you do

Yeah that pretty much sums this clown up.

Zamthos
03-04-2013, 07:38 PM
Mort, dude, didn't you just hire a 'brilliant' coder? Why couldn't he fix it? "Brilliant" and "better than me" are two different things, just saying. You've been doing this for 10 years, you should be able to speak in fluent C++ by now.

jimrocken
03-04-2013, 07:50 PM
i don't see coding there except the maximum value a uint32 can hold (could google for that... just saying...)

it really is basic math... sorry mort but i kinda have to agree on this one... that was pretty simple...

Drajor
03-04-2013, 08:42 PM
I had a go at expressing the exp curve as a single (mathematical) function. With those strange coefficients I think you could only get a pretty rough approximation because of the relatively large numbers being used.

To Mort: Try setting a character to level 89. If that works try setting them to 90. If setting them to 90 fails then this issue is almost certainly the result of an integer being cast incorrectly.

To fix that, search your code for references to GetEXPForLevel. Look for code that is simliar to 'int x = GetEXPForLevel(blah)' and change it to 'uint32 x = GetEXPForLevel(blah)'. If it is not that simple, then you will have to start looking at the uses of 'x' in other parts of the code.

KingMort
03-04-2013, 09:27 PM
Thank you for the assistance will look into this. And thank you for the criticism and everything... Appreciate you all. Like I said in the beginning of the post as far as C++ stuff goes I am n00bsauce.. I don't mean to upset anyone by my questions here, I thought that this was a forum that was for Support not flames and rants. As a Network Analyst my job is to build networks, servers, and troubleshoot workstations, no where in my job description is coding of any kind. Apologies if you thought I had boasted about coding at some point? I can only ever remember telling people I suck at this . Please forgive my ignorance, I don't mean to upset anyone I just want to fix my problem.

Mort

Uleat
03-04-2013, 09:39 PM
Do we need to change this to double from float and add a con check for '(base*mod) > ~0'?

lerxst2112
03-04-2013, 10:58 PM
Do we need to change this to double from float and add a con check for '(base*mod) > ~0'?

Why? There shouldn't be an issue with range or precision using a float.

Uleat
03-05-2013, 12:11 AM
Nope, you're right...

x = 3000000000, y = 3E+09, z = 3000000000

x as uint32 = 3,000,000,000
y as single = x
z as uint32 = y


I'm just not seeing where a conversion issue is occurring in the above procedure...

lerxst2112
03-05-2013, 12:55 AM
It isn't there, it's somewhere else the value is being used.

Here's an example from Client::Death()

// now we apply the exp loss, unmem their spells, and make a corpse
// unless they're a GM (or less than lvl 10
if(!GetGM())
{
if(exploss > 0) {
int32 newexp = GetEXP();
if(exploss > newexp) {
//lost more than we have... wtf..
newexp = 1;
} else {
newexp -= exploss;
}
SetEXP(newexp, GetAAXP());
//m_epp.perAA = 0; //reset to no AA exp on death.
}


There may be more that are less obvious. Some of the rez and sacrifice code is suspect, but I'm too lazy to do the math.

Drajor
03-05-2013, 01:23 AM
My source is a few weeks out of date but in Client::SetLevel the return value of GetEXPForLevel is being cast as a float numerous times. That would do it. Change float to double.

float tmpxp = (float) ( (float) m_pp.exp - GetEXPForLevel( GetLevel() )) /
( (float) GetEXPForLevel(GetLevel()+1) - GetEXPForLevel(GetLevel()));
lu->exp = (uint32)(330.0f * tmpxp);

Holy sh*t wut!?

Drajor
03-05-2013, 02:02 AM
Ugh I just realised exp is stored cumulatively..

lerxst2112
03-05-2013, 01:55 PM
Float is probably ok there too. Without extracting that out into a test to see what the numbers are I'd guess you might lose a very small bit of precision, but a float isn't going to roll over to a negative number like a signed int would. Besides, that formula is just to tell the client how far to fill up the experience bar. If it was incorrect the server would still have the proper value and you'd level when you didn't expect it.

Armm
03-14-2013, 01:44 PM
Try what i posted here... Works for me..

http://www.eqemulator.org/forums/showthread.php?p=219466#post219466