mirror of
https://github.com/azerothcore/mod-transmog
synced 2025-11-29 22:48:30 +08:00
Use async SQL queries
This commit is contained in:
@@ -342,6 +342,7 @@ public:
|
|||||||
{
|
{
|
||||||
WorldSession* session = player->GetSession();
|
WorldSession* session = player->GetSession();
|
||||||
Item* oldItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
|
Item* oldItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
|
||||||
|
bool sendGossip = true;
|
||||||
if (oldItem)
|
if (oldItem)
|
||||||
{
|
{
|
||||||
uint32 price = sT->GetSpecialPrice(oldItem->GetTemplate());
|
uint32 price = sT->GetSpecialPrice(oldItem->GetTemplate());
|
||||||
@@ -351,8 +352,14 @@ public:
|
|||||||
ss << std::endl;
|
ss << std::endl;
|
||||||
if (sT->GetRequireToken())
|
if (sT->GetRequireToken())
|
||||||
ss << std::endl << std::endl << sT->GetTokenAmount() << " x " << sT->GetItemLink(sT->GetTokenEntry(), session);
|
ss << std::endl << std::endl << sT->GetTokenAmount() << " x " << sT->GetItemLink(sT->GetTokenEntry(), session);
|
||||||
|
std::string lineEnd = ss.str();
|
||||||
|
|
||||||
if (sT->GetUseCollectionSystem())
|
if (sT->GetUseCollectionSystem())
|
||||||
|
{
|
||||||
|
sendGossip = false;
|
||||||
|
|
||||||
|
std::string query = "SELECT item_template_id FROM custom_unlocked_appearances WHERE account_id = " + std::to_string(player->GetSession()->GetAccountId()) + " ORDER BY item_template_id";
|
||||||
|
session->GetQueryProcessor().AddCallback(CharacterDatabase.AsyncQuery(query).WithCallback([=](QueryResult result)
|
||||||
{
|
{
|
||||||
uint16 pageNumber = 0;
|
uint16 pageNumber = 0;
|
||||||
uint32 startValue = 0;
|
uint32 startValue = 0;
|
||||||
@@ -364,9 +371,6 @@ public:
|
|||||||
startValue = (pageNumber * (MAX_OPTIONS - 2));
|
startValue = (pageNumber * (MAX_OPTIONS - 2));
|
||||||
endValue = (pageNumber + 1) * (MAX_OPTIONS - 2) - 1;
|
endValue = (pageNumber + 1) * (MAX_OPTIONS - 2) - 1;
|
||||||
}
|
}
|
||||||
QueryResult result = CharacterDatabase.Query(
|
|
||||||
"SELECT item_template_id FROM custom_unlocked_appearances WHERE account_id = {} ORDER BY item_template_id",
|
|
||||||
player->GetSession()->GetAccountId());
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
std::vector<Item*> allowedItems;
|
std::vector<Item*> allowedItems;
|
||||||
@@ -389,7 +393,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Item* newItem = allowedItems.at(i);
|
Item* newItem = allowedItems.at(i);
|
||||||
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0) + sT->GetItemLink(newItem, session), slot, newItem->GetEntry(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n" + sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10) + sT->GetItemLink(newItem, session) + ss.str(), price, false);
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0) + sT->GetItemLink(newItem, session), slot, newItem->GetEntry(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n" + sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10) + sT->GetItemLink(newItem, session) + lineEnd, price, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gossipPageNumber == EQUIPMENT_SLOT_END + 11)
|
if (gossipPageNumber == EQUIPMENT_SLOT_END + 11)
|
||||||
@@ -412,6 +416,12 @@ public:
|
|||||||
{
|
{
|
||||||
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Next Page", EQUIPMENT_SLOT_END + 11, slot);
|
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Next Page", EQUIPMENT_SLOT_END + 11, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Enchant_Disenchant:30:30:-18:0|tRemove transmogrification", EQUIPMENT_SLOT_END + 3, slot, "Remove transmogrification from the slot?", 0, false);
|
||||||
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-Undo:30:30:-18:0|tUpdate menu", EQUIPMENT_SLOT_END, slot);
|
||||||
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack...", EQUIPMENT_SLOT_END + 1, 0);
|
||||||
|
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -428,7 +438,7 @@ public:
|
|||||||
if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
|
if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
|
||||||
continue;
|
continue;
|
||||||
++limit;
|
++limit;
|
||||||
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0) + sT->GetItemLink(newItem, session), slot, newItem->GetGUID().GetCounter(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n" + sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10) + sT->GetItemLink(newItem, session) + ss.str(), price, false);
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0) + sT->GetItemLink(newItem, session), slot, newItem->GetGUID().GetCounter(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n" + sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10) + sT->GetItemLink(newItem, session) + lineEnd, price, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
|
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
|
||||||
@@ -454,11 +464,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sendGossip) {
|
||||||
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Enchant_Disenchant:30:30:-18:0|tRemove transmogrification", EQUIPMENT_SLOT_END + 3, slot, "Remove transmogrification from the slot?", 0, false);
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Enchant_Disenchant:30:30:-18:0|tRemove transmogrification", EQUIPMENT_SLOT_END + 3, slot, "Remove transmogrification from the slot?", 0, false);
|
||||||
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-Undo:30:30:-18:0|tUpdate menu", EQUIPMENT_SLOT_END, slot);
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-Undo:30:30:-18:0|tUpdate menu", EQUIPMENT_SLOT_END, slot);
|
||||||
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack...", EQUIPMENT_SLOT_END + 1, 0);
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack...", EQUIPMENT_SLOT_END + 1, 0);
|
||||||
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
|
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PS_Transmogrification : public PlayerScript
|
class PS_Transmogrification : public PlayerScript
|
||||||
@@ -477,12 +489,16 @@ private:
|
|||||||
tempStream << std::hex << ItemQualityColors[itemTemplate->Quality];
|
tempStream << std::hex << ItemQualityColors[itemTemplate->Quality];
|
||||||
std::string itemQuality = tempStream.str();
|
std::string itemQuality = tempStream.str();
|
||||||
bool showChatMessage = !(player->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value);
|
bool showChatMessage = !(player->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value);
|
||||||
QueryResult result = CharacterDatabase.Query("SELECT account_id, item_template_id FROM custom_unlocked_appearances WHERE account_id = {} AND item_template_id = {}", accountId, itemId);
|
std::string query = "SELECT account_id, item_template_id FROM custom_unlocked_appearances WHERE account_id = " + std::to_string(accountId) + " AND item_template_id = " + std::to_string(itemId);
|
||||||
if (!result) {
|
player->GetSession()->GetQueryProcessor().AddCallback(CharacterDatabase.AsyncQuery(query).WithCallback([=](QueryResult result)
|
||||||
|
{
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
if (showChatMessage)
|
if (showChatMessage)
|
||||||
ChatHandler(player->GetSession()).PSendSysMessage( R"(|c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r has been added to your appearance collection.)", itemQuality.c_str(), itemId, itemName.c_str());
|
ChatHandler(player->GetSession()).PSendSysMessage( R"(|c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r has been added to your appearance collection.)", itemQuality.c_str(), itemId, itemName.c_str());
|
||||||
CharacterDatabase.Execute( "INSERT INTO custom_unlocked_appearances (account_id, item_template_id) VALUES ({}, {})", accountId, itemId);
|
CharacterDatabase.Execute( "INSERT INTO custom_unlocked_appearances (account_id, item_template_id) VALUES ({}, {})", accountId, itemId);
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
PS_Transmogrification() : PlayerScript("Player_Transmogrify") { }
|
PS_Transmogrification() : PlayerScript("Player_Transmogrify") { }
|
||||||
|
|||||||
Reference in New Issue
Block a user