dofile( "data/scripts/game_helpers.lua" )
dofile( "data/scripts/lib/utilities.lua" )

function item_pickup( entity_item, entity_who_picked, item_name )
	local pos_x, pos_y = EntityGetTransform( entity_item )
	
	local money = 0
	
	edit_component( entity_who_picked, "WalletComponent", function(comp,vars)
		money = ComponentGetValueInt( comp, "money")
	end)
	
	local value = 10
	local extra_money_count = GameGetGameEffectCount( entity_who_picked, "EXTRA_MONEY" )
	if extra_money_count > 0 then
		for i=1,extra_money_count do
			value = value * 2
		end
	end
	
	-- Blood Money perk (dirty hard-coded fun)
	local flag = "PERK_PICKED_BLOOD_MONEY" -- get_perk_picked_flag_name("BLOOD_MONEY")
	if GameHasFlagRun(flag) then --"PERK_PICKED_BLOOD_MONEY"
	
		-- Reduce value to 25%
		value = math.ceil(value * 0.25)
		
		-- Heal
		local damagemodels = EntityGetComponent( entity_who_picked, "DamageModelComponent" )
		if( damagemodels ~= nil ) then
			for i,v in ipairs(damagemodels) do
				hp = tonumber( ComponentGetValue( v, "hp" ) )
				max_hp = tonumber( ComponentGetValue( v, "max_hp") )
				hp = hp + 0.4 -- 10 Health
				if( hp > max_hp ) then hp = max_hp end
				ComponentSetValue( v, "hp", hp)
			end
		end
		
	end
	

	money = money + value
	
	edit_component( entity_who_picked, "WalletComponent", function(comp,vars)
		vars.money = money
	end)

	shoot_projectile( entity_item, "data/entities/particles/gold_pickup.xml", pos_x, pos_y, 0, 0 )
	EntityKill( entity_item )
end