Page 1 of 1

Save % when characters' lvl manually changed :geek:

Posted: Fri Aug 04, 2017 5:46 pm
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?

Re: setPercentToCurrentLevel?

Posted: Fri Aug 04, 2017 9:02 pm
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.

Re: setPercentToCurrentLevel?

Posted: Fri Aug 04, 2017 10:41 pm
by KGB1st
not correct, high canculations :\

Re: setPercentToCurrentLevel?

Posted: Tue Aug 08, 2017 1:42 pm
by KGB1st
what, nobody unknown how do it better, without crazy whiles' canculation?)

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

Posted: Tue Aug 08, 2017 6:57 pm
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: