File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -1828,8 +1828,31 @@ Local<Value> PlayerClass::reduceExperience(const Arguments& args) {
1828
1828
return Local<Value>();
1829
1829
}
1830
1830
1831
- player->addExperience (-args[0 ].toInt ());
1832
- return Boolean::newBoolean (true );
1831
+ float exp = args[0 ].asNumber ().toFloat ();
1832
+ auto attr = player->getMutableAttribute (Player::EXPERIENCE);
1833
+ if (!attr) {
1834
+ return Boolean::newBoolean (false );
1835
+ }
1836
+ int neededExp = player->getXpNeededForNextLevel ();
1837
+ int currentExp = static_cast <int >(attr->getCurrentValue () * neededExp);
1838
+ if (exp <= currentExp) {
1839
+ attr->setCurrentValue (static_cast <float >(currentExp - exp) / neededExp);
1840
+ return Boolean::newBoolean (true );
1841
+ }
1842
+ attr->setCurrentValue (0 );
1843
+ size_t needExp = exp - currentExp;
1844
+ int level = player->getPlayerLevel ();
1845
+ while (level > 0 ) {
1846
+ player->addLevels (-1 );
1847
+ int levelXp = player->getXpNeededForNextLevel ();
1848
+ if (needExp < levelXp) {
1849
+ attr->setCurrentValue (static_cast <float >(levelXp - needExp) / player->getXpNeededForNextLevel ());
1850
+ return Boolean::newBoolean (true );
1851
+ }
1852
+ needExp -= levelXp;
1853
+ level = player->getPlayerLevel ();
1854
+ }
1855
+ return Boolean::newBoolean (false );
1833
1856
}
1834
1857
CATCH (" Fail in reduceExperience!" );
1835
1858
}
You can’t perform that action at this time.
0 commit comments