mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
Add GetNPCBySpawnID() to Perl/Lua.
This commit is contained in:
parent
954247956e
commit
0b03f27660
@ -1097,6 +1097,22 @@ NPC *EntityList::GetNPCByNPCTypeID(uint32 npc_id)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NPC *EntityList::GetNPCBySpawnID(uint32 spawn_id)
|
||||
{
|
||||
if (spawn_id == 0 || npc_list.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto it = npc_list.begin();
|
||||
while (it != npc_list.end()) {
|
||||
if (it->second->GetSpawnGroupId() == spawn_id) {
|
||||
return it->second;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Mob *EntityList::GetMob(uint16 get_id)
|
||||
{
|
||||
Entity *ent = nullptr;
|
||||
|
||||
@ -166,6 +166,7 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
NPC *GetNPCByNPCTypeID(uint32 npc_id);
|
||||
NPC *GetNPCBySpawnID(uint32 spawn_id);
|
||||
inline Merc *GetMercByID(uint16 id)
|
||||
{
|
||||
auto it = merc_list.find(id);
|
||||
|
||||
@ -80,6 +80,11 @@ Lua_NPC Lua_EntityList::GetNPCByNPCTypeID(int npc_type) {
|
||||
return Lua_NPC(self->GetNPCByNPCTypeID(npc_type));
|
||||
}
|
||||
|
||||
Lua_NPC Lua_EntityList::GetNPCBySpawnID(uint32 spawn_id) {
|
||||
Lua_Safe_Call_Class(Lua_NPC);
|
||||
return Lua_NPC(self->GetNPCBySpawnID(spawn_id));
|
||||
}
|
||||
|
||||
Lua_Client Lua_EntityList::GetClientByName(const char *name) {
|
||||
Lua_Safe_Call_Class(Lua_Client);
|
||||
return Lua_Client(self->GetClientByName(name));
|
||||
@ -449,6 +454,7 @@ luabind::scope lua_register_entity_list() {
|
||||
.def("IsMobSpawnedByNpcTypeID", (bool(Lua_EntityList::*)(int))&Lua_EntityList::IsMobSpawnedByNpcTypeID)
|
||||
.def("GetNPCByID", (Lua_NPC(Lua_EntityList::*)(int))&Lua_EntityList::GetNPCByID)
|
||||
.def("GetNPCByNPCTypeID", (Lua_NPC(Lua_EntityList::*)(int))&Lua_EntityList::GetNPCByNPCTypeID)
|
||||
.def("GetNPCBySpawnID", (Lua_NPC(Lua_EntityList::*)(int))&Lua_EntityList::GetNPCBySpawnID)
|
||||
.def("GetClientByName", (Lua_Client(Lua_EntityList::*)(const char*))&Lua_EntityList::GetClientByName)
|
||||
.def("GetClientByAccID", (Lua_Client(Lua_EntityList::*)(uint32))&Lua_EntityList::GetClientByAccID)
|
||||
.def("GetClientByID", (Lua_Client(Lua_EntityList::*)(int))&Lua_EntityList::GetClientByID)
|
||||
|
||||
@ -54,6 +54,7 @@ public:
|
||||
bool IsMobSpawnedByNpcTypeID(int npc_type);
|
||||
Lua_NPC GetNPCByID(int id);
|
||||
Lua_NPC GetNPCByNPCTypeID(int npc_type);
|
||||
Lua_NPC GetNPCBySpawnID(uint32 spawn_id);
|
||||
Lua_Client GetClientByName(const char *name);
|
||||
Lua_Client GetClientByAccID(uint32 acct_id);
|
||||
Lua_Client GetClientByID(int id);
|
||||
|
||||
@ -219,6 +219,34 @@ XS(XS_EntityList_GetNPCByNPCTypeID) {
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
XS(XS_EntityList_GetNPCBySpawnID); /* prototype to pass -Wmissing-prototypes */
|
||||
XS(XS_EntityList_GetNPCBySpawnID) {
|
||||
dXSARGS;
|
||||
if (items != 2)
|
||||
Perl_croak(aTHX_ "Usage: EntityList::GetNPCBySpawnID(THIS, spawn_id)");
|
||||
{
|
||||
EntityList *THIS;
|
||||
NPC *RETVAL;
|
||||
uint32 spawn_id = (uint32) SvUV(ST(1));
|
||||
|
||||
if (sv_derived_from(ST(0), "EntityList")) {
|
||||
IV tmp = SvIV((SV *) SvRV(ST(0)));
|
||||
THIS = INT2PTR(EntityList *, tmp);
|
||||
} else {
|
||||
Perl_croak(aTHX_ "THIS is not of type EntityList");
|
||||
}
|
||||
|
||||
if (THIS == nullptr) {
|
||||
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
|
||||
}
|
||||
|
||||
RETVAL = THIS->GetNPCBySpawnID(spawn_id);
|
||||
ST(0) = sv_newmortal();
|
||||
sv_setref_pv(ST(0), "NPC", (void *) RETVAL);
|
||||
}
|
||||
XSRETURN(1);
|
||||
}
|
||||
|
||||
XS(XS_EntityList_GetClientByName); /* prototype to pass -Wmissing-prototypes */
|
||||
XS(XS_EntityList_GetClientByName) {
|
||||
dXSARGS;
|
||||
@ -1998,6 +2026,7 @@ XS(boot_EntityList) {
|
||||
newXSproto(strcpy(buf, "IsMobSpawnedByNpcTypeID"), XS_EntityList_IsMobSpawnedByNpcTypeID, file, "$$");
|
||||
newXSproto(strcpy(buf, "GetNPCByID"), XS_EntityList_GetNPCByID, file, "$$");
|
||||
newXSproto(strcpy(buf, "GetNPCByNPCTypeID"), XS_EntityList_GetNPCByNPCTypeID, file, "$$");
|
||||
newXSproto(strcpy(buf, "GetNPCBySpawnID"), XS_EntityList_GetNPCBySpawnID, file, "$$");
|
||||
newXSproto(strcpy(buf, "GetClientByName"), XS_EntityList_GetClientByName, file, "$$");
|
||||
newXSproto(strcpy(buf, "GetClientByAccID"), XS_EntityList_GetClientByAccID, file, "$$");
|
||||
newXSproto(strcpy(buf, "GetClientByID"), XS_EntityList_GetClientByID, file, "$$");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user