Esempio n. 1
0
void CShop::BuyItem(int index)
{
	CShopItemPtr forSaleItem = _itemsForSale[_forSaleTop + index];
	CShopItemPtr boughtItem = FindPurchasedByID(forSaleItem->GetID());

	forSaleItem->ChangeCount(-1);
	ChangeGold(-(forSaleItem->GetCost()));

	// if the weapon class wasn't in the purchased item list, add it
	if (boughtItem == NULL)
	{
		boughtItem = CShopItemPtr(new CShopItem(
			*forSaleItem, 0, forSaleItem->GetCost(), forSaleItem->GetPersistent())
		);

		_itemsPurchased.Append(boughtItem);

		// scroll so new item is visible in purchased list
		if (_itemsPurchased.Num() > _purchasedTop + LIST_SIZE_PURCHASED)
		{
			_purchasedTop = _itemsPurchased.Num() - LIST_SIZE_PURCHASED;
		}
	}

	boughtItem->ChangeCount(1);
}
Esempio n. 2
0
void CShop::SellItem(int index)
{
	CShopItemPtr boughtItem = _itemsPurchased[_purchasedTop + index];
	CShopItemPtr forSaleItem = FindForSaleByID(boughtItem->GetID());
	boughtItem->ChangeCount(-1);

	// If last in the purchased items list, remove it from the list
	if (boughtItem->GetCount() == 0)
	{
		_itemsPurchased.RemoveIndex(_purchasedTop + index);
		// scroll so appropriate items visible
		if ((_purchasedTop >= _itemsPurchased.Num()) || (_purchasedTop % LIST_SIZE_PURCHASED != 0)) {
			_purchasedTop = _itemsPurchased.Num() - LIST_SIZE_PURCHASED;
			if (_purchasedTop < 0) _purchasedTop = 0;
		}
	}

	ChangeGold(boughtItem->GetCost());

	// If the weapon class wasn't in the for sale list (it should be), add it
	if (forSaleItem == NULL)
	{
		forSaleItem = CShopItemPtr(new CShopItem(*boughtItem, 0, boughtItem->GetCost(), boughtItem->GetPersistent()));

		_itemsForSale.Append(forSaleItem);
	}

	forSaleItem->ChangeCount(1);
}