Skip to content

Commit

Permalink
[Quest API] Add GetAAEXPPercentage() and GetEXPPercentage() to Perl/L…
Browse files Browse the repository at this point in the history
…ua (#4044)

* Initial Push

* Push

* Push.
  • Loading branch information
Kinglykrab authored Feb 4, 2024
1 parent 3f9a604 commit 0ffea36
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
22 changes: 22 additions & 0 deletions zone/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12097,3 +12097,25 @@ void Client::SetEXPModifier(uint32 zone_id, float exp_modifier, int16 instance_v

database.LoadCharacterEXPModifier(this);
}

int Client::GetAAEXPPercentage()
{
int scaled = static_cast<int>(330.0f * static_cast<float>(GetAAXP()) / GetRequiredAAExperience());

return static_cast<int>(std::round(scaled * 100.0 / 330.0));
}

int Client::GetEXPPercentage()
{
float norm = 0.0f;
uint32_t min = GetEXPForLevel(GetLevel());
uint32_t max = GetEXPForLevel(GetLevel() + 1);

if (min != max) {
norm = static_cast<float>(GetEXP() - min) / (max - min);
}

int scaled = static_cast<int>(330.0f * norm); // scale and truncate

return static_cast<int>(std::round(scaled * 100.0 / 330.0)); // unscaled pct
}
3 changes: 3 additions & 0 deletions zone/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,9 @@ class Client : public Mob
void SetTitleSuffix(std::string suffix);
void MemorizeSpell(uint32 slot, uint32 spell_id, uint32 scribing, uint32 reduction = 0);

int GetAAEXPPercentage();
int GetEXPPercentage();

// Item methods
void UseAugmentContainer(int container_slot);
void EVENT_ITEM_ScriptStopReturn();
Expand Down
14 changes: 14 additions & 0 deletions zone/lua_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,18 @@ void Lua_Client::ClearXTargets()
self->ClearXTargets();
}

int Lua_Client::GetAAEXPPercentage()
{
Lua_Safe_Call_Int();
return self->GetAAEXPPercentage();
}

int Lua_Client::GetEXPPercentage()
{
Lua_Safe_Call_Int();
return self->GetEXPPercentage();
}

luabind::scope lua_register_client() {
return luabind::class_<Lua_Client, Lua_Mob>("Client")
.def(luabind::constructor<>())
Expand Down Expand Up @@ -3400,6 +3412,7 @@ luabind::scope lua_register_client() {
.def("GetAAEXPModifier", (float(Lua_Client::*)(void))&Lua_Client::GetAAEXPModifier)
.def("GetAAEXPModifier", (float(Lua_Client::*)(uint32))&Lua_Client::GetAAEXPModifier)
.def("GetAAEXPModifier", (float(Lua_Client::*)(uint32,int16))&Lua_Client::GetAAEXPModifier)
.def("GetAAEXPPercentage", (int(Lua_Client::*)(void))&Lua_Client::GetAAEXPPercentage)
.def("GetAAExp", (uint32(Lua_Client::*)(void))&Lua_Client::GetAAExp)
.def("GetAAPercent", (uint32(Lua_Client::*)(void))&Lua_Client::GetAAPercent)
.def("GetAAPoints", (int(Lua_Client::*)(void))&Lua_Client::GetAAPoints)
Expand Down Expand Up @@ -3459,6 +3472,7 @@ luabind::scope lua_register_client() {
.def("GetEXPModifier", (float(Lua_Client::*)(void))&Lua_Client::GetEXPModifier)
.def("GetEXPModifier", (float(Lua_Client::*)(uint32))&Lua_Client::GetEXPModifier)
.def("GetEXPModifier", (float(Lua_Client::*)(uint32,int16))&Lua_Client::GetEXPModifier)
.def("GetEXPPercentage", (int(Lua_Client::*)(void))&Lua_Client::GetEXPPercentage)
.def("GetEbonCrystals", (uint32(Lua_Client::*)(void))&Lua_Client::GetEbonCrystals)
.def("GetEndurance", (int(Lua_Client::*)(void))&Lua_Client::GetEndurance)
.def("GetEndurancePercent", (int(Lua_Client::*)(void))&Lua_Client::GetEndurancePercent)
Expand Down
2 changes: 2 additions & 0 deletions zone/lua_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ class Lua_Client : public Lua_Mob
void SummonItemIntoInventory(luabind::object item_table);
bool HasItemOnCorpse(uint32 item_id);
void ClearXTargets();
int GetAAEXPPercentage();
int GetEXPPercentage();

void ApplySpell(int spell_id);
void ApplySpell(int spell_id, int duration);
Expand Down
12 changes: 12 additions & 0 deletions zone/perl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3088,6 +3088,16 @@ void Perl_Client_ClearXTargets(Client* self)
self->ClearXTargets();
}

int Perl_Client_GetAAEXPPercentage(Client* self)
{
return self->GetAAEXPPercentage();
}

int Perl_Client_GetEXPPercentage(Client* self)
{
return self->GetEXPPercentage();
}

void perl_register_client()
{
perl::interpreter perl(PERL_GET_THX);
Expand Down Expand Up @@ -3204,6 +3214,7 @@ void perl_register_client()
package.add("GetAAEXPModifier", (float(*)(Client*))&Perl_Client_GetAAEXPModifier);
package.add("GetAAEXPModifier", (float(*)(Client*, uint32))&Perl_Client_GetAAEXPModifier);
package.add("GetAAEXPModifier", (float(*)(Client*, uint32, int16))&Perl_Client_GetAAEXPModifier);
package.add("GetAAEXPPercentage", &Perl_Client_GetAAEXPPercentage);
package.add("GetAAExp", &Perl_Client_GetAAExp);
package.add("GetAALevel", &Perl_Client_GetAALevel);
package.add("GetAAPercent", &Perl_Client_GetAAPercent);
Expand Down Expand Up @@ -3265,6 +3276,7 @@ void perl_register_client()
package.add("GetEXPModifier", (float(*)(Client*))&Perl_Client_GetEXPModifier);
package.add("GetEXPModifier", (float(*)(Client*, uint32))&Perl_Client_GetEXPModifier);
package.add("GetEXPModifier", (float(*)(Client*, uint32, int16))&Perl_Client_GetEXPModifier);
package.add("GetEXPPercentage", &Perl_Client_GetEXPPercentage);
package.add("GetEbonCrystals", &Perl_Client_GetEbonCrystals);
package.add("GetEndurance", &Perl_Client_GetEndurance);
package.add("GetEnduranceRatio", &Perl_Client_GetEnduranceRatio);
Expand Down

0 comments on commit 0ffea36

Please sign in to comment.