Room Clear Awards

From Binding of Isaac: Rebirth Wiki
Revision as of 20:58, 15 November 2018 by Zamie (talk | contribs) (Created page with "TODO <nowiki> local room = Game():GetLevel():GetCurrentRoom() local awardSeed = room.AwardSeed local player = Game():GetPlayer(0) local difficulty = Game().Difficulty local...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

TODO

local room = Game():GetLevel():GetCurrentRoom()
local awardSeed = room.AwardSeed
local player = Game():GetPlayer(0)
local difficulty = Game().Difficulty

local rng = RNG()
rng:SetSeed(awardSeed, 35) --5, 9, 7

local unk1 = rng:RandomFloat()
if (player:HasCollectible(COLLECTIBLE_LUCKYFOOT)) then
	unk1 = (unk1 * 0.9) + 0.1
end

local luck = math.max(math.min(player.Luck, 10), 0) --Clamp to 0-10

local pickupPercent = rng:RandomFloat() * luck * 0.1 + unk1

if (player:HasTrinket(TRINKET_LUCKY_TOE)) then
	if (player:HasCollectible(COLLECTIBLE_LUCKYFOOT) and luck > 0) then
		pickupPercent = (pickupPercent * 0.98) + 0.02
	else
		pickupPercent = (pickupPercent * 0.9) + 0.1
	end
end

local pickupAward = COLLECTIBLE_NULL
local pickupCount = 1

if (pickupPercent > 0.22) then
	if (pickupPercent < 0.3) then
		if (rng:RandomInt(3) == 0) then
			pickupAward = PICKUP_TAROTCARD
		elseif (rng:RandomInt(2) == 0) then
			pickupAward = PICKUP_TRINKET
		else
			pickupAward = PICKUP_PILL
		end
	elseif (pickupPercent <= 0.45) then
		pickupAward = PICKUP_COIN
	elseif (pickupPercent < 0.5 and player:HasTrinket(TRINKET_RIB_OF_GREED)) then
		pickupAward = PICKUP_COIN
	elseif (pickupPercent < 0.6 and (not player:HasTrinket(TRINKET_DAEMONS_TAIL) or rng:RandomInt(5) == 0)) then
		pickupAward = PICKUP_HEART
	elseif (pickupPercent < 0.8) then
		pickupAward = PICKUP_KEY
	elseif (pickupPercent <= 0.95) then
		pickupAward = PICKUP_CHEST
	else
		pickupAward = PICKUP_BOMB
	end
	
	if (rng:RandomInt(20) == 0 or (rng:RandomInt(15) == 0 and player:HasTrinket(TRINKET_WATCH_BATTERY))) then
		pickupAward = PICKUP_LIL_BATTERY
	end
	
	if (rng:RandomInt(50) == 0) then
		pickupAward = PICKUP_GRAB_BAG
	end
	
	if (player:HasTrinket(TRINKET_ACE_SPADES) and rng:RandomInt(10) == 0) then
		pickupAward = PICKUP_TAROTCARD
	elseif (player:HasTrinket(TRINKET_SAFETY_CAP) and rng:RandomInt(10) == 0) then
		pickupAward = PICKUP_PILL
	elseif (player:HasTrinket(TRINKET_MATCH_STICK) and rng:RandomInt(10) == 0) then
		pickupAward = PICKUP_BOMB
	elseif (player:HasTrinket(TRINKET_CHILDS_HEART) and rng:RandomInt(10) == 0 and (not player:HasTrinket(TRINKET_DAEMONS_TAIL) or rng:RandomInt(5) == 0)) then
		pickupAward = PICKUP_HEART
	elseif (player:HasTrinket(TRINKET_RUSTED_KEY) and rng:RandomInt(10) == 0) then
		pickupAward = PICKUP_KEY
	end
	
		
	if (player:HasCollectible(COLLECTIBLE_SMELTER) and rng:RandomInt(50) == 0) then
		pickupAward = PICKUP_TRINKET
	end
end


if (player:HasCollectible(COLLECTIBLE_GUPPYS_TAIL)) then
	if (rng:RandomInt(3) != 0) then
		if (rng:RandomInt(3) == 0) then
			pickupAward = PICKUP_NULL
		end
	else
		if (rng:RandomInt(2) != 0) then
			pickupAward = PICKUP_LOCKEDCHEST
		else
			pickupAward = PICKUP_CHEST
		end
	end
end

if (player:HasCollectible(COLLECTIBLE_CONTRACT_FROM_BELOW) and pickupAward != PICKUP_TRINKET) then
	pickupCount = player:GetCollectibleNum(COLLECTIBLE_CONTRACT_FROM_BELOW) + 1
	--The chance of getting nothing goes down with each contract exponentially
	--This can be replaced with `math.pow(0.666, pickupCount)`.
	--I guess this is an assembly optimization. Although why isn't 1 optimized :shrug:
	local nothingChance = 0.443556
	if (pickupCount - 1 != 2) then
		nothingChance = math.pow(0.666, pickupCount)
	end
	
	if (nothingChance * 0.5 > rng:NextFloat()) then
		pickupCount = 0
	end
end

if (difficulty == 1 and pickupAward == PICKUP_HEART) then
	if rng:RandomInt(100) >= 35 then
		pickupAward = PICKUP_NULL
	end
end

if (player:HasCollectible(COLLECTIBLE_BROKEN_MODEM) and rng:RandomInt(4) == 0 and pickupCount >= 1 and
		(pickupAward == PICKUP_COIN or pickupAward == PICKUP_HEART or pickupAward == PICKUP_KEY or pickupAward == PICKUP_GRAB_BAG or pickupAward == PICKUP_BOMB) then
	pickupCount = pickupCount + 1
end

if (pickupCount > 0 and pickupAward != PICKUP_NULL) then
	local subType = 0
	for i=1, pickupCount do
		local ent = Game():Spawn(ENTITY_PICKUP, pickupAward, nearCenter, Vector(0, 0), 0, subtype, rng:Next())
		subType = ent.SubType
	end
end