void MailDraft::prepareItems(Player* receiver, SQLTransaction& trans) { if (!m_mailTemplateId || !m_mailTemplateItemsNeed) return; m_mailTemplateItemsNeed = false; Loot mailLoot; // can be empty mailLoot.FillLoot(m_mailTemplateId, LootTemplates_Mail, receiver, true, true); uint32 max_slot = mailLoot.GetMaxSlotInLootFor(receiver); for (uint32 i = 0; m_items.size() < MAX_MAIL_ITEMS && i < max_slot; ++i) { if (LootItem* lootitem = mailLoot.LootItemInSlot(i, receiver)) { if (Item* item = Item::CreateItem(lootitem->itemid, lootitem->count, receiver)) { item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted AddItem(item); } } } }
void Mail::prepareTemplateItems( Player* receiver ) { if (!mailTemplateId || !items.empty()) return; has_items = true; Loot mailLoot; // can be empty mailLoot.FillLoot(mailTemplateId, LootTemplates_Mail, receiver, true, true); CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("UPDATE mail SET has_items = 1 WHERE id = %u", messageID); uint32 max_slot = mailLoot.GetMaxSlotInLootFor(receiver); for(uint32 i = 0; items.size() < MAX_MAIL_ITEMS && i < max_slot; ++i) { if (LootItem* lootitem = mailLoot.LootItemInSlot(i, receiver)) { if (Item* item = Item::CreateItem(lootitem->itemid, lootitem->count, receiver)) { item->SaveToDB(); AddItem(item->GetGUIDLow(), item->GetEntry()); receiver->AddMItem(item); CharacterDatabase.PExecute("INSERT INTO mail_items (mail_id,item_guid,item_template,receiver) VALUES ('%u', '%u', '%u','%u')", messageID, item->GetGUIDLow(), item->GetEntry(), receiver->GetGUIDLow()); } } } CharacterDatabase.CommitTransaction(); }
void WorldSession::SendMailTemplateTo(Player* receiver, Object* sender, uint8 stationery, uint16 mailTemplateId, uint32 money, uint32 COD, uint32 checked, uint32 deliver_delay) { Loot mailLoot; mailLoot.FillLoot(mailTemplateId, LootTemplates_Mail, receiver,true); // fill mail MailItemsInfo mi; // item list preparing uint32 max_slot = mailLoot.GetMaxSlotInLootFor(receiver); for(uint32 i = 0; mi.size() < MAX_MAIL_ITEMS && i < max_slot; ++i) { if (LootItem* lootitem = mailLoot.LootItemInSlot(i,receiver)) { if (Item* item = Item::CreateItem(lootitem->itemid,lootitem->count,receiver)) { item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted mi.AddItem(item); } } } WorldSession::SendMailTo(receiver, sender, stationery, receiver->GetGUIDLow(), "", 0, &mi, money, COD, checked,deliver_delay,mailTemplateId); }