[Bots] Change HasBotItem(item_id) to return slot_id instead of bool. (#2966)

This commit is contained in:
Aeadoin 2023-02-19 16:13:28 -05:00 committed by GitHub
parent 443abf9199
commit c13f9f80d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 15 deletions

View File

@ -4478,23 +4478,19 @@ uint32 Bot::CountBotItem(uint32 item_id) {
return item_count; return item_count;
} }
bool Bot::HasBotItem(uint32 item_id) { int16 Bot::HasBotItem(uint32 item_id) {
bool has_item = false; EQ::ItemInstance const *inst = nullptr;
EQ::ItemInstance *inst = nullptr;
for (uint16 slot_id = EQ::invslot::EQUIPMENT_BEGIN; slot_id <= EQ::invslot::EQUIPMENT_END; ++slot_id) { for (uint16 slot_id = EQ::invslot::EQUIPMENT_BEGIN; slot_id <= EQ::invslot::EQUIPMENT_END; ++slot_id) {
inst = GetBotItem(slot_id); inst = GetBotItem(slot_id);
if (!inst || !inst->GetItem()) { if (!inst || !inst->GetItem()) {
continue; continue;
} }
if (inst->GetID() == item_id) { if (inst->GetID() == item_id) {
has_item = true; return slot_id;
break;
} }
} }
return INVALID_INDEX;
return has_item;
} }
void Bot::RemoveBotItem(uint32 item_id) { void Bot::RemoveBotItem(uint32 item_id) {

View File

@ -720,7 +720,7 @@ public:
uint32 CountBotItem(uint32 item_id); uint32 CountBotItem(uint32 item_id);
std::map<uint16, uint32> GetBotItemSlots(); std::map<uint16, uint32> GetBotItemSlots();
uint32 GetBotItemBySlot(uint16 slot_id); uint32 GetBotItemBySlot(uint16 slot_id);
bool HasBotItem(uint32 item_id); int16 HasBotItem(uint32 item_id);
void RemoveBotItem(uint32 item_id); void RemoveBotItem(uint32 item_id);
uint32 GetTotalPlayTime(); uint32 GetTotalPlayTime();

View File

@ -116,7 +116,7 @@ void command_gearup(Client *c, const Seperator *sep)
if (t->IsClient()) { if (t->IsClient()) {
has_item = t->CastToClient()->GetInv().HasItem(item_id, 1, invWhereWorn) != INVALID_INDEX; has_item = t->CastToClient()->GetInv().HasItem(item_id, 1, invWhereWorn) != INVALID_INDEX;
} else if (t->IsBot()) { } else if (t->IsBot()) {
has_item = t->CastToBot()->HasBotItem(item_id); has_item = t->CastToBot()->HasBotItem(item_id) != INVALID_INDEX;
} }
bool can_wear_item = false; bool can_wear_item = false;

View File

@ -65,8 +65,8 @@ Lua_Mob Lua_Bot::GetOwner() {
return Lua_Mob(self->GetOwner()); return Lua_Mob(self->GetOwner());
} }
bool Lua_Bot::HasBotItem(uint32 item_id) { int16 Lua_Bot::HasBotItem(uint32 item_id) {
Lua_Safe_Call_Bool(); Lua_Safe_Call_Int();
return self->HasBotItem(item_id); return self->HasBotItem(item_id);
} }
@ -507,7 +507,7 @@ luabind::scope lua_register_bot() {
.def("GetRawItemAC", (int(Lua_Bot::*)(void))&Lua_Bot::GetRawItemAC) .def("GetRawItemAC", (int(Lua_Bot::*)(void))&Lua_Bot::GetRawItemAC)
.def("GetSpellDamage", (int(Lua_Bot::*)(void))&Lua_Bot::GetSpellDamage) .def("GetSpellDamage", (int(Lua_Bot::*)(void))&Lua_Bot::GetSpellDamage)
.def("HasAugmentEquippedByID", (bool(Lua_Bot::*)(uint32))&Lua_Bot::HasAugmentEquippedByID) .def("HasAugmentEquippedByID", (bool(Lua_Bot::*)(uint32))&Lua_Bot::HasAugmentEquippedByID)
.def("HasBotItem", (bool(Lua_Bot::*)(uint32))&Lua_Bot::HasBotItem) .def("HasBotItem", (int16(Lua_Bot::*)(uint32))&Lua_Bot::HasBotItem)
.def("HasBotSpellEntry", (bool(Lua_Bot::*)(uint16)) & Lua_Bot::HasBotSpellEntry) .def("HasBotSpellEntry", (bool(Lua_Bot::*)(uint16)) & Lua_Bot::HasBotSpellEntry)
.def("HasItemEquippedByID", (bool(Lua_Bot::*)(uint32))&Lua_Bot::HasItemEquippedByID) .def("HasItemEquippedByID", (bool(Lua_Bot::*)(uint32))&Lua_Bot::HasItemEquippedByID)
.def("IsGrouped", (bool(Lua_Bot::*)(void))&Lua_Bot::IsGrouped) .def("IsGrouped", (bool(Lua_Bot::*)(void))&Lua_Bot::IsGrouped)

View File

@ -43,7 +43,7 @@ public:
uint32 GetBotItemIDBySlot(uint16 slot_id); uint32 GetBotItemIDBySlot(uint16 slot_id);
int GetExpansionBitmask(); int GetExpansionBitmask();
Lua_Mob GetOwner(); Lua_Mob GetOwner();
bool HasBotItem(uint32 item_id); int16 HasBotItem(uint32 item_id);
void OwnerMessage(std::string message); void OwnerMessage(std::string message);
bool ReloadBotDataBuckets(); bool ReloadBotDataBuckets();
bool ReloadBotOwnerDataBuckets(); bool ReloadBotOwnerDataBuckets();

View File

@ -90,7 +90,7 @@ uint32 Perl_Bot_CountBotItem(Bot* self, uint32 item_id)
return self->CountBotItem(item_id); return self->CountBotItem(item_id);
} }
bool Perl_Bot_HasBotItem(Bot* self, uint32 item_id) int16 Perl_Bot_HasBotItem(Bot* self, uint32 item_id)
{ {
return self->HasBotItem(item_id); return self->HasBotItem(item_id);
} }