Exemplo n.º 1
0
bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid)
{
    if(!Item::LoadFromDB(guid, owner_guid))
        return false;

    // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`)
    for (uint32 i = 0; i < GetProto()->ContainerSlots; i++)
    {
        SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0);
        if (m_bagslot[i])
        {
            delete m_bagslot[i];
            m_bagslot[i] = NULL;
        }
    }

    if(!IsInBag())                                          // equiped bag
    {
        QueryResult *result = sDatabase.PQuery("SELECT `slot`,`item`,`item_template` FROM `character_inventory` WHERE `guid` = '%u' AND `bag` = '%u'", GUID_LOPART(GetOwnerGUID()), GetGUIDLow());

        if (result)
        {
            do
            {
                Field *fields = result->Fetch();
                uint8  slot      = fields[0].GetUInt8();
                uint32 item_guid = fields[1].GetUInt32();
                uint32 item_id   = fields[2].GetUInt32();

                ItemPrototype const *proto = objmgr.GetItemPrototype(item_id);

                if(!proto)
                {
                    sLog.outError( "Bag::LoadFromDB: Player %d have unknown item (id: #%u) in bag #%u, skipped.", GUID_LOPART(GetOwnerGUID()), item_id, GetSlot());
                    continue;
                }

                Item *item = NewItemOrBag(proto);
                item->SetSlot(NULL_SLOT);
                if(!item->LoadFromDB(item_guid, owner_guid))
                {
                    delete item;
                    continue;
                }
                StoreItem( slot, item, true );
                item->SetState(ITEM_UNCHANGED);
            } while (result->NextRow());

            delete result;
        }
    }
    return true;
}
Exemplo n.º 2
0
CUICellItem* CUIBagWnd::GetItemBySectoin(const shared_str& sectionName, bool bCreateOnFail){

	u32 sz			= m_allItems.size();

	for (u32 i = 0; i < sz; i++)
	{
		CInventoryItem* iitem		= (CInventoryItem*)m_allItems[i]->m_pData;

		if( iitem->object().cNameSect() == sectionName )
		{
			if (IsInBag(m_allItems[i]))
                return m_allItems[i];
		}
	}
	return NULL;
}
Exemplo n.º 3
0
CUICellItem* CUIBagWnd::GetItemBySectoin(const u8 grpNum, u8 uIndexInSlot)
{
	u32 sz				= m_allItems.size();
	CUICellItem*		item;

	for (u32 i = 0; i < sz; i++)
	{
		item			= m_allItems[i];

		if (m_info[item->m_index].pos_in_section == uIndexInSlot &&	m_info[item->m_index].section == grpNum	)
		{
			if (IsInBag(item))
                return item;
		}
	}

	return NULL;
}
Exemplo n.º 4
0
bool CUIBagWnd::CanBuy(CUICellItem* itm)
{
	VERIFY					(itm);
	if (!IsInBag(itm))
		return false;

	CInventoryItem* iitm	= (CInventoryItem*)itm->m_pData;

	if (m_bIgnoreMoney)
	{
		if (m_bIgnoreRank)
            return true;
		else if (g_mp_restrictions.IsAvailable(iitm->object().cNameSect()))
			return true;
	}
	else if (m_bIgnoreRank)
	{
		if (m_info[itm->m_index].price < m_money)
			return true;
	}

	return m_info[itm->m_index].active && (!m_info[itm->m_index].bought);
}
Exemplo n.º 5
0
void CUIBagWnd::UpdateBuyPossibility()
{
	u32 sz		= m_allItems.size();

	for (u32 i = 0; i<sz; i++)
	{
		if (IsInBag(m_allItems[i]))
		{
			if (m_info[m_allItems[i]->m_index].bought)
			{
				m_allItems[i]->SetColor(0x00ffffff);
			}
			else if (UpdateRank(m_allItems[i]))		// update price if there no restriction for rank
			{
				if (UpdatePrice(m_allItems[i], i))
				{
					if (m_info[i].external)
                        SET_EXTERNAL_COLOR(m_allItems[i]);
				}
			}
		}
	}
}
Exemplo n.º 6
0
bool Item::IsEquipped() const
{
    return !IsInBag() && m_slot < EQUIPMENT_SLOT_END;
}
Exemplo n.º 7
0
bool CUIBagWnd::OnKeyboard(int dik, EUIMessages keyboard_action)
{
	int iGroup;

	if (DIK_ESCAPE == dik)
	{
		m_btnBack.OnClick();
		return true;
	}

	switch (GetMenuLevel())
	{
	case mlRoot:
		R_ASSERT2(false,"error: CUIBagWnd on level <mlRoot> can't handle keyboard");
		break;
	case mlBoxes:

		if (DIK_ESCAPE == dik)
		{
			ShowSectionEx(-1);			return true;
		}

		switch (dik)
		{
		case DIK_1:
			OnBtnShotgunsClicked();					return true;

		case DIK_2:
			OnBtnMachinegunsClicked();				return true;

		case DIK_3:
			OnBtnSniperClicked();					return true;

		case DIK_4:
			OnBtnHeavyClicked();					return true;
		}
		break;

	case mlWpnSubType:		
		iGroup = GetCurrentGroupIndex();
		if (DIK_ESCAPE == dik)
		{
			if (iGroup >= GROUP_31 && iGroup <= GROUP_34 )
				ShowSectionEx(GROUP_BOXES);
			else
				ShowSectionEx(-1);

			return true;
		}

		if (dik <= DIK_0 && dik >= DIK_1)
		{
			CUICellItem* itm = GetItemByKey(dik,GetCurrentGroupIndex());
			if (itm && IsInBag(itm))
                itm->GetMessageTarget()->SendMessage(itm, DRAG_DROP_ITEM_DB_CLICK, NULL);
		}
		break;
	default:
		NODEFAULT;
	}

	return false;
}