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); }
bool CShop::MergeIntoStartingEquipment( const idStr &itemName, int quantity, bool isWeapon, bool isMeleeWeapon ) { CShopItemPtr startingItem = FindStartingItemByID( itemName ); if( !startingItem ) { return false; // item not found } int oldQuantity = startingItem->GetCount(); int newQuantity = oldQuantity + quantity; // Weapons have ammo limits. Even though you might have // adjusted that already in the incoming item, // you have to check again when it's added to // the existing amount already in the starting items. if( isWeapon ) { if( isMeleeWeapon ) { // Don't stack anything for melee weapons, otherwise we end up with 2 shortswords newQuantity = oldQuantity; } else { // Arrow-based weapons need ammo int maxAmmo = GetMaxAmmo( itemName ); if( newQuantity > maxAmmo ) { newQuantity = maxAmmo; } } quantity = newQuantity - oldQuantity; // amount to give } else if( !startingItem->GetStackable() ) { quantity = 0; // don't adjust item's quantity } if( quantity > 0 ) { startingItem->ChangeCount( quantity ); // add quantity to count } return true; // item found }