本文整理汇总了C++中Item::GetGUIDLow方法的典型用法代码示例。如果您正苦于以下问题:C++ Item::GetGUIDLow方法的具体用法?C++ Item::GetGUIDLow怎么用?C++ Item::GetGUIDLow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Item
的用法示例。
在下文中一共展示了Item::GetGUIDLow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleWrapItemOpcode
void WorldSession::HandleWrapItemOpcode(WorldPacket& recv_data)
{
sLog.outDebug("Received opcode CMSG_WRAP_ITEM");
uint8 gift_bag, gift_slot, item_bag, item_slot;
//recv_data.hexlike();
recv_data >> gift_bag >> gift_slot; // paper
recv_data >> item_bag >> item_slot; // item
sLog.outDebug("WRAP: receive gift_bag = %u, gift_slot = %u, item_bag = %u, item_slot = %u", gift_bag, gift_slot, item_bag, item_slot);
Item *gift = _player->GetItemByPos( gift_bag, gift_slot );
if(!gift)
{
_player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL );
return;
}
if(!gift->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPER))// cheating: non-wrapper wrapper
{
_player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL );
return;
}
Item *item = _player->GetItemByPos( item_bag, item_slot );
if( !item )
{
_player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, item, NULL );
return;
}
if(item==gift) // not possable with pacjket from real client
{
_player->SendEquipError( EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, NULL );
return;
}
if(item->IsEquipped())
{
_player->SendEquipError( EQUIP_ERR_EQUIPPED_CANT_BE_WRAPPED, item, NULL );
return;
}
if(item->GetUInt64Value(ITEM_FIELD_GIFTCREATOR)) // HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
{
_player->SendEquipError( EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, NULL );
return;
}
if(item->IsBag())
{
_player->SendEquipError( EQUIP_ERR_BAGS_CANT_BE_WRAPPED, item, NULL );
return;
}
if(item->IsSoulBound())
{
_player->SendEquipError( EQUIP_ERR_BOUND_CANT_BE_WRAPPED, item, NULL );
return;
}
if(item->GetMaxStackCount() != 1)
{
_player->SendEquipError( EQUIP_ERR_STACKABLE_CANT_BE_WRAPPED, item, NULL );
return;
}
// maybe not correct check (it is better than nothing)
if(item->GetProto()->MaxCount>0)
{
_player->SendEquipError( EQUIP_ERR_UNIQUE_CANT_BE_WRAPPED, item, NULL );
return;
}
CharacterDatabase.BeginTransaction();
CharacterDatabase.PExecute("INSERT INTO character_gifts VALUES ('%u', '%u', '%u', '%u')", GUID_LOPART(item->GetOwnerGUID()), item->GetGUIDLow(), item->GetEntry(), item->GetUInt32Value(ITEM_FIELD_FLAGS));
item->SetEntry(gift->GetEntry());
switch (item->GetEntry())
{
case 5042: item->SetEntry( 5043); break;
case 5048: item->SetEntry( 5044); break;
case 17303: item->SetEntry(17302); break;
case 17304: item->SetEntry(17305); break;
case 17307: item->SetEntry(17308); break;
case 21830: item->SetEntry(21831); break;
}
item->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, _player->GetGUID());
item->SetUInt32Value(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
item->SetState(ITEM_CHANGED, _player);
if(item->GetState()==ITEM_NEW) // save new item, to have alway for `character_gifts` record in `item_instance`
{
// after save it will be impossible to remove the item from the queue
item->RemoveFromUpdateQueueOf(_player);
item->SaveToDB(); // item gave inventory record unchanged and can be save standalone
}
CharacterDatabase.CommitTransaction();
//.........这里部分代码省略.........
示例2: SendReturnToSender
/*
* Returns a mail to its sender.
* @param sender_acc The id of the account of the sender.
* @param sender_guid The low part of the GUID of the sender.
* @param receiver_guid The low part of the GUID of the reciever.
*/
void MailDraft::SendReturnToSender(uint32 sender_acc, ObjectGuid sender_guid, ObjectGuid receiver_guid)
{
Player *receiver = sObjectMgr.GetPlayer(receiver_guid);
uint32 rc_account = 0;
if (!receiver)
rc_account = sObjectMgr.GetPlayerAccountIdByGUID(receiver_guid);
if (!receiver && !rc_account) // sender not exist
{
deleteIncludedItems(true);
return;
}
// prepare mail and send in other case
bool needItemDelay = false;
if (!m_items.empty())
{
// if item send to character at another account, then apply item delivery delay
needItemDelay = sender_acc != rc_account;
// set owner to new receiver (to prevent delete item with sender char deleting)
CharacterDatabase.BeginTransaction();
for (MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Item* item = mailItemIter->second;
item->SaveToDB(); // item not in inventory and can be save standalone
// owner in data will set at mail receive and item extracting
CharacterDatabase.PExecute("UPDATE item_instance SET owner_guid = '%u' WHERE guid='%u'", receiver_guid.GetCounter(), item->GetGUIDLow());
}
CharacterDatabase.CommitTransaction();
}
// If theres is an item, there is a one hour delivery delay.
uint32 deliver_delay = needItemDelay ? sWorld.getConfig(CONFIG_UINT32_MAIL_DELIVERY_DELAY) : 0;
// will delete item or place to receiver mail list
SendMailTo(MailReceiver(receiver, receiver_guid), MailSender(MAIL_NORMAL, sender_guid.GetCounter()), MAIL_CHECK_MASK_RETURNED, deliver_delay);
}
示例3: SendAuctionWonMail
//does not clear ram
void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, SQLTransaction& trans)
{
Item* pItem = GetAItem(auction->itemGUIDLow);
if (!pItem)
return;
uint32 bidderAccId = 0;
uint64 bidderGuid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
Player* bidder = ObjectAccessor::FindPlayer(bidderGuid);
// data for gm.log
std::string bidderName;
bool logGmTrade = false;
if (bidder)
{
bidderAccId = bidder->GetSession()->GetAccountId();
bidderName = bidder->GetName();
logGmTrade = bidder->GetSession()->HasPermission(RBAC_PERM_LOG_GM_TRADE);
}
else
{
bidderAccId = sObjectMgr->GetPlayerAccountIdByGUID(bidderGuid);
logGmTrade = AccountMgr::HasPermission(bidderAccId, RBAC_PERM_LOG_GM_TRADE, realmID);
if (logGmTrade && !sObjectMgr->GetPlayerNameByGUID(bidderGuid, bidderName))
bidderName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
}
if (logGmTrade)
{
std::string ownerName;
if (!sObjectMgr->GetPlayerNameByGUID(auction->owner, ownerName))
ownerName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
uint32 ownerAccId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner);
sLog->outCommand(bidderAccId, "GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
bidderName.c_str(), bidderAccId, pItem->GetTemplate()->Name1.c_str(), pItem->GetEntry(), pItem->GetCount(), auction->bid, ownerName.c_str(), ownerAccId);
}
// receiver exist
if (bidder || bidderAccId)
{
// set owner to bidder (to prevent delete item with sender char deleting)
// owner in `data` will set at mail receive and item extracting
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ITEM_OWNER);
stmt->setUInt32(0, auction->bidder);
stmt->setUInt32(1, pItem->GetGUIDLow());
trans->Append(stmt);
if (bidder)
{
bidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, bidderGuid, 0, 0, auction->itemEntry);
// FIXME: for offline player need also
bidder->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS, 1);
}
MailDraft(auction->BuildAuctionMailSubject(AUCTION_WON), AuctionEntry::BuildAuctionMailBody(auction->owner, auction->bid, auction->buyout, 0, 0))
.AddItem(pItem)
.SendMailTo(trans, MailReceiver(bidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
}
}
示例4: SendAuctionWonMail
//does not clear ram
void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
{
Item *pItem = GetAItem(auction->item_guidlow);
if(!pItem)
return;
ObjectGuid bidder_guid = ObjectGuid(HIGHGUID_PLAYER, auction->bidder);
Player *bidder = sObjectMgr.GetPlayer(bidder_guid);
uint32 bidder_accId = 0;
// data for gm.log
if( sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE) )
{
uint32 bidder_security = 0;
std::string bidder_name;
if (bidder)
{
bidder_accId = bidder->GetSession()->GetAccountId();
bidder_security = bidder->GetSession()->GetSecurity();
bidder_name = bidder->GetName();
}
else
{
bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
bidder_security = sAccountMgr.GetSecurity(bidder_accId);
if (bidder_security > SEC_PLAYER ) // not do redundant DB requests
{
if (!sObjectMgr.GetPlayerNameByGUID(bidder_guid, bidder_name))
bidder_name = sObjectMgr.GetMangosStringForDBCLocale(LANG_UNKNOWN);
}
}
if (bidder_security > SEC_PLAYER)
{
ObjectGuid owner_guid = ObjectGuid(HIGHGUID_PLAYER, auction->owner);
std::string owner_name;
if(!sObjectMgr.GetPlayerNameByGUID(owner_guid, owner_name))
owner_name = sObjectMgr.GetMangosStringForDBCLocale(LANG_UNKNOWN);
uint32 owner_accid = sObjectMgr.GetPlayerAccountIdByGUID(owner_guid);
sLog.outCommand(bidder_accId,"GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
bidder_name.c_str(),bidder_accId,pItem->GetProto()->Name1,pItem->GetEntry(),pItem->GetCount(),auction->bid,owner_name.c_str(),owner_accid);
}
}
else if (!bidder)
bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
// receiver exist
if(bidder || bidder_accId)
{
std::ostringstream msgAuctionWonSubject;
msgAuctionWonSubject << auction->item_template << ":0:" << AUCTION_WON;
std::ostringstream msgAuctionWonBody;
msgAuctionWonBody.width(16);
msgAuctionWonBody << std::right << std::hex << auction->owner;
msgAuctionWonBody << std::dec << ":" << auction->bid << ":" << auction->buyout;
DEBUG_LOG( "AuctionWon body string : %s", msgAuctionWonBody.str().c_str() );
// set owner to bidder (to prevent delete item with sender char deleting)
// owner in `data` will set at mail receive and item extracting
CharacterDatabase.PExecute("UPDATE item_instance SET owner_guid = '%u' WHERE guid='%u'",auction->bidder,pItem->GetGUIDLow());
CharacterDatabase.CommitTransaction();
if (bidder)
{
bidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, bidder_guid, 0, 0, auction->item_template);
// FIXME: for offline player need also
bidder->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS, 1);
}
else
RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !!
// will delete item or place to receiver mail list
MailDraft(msgAuctionWonSubject.str(), msgAuctionWonBody.str())
.AddItem(pItem)
.SendMailTo(MailReceiver(bidder,auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
}
// receiver not exist
else
{
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid='%u'", pItem->GetGUIDLow());
RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !!
delete pItem;
}
}
示例5: HandleGetMailList
//called when player lists his received mails
void WorldSession::HandleGetMailList(WorldPacket & recv_data)
{
uint64 mailbox;
recv_data >> mailbox;
if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX))
return;
Player* player = _player;
//load players mails, and mailed items
if (!player->m_mailsLoaded)
player ->_LoadMail();
// client can't work with packets > max int16 value
const uint32 maxPacketSize = 32767;
uint32 mailsCount = 0; // real send to client mails amount
uint32 realCount = 0; // real mails amount
WorldPacket data(SMSG_MAIL_LIST_RESULT, (200)); // guess size
data << uint32(0); // real mail's count
data << uint8(0); // mail's count
time_t cur_time = time(NULL);
for (PlayerMails::iterator itr = player->GetMailBegin(); itr != player->GetMailEnd(); ++itr)
{
// packet send mail count as uint8, prevent overflow
if (mailsCount >= 254)
{
realCount += 1;
continue;
}
// skip deleted or not delivered (deliver delay not expired) mails
if ((*itr)->state == MAIL_STATE_DELETED || cur_time < (*itr)->deliver_time)
continue;
uint8 item_count = (*itr)->items.size(); // max count is MAX_MAIL_ITEMS (12)
size_t next_mail_size = 2+4+1+((*itr)->messageType == MAIL_NORMAL ? 8 : 4)+4*8+((*itr)->subject.size()+1)+((*itr)->body.size()+1)+1+item_count*(1+4+4+7*3*4+4+4+4+4+4+4+1);
if (data.wpos()+next_mail_size > maxPacketSize)
{
realCount += 1;
continue;
}
data << uint16(next_mail_size); // Message size
data << uint32((*itr)->messageID); // Message ID
data << uint8((*itr)->messageType); // Message Type
switch ((*itr)->messageType)
{
case MAIL_NORMAL: // sender guid
data << uint64(MAKE_NEW_GUID((*itr)->sender, 0, HIGHGUID_PLAYER));
break;
case MAIL_CREATURE:
case MAIL_GAMEOBJECT:
case MAIL_AUCTION:
data << uint32((*itr)->sender); // creature/gameobject entry, auction id
break;
case MAIL_ITEM: // item entry (?) sender = "Unknown", NYI
data << uint32(0); // item entry
break;
}
data << uint32((*itr)->COD); // COD
data << uint32(0); // probably changed in 3.3.3
data << uint32((*itr)->stationery); // stationery (Stationery.dbc)
data << uint32((*itr)->money); // Gold
data << uint32((*itr)->checked); // flags
data << float(((*itr)->expire_time-time(NULL))/DAY); // Time
data << uint32((*itr)->mailTemplateId); // mail template (MailTemplate.dbc)
data << (*itr)->subject; // Subject string - once 00, when mail type = 3, max 256
data << (*itr)->body; // message? max 8000
data << uint8(item_count); // client limit is 0x10
for (uint8 i = 0; i < item_count; ++i)
{
Item* item = player->GetMItem((*itr)->items[i].item_guid);
// item index (0-6?)
data << uint8(i);
// item guid low?
data << uint32((item ? item->GetGUIDLow() : 0));
// entry
data << uint32((item ? item->GetEntry() : 0));
for (uint8 j = 0; j < MAX_INSPECTED_ENCHANTMENT_SLOT; ++j)
{
data << uint32((item ? item->GetEnchantmentId((EnchantmentSlot)j) : 0));
data << uint32((item ? item->GetEnchantmentDuration((EnchantmentSlot)j) : 0));
data << uint32((item ? item->GetEnchantmentCharges((EnchantmentSlot)j) : 0));
}
// can be negative
data << int32((item ? item->GetItemRandomPropertyId() : 0));
// unk
data << uint32((item ? item->GetItemSuffixFactor() : 0));
// stack count
data << uint32((item ? item->GetCount() : 0));
//.........这里部分代码省略.........
示例6: HandlePetitionBuyOpcode
//.........这里部分代码省略.........
break;
default:
sLog->outDebug("unknown selection at buy arena petition: %u", clientIndex);
return;
}
if (_player->GetArenaTeamId(clientIndex - 1)) // arenaSlot+1 as received from client
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM);
return;
}
}
if (type == 9)
{
if (sObjectMgr->GetGuildByName(name))
{
SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_EXISTS_S);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
SendGuildCommandResult(GUILD_CREATE_S, name, ERR_GUILD_NAME_INVALID);
return;
}
}
else
{
if (sObjectMgr->GetArenaTeamByName(name))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID);
return;
}
}
ItemPrototype const *pProto = sObjectMgr->GetItemPrototype(charterid);
if (!pProto)
{
_player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, NULL, charterid, 0);
return;
}
if (_player->GetMoney() < cost)
{ //player hasn't got enough money
_player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, charterid, 0);
return;
}
ItemPosCountVec dest;
uint8 msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, charterid, pProto->BuyCount);
if (msg != EQUIP_ERR_OK)
{
_player->SendBuyError(msg, creature, charterid, 0);
return;
}
_player->ModifyMoney(-(int32)cost);
Item *charter = _player->StoreNewItem(dest, charterid, true);
if (!charter)
return;
charter->SetUInt32Value(ITEM_FIELD_ENCHANTMENT, charter->GetGUIDLow());
// ITEM_FIELD_ENCHANTMENT is guild/arenateam id
// ITEM_FIELD_ENCHANTMENT+1 is current signatures count (showed on item)
charter->SetState(ITEM_CHANGED, _player);
_player->SendNewItem(charter, 1, true, false);
// a petition is invalid, if both the owner and the type matches
// we checked above, if this player is in an arenateam, so this must be
// datacorruption
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type);
std::ostringstream ssInvalidPetitionGUIDs;
if (result)
{
do
{
Field *fields = result->Fetch();
ssInvalidPetitionGUIDs << "'" << fields[0].GetUInt32() << "' , ";
} while (result->NextRow());
}
// delete petitions with the same guid as this one
ssInvalidPetitionGUIDs << "'" << charter->GetGUIDLow() << "'";
sLog->outDebug("Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs.str().c_str());
CharacterDatabase.EscapeString(name);
CharacterDatabase.BeginTransaction();
CharacterDatabase.PExecute("DELETE FROM petition WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str());
CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str());
CharacterDatabase.PExecute("INSERT INTO petition (ownerguid, petitionguid, name, type) VALUES ('%u', '%u', '%s', '%u')",
_player->GetGUIDLow(), charter->GetGUIDLow(), name.c_str(), type);
CharacterDatabase.CommitTransaction();
}
示例7: SendMailTo
void MailDraft::SendMailTo(SQLTransaction& trans, MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked, uint32 deliver_delay)
{
Player* pReceiver = receiver.GetPlayer(); // can be NULL
Player* pSender = sObjectMgr->GetPlayerByLowGUID(sender.GetSenderId());
if (pReceiver)
prepareItems(pReceiver, trans); // generate mail template items
uint32 mailId = sObjectMgr->GenerateMailID();
if (receiver.GetPlayerGUIDLow() == auctionbot.GetAHBplayerGUID())
{
if (sender.GetMailMessageType() == MAIL_AUCTION) // auction mail with items
deleteIncludedItems(trans, true);
return;
}
time_t deliver_time = time(NULL) + deliver_delay;
//expire time if COD 3 days, if no COD 30 days, if auction sale pending 1 hour
uint32 expire_delay;
// auction mail without any items and money
if (sender.GetMailMessageType() == MAIL_AUCTION && m_items.empty() && !m_money)
expire_delay = sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY);
// mail from battlemaster (rewardmarks) should last only one day
else if (sender.GetMailMessageType() == MAIL_CREATURE && sBattlegroundMgr->GetBattleMasterBG(sender.GetSenderId()) != BATTLEGROUND_TYPE_NONE)
expire_delay = DAY;
// default case: expire time if COD 3 days, if no COD 30 days (or 90 days if sender is a game master)
else
if (m_COD)
expire_delay = 3 * DAY;
else
expire_delay = pSender && pSender->isGameMaster() ? 90 * DAY : 30 * DAY;
time_t expire_time = deliver_time + expire_delay;
// Add to DB
uint8 index = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_MAIL);
stmt->setUInt32( index, mailId);
stmt->setUInt8 (++index, uint8(sender.GetMailMessageType()));
stmt->setInt8 (++index, int8(sender.GetStationery()));
stmt->setUInt16(++index, GetMailTemplateId());
stmt->setUInt32(++index, sender.GetSenderId());
stmt->setUInt32(++index, receiver.GetPlayerGUIDLow());
stmt->setString(++index, GetSubject());
stmt->setString(++index, GetBody());
stmt->setBool (++index, !m_items.empty());
stmt->setUInt64(++index, uint64(expire_time));
stmt->setUInt64(++index, uint64(deliver_time));
stmt->setUInt32(++index, m_money);
stmt->setUInt32(++index, m_COD);
stmt->setUInt8 (++index, uint8(checked));
trans->Append(stmt);
for (MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Item* pItem = mailItemIter->second;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_MAIL_ITEM);
stmt->setUInt32(0, mailId);
stmt->setUInt32(1, pItem->GetGUIDLow());
stmt->setUInt32(2, receiver.GetPlayerGUIDLow());
trans->Append(stmt);
}
// For online receiver update in game mail status and data
if (pReceiver)
{
pReceiver->AddNewMailDeliverTime(deliver_time);
if (pReceiver->IsMailsLoaded())
{
Mail* m = new Mail;
m->messageID = mailId;
m->mailTemplateId = GetMailTemplateId();
m->subject = GetSubject();
m->body = GetBody();
m->money = GetMoney();
m->COD = GetCOD();
for (MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Item* item = mailItemIter->second;
m->AddItem(item->GetGUIDLow(), item->GetEntry());
}
m->messageType = sender.GetMailMessageType();
m->stationery = sender.GetStationery();
m->sender = sender.GetSenderId();
m->receiver = receiver.GetPlayerGUIDLow();
m->expire_time = expire_time;
m->deliver_time = deliver_time;
m->checked = checked;
m->state = MAIL_STATE_UNCHANGED;
pReceiver->AddMail(m); // to insert new mail to beginning of maillist
if (!m_items.empty())
{
//.........这里部分代码省略.........
示例8: HandleMailTakeItem
/**
* Handles the packet sent by the client when taking an item from the mail.
*/
void WorldSession::HandleMailTakeItem(WorldPacket & recv_data )
{
ObjectGuid mailboxGuid;
uint32 mailId;
uint32 itemId;
recv_data >> mailboxGuid;
recv_data >> mailId;
recv_data >> itemId; // item guid low
if (!CheckMailBox(mailboxGuid))
return;
Player* pl = _player;
Mail* m = pl->GetMail(mailId);
if(!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
{
pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR);
return;
}
// prevent cheating with skip client money check
if(pl->GetMoney() < m->COD)
{
pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_NOT_ENOUGH_MONEY);
return;
}
Item *it = pl->GetMItem(itemId);
ItemPosCountVec dest;
InventoryResult msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, dest, it, false );
if (msg == EQUIP_ERR_OK)
{
m->RemoveItem(itemId);
m->removedItems.push_back(itemId);
if (m->COD > 0) // if there is COD, take COD money from player and send them to sender by mail
{
ObjectGuid sender_guid = ObjectGuid(HIGHGUID_PLAYER, m->sender);
Player *sender = sObjectMgr.GetPlayer(sender_guid);
uint32 sender_accId = 0;
if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE) )
{
std::string sender_name;
if(sender)
{
sender_accId = sender->GetSession()->GetAccountId();
sender_name = sender->GetName();
}
else if (sender_guid)
{
// can be calculated early
sender_accId = sAccountMgr.GetPlayerAccountIdByGUID(sender_guid);
if(!sAccountMgr.GetPlayerNameByGUID(sender_guid, sender_name))
sender_name = sObjectMgr.GetMangosStringForDBCLocale(LANG_UNKNOWN);
}
sLog.outCommand(GetAccountId(), "GM %s (Account: %u) receive mail item: %s (Entry: %u Count: %u) and send COD money: %u to player: %s (Account: %u)",
GetPlayerName(), GetAccountId(), it->GetProto()->Name1, it->GetEntry(), it->GetCount(), m->COD, sender_name.c_str(), sender_accId);
}
else if (!sender)
sender_accId = sAccountMgr.GetPlayerAccountIdByGUID(sender_guid);
// check player existence
if(sender || sender_accId)
{
MailDraft(m->subject, "")
.SetMoney(m->COD)
.SendMailTo(MailReceiver(sender, sender_guid), _player, MAIL_CHECK_MASK_COD_PAYMENT);
}
pl->ModifyMoney( -int32(m->COD) );
}
m->COD = 0;
m->state = MAIL_STATE_CHANGED;
pl->m_mailsUpdated = true;
pl->RemoveMItem(it->GetGUIDLow());
uint32 count = it->GetCount(); // save counts before store and possible merge with deleting
pl->MoveItemToInventory(dest, it, true);
CharacterDatabase.BeginTransaction();
pl->SaveInventoryAndGoldToDB();
pl->_SaveMail();
CharacterDatabase.CommitTransaction();
pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_OK, 0, itemId, count);
}
else
pl->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_EQUIP_ERROR, msg);
}
示例9: CreateItem
Item* Item::CreateItem( uint32 item, uint32 count, Player const* player )
{
if (count < 1)
return NULL; //don't create item at zero count
if (ItemPrototype const *pProto = ObjectMgr::GetItemPrototype(item))
{
if (count > pProto->GetMaxStackSize())
count = pProto->GetMaxStackSize();
MANGOS_ASSERT(count !=0 && "pProto->Stackable==0 but checked at loading already");
Item *pItem = NewItemOrBag( pProto );
if (pItem->Create(sObjectMgr.GenerateItemLowGuid(), item, player) )
{
/** World of Warcraft Armory **/
if (sWorld.getConfig(CONFIG_BOOL_ARMORY_SUPPORT))
{
if (pProto->Quality > 2 && pProto->Flags != 2048 && (pProto->Class == ITEM_CLASS_WEAPON || pProto->Class == ITEM_CLASS_ARMOR) && player)
{
std::ostringstream ss;
sLog.outDetail("WoWArmory: write feed log (guid: %u, type: 2, data: %u)", player->GetGUIDLow(), item);
ss << "REPLACE INTO armory_character_feed_log (guid, type, data, date, counter, item_guid) VALUES (" << player->GetGUIDLow() << ", 2, " << item << ", UNIX_TIMESTAMP(NOW()), 1," << pItem->GetGUIDLow() << ")";
CharacterDatabase.PExecute( ss.str().c_str() );
}
}
/** World of Warcraft Armory **/
pItem->SetCount( count );
return pItem;
}
else
delete pItem;
}
return NULL;
}
示例10: HandlePetitionBuyOpcode
//.........这里部分代码省略.........
}
}
if (type == GUILD_CHARTER_TYPE)
{
if (sGuildMgr->GetGuildByName(name))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, name);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, name);
return;
}
}
else
{
if (sArenaTeamMgr->GetArenaTeamByName(name))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID);
return;
}
}
ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(charterid);
if (!pProto)
{
_player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, NULL, charterid, 0);
return;
}
if (!_player->HasEnoughMoney(cost))
{ //player hasn't got enough money
_player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, charterid, 0);
return;
}
ItemPosCountVec dest;
InventoryResult msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, charterid, pProto->BuyCount);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, NULL, NULL, charterid);
return;
}
_player->ModifyMoney(-(int32)cost);
Item* charter = _player->StoreNewItem(dest, charterid, true);
if (!charter)
return;
charter->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, charter->GetGUIDLow());
// ITEM_FIELD_ENCHANTMENT_1_1 is guild/arenateam id
// ITEM_FIELD_ENCHANTMENT_1_1+1 is current signatures count (showed on item)
charter->SetState(ITEM_CHANGED, _player);
_player->SendNewItem(charter, 1, true, false);
// a petition is invalid, if both the owner and the type matches
// we checked above, if this player is in an arenateam, so this must be
// datacorruption
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_BY_OWNER);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt8(1, type);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
std::ostringstream ssInvalidPetitionGUIDs;
if (result)
{
do
{
Field* fields = result->Fetch();
ssInvalidPetitionGUIDs << '\'' << fields[0].GetUInt32() << "', ";
} while (result->NextRow());
}
// delete petitions with the same guid as this one
ssInvalidPetitionGUIDs << '\'' << charter->GetGUIDLow() << '\'';
TC_LOG_DEBUG("network", "Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs.str().c_str());
CharacterDatabase.EscapeString(name);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
trans->PAppend("DELETE FROM petition WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str());
trans->PAppend("DELETE FROM petition_sign WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str());
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PETITION);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt32(1, charter->GetGUIDLow());
stmt->setString(2, name);
stmt->setUInt8(3, uint8(type));
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
}
示例11: SendAuctionWonMail
//does not clear ram
void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction, SQLTransaction& trans)
{
Item *pItem = GetAItem(auction->item_guidlow);
if (!pItem)
return;
uint32 bidder_accId = 0;
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
Player *bidder = sObjectMgr->GetPlayer(bidder_guid);
// data for gm.log
if (sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE))
{
uint32 bidder_security = 0;
std::string bidder_name;
if (bidder)
{
bidder_accId = bidder->GetSession()->GetAccountId();
bidder_security = bidder->GetSession()->GetSecurity();
bidder_name = bidder->GetName();
}
else
{
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(bidder_guid);
bidder_security = sAccountMgr->GetSecurity(bidder_accId, realmID);
if (bidder_security > SEC_PLAYER) // not do redundant DB requests
{
if (!sObjectMgr->GetPlayerNameByGUID(bidder_guid, bidder_name))
bidder_name = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
}
}
if (bidder_security > SEC_PLAYER)
{
std::string owner_name;
if (!sObjectMgr->GetPlayerNameByGUID(auction->owner, owner_name))
owner_name = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
uint32 owner_accid = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner);
sLog->outCommand(bidder_accId, "GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
bidder_name.c_str(), bidder_accId, pItem->GetTemplate()->Name1.c_str(), pItem->GetEntry(), pItem->GetCount(), auction->bid, owner_name.c_str(), owner_accid);
}
}
// receiver exist
if (bidder || bidder_accId)
{
std::ostringstream msgAuctionWonSubject;
msgAuctionWonSubject << auction->item_template << ":0:" << AUCTION_WON;
std::ostringstream msgAuctionWonBody;
msgAuctionWonBody.width(16);
msgAuctionWonBody << std::right << std::hex << auction->owner;
msgAuctionWonBody << std::dec << ":" << auction->bid << ":" << auction->buyout;
sLog->outDebug(LOG_FILTER_AUCTIONHOUSE, "AuctionWon body string : %s", msgAuctionWonBody.str().c_str());
// set owner to bidder (to prevent delete item with sender char deleting)
// owner in `data` will set at mail receive and item extracting
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SET_ITEM_OWNER);
stmt->setUInt32(0, auction->bidder);
stmt->setUInt32(1, pItem->GetGUIDLow());
trans->Append(stmt);
if (bidder)
{
bidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, bidder_guid, 0, 0, auction->item_template);
// FIXME: for offline player need also
bidder->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS, 1);
}
MailDraft(msgAuctionWonSubject.str(), msgAuctionWonBody.str())
.AddItem(pItem)
.SendMailTo(trans, MailReceiver(bidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
}
}
示例12: HandleGetItemState
bool ChatHandler::HandleGetItemState(const char* args)
{
if (!args)
return false;
std::string state_str = args;
ItemUpdateState state = ITEM_UNCHANGED;
bool list_queue = false, check_all = false;
if (state_str == "unchanged") state = ITEM_UNCHANGED;
else if (state_str == "changed") state = ITEM_CHANGED;
else if (state_str == "new") state = ITEM_NEW;
else if (state_str == "removed") state = ITEM_REMOVED;
else if (state_str == "queue") list_queue = true;
else if (state_str == "check_all") check_all = true;
else return false;
Player* player = getSelectedPlayer();
if (!player) player = m_session->GetPlayer();
if (!list_queue && !check_all)
{
state_str = "The player has the following " + state_str + " items: ";
SendSysMessage(state_str.c_str());
for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
{
if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
continue;
Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
if (!item) continue;
if (!item->IsBag())
{
if (item->GetState() == state)
PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
}
else
{
Bag *bag = (Bag*)item;
const ItemPrototype *proto = bag->GetProto();
for (uint8 j = 0; j < proto->ContainerSlots; ++j)
{
Item* item = bag->GetItemByPos(j);
if (item && item->GetState() == state)
PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
}
}
}
}
if (list_queue)
{
std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
for(size_t i = 0; i < updateQueue.size(); i++)
{
Item *item = updateQueue[i];
if(!item) continue;
Bag *container = item->GetContainer();
uint8 bag_slot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
std::string st;
switch(item->GetState())
{
case ITEM_UNCHANGED: st = "unchanged"; break;
case ITEM_CHANGED: st = "changed"; break;
case ITEM_NEW: st = "new"; break;
case ITEM_REMOVED: st = "removed"; break;
}
PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot, item->GetSlot(), item->GetGUIDLow(), st.c_str());
}
if (updateQueue.empty())
PSendSysMessage("updatequeue empty");
}
if (check_all)
{
bool error = false;
std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
{
if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
continue;
Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
if (!item) continue;
if (item->GetSlot() != i)
{
PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i, item->GetGUIDLow(), item->GetSlot());
error = true; continue;
}
if (item->GetOwnerGUID() != player->GetGUID())
{
PSendSysMessage("for the item at slot %d and itemguid %d, owner's guid (%d) and player's guid (%d) don't match!", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()), player->GetGUIDLow());
error = true; continue;
}
//.........这里部分代码省略.........
示例13: HandleGetMailList
//.........这里部分代码省略.........
if (data.wpos() + nextMailSize > maxPacketSize)
{
realCount += 1;
continue;
}
data.WriteBit(mail->messageType != MAIL_NORMAL ? 1 : 0);
data.WriteBits(mail->subject.size(), 8);
data.WriteBits(mail->body.size(), 13);
data.WriteBit(0);
data.WriteBit(0);
size_t itemCountPos = data.bitwpos();
data.WriteBits(0, 17); // placeholder
data.WriteBit(1); // has guid
ObjectGuid guid = mail->messageType == MAIL_NORMAL ? MAKE_NEW_GUID(mail->sender, 0, HIGHGUID_PLAYER) : 0;
data.WriteBit(guid[2]);
data.WriteBit(guid[6]);
data.WriteBit(guid[7]);
data.WriteBit(guid[0]);
data.WriteBit(guid[5]);
data.WriteBit(guid[3]);
data.WriteBit(guid[1]);
data.WriteBit(guid[4]);
uint8 trueItemCount = 0;
for (uint8 i = 0; i < itemCount; i++)
{
Item* item = player->GetMItem(mail->items[i].item_guid);
if (!item)
continue;
data.WriteBit(0);
mailData << uint32(item->GetGUIDLow());
mailData << uint32(4); // unknown
mailData << uint32(item->GetSpellCharges());
mailData << uint32(item->GetUInt32Value(ITEM_FIELD_DURABILITY));
mailData << uint32(0); // unknown
for (uint8 j = 0; j < MAX_INSPECTED_ENCHANTMENT_SLOT; j++)
{
mailData << uint32(item->GetEnchantmentCharges((EnchantmentSlot)j));
mailData << uint32(item->GetEnchantmentDuration((EnchantmentSlot)j));
mailData << uint32(item->GetEnchantmentId((EnchantmentSlot)j));
}
mailData << uint32(item->GetItemSuffixFactor());
mailData << int32(item->GetItemRandomPropertyId());
mailData << uint32(item->GetUInt32Value(ITEM_FIELD_MAX_DURABILITY));
mailData << uint32(item->GetCount());
mailData << uint8(i);
mailData << uint32(item->GetEntry());
trueItemCount++;
}
data.PutBits(itemCountPos, trueItemCount, 17);
mailData.WriteString(mail->body);
mailData << uint32(mail->messageID);
mailData.WriteByteSeq(guid[4]);
mailData.WriteByteSeq(guid[0]);
mailData.WriteByteSeq(guid[5]);
mailData.WriteByteSeq(guid[3]);
mailData.WriteByteSeq(guid[1]);
mailData.WriteByteSeq(guid[7]);
mailData.WriteByteSeq(guid[2]);
mailData.WriteByteSeq(guid[6]);
mailData << uint32(mail->mailTemplateId);
mailData << uint64(mail->COD);
mailData.WriteString(mail->subject);
mailData << uint32(mail->stationery);
mailData << float(float(mail->expire_time - time(NULL)) / DAY);
mailData << uint64(mail->money);
mailData << uint32(mail->checked);
if (mail->messageType != MAIL_NORMAL)
mailData << uint32(mail->sender);
mailData << uint8(mail->messageType);
mailData << uint32(0); // unknown
realCount++;
mailCount++;
}
data.FlushBits();
data.append(mailData);
data.put<uint32>(0, realCount);
data.PutBits(mailCountPos, mailCount, 18);
SendPacket(&data);
// recalculate m_nextMailDelivereTime and unReadMails
_player->UpdateNextMailTimeAndUnreads();
}
示例14: SendMailTo
/**
* Sends a mail.
*
* @param receiver The MailReceiver to which this mail is sent.
* @param sender The MailSender from which this mail is originated.
* @param checked The mask used to specify the mail.
* @param deliver_delay The delay after which the mail is delivered in seconds
*/
void MailDraft::SendMailTo(MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked, uint32 deliver_delay, uint32 expire_delay)
{
Player* pReceiver = receiver.GetPlayer(); // can be NULL
MasterPlayer* masterReceiver = sObjectAccessor.FindMasterPlayer(receiver.GetPlayerGuid());
bool has_items = !m_items.empty();
// generate mail template items for online player, for offline player items will generated at open
if (pReceiver)
{
if (prepareItems(pReceiver))
has_items = true;
}
uint32 mailId = sObjectMgr.GenerateMailID();
time_t deliver_time = time(NULL) + deliver_delay;
if (!expire_delay)
{
// expire time if COD 3 days, if no COD 30 days, if auction sale pending 1 hour
// auction mail without any items and money (auction sale note) pending 1 hour
if (sender.GetMailMessageType() == MAIL_AUCTION && m_items.empty() && !m_money)
expire_delay = HOUR;
// default case: expire time if COD 3 days, if no COD 30 days
else
expire_delay = (m_COD > 0) ? 3 * DAY : 30 * DAY;
}
time_t expire_time = deliver_time + expire_delay;
// Add to DB
std::string safe_subject = GetSubject();
CharacterDatabase.BeginTransaction();
CharacterDatabase.escape_string(safe_subject);
CharacterDatabase.PExecute("INSERT INTO mail (id,messageType,stationery,mailTemplateId,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked) "
"VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '%s', '%u', '%u', '" UI64FMTD "','" UI64FMTD "', '%u', '%u', '%u')",
mailId, sender.GetMailMessageType(), sender.GetStationery(), GetMailTemplateId(), sender.GetSenderId(), receiver.GetPlayerGuid().GetCounter(), safe_subject.c_str(), GetBodyId(), (has_items ? 1 : 0), (uint64)expire_time, (uint64)deliver_time, m_money, m_COD, checked);
for (MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Item* item = mailItemIter->second;
CharacterDatabase.PExecute("INSERT INTO mail_items (mail_id,item_guid,item_template,receiver) VALUES ('%u', '%u', '%u','%u')",
mailId, item->GetGUIDLow(), item->GetEntry(), receiver.GetPlayerGuid().GetCounter());
}
CharacterDatabase.CommitTransaction();
// For online receiver update in game mail status and data
if (masterReceiver)
{
masterReceiver->AddNewMailDeliverTime(deliver_time);
Mail *m = new Mail;
m->messageID = mailId;
m->mailTemplateId = GetMailTemplateId();
m->subject = GetSubject();
m->itemTextId = GetBodyId();
m->money = GetMoney();
m->COD = GetCOD();
for (MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Item* item = mailItemIter->second;
m->AddItem(item->GetGUIDLow(), item->GetEntry());
}
m->messageType = sender.GetMailMessageType();
m->stationery = sender.GetStationery();
m->sender = sender.GetSenderId();
m->receiverGuid = receiver.GetPlayerGuid();
m->expire_time = expire_time;
m->deliver_time = deliver_time;
m->checked = checked;
m->state = MAIL_STATE_UNCHANGED;
masterReceiver->AddMail(m); // to insert new mail to beginning of maillist
if (!m_items.empty())
{
for (MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
masterReceiver->AddMItem(mailItemIter->second);
}
}
else if (!m_items.empty())
deleteIncludedItems();
}
示例15: SendMailTo
/**
* Sends a mail.
*
* @param receiver The MailReceiver to which this mail is sent.
* @param sender The MailSender from which this mail is originated.
* @param checked The mask used to specify the mail.
* @param deliver_delay The delay after which the mail is delivered in seconds
*/
void MailDraft::SendMailTo(MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked, uint32 deliver_delay)
{
Player* pReceiver = receiver.GetPlayer(); // can be NULL
if (pReceiver)
prepareItems(pReceiver); // generate mail template items
uint32 mailId = sObjectMgr.GenerateMailID();
time_t deliver_time = time(NULL) + deliver_delay;
uint32 expire_delay;
// auction mail without any items and money (auction sale note) pending 1 hour
if (sender.GetMailMessageType() == MAIL_AUCTION && m_items.empty() && !m_money)
expire_delay = HOUR;
// mail from battlemaster (rewardmarks) should last only one day
else if (sender.GetMailMessageType() == MAIL_CREATURE && sBattleGroundMgr.GetBattleMasterBG(sender.GetSenderId()) != BATTLEGROUND_TYPE_NONE)
expire_delay = DAY;
// default case: expire time if COD 3 days, if no COD 30 days
else
expire_delay = (m_COD > 0) ? 3 * DAY : 30 * DAY;
time_t expire_time = deliver_time + expire_delay;
// Add to DB
std::string safe_subject = GetSubject();
CharacterDatabase.BeginTransaction();
CharacterDatabase.escape_string(safe_subject);
std::string safe_body = GetBody();
CharacterDatabase.BeginTransaction();
CharacterDatabase.escape_string(safe_body);
CharacterDatabase.PExecute("INSERT INTO mail (id,messageType,stationery,mailTemplateId,sender,receiver,subject,body,has_items,expire_time,deliver_time,money,cod,checked) "
"VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '%s', '%s', '%u', '" UI64FMTD "','" UI64FMTD "', '%u', '%u', '%d')",
mailId, sender.GetMailMessageType(), sender.GetStationery(), GetMailTemplateId(), sender.GetSenderId(), receiver.GetPlayerGUIDLow(), safe_subject.c_str(), safe_body.c_str(), (m_items.empty() ? 0 : 1), (uint64)expire_time, (uint64)deliver_time, m_money, m_COD, checked);
for(MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Item* item = mailItemIter->second;
CharacterDatabase.PExecute("INSERT INTO mail_items (mail_id,item_guid,item_template,receiver) VALUES ('%u', '%u', '%u','%u')", mailId, item->GetGUIDLow(), item->GetEntry(), receiver.GetPlayerGUIDLow());
}
CharacterDatabase.CommitTransaction();
// For online receiver update in game mail status and data
if (pReceiver)
{
pReceiver->AddNewMailDeliverTime(deliver_time);
Mail *m = new Mail;
m->messageID = mailId;
m->mailTemplateId = GetMailTemplateId();
m->subject = GetSubject();
m->body = GetBody();
m->money = GetMoney();
m->COD = GetCOD();
for(MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Item* item = mailItemIter->second;
m->AddItem(item->GetGUIDLow(), item->GetEntry());
}
m->messageType = sender.GetMailMessageType();
m->stationery = sender.GetStationery();
m->sender = sender.GetSenderId();
m->receiver = receiver.GetPlayerGUIDLow();
m->expire_time = expire_time;
m->deliver_time = deliver_time;
m->checked = checked;
m->state = MAIL_STATE_UNCHANGED;
pReceiver->AddMail(m); // to insert new mail to beginning of maillist
if (!m_items.empty())
{
for(MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
pReceiver->AddMItem(mailItemIter->second);
}
}
else if (!m_items.empty())
deleteIncludedItems();
}