Skip to content

Instantly share code, notes, and snippets.

@bladecoding
Last active April 6, 2021 10:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bladecoding/e2822580734366633347ac98dfe4a8d9 to your computer and use it in GitHub Desktop.
Save bladecoding/e2822580734366633347ac98dfe4a8d9 to your computer and use it in GitHub Desktop.
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 pickupPercent = rng:RandomFloat()
if (player:HasCollectible(COLLECTIBLE_LUCKYFOOT)) then
pickupPercent = (pickupPercent * 0.9) + 0.1
end
local luck = math.max(math.min(player.Luck, 10), 0) --Clamp to 0-10
--Max luck increases the pickupPercent range from 0-1 to 0-2
--That means the more luck you have, the more likely you are to get chests.
pickupPercent = rng:RandomFloat() * luck * 0.1 + pickupPercent
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_BOMB
else
pickupAward = PICKUP_CHEST
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
local nothingChance = math.pow(0.666, pickupCount - 1)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment