[API] perl added GetNPCStat(identifier) (#2012)

* [API] perl added GetNPCStat

Returns values of the modifiers from ModifyNPCStat

* https://github.com/EQEmu/Server/pull/2012
This commit is contained in:
KayenEQ 2022-02-20 14:00:28 -05:00 committed by GitHub
parent aa9320de3c
commit 1c0524681e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 165 additions and 0 deletions

View File

@ -653,6 +653,12 @@ bool Lua_NPC::HasAISpellEffect(int spell_effect_id)
return self->HasAISpellEffect(spell_effect_id);
}
float Lua_NPC::GetNPCStat(const char* identifier)
{
Lua_Safe_Call_Real();
return self->GetNPCStat(identifier);
}
luabind::scope lua_register_npc() {
return luabind::class_<Lua_NPC, Lua_Mob>("NPC")
.def(luabind::constructor<>())
@ -708,6 +714,7 @@ luabind::scope lua_register_npc() {
.def("GetNPCHate", (int(Lua_NPC::*)(Lua_Mob))&Lua_NPC::GetNPCHate)
.def("GetNPCSpellsID", (int(Lua_NPC::*)(void))&Lua_NPC::GetNPCSpellsID)
.def("GetNPCSpellsID", (int(Lua_NPC::*)(void))&Lua_NPC::GetNPCSpellsID)
.def("GetNPCStat", (float(Lua_NPC::*)(const char*))&Lua_NPC::GetNPCStat)
.def("GetPetSpellID", (int(Lua_NPC::*)(void))&Lua_NPC::GetPetSpellID)
.def("GetPlatinum", (uint32(Lua_NPC::*)(void))&Lua_NPC::GetPlatinum)
.def("GetPrimSkill", (int(Lua_NPC::*)(void))&Lua_NPC::GetPrimSkill)

View File

@ -152,6 +152,7 @@ public:
void AddAISpellEffect(int spell_effect_id, int base_value, int limit_value, int max_value);
void RemoveAISpellEffect(int spell_effect_id);
bool HasAISpellEffect(int spell_effect_id);
float GetNPCStat(const char* identifier);
};
#endif

View File

@ -2637,6 +2637,142 @@ void NPC::ModifyNPCStat(const char *identifier, const char *new_value)
}
}
float NPC::GetNPCStat(const char *identifier)
{
std::string id = str_tolower(identifier);
if (id == "ac") {
return AC;
}
else if (id == "str") {
return STR;
}
else if (id == "sta") {
return STA;
}
else if (id == "agi") {
return AGI;
}
else if (id == "dex") {
return DEX;
}
else if (id == "wis") {
return WIS;
}
else if (id == "int" || id == "_int") {
return INT;
}
else if (id == "cha") {
return CHA;
}
else if (id == "max_hp") {
return base_hp;
}
else if (id == "max_mana") {
return npc_mana;
}
else if (id == "mr") {
return MR;
}
else if (id == "fr") {
return FR;
}
else if (id == "cr") {
return CR;
}
else if (id == "cor") {
return Corrup;
}
else if (id == "phr") {
return PhR;
}
else if (id == "pr") {
return PR;
}
else if (id == "dr") {
return DR;
}
else if (id == "phr") {
return PhR;
}
else if (id == "runspeed") {
return runspeed;
}
else if (id == "attack_speed") {
return attack_speed;
}
else if (id == "attack_delay") {
return attack_delay;
}
else if (id == "atk") {
return ATK;
}
else if (id == "accuracy") {
return accuracy_rating;
}
else if (id == "avoidance") {
return avoidance_rating;
}
else if (id == "trackable") {
return trackable;
}
else if (id == "min_hit") {
return min_dmg;
}
else if (id == "max_hit") {
return max_dmg;
}
else if (id == "attack_count") {
return attack_count;
}
else if (id == "see_invis") {
return see_invis;
}
else if (id == "see_invis_undead") {
return see_invis_undead;
}
else if (id == "see_hide") {
return see_hide;
}
else if (id == "see_improved_hide") {
return see_improved_hide;
}
else if (id == "hp_regen") {
return hp_regen;
}
else if (id == "mana_regen") {
return mana_regen;
}
else if (id == "level") {
return GetOrigLevel();
}
else if (id == "aggro") {
return pAggroRange;
}
else if (id == "assist") {
return pAssistRange;
}
else if (id == "slow_mitigation") {
return slow_mitigation;
}
else if (id == "loottable_id") {
return loottable_id;
}
else if (id == "healscale") {
return healscale;
}
else if (id == "spellscale") {
return spellscale;
}
else if (id == "npc_spells_id") {
return npc_spells_id;
}
else if (id == "npc_spells_effects_id") {
return npc_spells_effects_id;
}
}
void NPC::LevelScale() {
uint8 random_level = (zone->random.Int(level, maxlevel));

View File

@ -408,6 +408,7 @@ public:
void SetAvoidanceRating(int32 d) { avoidance_rating = d;}
int32 GetRawAC() const { return AC; }
float GetNPCStat(const char *identifier);
void ModifyNPCStat(const char *identifier, const char *new_value);
virtual void SetLevel(uint8 in_level, bool command = false);

View File

@ -1268,6 +1268,25 @@ XS(XS_NPC_ModifyNPCStat) {
XSRETURN_EMPTY;
}
XS(XS_NPC_GetNPCStat); /* prototype to pass -Wmissing-prototypes */
XS(XS_NPC_GetNPCStat) {
dXSARGS;
if (items != 2)
Perl_croak(aTHX_ "Usage: NPC::GetNPCStat(THIS, string key)"); // @categories Stats and Attributes
{
NPC *THIS;
float RETVAL;
Const_char *identifier = (Const_char *)SvPV_nolen(ST(1));
dXSTARG;
VALIDATE_THIS_IS_NPC;
RETVAL = THIS->GetNPCStat(identifier);
XSprePUSH;
PUSHn((double)RETVAL);
}
XSRETURN(1);
}
XS(XS_NPC_AddSpellToNPCList); /* prototype to pass -Wmissing-prototypes */
XS(XS_NPC_AddSpellToNPCList) {
dXSARGS;
@ -1954,6 +1973,7 @@ XS(boot_NPC) {
newXSproto(strcpy(buf, "GetNPCFactionID"), XS_NPC_GetNPCFactionID, file, "$");
newXSproto(strcpy(buf, "GetNPCHate"), XS_NPC_GetNPCHate, file, "$$");
newXSproto(strcpy(buf, "GetNPCSpellsID"), XS_NPC_GetNPCSpellsID, file, "$");
newXSproto(strcpy(buf, "GetNPCStat"), XS_NPC_GetNPCStat, file, "$$");
newXSproto(strcpy(buf, "GetPetSpellID"), XS_NPC_GetPetSpellID, file, "$");
newXSproto(strcpy(buf, "GetPlatinum"), XS_NPC_GetPlatinum, file, "$");
newXSproto(strcpy(buf, "GetPrimSkill"), XS_NPC_GetPrimSkill, file, "$");