Removed some unnecessary database queries.

Removed unnecessary database queries in some command handlers.
Replaced them with access to cached data or queries for only the needed data.
Move database access in gossip select code to less often called place.
This commit is contained in:
hunuza 2008-11-02 15:58:24 +01:00 committed by tomrus88
parent 004bdf1d3c
commit 79cb959991
2 changed files with 50 additions and 45 deletions

View file

@ -821,16 +821,18 @@ void Creature::OnGossipSelect(Player* player, uint32 option)
return;
}
switch (gossip->Action)
{
case GOSSIP_OPTION_GOSSIP:
{
uint32 textid = GetGossipTextId(action, zoneid);
if (textid == 0)
textid=GetNpcTextId();
switch (gossip->Action)
{
case GOSSIP_OPTION_GOSSIP:
player->PlayerTalkClass->CloseGossip();
player->PlayerTalkClass->SendTalking(textid);
break;
}
case GOSSIP_OPTION_SPIRITHEALER:
if (player->isDead())
CastSpell(this,17251,true,NULL,NULL,player->GetGUID());

View file

@ -1988,26 +1988,21 @@ bool ChatHandler::HandleAddItemSetCommand(const char* args)
sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE itemset = %u",itemsetId);
if(!result)
bool found = false;
for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
{
PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
if (!pProto)
continue;
SetSentErrorMessage(true);
return false;
}
do
if (pProto->ItemSet == itemsetId)
{
Field *fields = result->Fetch();
uint32 itemId = fields[0].GetUInt32();
found = true;
ItemPosCountVec dest;
uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, 1 );
uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
if (msg == EQUIP_ERR_OK)
{
Item* item = plTarget->StoreNewItem( dest, itemId, true);
Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
// remove binding (let GM give it to another player later)
if (pl==plTarget)
@ -2020,12 +2015,18 @@ bool ChatHandler::HandleAddItemSetCommand(const char* args)
else
{
pl->SendEquipError( msg, NULL, NULL );
PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, 1);
PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
}
}
}
}while( result->NextRow() );
if (!found)
{
PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
delete result;
SetSentErrorMessage(true);
return false;
}
return true;
}
@ -4680,17 +4681,19 @@ bool ChatHandler::HandleAddQuest(const char* args)
}
// check item starting quest (it can work incorrectly if added without item in inventory)
QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry);
if(result)
for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
{
Field* fields = result->Fetch();
uint32 item_id = fields[0].GetUInt32();
delete result;
ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
if (!pProto)
continue;
PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry,item_id);
if (pProto->StartQuest == entry)
{
PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
SetSentErrorMessage(true);
return false;
}
}
// ok, normal (creature/GO starting) quest
if( player->CanAddQuest( pQuest, true ) )