Save % when characters' lvl manually changed :geek:

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

Save % when characters' lvl manually changed :geek:

Post by KGB1st »

Code: Select all

public float getPercentFromCurrentLevel(long exp, int level)
{
	long expPerLevel = getExpForLevel(level);
	long expPerLevel2 = getExpForLevel(level + 1);
	return (float) (exp - expPerLevel) / (expPerLevel2 - expPerLevel);
}
Have something for setPercentToCurrentLevel?
Last edited by KGB1st on Tue Aug 08, 2017 6:59 pm, edited 1 time in total.
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

Re: setPercentToCurrentLevel?

Post by KGB1st »

Restore to the users their lvls percantage..

for example, we used some func wich sets 20 lvl to the character, but it was 23 and has 86%

Code: Select all

activeChar.removeExpAndSp(activeChar.getExp() - ExperienceData.getInstance().getExpForLevel(20), 0);
and in future we want to restore it again.

Code: Select all

if(iCharLevel != 85)
{
	long l_ExpForLvl = ExperienceData.getInstance().getExpForLevel(iCharLevel);
	long l_ExpForLvlInc = ExperienceData.getInstance().getExpForLevel(iCharLevel+1);
	
	long lTempExp;
													
	lTempExp = l_ExpForLvl;
	
	while(lTempExp < l_ExpForLvlInc)
	{
		float fGetNewPercent = ExperienceData.getInstance().getPercentFromCurrentLevel(lTempExp, iCharLevel);
		String strNewPercent = String.format("%.2f", fGetNewPercent);
		
		if(strPercent.equals(strNewPercent) )
		{
			activeChar.addExpAndSp(lTempExp - l_ExpForLvl, 0); //set percantage
			activeChar.sendMessage(strPercent);
			break;
		}
		
		lTempExp += 1; // inc works only for int in Java, so I used this method
	}
}
Sorry my easy java lvl. strPercent it's real lvls percentage of a character.
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

Re: setPercentToCurrentLevel?

Post by KGB1st »

not correct, high canculations :\
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

Re: setPercentToCurrentLevel?

Post by KGB1st »

what, nobody unknown how do it better, without crazy whiles' canculation?)
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

Re: Save % when characters' lvl manually changed :geek:

Post by KGB1st »

I enabled some logic and maked percentages' calculation more arithmetically..
2017-08-09_001824.jpg

but had a problem with numbers' accuracy when converted float to long(I think it is) at first time, and didn't understand why it happed :crazy:
Later I understood that it was happened because I use pow in -4 so I understand that I must increase numbers' accuracy..
I think it's better that calculation in while, long it's a big and not profitable range for it :\

Finally work code

Code: Select all

//lVar1=char lvl (long value, presented as exp)
//lVar2=char lvl+1 (long value, presented as exp)
//fVar3=percent from old lvl, or manual (float value, presented as %.4f in canculations)

if((lVar1<=85)&&(lVar1>1)) long lPercResult=(((((lVar1-lVar2)/100)*(long)(fVar3*10000)))/100);//maybe require diff %.5f

Code: Select all

//Example: now u can use it for your characters' new lvl as additional operation
activeChar.addExpAndSp(lPercResult, 0);

//or make it as fast canculator for lvl down operation with % saving
activeChar.addExpAndSp((activeChar.getExp()-ExperienceData.getInstance().getExpForLevel(lvl))+lPercResult); //lvl up + %
P.S. for more info look at ExperienceData :silent:
You do not have the required permissions to view the files attached to this post.
Post Reply