Exemple #1
0
Item* Item::CreateItem(uint32 item, uint32 count, Player const* player, uint32 randomPropertyId)
{
    if (count < 1)
        return nullptr;                                        // 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))
        {
            pItem->SetCount(count);
            if (uint32 randId = randomPropertyId ? randomPropertyId : Item::GenerateItemRandomPropertyId(item))
                pItem->SetItemRandomProperties(randId);

            return pItem;
        }
        else
            delete pItem;
    }
    return nullptr;
}
Exemple #2
0
Item* Item::CreateItem(uint32 item, uint32 count, Player const* player )
{
    if (count < 1 )
        return NULL;                                        //don't create item at zero count

    ItemPrototype const *pProto = objmgr.GetItemPrototype(item);
    if (pProto )
    {
        if (count > pProto->Stackable )
            count = pProto->Stackable;

        assert(count !=0 && "pProto->Stackable==0 but checked at loading already");

        Item *pItem = NewItemOrBag(pProto);
        if (pItem->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM), item, player) )
        {
            pItem->SetCount(count);
            return pItem;
        }
        else
            delete pItem;
    }
    else
        assert(false);
    return NULL;
}
Exemple #3
0
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;
}
Exemple #4
0
Item* Item::CreateItem(uint32 item, uint32 count, Player const* player)
{
    if (count < 1)
        return NULL;                                        //don't create item at zero count

    ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(item);
    if (pProto)
    {
        if (count > pProto->GetMaxStackSize())
            count = pProto->GetMaxStackSize();

        ASSERT(count !=0 && "pProto->Stackable == 0 but checked at loading already");

        Item* pItem = NewItemOrBag(pProto);
        if (pItem->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_ITEM), item, player))
        {
            pItem->SetCount(count);
            return pItem;
        }
        else
            delete pItem;
    }
    else
        ASSERT(false);
    return NULL;
}
Exemple #5
0
Item* Item::CreateItem(uint32 item, uint32 count, Player const* player)
{
    if (count < 1)
        return NULL;                                        //don't create item at zero count

    ItemPrototype const *pProto = objmgr.GetItemPrototype(item);
    if (pProto)
    {
        if (count > pProto->GetMaxStackSize())
            count = pProto->GetMaxStackSize();

        if (pProto->Quality > 2 && pProto->Flags != 2048 && (pProto->Class == ITEM_CLASS_WEAPON || pProto->Class == ITEM_CLASS_ARMOR) && player)
        {
            /* WoWArmory Feed Log */
            std::ostringstream ss;
            sLog.outDetail("WoWArmory: write feed log (guid: %u, type: 2, data: %u", player->GetGUIDLow(), item);
            ss << "REPLACE INTO character_feed_log (guid, type, data, counter) VALUES (" << player->GetGUIDLow() << ", 2, " << item << ", 1)";
            CharacterDatabase.PExecute( ss.str().c_str() );
        }
		assert(count !=0 && "pProto->Stackable == 0 but checked at loading already");

        Item *pItem = NewItemOrBag(pProto);
        if (pItem->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM), item, player))
        {
            pItem->SetCount(count);
            return pItem;
        }
        else
            delete pItem;
    }
    else
        assert(false);
    return NULL;
}
Exemple #6
0
Item* Item::CreateItem(uint32 itemEntry, uint32 count, Player const* player)
{
    if (count < 1)
        return NULL;                                        //don't create item at zero count

    ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemEntry);
    if (proto)
    {
        if (count > proto->GetMaxStackSize())
            count = proto->GetMaxStackSize();

        ASSERT(count != 0 && "pProto->Stackable == 0 but checked at loading already");

        Item* item = NewItemOrBag(proto);
        if (item->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), itemEntry, player))
        {
            item->SetCount(count);
            return item;
        }
        else
            delete item;
    }
    else
        ABORT();
    return NULL;
}
//used when player copies mail body to his inventory
void WorldSession::HandleMailCreateTextItem(WorldPackets::Mail::MailCreateTextItem& packet)
{
    if (!CanOpenMailBox(packet.Mailbox))
        return;

    Player* player = _player;

    Mail* m = player->GetMail(packet.MailID);
    if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(nullptr) || (m->checked & MAIL_CHECK_MASK_COPIED))
    {
        player->SendMailResult(packet.MailID, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
        return;
    }

    Item* bodyItem = new Item;                              // This is not bag and then can be used new Item.
    if (!bodyItem->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), MAIL_BODY_ITEM_TEMPLATE, player))
    {
        delete bodyItem;
        return;
    }

    // in mail template case we need create new item text
    if (m->mailTemplateId)
    {
        MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId);
        if (!mailTemplateEntry)
        {
            player->SendMailResult(packet.MailID, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
            return;
        }

        bodyItem->SetText(mailTemplateEntry->Body->Str[GetSessionDbcLocale()]);
    }
    else
        bodyItem->SetText(m->body);

    if (m->messageType == MAIL_NORMAL)
        bodyItem->SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid::Create<HighGuid::Player>(m->sender));

    bodyItem->SetFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_READABLE);

    ItemPosCountVec dest;
    uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false);
    if (msg == EQUIP_ERR_OK)
    {
        m->checked = m->checked | MAIL_CHECK_MASK_COPIED;
        m->state = MAIL_STATE_CHANGED;
        player->m_mailsUpdated = true;

        player->StoreItem(dest, bodyItem, true);
        player->SendMailResult(packet.MailID, MAIL_MADE_PERMANENT, MAIL_OK);
    }
    else
    {
        player->SendMailResult(packet.MailID, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
        delete bodyItem;
    }
}
Exemple #8
0
/**
 * Handles the packet sent by the client when he copies the body a mail to his inventory.
 *
 * When a player copies the body of a mail to his inventory this method is called. It will create
 * a new item with the text of the mail and store it in the players inventory (if possible).
 *
 */
void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data)
{
    ObjectGuid mailboxGuid;
    uint32 mailId;

    recv_data >> mailboxGuid;
    recv_data >> mailId;
    recv_data.read_skip<uint32>();                          // mailTemplateId, non need, Mail store own 100% correct value anyway

    if (!CheckMailBox(mailboxGuid))
        return;

    ForwardPacketToMaster();
    MasterPlayer* pl = GetMasterPlayer();
    ASSERT(pl);
    Player* loadedPlayer = _player;

    Mail* m = pl->GetMail(mailId);
    if (!m || (!m->itemTextId && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL) || m->checked & MAIL_CHECK_MASK_COPIED)
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
        return;
    }

    uint32 itemTextId = m->itemTextId;

    Item *bodyItem = new Item;                              // This is not bag and then can be used new Item.
    if (!bodyItem->Create(sObjectMgr.GenerateItemLowGuid(), MAIL_BODY_ITEM_TEMPLATE, pl->GetObjectGuid()))
    {
        delete bodyItem;
        return;
    }

    bodyItem->SetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID, itemTextId);
    bodyItem->SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid(HIGHGUID_PLAYER, m->sender));

    DETAIL_LOG("HandleMailCreateTextItem mailid=%u", mailId);

    ItemPosCountVec dest;
    uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false);
    if (msg == EQUIP_ERR_OK)
    {
        m->checked = m->checked | MAIL_CHECK_MASK_COPIED;
        m->state = MAIL_STATE_CHANGED;
        pl->MarkMailsUpdated();

        loadedPlayer->StoreItem(dest, bodyItem, true);
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK);
    }
    else
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
        delete bodyItem;
    }
}
Exemple #9
0
/**
 * Handles the packet sent by the client when he copies the body a mail to his inventory.
 *
 * When a player copies the body of a mail to his inventory this method is called. It will create
 * a new item with the text of the mail and store it in the players inventory (if possible).
 *
 */
void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data )
{
    uint64 mailbox;
    uint32 mailId;

    recv_data >> mailbox;
    recv_data >> mailId;
    recv_data.read_skip<uint32>();                          // mailTemplateId, non need, Mail store own 100% correct value anyway

    if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX))
        return;

    Player *pl = _player;

    Mail* m = pl->GetMail(mailId);
    if (!m || (!m->itemTextId && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
        return;
    }

    uint32 itemTextId = m->itemTextId;

    Item *bodyItem = new Item;                              // This is not bag and then can be used new Item.
    if(!bodyItem->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_ITEM), MAIL_BODY_ITEM_TEMPLATE, pl))
    {
        delete bodyItem;
        return;
    }

    bodyItem->SetUInt32Value( ITEM_FIELD_ITEM_TEXT_ID, itemTextId );
    bodyItem->SetUInt32Value( ITEM_FIELD_CREATOR, m->sender);

    sLog.outDetail("HandleMailCreateTextItem mailid=%u",mailId);

    ItemPosCountVec dest;
    uint8 msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, dest, bodyItem, false );
    if( msg == EQUIP_ERR_OK )
    {
        m->itemTextId = 0;
        m->state = MAIL_STATE_CHANGED;
        pl->m_mailsUpdated = true;

        pl->StoreItem(dest, bodyItem, true);
        //bodyItem->SetState(ITEM_NEW, pl); is set automatically
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK);
    }
    else
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
        delete bodyItem;
    }
}
Exemple #10
0
bool ChatHandler::HandleAddItemCommand(const char* args)
{
    
    WorldPacket data;

    if (!*args)  
        return false;

    char* citemid = strtok((char*)args, " ");
    char* cPos = strtok(NULL, " ");
    char* cVal = strtok(NULL, " ");

    uint32 itemid=atol(citemid);

    Player*    pl = m_session->GetPlayer();
    bool   slotfree=false;
    uint8  i,slot;
    uint32 Pos=5,Val=1;
    

    for(i =    INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END;    i++)
    {
        if (pl->GetItemBySlot(i) == NULL)
        {
            slot = i;
            slotfree=true;
            break;
        }
    }
    if (slotfree)
    {
        Item *item = new Item();    
        item->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM),    itemid, pl);

		if (!item)
			return true;
        
        
        if ((cPos) && (cVal)){
            Pos=(uint32)atol(cPos);
            Val=(uint32)atol(cVal);
            
            item->SetUInt32Value( Pos, Val );
        }

        pl->AddItemToSlot(    slot, item );
    }else{
        FillSystemMessageData(&data, m_session, "Bag is full.");
        m_session->SendPacket(&data);
    }

    return true;
}
Exemple #11
0
void WorldSession::HandleMailCreateTextItem(WorldPacket	& recv_data	)
{
	uint32 unk1,unk2,mailid;

	recv_data >> unk1 >> unk2 >> mailid;

	sLog.outString("Mail:: CreateTextItem unk1=%d,unk2=%d,mailid=%d",unk1,unk2,mailid);

	uint32 sbit2=5;
	bool   slotfree=false;
	WorldPacket	Data;
	uint8 i,slot;

	Player*	pl = GetPlayer();
	//Item *item = new Item();

	for(i =	INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END;	++i)
	{
		if (GetPlayer()->GetItemBySlot(i) == NULL)
		{
			slot = i;
			slotfree=true;
			break;
		}
	}
	if (slotfree)
	{
		Item *item = new Item();
		//item->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM), itemid, GetPlayer());
		
		// fix me
		// you need	to create a	litter item	to database	and	add	this item pagetext id and pagetext
		item->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM),	889, GetPlayer());
		GetPlayer()->AddItemToSlot(	slot, item );

		Data.Initialize(SMSG_SEND_MAIL_RESULT);
		Data <<	uint32(mailid);
		Data <<	uint32(sbit2);
		Data <<	uint32(0);
		SendPacket(&Data);	  //delete mail	copy
	}
	else
	{ 
		Data.Initialize(SMSG_SEND_MAIL_RESULT);
		Data <<	uint32(mailid);
		Data <<	uint32(0);
		Data <<	uint32(1);
		SendPacket(&Data);	 //error, bag is full
	}
    
}
Exemple #12
0
void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data )
{
    uint8 slot = 0;
    uint32 itemid = 0;
    uint8 lootSlot = 0;
    WorldPacket data;
#ifndef ENABLE_GRID_SYSTEM
    Creature* pCreature = objmgr.GetObject<Creature>(GetPlayer()->GetLootGUID());
#else
    Creature* pCreature = ObjectAccessor::Instance().GetCreature(*_player, _player->GetLootGUID());
#endif
    if (!pCreature)
        return;

    recv_data >> lootSlot;
    lootSlot -=1;                                 //to prevent Slot 0 from been used "Still Rolling for item fix"


    slot = GetPlayer()->FindFreeItemSlot(INVTYPE_SLOT_ITEM);

    if (slot == INVENTORY_SLOT_ITEM_END)
    {
        // Our User doesn't have a free Slot in there bag
        data.Initialize( SMSG_INVENTORY_CHANGE_FAILURE );
        data << uint8(48);                        // Inventory Full
        data << uint64(0);
        data << uint64(0);
        data << uint8(0);
        SendPacket( &data );
        return;
    }

    if (pCreature->getItemAmount(lootSlot) == 0)  //Can't sell the item for cash
        return;

    itemid = pCreature->getItemId(lootSlot);
    pCreature->setItemAmount(lootSlot, 0);

    Item *item = new Item();
    ASSERT(item);

    item->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM), itemid, GetPlayer());
    GetPlayer()->AddItemToSlot(slot, item);

    data.Initialize( SMSG_LOOT_REMOVED );
    data << uint8(lootSlot+1);
    SendPacket( &data );

}
Exemple #13
0
void ItemHandler::createItemUpdate (NetworkPacket *data, GameClient *pClient, int invcount)
{
    UpdateMask invUpdateMask;

    invUpdateMask.SetLength (64);
    Item *tempitem = new Item;

    invUpdateMask.SetBit (OBJECT_FIELD_GUID);
    invUpdateMask.SetBit (OBJECT_FIELD_GUID+1);
    invUpdateMask.SetBit (OBJECT_FIELD_TYPE);
    invUpdateMask.SetBit (OBJECT_FIELD_ENTRY);
    invUpdateMask.SetBit (OBJECT_FIELD_SCALE_X);
    invUpdateMask.SetBit (OBJECT_FIELD_PADDING);
    invUpdateMask.SetBit (ITEM_FIELD_OWNER);
    invUpdateMask.SetBit (ITEM_FIELD_CONTAINED);
    invUpdateMask.SetBit (ITEM_FIELD_OWNER +1);
    invUpdateMask.SetBit (ITEM_FIELD_CONTAINED +1);
    invUpdateMask.SetBit (ITEM_FIELD_STACK_COUNT);
    tempitem->Create(pClient->getCurrentChar()->getGuidBySlot(invcount),pClient->getCurrentChar()->getItemIdBySlot(invcount));
    tempitem->setUpdateValue (OBJECT_FIELD_GUID,
        pClient->getCurrentChar()->getGuidBySlot(invcount),
        invUpdateMask.data);
    tempitem->setUpdateValue (OBJECT_FIELD_GUID+1, 0x00000040,
        invUpdateMask.data);
    tempitem->setUpdateValue (OBJECT_FIELD_TYPE, 0x00000003,
        invUpdateMask.data);
    tempitem->setUpdateValue (OBJECT_FIELD_ENTRY,
        pClient->getCurrentChar()->getItemIdBySlot(invcount),
        invUpdateMask.data);
    tempitem->setUpdateFloatValue (OBJECT_FIELD_SCALE_X, 1.0f,
        invUpdateMask.data);
    tempitem->setUpdateValue (OBJECT_FIELD_PADDING, 0xeeeeeeee,
        invUpdateMask.data);
    tempitem->setUpdateValue (ITEM_FIELD_OWNER,
        pClient->getCurrentChar()->GetGUID().sno,
        invUpdateMask.data);
    tempitem->setUpdateValue (ITEM_FIELD_CONTAINED,
        pClient->getCurrentChar()->GetGUID().sno,
        invUpdateMask.data);
    tempitem->setUpdateValue (ITEM_FIELD_OWNER + 1, 0,
        invUpdateMask.data);
    tempitem->setUpdateValue (ITEM_FIELD_CONTAINED + 1, 0,
        invUpdateMask.data);
    tempitem->setUpdateValue (ITEM_FIELD_STACK_COUNT, 1,
        invUpdateMask.data);

    tempitem->CreateObject(&invUpdateMask, data, 0);
}
Exemple #14
0
//used when player copies mail body to his inventory
void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data )
{
    CHECK_PACKET_SIZE(recv_data,8+4);

    uint64 mailbox;
    uint32 mailId;

    recv_data >> mailbox >> mailId;

    Player *pl = _player;

    Mail* m = pl->GetMail(mailId);
    if(!m || !m->itemTextId || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
        return;
    }

    Item *bodyItem = new Item;                              // This is not bag and then can be used new Item.
    if(!bodyItem->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM), MAIL_BODY_ITEM_TEMPLATE, pl))
    {
        delete bodyItem;
        return;
    }

    bodyItem->SetUInt32Value( ITEM_FIELD_ITEM_TEXT_ID , m->itemTextId );
    bodyItem->SetUInt32Value( ITEM_FIELD_CREATOR, m->sender);

    sLog.outDetail("HandleMailCreateTextItem mailid=%u",mailId);

    ItemPosCountVec dest;
    uint8 msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, dest, bodyItem, false );
    if( msg == EQUIP_ERR_OK )
    {
        m->itemTextId = 0;
        m->state = MAIL_STATE_CHANGED;
        pl->m_mailsUpdated = true;

        pl->StoreItem(dest, bodyItem, true);
        //bodyItem->SetState(ITEM_NEW, pl); is set automatically
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, 0);
    }
    else
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_BAG_FULL, msg);
        delete bodyItem;
    }
}
		bool CreateItemAndMailToPlayer(Player *pPlayer, uint32 itemId)
		{
			Item *pItem = new Item();
			if(pItem->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_ITEM), itemId, pPlayer) == false)
				return false;

			MailSender toSend(MAIL_NORMAL, pPlayer->GetGUIDLow(), MAIL_STATIONERY_GM);
			SQLTransaction trans = CharacterDatabase.BeginTransaction();
			pItem->SaveToDB(trans);

			MailDraft mailDraft(REQUESTER_DEFAULT_MAIL_SUBJECT, REQUESTER_DEFAULT_MAIL_BODY);
			mailDraft.AddItem(pItem);
			mailDraft.SendMailTo(trans, MailReceiver(pPlayer), toSend);
			CharacterDatabase.CommitTransaction(trans);
			return true;
		}
Exemple #16
0
Item * ObjectMgr::CreateItem(uint32 entry, Player * owner, ItemPrototype * proto)
{
	if(proto == 0) return 0;

	if(proto->InventoryType == INVTYPE_BAG)
	{
		Container * pContainer = new Container(HIGHGUID_TYPE_CONTAINER,GenerateLowGuid(HIGHGUID_TYPE_CONTAINER));
		pContainer->Create(entry, owner, proto);
		pContainer->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);
		return pContainer;
	}
	else
	{
		Item * pItem = ItemPool.PooledNew();
		pItem->Init( HIGHGUID_TYPE_ITEM, GenerateLowGuid(HIGHGUID_TYPE_ITEM) );
		pItem->Create(entry, owner, proto);
		pItem->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);
		return pItem;
	}
}
Exemple #17
0
void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data)
{
    CHECK_PACKET_SIZE(recv_data,8+4);

    ObjectGuid mailboxGuid;
    uint32 mailId;

    recv_data >> mailboxGuid;
    recv_data >> mailId;
    recv_data.read_skip<uint32>();                          // mailTemplateId, non need, Mail store own 100% correct value anyway

    if (!CheckMailBox(mailboxGuid))
        return;

    Player *pl = _player;

    Mail* m = pl->GetMail(mailId);
    if (!m || (!m->itemTextId && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
        return;
    }

    uint32 itemTextId = m->itemTextId;

    // in mail template case we need create new item text
    if(!itemTextId)
    {
        MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId);
        if (!mailTemplateEntry)
        {
            pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
            return;
        }

        itemTextId = sObjectMgr.CreateItemText(mailTemplateEntry->content[GetSessionDbcLocale()]);
    }

    Item *bodyItem = new Item;                              // This is not bag and then can be used new Item.
    if (!bodyItem->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_ITEM), MAIL_BODY_ITEM_TEMPLATE, pl))
    {
        delete bodyItem;
        return;
    }

    bodyItem->SetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID , itemTextId);
    bodyItem->SetUInt32Value(ITEM_FIELD_CREATOR, m->sender);

    sLog.outDetail("HandleMailCreateTextItem mailid=%u",mailId);

    ItemPosCountVec dest;
    uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false);
    if (msg == EQUIP_ERR_OK)
    {
        m->checked = m->checked | MAIL_CHECK_MASK_COPIED;
        m->state = MAIL_STATE_CHANGED;
        pl->m_mailsUpdated = true;

        pl->StoreItem(dest, bodyItem, true);
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK);
    }
    else
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
        delete bodyItem;
    }
}
//used when player copies mail body to his inventory
void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data)
{
    uint64 mailbox;
    uint32 mailId;

    recv_data >> mailbox;
    recv_data >> mailId;

    if (!GetPlayer()->GetGameObjectIfCanInteractWith(mailbox, GAMEOBJECT_TYPE_MAILBOX))
        return;

    Player *pl = _player;

    Mail* m = pl->GetMail(mailId);
    if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
        return;
    }

    Item *bodyItem = new Item;                              // This is not bag and then can be used new Item.
    if (!bodyItem->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_ITEM), MAIL_BODY_ITEM_TEMPLATE, pl))
    {
        delete bodyItem;
        return;
    }

    // in mail template case we need create new item text
    if (m->mailTemplateId)
    {
        MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId);
        if (!mailTemplateEntry)
        {
            pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
            return;
        }

        bodyItem->SetText(mailTemplateEntry->content);
    }
    else
        bodyItem->SetText(m->body);

    bodyItem->SetUInt32Value(ITEM_FIELD_CREATOR, m->sender);
    bodyItem->SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_MAIL_TEXT_MASK);

    sLog->outDetail("HandleMailCreateTextItem mailid=%u", mailId);

    ItemPosCountVec dest;
    uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false);
    if (msg == EQUIP_ERR_OK)
    {
        m->checked = m->checked | MAIL_CHECK_MASK_COPIED;
        m->state = MAIL_STATE_CHANGED;
        pl->m_mailsUpdated = true;

        pl->StoreItem(dest, bodyItem, true);
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK);
    }
    else
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
        delete bodyItem;
    }
}
Exemple #19
0
void
Spell::Effect_Create_Item(uint32 i)
{
	// NEEDS TO BE REDONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	Player* pUnit = (Player*)m_caster;
	uint8 slot = 0;
	for(uint8 i=INVENTORY_SLOT_ITEM_START; i<INVENTORY_SLOT_ITEM_END; ++i){// check if there is a free slot for the item to conjure
		if(pUnit->GetItemBySlot(i) == 0)
				slot = i;
		if(slot == 0){
			SendCastResult(CAST_FAIL_MUST_HAVE_XXXX_IN_MAINHAND); // ZeHaM: Wtf has this got to do with adding an item ?? o_O
			return;
		}

		Item* pItem;
		uint8 curSlot;
		for(uint32 i=0;i<8; ++i){
			for(uint32 j=0; j<m_spellInfo->ReagentCount[i]; ++j){
				if(j>10)// little protection to prevent loops in here
					break;
				if(m_spellInfo->Reagent[i] == 0)
					continue;
				curSlot = (uint8)pUnit->GetSlotByItemID(m_spellInfo->Reagent[i]);
				if(curSlot == 0)
					continue;
				pItem = new Item;
				pItem = pUnit->GetItemBySlot(curSlot);
				
				// if there are more then 1 in stack then just reduce it by 1
				if(pItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT) > 1){ 
					pItem->SetUInt32Value(ITEM_FIELD_STACK_COUNT,pItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT)-1);
				}else{// otherwise delete it from player and db
					pUnit->RemoveItemFromSlot(curSlot);
					pItem->DeleteFromDB();
				}
				pItem = NULL;
				curSlot = 0;
			}
		}

		pItem = NULL;
		Item* newItem;
		for(i=0; i<2; ++i){// now create the Items
			if(m_spellInfo->EffectItemType[i] == 0)
				continue;

			slot = 0;
			// check if there is a free slot for the item to conjure
			for (uint8 i = INVENTORY_SLOT_ITEM_START; i<INVENTORY_SLOT_ITEM_END; ++i){
				if(pUnit->GetItemBySlot(i) == 0)
					slot = i;
			}
			if(slot == 0){
				SendCastResult(0x18);
				return;
			}
			newItem = new Item;
			newItem->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM),m_spellInfo->EffectItemType[i],pUnit);
			pUnit->AddItemToSlot(slot,newItem);
			newItem = NULL;
		}
	}
}
Exemple #20
0
/**
 * Handles the packet sent by the client when he copies the body a mail to his inventory.
 *
 * When a player copies the body of a mail to his inventory this method is called. It will create
 * a new item with the text of the mail and store it in the players inventory (if possible).
 *
 */
void WorldSession::HandleMailCreateTextItem(WorldPacket& recv_data)
{
    ObjectGuid mailboxGuid;
    uint32 mailId;

    recv_data >> mailboxGuid;
    recv_data >> mailId;

    if (!CheckMailBox(mailboxGuid))
        return;

    Player* pl = _player;

    Mail* m = pl->GetMail(mailId);
    if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
        return;
    }

    Item* bodyItem = new Item;                              // This is not bag and then can be used new Item.
    if (!bodyItem->Create(sObjectMgr.GenerateItemLowGuid(), MAIL_BODY_ITEM_TEMPLATE, pl))
    {
        delete bodyItem;
        return;
    }

    // in mail template case we need create new item text
    if (m->mailTemplateId)
    {
        MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId);
        if (!mailTemplateEntry)
        {
            pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
            return;
        }

        bodyItem->SetText(mailTemplateEntry->content[GetSessionDbcLocale()]);
    }
    else
        bodyItem->SetText(m->body);

    bodyItem->SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid(HIGHGUID_PLAYER, m->sender));
    bodyItem->SetFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_READABLE | ITEM_DYNFLAG_UNK15 | ITEM_DYNFLAG_UNK16);


    DETAIL_LOG("HandleMailCreateTextItem mailid=%u", mailId);

    ItemPosCountVec dest;
    InventoryResult msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false);
    if (msg == EQUIP_ERR_OK)
    {
        m->checked = m->checked | MAIL_CHECK_MASK_COPIED;
        m->state = MAIL_STATE_CHANGED;
        pl->m_mailsUpdated = true;

        pl->StoreItem(dest, bodyItem, true);
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK);
    }
    else
    {
        pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
        delete bodyItem;
    }
}
Exemple #21
0
Item* Item::CreateItem(uint64 ItemID, Player const* Owner)
{
    Item* pNewItem = new Item;
    return pNewItem->Create(ItemID, Owner) ? pNewItem : nullptr;
}
Exemple #22
0
void WorldSession::_HandleUpdateObjectOpcode(WorldPacket& recvPacket)
{
    uint8 utype;
    //uint8 hasTransport;
    uint32 usize, ublocks, readblocks=0;
    uint64 uguid;
    recvPacket >> ublocks; // >> hasTransport;
    //logdev("UpdateObject: blocks = %u, hasTransport = %u", ublocks, hasTransport);
    logdev("UpdateObject: blocks = %u", ublocks);
    while((recvPacket.rpos() < recvPacket.size())&& (readblocks < ublocks))
    {
        recvPacket >> utype;
        switch(utype)
        {
        case UPDATETYPE_VALUES:
        {
            uguid = recvPacket.GetPackedGuid();
            _ValuesUpdate(uguid,recvPacket);
        }
        break;

        case UPDATETYPE_MOVEMENT:
        {
            recvPacket >> uguid; // the guid is NOT packed here!
            uint8 tyid;
            Object *obj = objmgr.GetObj(uguid, true); // here we update also depleted objects, its just safer
            if(obj)
                tyid = obj->GetTypeId();
            else // sometimes objects get deleted BEFORE a last update packet arrives, this must be handled also
            {
                tyid = GetTypeIdByGuid(uguid);
                logerror("Got UpdateObject_Movement for unknown object "I64FMT". Using typeid %u",uguid,(uint32)tyid);
            }

            if(obj)
                this->_MovementUpdate(tyid,uguid,recvPacket);
        }
        break;

        case UPDATETYPE_CREATE_OBJECT2: // will be sent when our very own character is created
        case UPDATETYPE_CREATE_OBJECT: // will be sent on any other object creation
        {
            uguid = recvPacket.GetPackedGuid();
            uint8 objtypeid;
            recvPacket >> objtypeid;
            logdebug("Create Object type %u with guid "I64FMT,objtypeid,uguid);
            // dont create objects if already present in memory.
            // recreate every object except ourself!
            if(objmgr.GetObj(uguid))
            {
                if(uguid != GetGuid())
                {
                    logdev("- already exists, deleting old, creating new object");
                    objmgr.Remove(uguid, false);
                    // do not call script here, since the object does not really get deleted
                }
                else
                {
                    logdev("- already exists, but not deleted (has our current GUID)");
                }
            }

            // only if the obj didnt exist or was just deleted above, create it....
            if(!objmgr.GetObj(uguid))
            {
                switch(objtypeid)
                {
                case TYPEID_OBJECT: // no data to read
                {
                    logerror("Recieved wrong UPDATETYPE_CREATE_OBJECT to create Object base type!");
                    logerror("%s",toHexDump((uint8*)recvPacket.contents(),recvPacket.size(),true).c_str());
                }
                case TYPEID_ITEM:
                {
                    Item *item = new Item();
                    item->Create(uguid);
                    objmgr.Add(item);
                    break;
                }
                case TYPEID_CONTAINER:
                {
                    Bag *bag = new Bag();
                    bag->Create(uguid);
                    objmgr.Add(bag);
                    break;
                }
                case TYPEID_UNIT:
                {
                    Unit *unit = new Unit();
                    unit->Create(uguid);
                    objmgr.Add(unit);
                    break;
                }
                case TYPEID_PLAYER:
                {
                    if(GetGuid() == uguid) // objmgr.Add() would cause quite some trouble if we added ourself again
                        break;
                    Player *player = new Player();
                    player->Create(uguid);
                    objmgr.Add(player);
                    break;
                }
                case TYPEID_GAMEOBJECT:
                {
                    GameObject *go = new GameObject();
                    go->Create(uguid);
                    objmgr.Add(go);
                    break;
                }
                case TYPEID_CORPSE:
                {
                    Corpse *corpse = new Corpse();
                    corpse->Create(uguid);
                    objmgr.Add(corpse);
                    break;
                }
                case TYPEID_DYNAMICOBJECT:
                {
                    DynamicObject *dobj = new DynamicObject();
                    dobj->Create(uguid);
                    objmgr.Add(dobj);
                    break;
                }
                }
            }
            else
            {
                logdebug("Obj "I64FMT" not created, already exists",uguid);
            }
            // ...regardless if it was freshly created or already present, update its values and stuff now...
            this->_MovementUpdate(objtypeid, uguid, recvPacket);
            this->_ValuesUpdate(uguid, recvPacket);

            // ...and ask the server for eventually missing data.
            _QueryObjectInfo(uguid);


            // call script "_OnObjectCreate"
            if(GetInstance()->GetScripts()->ScriptExists("_onobjectcreate"))
            {
                CmdSet Set;
                Set.defaultarg = toString(uguid);
                Set.arg[0] = toString(objtypeid);
                GetInstance()->GetScripts()->RunScript("_onobjectcreate", &Set);
            }

            // if our own character got finally created, we have successfully entered the world,
            // and should have gotten all info about our char already.
        }
        break;

        case UPDATETYPE_OUT_OF_RANGE_OBJECTS:
        {
            recvPacket >> usize;
            for(uint16 i=0; i<usize; i++)
            {
                uguid = recvPacket.GetPackedGuid(); // not 100% sure if this is correct
                logdebug("GUID "I64FMT" out of range",uguid);

                // call script just before object removal
                if(GetInstance()->GetScripts()->ScriptExists("_onobjectdelete"))
                {
                    Object *del_obj = objmgr.GetObj(uguid);
                    CmdSet Set;
                    Set.defaultarg = toString(uguid);
                    Set.arg[0] = del_obj ? toString(del_obj->GetTypeId()) : "";
                    Set.arg[1] = "true"; // out of range = true
                    GetInstance()->GetScripts()->RunScript("_onobjectdelete", &Set);
                }

                objmgr.Remove(uguid, false);
            }
        }
        break;

        default:
        {
            logerror("UPDATE_OBJECT: Got unk updatetype 0x%X",utype);
            logerror("UPDATE_OBJECT: Read %u / %u bytes, skipped rest",recvPacket.rpos(),recvPacket.size());
            logerror("%s",toHexDump((uint8*)recvPacket.contents(),recvPacket.size(),true).c_str());
            char buf[100];
            sprintf(buf,"Got unk updatetype=0x%X, read %u / %u bytes",utype,recvPacket.rpos(),recvPacket.size());

            if(GetInstance()->GetConf()->dumpPackets)
            {
                char buf[100];
                sprintf(buf,"Got unk updatetype=0x%X, read %u / %u bytes",utype,recvPacket.rpos(),recvPacket.size());
                DumpPacket(recvPacket, recvPacket.rpos(),buf);
            }

            return;
        }
        } // switch
        readblocks++;
    } // while

} // func