Decouple zone calls, cleanup logic

This commit is contained in:
Akkadius
2020-04-19 04:36:39 -05:00
parent ebda1cf601
commit 373fb3f0e7
57 changed files with 705 additions and 467 deletions
+35 -34
View File
@@ -24,6 +24,7 @@
#include "../common/eqemu_logsys.h"
#include "zonedb.h"
#include "zone_store.h"
#include "bot.h"
#include "client.h"
@@ -192,7 +193,7 @@ bool BotDatabase::QueryBotCount(const uint32 owner_id, uint32& bot_count)
return false;
if (!results.RowCount())
return true;
auto row = results.begin();
bot_count = atoi(row[0]);
@@ -314,7 +315,7 @@ bool BotDatabase::LoadBotID(const uint32 owner_id, const std::string& bot_name,
return false;
if (!results.RowCount())
return true;
auto row = results.begin();
bot_id = atoi(row[0]);
@@ -451,7 +452,7 @@ bool BotDatabase::SaveNewBot(Bot* bot_inst, uint32& bot_id)
{
if (!bot_inst)
return false;
query = StringFormat(
"INSERT INTO `bot_data` ("
" `owner_id`,"
@@ -596,7 +597,7 @@ bool BotDatabase::SaveBot(Bot* bot_inst)
{
if (!bot_inst)
return false;
query = StringFormat(
"UPDATE `bot_data`"
" SET"
@@ -1014,7 +1015,7 @@ bool BotDatabase::LoadTimers(Bot* bot_inst)
if (timer_id >= 0 && timer_id < MaxTimer && timer_value < (Timer::GetCurrentTime() + max_value))
bot_timers[timer_id] = timer_value;
}
return true;
}
@@ -1127,7 +1128,7 @@ bool BotDatabase::QueryInventoryCount(const uint32 bot_id, uint32& item_count)
{
if (!bot_id)
return false;
query = StringFormat("SELECT COUNT(`inventories_index`) FROM `bot_inventories` WHERE `bot_id` = '%u'", bot_id);
auto results = database.QueryDatabase(query);
if (!results.Success())
@@ -1173,7 +1174,7 @@ bool BotDatabase::LoadItems(const uint32 bot_id, EQEmu::InventoryProfile& invent
return false;
if (!results.RowCount())
return true;
for (auto row = results.begin(); row != results.end(); ++row) {
int16 slot_id = atoi(row[0]);
if (slot_id < EQEmu::invslot::EQUIPMENT_BEGIN || slot_id > EQEmu::invslot::EQUIPMENT_END)
@@ -1281,7 +1282,7 @@ bool BotDatabase::LoadItemBySlot(const uint32 bot_id, const uint32 slot_id, uint
{
if (!bot_id || slot_id > EQEmu::invslot::EQUIPMENT_END)
return false;
query = StringFormat("SELECT `item_id` FROM `bot_inventories` WHERE `bot_id` = '%i' AND `slot_id` = '%i' LIMIT 1", bot_id, slot_id);
auto results = database.QueryDatabase(query);
if (!results.Success())
@@ -1305,11 +1306,11 @@ bool BotDatabase::SaveItemBySlot(Bot* bot_inst, const uint32 slot_id, const EQEm
if (!item_inst || !item_inst->GetID())
return true;
uint32 augment_id[EQEmu::invaug::SOCKET_COUNT] = { 0, 0, 0, 0, 0, 0 };
for (int augment_iter = EQEmu::invaug::SOCKET_BEGIN; augment_iter <= EQEmu::invaug::SOCKET_END; ++augment_iter)
augment_id[augment_iter] = item_inst->GetAugmentItemID(augment_iter);
uint16 item_charges = 0;
if (item_inst->GetCharges() >= 0)
item_charges = item_inst->GetCharges();
@@ -1400,7 +1401,7 @@ bool BotDatabase::LoadEquipmentColor(const uint32 bot_id, const uint8 material_s
int16 slot_id = EQEmu::InventoryProfile::CalcSlotFromMaterial(material_slot_id);
if (slot_id == INVALID_INDEX)
return false;
query = StringFormat("SELECT `inst_color` FROM `bot_inventories` WHERE `bot_id` = '%u' AND `slot_id` = '%u' LIMIT 1", bot_id, slot_id);
auto results = database.QueryDatabase(query);
if (!results.Success())
@@ -1451,7 +1452,7 @@ bool BotDatabase::LoadPetIndex(const uint32 bot_id, uint32& pet_index)
{
if (!bot_id)
return false;
query = StringFormat("SELECT `pets_index` FROM `bot_pets` WHERE `bot_id` = '%u' LIMIT 1", bot_id);
auto results = database.QueryDatabase(query);
if (!results.Success())
@@ -1461,7 +1462,7 @@ bool BotDatabase::LoadPetIndex(const uint32 bot_id, uint32& pet_index)
auto row = results.begin();
pet_index = atoi(row[0]);
return true;
}
@@ -1479,7 +1480,7 @@ bool BotDatabase::LoadPetSpellID(const uint32 bot_id, uint32& pet_spell_id)
auto row = results.begin();
pet_spell_id = atoi(row[0]);
return true;
}
@@ -1506,7 +1507,7 @@ bool BotDatabase::LoadPetStats(const uint32 bot_id, std::string& pet_name, uint3
pet_name = row[1];
pet_mana = atoi(row[2]);
pet_hp = atoi(row[3]);
return true;
}
@@ -1514,7 +1515,7 @@ bool BotDatabase::SavePetStats(const uint32 bot_id, const std::string& pet_name,
{
if (!bot_id || pet_name.empty() || !pet_spell_id || pet_spell_id > SPDAT_RECORDS)
return false;
if (!DeletePetItems(bot_id))
return false;
if (!DeletePetBuffs(bot_id))
@@ -1607,14 +1608,14 @@ bool BotDatabase::LoadPetBuffs(const uint32 bot_id, SpellBuff_Struct* pet_buffs)
++buff_index;
}
return true;
}
bool BotDatabase::SavePetBuffs(const uint32 bot_id, const SpellBuff_Struct* pet_buffs, bool delete_flag)
{
// Only use 'delete_flag' if not invoked after a botdb.SavePetStats() call
if (!bot_id || !pet_buffs)
return false;
@@ -1701,14 +1702,14 @@ bool BotDatabase::LoadPetItems(const uint32 bot_id, uint32* pet_items)
pet_items[item_index] = atoi(row[0]);
++item_index;
}
return true;
}
bool BotDatabase::SavePetItems(const uint32 bot_id, const uint32* pet_items, bool delete_flag)
{
// Only use 'delete_flag' if not invoked after a botdb.SavePetStats() call
if (!bot_id || !pet_items)
return false;
@@ -1777,7 +1778,7 @@ bool BotDatabase::LoadInspectMessage(const uint32 bot_id, InspectMessage_Struct&
return true;
memcpy(inspect_message.text, bot_message.c_str(), bot_message.size());
return true;
}
@@ -1785,7 +1786,7 @@ bool BotDatabase::SaveInspectMessage(const uint32 bot_id, const InspectMessage_S
{
if (!bot_id)
return false;
if (!DeleteInspectMessage(bot_id))
return false;
@@ -1825,7 +1826,7 @@ bool BotDatabase::SaveAllInspectMessages(const uint32 owner_id, const InspectMes
if (!DeleteAllInspectMessages(owner_id))
return false;
std::string bot_message = inspect_message.text;
if (bot_message.size() > 255)
bot_message = bot_message.substr(0, 255);
@@ -1907,7 +1908,7 @@ bool BotDatabase::SaveHelmAppearance(const uint32 owner_id, const uint32 bot_id,
{
if (!owner_id || !bot_id)
return false;
query = StringFormat(
"UPDATE `bot_data`"
" SET `show_helm` = '%u'"
@@ -2025,7 +2026,7 @@ bool BotDatabase::CreateCloneBot(const uint32 owner_id, const uint32 bot_id, con
{
if (!owner_id || !bot_id || clone_name.empty())
return false;
query = StringFormat(
"INSERT INTO `bot_data`"
" ("
@@ -2198,7 +2199,7 @@ bool BotDatabase::CreateCloneBotInventory(const uint32 owner_id, const uint32 bo
DeleteItems(clone_id);
return false;
}
return true;
}
@@ -2237,7 +2238,7 @@ bool BotDatabase::LoadOwnerOptions(Client *owner)
}
for (auto row : results) {
owner->SetBotOption(static_cast<Client::BotOwnerOption>(atoul(row[0])), (atoul(row[1]) != 0));
}
@@ -2369,7 +2370,7 @@ bool BotDatabase::LoadBotGroupIDByLeaderID(const uint32 leader_id, uint32& botgr
auto row = results.begin();
botgroup_id = atoi(row[0]);
return true;
}
@@ -2387,7 +2388,7 @@ bool BotDatabase::LoadBotGroupIDByMemberID(const uint32 member_id, uint32& botgr
auto row = results.begin();
botgroup_id = atoi(row[0]);
return true;
}
@@ -2405,7 +2406,7 @@ bool BotDatabase::LoadLeaderIDByBotGroupName(const std::string& group_name, uint
auto row = results.begin();
leader_id = atoi(row[0]);
return true;
}
@@ -2423,7 +2424,7 @@ bool BotDatabase::LoadLeaderIDByBotGroupID(const uint32 group_id, uint32& leader
auto row = results.begin();
leader_id = atoi(row[0]);
return true;
}
@@ -2441,7 +2442,7 @@ bool BotDatabase::LoadBotGroupNameByBotGroupID(const uint32 group_id, std::strin
auto row = results.begin();
botgroup_name = row[0];
return true;
}
@@ -2459,7 +2460,7 @@ bool BotDatabase::LoadBotGroupNameByLeaderID(const uint32 leader_id, std::string
auto row = results.begin();
botgroup_name = row[0];
return true;
}
@@ -2603,7 +2604,7 @@ bool BotDatabase::LoadBotGroup(const std::string& group_name, std::map<uint32, s
for (auto row = results.begin(); row != results.end(); ++row)
member_list[botgroup_id].push_back(atoi(row[0]));
return true;
}