--Rupees (previously Blue Balls)
--By Callmore and fucked with by Ivo, further fucked with by weblorex

freeslot("MT_RUPEE", "sfx_rupee")

local function RupeeSpecial(mt, mt2)
	--print("FUCKINGSPECIAL")
	if not (mt2.valid and mt2.player and mt2.player.valid) then return true end
	if not mt.pickedup then
		mt.pickedup = {}
	end
	if mt.pickedup[mt2.player] then
		return true
	end
	mt.pickedup[mt2.player] = true
	mt2.player.kartstuff[k_driftboost] = $+10
	S_StartSoundAtVolume(nil, sfx_rupee, 160, mt2.player)
	--print("FUCKINGSPEED")
	return true
end

addHook("TouchSpecial", RupeeSpecial, MT_RUPEE)
--print("FUCKINGBALLS")

local function RupeeThink(mo)
    --Thinker for ivo's blue balls
	if not mo.pickedup then return end
    local newFlags = 0
    if not splitscreen then
        if mo.pickedup[displayplayers[0]] then
            newFlags = MF2_DONTDRAW
        end
        mo.flags2 = ($&~MF2_DONTDRAW)|newFlags
    else
        for p, n in displayplayers.iterate do
            if not mo.pickedup[p] then
                newFlags = MFE_DRAWONLYFORP1 << n
            end
            if newFlags then
                local flgs = MFE_DRAWONLYFORP1|MFE_DRAWONLYFORP2|MFE_DRAWONLYFORP3|MFE_DRAWONLYFORP4
                mo.eflags = ($&~flgs)|newFlags
            else
                mo.flags2 = $|MF2_DONTDRAW
            end
        end
    end
end

addHook("MobjThinker", RupeeThink, MT_RUPEE)