Example #1
0
CInventoryItemPtr CInventory::ValidateLoot(idEntity *ent, const bool gotFromShop) // grayman (#2376)
{
	CInventoryItemPtr rc;
	int LGroupVal = 0;
	int dummy1(0), dummy2(0), dummy3(0); // for calling GetLoot

	LootType lootType = CInventoryItem::GetLootTypeFromSpawnargs(ent->spawnArgs);
	int value = ent->spawnArgs.GetInt("inv_loot_value", "-1");

	// grayman (#2376) - if anyone ever marks loot "inv_map_start" and it's a valid shop
	// item, the player inventory will already have it at this point.

	if (gotFromShop)
	{
		value = -1;
	}

	if (lootType != LOOT_NONE && value > 0)
	{
		idStr pickedUpMsg = idStr(value);

		// If we have an anonymous loot item, we don't need to 
		// store it in the inventory.
		switch (lootType)
		{
			case LOOT_GOLD:
				m_Gold += value;
				LGroupVal = m_Gold;
				pickedUpMsg += common->Translate("#str_07320");	// " in Gold"
			break;

			case LOOT_GOODS:
				m_Goods += value;
				LGroupVal = m_Goods;
				pickedUpMsg += common->Translate("#str_07321");	// " in Goods"
			break;

			case LOOT_JEWELS:
				m_Jewelry += value;
				LGroupVal = m_Jewelry;
				pickedUpMsg += common->Translate("#str_07322");	// " in Jewels"
			break;
			
			default: break;
		}

		m_LootItemCount++;

		rc = GetItemByType(CInventoryItem::IT_LOOT_INFO);

		assert(rc != NULL); // the loot item must exist

		// greebo: Update the total loot value in the objectives system BEFORE
		// the InventoryCallback. Some comparisons rely on a valid total loot value.
		gameLocal.m_MissionData->ChangeFoundLoot(lootType, value);

		// Objective Callback for loot on a specific entity:
		// Pass the loot type name and the net loot value of that group
		gameLocal.m_MissionData->InventoryCallback( 
			ent, 
			sLootTypeName[lootType], 
			LGroupVal, 
			GetLoot( dummy1, dummy2, dummy3 ), 
			true 
		);

		// Take the loot icon of the picked up item and use it for the loot stats item

		idStr lootIcon = ent->spawnArgs.GetString("inv_icon");
		if (rc != NULL && !lootIcon.IsEmpty())
		{
			rc->SetIcon(lootIcon);
		}
		
		if (!ent->spawnArgs.GetBool("inv_map_start", "0") && !ent->spawnArgs.GetBool("inv_no_pickup_message", "0"))
		{
			NotifyOwnerAboutPickup(pickedUpMsg, rc);
		}
	}
	else
	{
		DM_LOG(LC_STIM_RESPONSE, LT_ERROR)LOGSTRING("Item %s doesn't have an inventory name and is not anonymous.\r", ent->name.c_str());
	}

	return rc;
}