Add ScaleNPC() to Perl and Lua. (#1238)

This commit is contained in:
Alex 2021-02-09 00:08:07 -05:00 committed by GitHub
parent f2b67ae969
commit 8f89f38f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 1 deletions

View File

@ -558,6 +558,12 @@ void Lua_NPC::RecalculateSkills()
self->RecalculateSkills();
}
void Lua_NPC::ScaleNPC(uint8 npc_level)
{
Lua_Safe_Call_Void();
self->ScaleNPC(npc_level);
}
luabind::scope lua_register_npc() {
return luabind::class_<Lua_NPC, Lua_Mob>("NPC")
.def(luabind::constructor<>())
@ -670,7 +676,8 @@ luabind::scope lua_register_npc() {
.def("MerchantCloseShop", (void(Lua_NPC::*)(void))&Lua_NPC::MerchantCloseShop)
.def("GetRawAC", (int(Lua_NPC::*)(void))&Lua_NPC::GetRawAC)
.def("GetAvoidanceRating", &Lua_NPC::GetAvoidanceRating)
.def("RecalculateSkills", (void(Lua_NPC::*)(void))&Lua_NPC::RecalculateSkills);
.def("RecalculateSkills", (void(Lua_NPC::*)(void))&Lua_NPC::RecalculateSkills)
.def("ScaleNPC", (void(Lua_NPC::*)(uint8))&Lua_NPC::ScaleNPC);
}
#endif

View File

@ -136,6 +136,7 @@ public:
void SetSimpleRoamBox(float box_size, float move_distance);
void SetSimpleRoamBox(float box_size, float move_distance, int move_delay);
void RecalculateSkills();
void ScaleNPC(uint8 npc_level);
};
#endif

View File

@ -3329,3 +3329,11 @@ void NPC::RecalculateSkills()
}
}
}
void NPC::ScaleNPC(uint8 npc_level) {
if (GetLevel() != npc_level) {
SetLevel(npc_level);
}
npc_scale_manager->ResetNPCScaling(this);
npc_scale_manager->ScaleNPC(this);
}

View File

@ -494,6 +494,8 @@ public:
inline bool IsSkipAutoScale() const { return skip_auto_scale; }
void ScaleNPC(uint8 npc_level);
void RecalculateSkills();
static LootDropEntries_Struct NewLootDropEntry();

View File

@ -164,6 +164,16 @@ void NpcScaleManager::ScaleNPC(NPC *npc)
}
}
void NpcScaleManager::ResetNPCScaling(NPC *npc) {
for (const auto &scaling_stat : scaling_stats) {
std::string stat_name = fmt::format("modify_stat_{}", scaling_stat);
std::string reset_value = "0";
if (npc->EntityVariableExists(stat_name.c_str())) {
npc->ModifyNPCStat(scaling_stat.c_str(), reset_value.c_str());
}
}
}
bool NpcScaleManager::LoadScaleData()
{
auto results = content_db.QueryDatabase(

View File

@ -87,6 +87,7 @@ public:
};
void ScaleNPC(NPC * npc);
void ResetNPCScaling(NPC * npc);
bool IsAutoScaled(NPC * npc);
bool LoadScaleData();

View File

@ -1711,6 +1711,20 @@ XS(XS_NPC_RecalculateSkills) {
XSRETURN_EMPTY;
}
XS(XS_NPC_ScaleNPC); /* prototype to pass -Wmissing-prototypes */
XS(XS_NPC_ScaleNPC) {
dXSARGS;
if (items != 2)
Perl_croak(aTHX_ "Usage: NPC::ScaleNPC(THIS, uint8 npc_level)");
{
NPC *THIS;
uint8 npc_level = (uint8) SvUV(ST(1));
VALIDATE_THIS_IS_NPC;
THIS->ScaleNPC(npc_level);
}
XSRETURN_EMPTY;
}
#ifdef __cplusplus
extern "C"
#endif
@ -1827,6 +1841,7 @@ XS(boot_NPC) {
newXSproto(strcpy(buf, "GetCombatState"), XS_NPC_GetCombatState, file, "$");
newXSproto(strcpy(buf, "SetSimpleRoamBox"), XS_NPC_SetSimpleRoamBox, file, "$$;$$");
newXSproto(strcpy(buf, "RecalculateSkills"), XS_NPC_RecalculateSkills, file, "$");
newXSproto(strcpy(buf, "ScaleNPC"), XS_NPC_ScaleNPC, file, "$$");
XSRETURN_YES;
}