Josh64

only trinket challenge 2.0

Jan 3rd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.31 KB | None | 0 0
  1. local Mod = RegisterMod("Challenge Only Trinkets", 1)
  2. local game = Game()
  3.  
  4. -- save data & custom achievement stuff --
  5.  
  6. local json = require("json")
  7. local GameState = {
  8. HeartKill = 0,
  9. SatanKill = 0,
  10. LambKill = 0,
  11. Trophy = 0
  12. }
  13.  
  14. local reevaluateCustomAchievements = false -- keeps track if custom achievements should be reevaluated (true if the endboss of the challenge is killed)
  15.  
  16. -- effect variants/ achievement papers
  17. EffectVariant.COSTUM_ACHIEVEMENT_PAPER = Isaac.GetEntityVariantByName("Costum Achievement Paper")
  18. EffectVariant.COSTUM_ACHIEVEMENT_PAPER_4 = Isaac.GetEntityVariantByName("Costum Achievement Paper 4")
  19. EffectVariant.COSTUM_ACHIEVEMENT_PAPER_5 = Isaac.GetEntityVariantByName("Costum Achievement Paper 5")
  20.  
  21. local Challenges = {
  22. CHALLENGE_ONLY_TRINKETS = Isaac.GetChallengeIdByName("Trinkets Only!")
  23. }
  24. local roomContains = {
  25. Famine = false,
  26. Pestilence = false,
  27. Death = false,
  28. War = false,
  29. Conquest = false,
  30. Fallen = false
  31. }
  32.  
  33. local waitForBeggar = false -- is "true" if a beggar spawned an item
  34. local collectible ={ -- keeps track which beggar type spawned an item
  35. Beggar = false,
  36. DemonBeggar = false,
  37. KeyBeggar = false,
  38. BombBeggar = false,
  39. ShellGame = false
  40. }
  41. local morphItem = false -- keeps rtack if an item is already morphed once
  42.  
  43.  
  44.  
  45. -- trinket pool
  46. function TrinketPools (item, pool, poolBackwards)
  47. if pool == nil then
  48. Isaac.ConsoleOutput("That works")
  49. end
  50. -- item = the current item
  51. -- pool = the current main pool.
  52. -- poolBackwards = the mirrored version of the current main pool. It is used to check which trinkets the player has
  53.  
  54. local maxNum = 0 -- keeps track of the max number of trinkets in the current main table/pool
  55. local curNum = 0 -- used to count down the places in the current main table/pool
  56.  
  57. local player = Isaac.GetPlayer(0)
  58. local hasEffect = player:GetEffects()
  59. local roomType = game:GetRoom():GetType()
  60.  
  61. -- get maxNum first of the main table/pool
  62. for a = 1, #pool do
  63. maxNum = maxNum + 1
  64. end
  65.  
  66. -- now go through very entity in the backwards table
  67. for b = 1, #poolBackwards do
  68. -- check if the player has a trinket or a trinket effect from the table
  69. if player:HasTrinket(poolBackwards[b])
  70. or hasEffect:HasTrinketEffect(poolBackwards[b]) then
  71. -- remove it from the main Table
  72. table.remove(pool, (maxNum - curNum))
  73. end
  74.  
  75. -- increase curNum so that the position to remove gets moved by 1 in the next cycle
  76.  
  77. curNum = curNum +1
  78. end
  79. -- spawn trinket
  80. if pool[1] ~= nil then -- the table which got check isn't empty yet
  81. local rng = player:GetCollectibleRNG(CollectibleType.COLLECTIBLE_SMELTER)
  82. local pickTrinket = rng:RandomInt(#pool)
  83.  
  84. -- morph the item to the picked trinket
  85. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool[pickTrinket], false)
  86. else
  87. -- the table is already empty. Spawn the error trinket
  88. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_ERROR, false)
  89.  
  90. Isaac.ConsoleOutput("That's an error for you")
  91. end
  92. end
  93.  
  94. function Mod:onStart()
  95. GameState = json.decode(Isaac.LoadModData(Mod)) -- decodes the data from the savefile (returns a lua table)
  96. end
  97. Mod:AddCallback(ModCallbacks.MC_POST_PLAYER_INIT, Mod.onStart)
  98.  
  99. function Mod:OnUpdate(player)
  100. local roomType = game:GetRoom():GetType()
  101.  
  102. -- do possible trophy spawning
  103.  
  104. -- costum achievements
  105. if reevaluateCustomAchievements == true then
  106. if game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then
  107.  
  108. -- first the achievements gained through Mom's Heart
  109. -- check for current gamestates
  110. if GameState.HeartKill == 2 then -- this should only proc once
  111. -- Isaac.ConsoleOutput("Yeeah")
  112. -- spawn the achievement paper
  113. local achievement = Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.COSTUM_ACHIEVEMENT_PAPER, 0, Vector(325, 275), Vector(0,0), player):ToEffect()
  114. -- achievement:GetSprite():ReplaceSpritesheet(3, "gfx/effects/first_challenge_won.png")
  115.  
  116. -- increase the trophy counter
  117. GameState.Trophy = GameState.Trophy + 1
  118.  
  119. -- check if the trophy should be spawned
  120. if GameState.Trophy == 2 then -- the 2 challenges have been beaten
  121. -- spawn the achievement paper
  122. -- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.COSTUM_ACHIEVEMENT_PAPER, 0, Vector(325, 275), Vector(0,0), player)
  123. end
  124.  
  125. reevaluateCustomAchievements = false
  126. elseif GameState.HeartKill == 10 then -- procs after 5 kills
  127. -- spawn the achievement paper
  128. -- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.COSTUM_ACHIEVEMENT_PAPER_4, 0, Vector(325, 275), Vector(0,0),, player)
  129.  
  130. reevaluateCustomAchievements = false
  131. end
  132.  
  133. -- check if the player has beaten the Lamb during the challenge
  134. if GameState.LambKill == 2 then -- this should only proc once
  135. -- spawn the achievement paper
  136. -- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.COSTUM_ACHIEVEMENT_PAPER_5, 0, Vector(325, 275), Vector(0,0), player):ToEffect()
  137.  
  138. reevaluateCustomAchievements = false
  139. end
  140. elseif game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then -- hard mode!... later
  141. -- check for current gamestates
  142. -- achievement gained through Satan
  143. if GameState.SatanKill == 1 then
  144. -- spawn the achievement paper
  145. -- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.COSTUM_ACHIEVEMENT_PAPER, 0, Vector(325, 275), Vector(0,0), player)
  146.  
  147. -- increase the trophy counter
  148. GameState.Trophy = GameState.Trophy + 1
  149.  
  150. -- check if the trophy should be spawned
  151. if GameState.Trophy == 2 then -- the 2 challenges have been beaten
  152. -- spawn the achievement paper
  153. -- Isaac.Spawn(EntityType.ENTITY_EFFECT, EffectVariant.COSTUM_ACHIEVEMENT_PAPER, 0, Vector(325, 275), Vector(0,0), player)
  154. end
  155. end
  156. reevaluateCustomAchievements = false
  157. Isaac.ConsoleOutput("Stop it!!! ")
  158. end
  159. end
  160.  
  161. -- check if the player plays the challenge
  162. if game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then
  163.  
  164. -- go through all room entities
  165. for _, entities in pairs(Isaac.GetRoomEntities()) do
  166. if entities.Type == EntityType.ENTITY_SLOT then
  167. if entities.Variant == 4 then -- normal beggar
  168.  
  169. if entities:GetSprite():IsEventTriggered("Prize") then
  170. Isaac.ConsoleOutput("Pay Prize")
  171. waitForBeggar = true
  172. collectible.Beggar = true
  173.  
  174. end
  175. elseif entities.Variant == 5 then -- demon beggar
  176. if entities:GetSprite():IsEventTriggered("Prize") then
  177. Isaac.ConsoleOutput("Pay Prize")
  178. waitForBeggar = true
  179. collectible.DemonBeggar = true
  180.  
  181. end
  182. elseif entities.Variant == 6 then -- shell game
  183. if entities:GetSprite():IsEventTriggered("Prize") then
  184. Isaac.ConsoleOutput("Pay Prize")
  185. waitForBeggar = true
  186. collectible.ShellGame = true
  187.  
  188. end
  189. elseif entities.Variant == 7 then -- key beggar
  190. if entities:GetSprite():IsEventTriggered("Prize") then
  191. Isaac.ConsoleOutput("Pay Prize")
  192. waitForBeggar = true
  193. collectible.KeyBeggar = true
  194.  
  195. end
  196. elseif entities.Variant == 9 then -- bomb beggar
  197. if entities:GetSprite():IsEventTriggered("Prize") then
  198. Isaac.ConsoleOutput("Pay Prize")
  199. waitForBeggar = true
  200. collectible.BombBeggar = true
  201.  
  202. end
  203. end
  204. end
  205.  
  206. if entities.Type == EntityType.ENTITY_PICKUP then
  207. if entities.Variant == PickupVariant.PICKUP_COLLECTIBLE then -- look for items
  208.  
  209. local item = entities
  210. -- check if a beggar spawned an item
  211. if waitForBeggar == true -- a beggar spawned an item
  212. and morphItem == false then -- item hasn't morphed yet
  213. if collectible.Beggar == true then
  214. -- get the beggar trinket "pool"
  215. local pool = {1,24,49,50,51,52,126} -- mostly the penny trinkets
  216. local poolBackwards = {126,52,51,50,49,24,1}
  217.  
  218. -- trinket pool stuff
  219. TrinketPools(item, pool, poolBackwards)
  220.  
  221. waitForBeggar = false
  222. collectible.Beggar = false
  223. morphItem = true -- the item is already morphed
  224.  
  225. elseif collectible.DemonBeggar == true then
  226. -- get the devil beggar trinket "pool"
  227. local pool = {61,111} -- Left Hand, Bloody Crown
  228. local poolBackwards = {111,61}
  229.  
  230. -- trinket pool stuff
  231. TrinketPools(item, pool, poolBackwards)
  232.  
  233. waitForBeggar = false
  234. collectible.DemonBeggar = false
  235. morphItem = true -- the item is already morphed
  236.  
  237. elseif collectible.ShellGame == true then
  238. Isaac.ConsoleOutput("Shell Game")
  239. -- get the shell game trinket "pool"
  240. local pool = {2,93} -- Petrified Poop, Used Diaper
  241. local poolBackwards = {93,2}
  242.  
  243. -- trinket pool stuff
  244. TrinketPools(item, pool, poolBackwards)
  245.  
  246. waitForBeggar = false
  247. collectible.ShellGame = false
  248. morphItem = true -- the item is already morphed
  249.  
  250. elseif collectible.KeyBeggar == true then
  251. -- get the key master trinket "pool"
  252. local pool = {19,36,83,124} -- key related trinkets
  253. local poolBackwards = {124,83,36,19}
  254.  
  255. -- trinket pool stuff
  256. TrinketPools(item, pool, poolBackwards)
  257.  
  258. waitForBeggar = false
  259. collectible.KeyBeggar = false
  260. morphItem = true -- the item is already morphed
  261.  
  262. elseif collectible.BombBeggar == true then
  263. -- get the bomb beggar trinket "pool"
  264. local pool = {71} -- Bob's Bladder / bomb related trinkets
  265.  
  266. -- morph the item to the picked trinket
  267. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool, false)
  268.  
  269. waitForBeggar = false
  270. collectible.KeyBeggar = false
  271. morphItem = true -- the item is already morphed
  272.  
  273. end
  274. end
  275.  
  276.  
  277. -- check for the SpawnerType (if possible) for stuff like beggars, slots, the player etc.
  278. if item.SpawnerType == EntityType.ENTITY_SLOT then
  279. -- check for the spawner variant (to differ between the slots)
  280. if item.SpawnerVariant == 1 then -- Slot Machine (doesn't work)
  281. -- get the slot machine trinket "pool"
  282. local pool = {121} -- while it makes no sense for one trinket [...]
  283. local poolBackwards = {121} -- [...] it allows to extend the trinket pool more easily
  284.  
  285. -- trinket pool stuff
  286. TrinketPools(item, pool, poolBackwards) -- gives the item itself and the both pools into the pool function
  287.  
  288. elseif item.SpawnerVariant == 2 then -- Blood Donation Machine
  289. -- get the blood donation machine trinket "pool"
  290. local pool = {34} -- Child's Heart
  291. local poolBackwards = {34}
  292.  
  293. -- trinket pool stuff
  294. TrinketPools(item, pool, poolBackwards)
  295.  
  296. elseif item.SpawnerVariant == 3 then -- Fortune Teller
  297. -- get the fortune teller trinket "pool"
  298. local pool = {102} -- Fragmented Card
  299. local poolBackwards = {102}
  300.  
  301. -- trinket pool stuff
  302. TrinketPools(item, pool, poolBackwards)
  303.  
  304. -- elseif item.SpawnerVariant == 5 then -- Devil Beggar
  305. -- elseif item.SpawnerVariant == 6 then -- Shell Game
  306. -- elseif item.SpawnerVariant == 7 then -- Key Master (Key Beggar)
  307. -- nothing for SpawnerVariant 8
  308. -- elseif item.SpawnerVariant == 9 then -- Bomb Beggar
  309. -- nothing for SpawnerVariant 10
  310. -- nothing for SpawnerVariant 11
  311.  
  312. elseif item.SpawnerVariant == 12 then -- Dressing Table
  313. -- get the dressing table trinket "pool"
  314. local pool = {16,17,44}
  315. local poolBackwards = {44,17,16}
  316.  
  317. -- trinket pool stuff
  318. TrinketPools(item, pool, poolBackwards)
  319. end
  320. elseif item.SpawnerType == EntityType.ENTITY_PICKUP then
  321. if item.SpawnerVariant == PickupVariant.PICKUP_LOCKEDCHEST then -- Golden Chest
  322. -- get the golden chest trinket "pool"
  323. local pool = {29,54,57}
  324. local poolBackwards = {57,54,29}
  325.  
  326. -- trinket pool stuff
  327. TrinketPools(item, pool, poolBackwards)
  328.  
  329. morphItem = true -- the item is already morphed
  330.  
  331. elseif item.SpawnerVariant == PickupVariant.PICKUP_REDCHEST then
  332. -- get the red chest trinket "pool"
  333. local pool = {40,43,80,107,128}
  334. local poolBackwards = {128,107,80,43,40}
  335.  
  336. -- trinket pool stuff
  337. TrinketPools(item, pool, poolBackwards)
  338.  
  339. morphItem = true -- the item is already morphed
  340.  
  341. elseif item.SpawnerVariant == PickupVariant.PICKUP_ETERNALCHEST then
  342. -- get the eternal/holy chest trinket "pool"
  343. local pool = {7,18,38,85,87,92,100,110,121} -- pool is shared with the angel room
  344. local poolBackwards = {121,110,100,92,87,85,38,18,7}
  345.  
  346. -- trinket pool stuff
  347. TrinketPools(item, pool, poolBackwards)
  348.  
  349. morphItem = true -- the item is already morphed
  350. end
  351.  
  352. elseif item.SpawnerType == EntityType.ENTITY_PLAYER then
  353. -- for item spawning trinkets/effects (inlucdes Lunch Bag and Wish Bone)
  354. -- needs thought tho
  355. end
  356.  
  357. -- Look for spcific items via the CollectibleType
  358. if (item.SubType == CollectibleType.COLLECTIBLE_LUMP_OF_COAL -- spawned from the Krampus fight
  359. or item.SubType == CollectibleType.COLLECTIBLE_KRAMPUS_HEAD) then
  360. -- possible needs room type?
  361. -- get krampu's trinket pool
  362. local pool = {35,95}
  363. local poolBackwards = {95,35}
  364.  
  365. -- trinket pool stuff
  366. TrinketPools(item, pool, poolBackwards)
  367.  
  368. morphItem = true -- the item is already morphed
  369.  
  370. elseif (item.SubType == CollectibleType.COLLECTIBLE_CUBE_OF_MEAT -- spawned by the horesman fight
  371. or item.SubType == CollectibleType.COLLECTIBLE_BALL_OF_BANDAGES
  372. or item.SubType == CollectibleType.COLLECTIBLE_WHITE_PONY) then -- spawned by Conquest
  373. -- get room data to see which horseman room it is
  374. if roomType == RoomType.ROOM_BOSS then -- first check the room type
  375. -- if roomData.IsFaminesRoom == true then
  376. if roomContains.Famine == true then
  377. -- morph the item into a locust. This will always happen regardless if the player has it or not
  378. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_FAMINE, false)
  379. -- elseif roomData.IsPestilencesRoom == true then
  380. elseif roomContains.Pestilence == true then
  381. -- morph the item into a locust. This will always happen regardless if the player has it or not
  382. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_PESTILENCE, false)
  383. -- elseif roomData.IsDeathsRoom == true then
  384. elseif roomContains.Death == true then
  385. -- morph the item into a locust. This will always happen regardless if the player has it or not
  386. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_DEATH, false)
  387. -- elseif roomData.IsWarsRoom == true then
  388. elseif roomContains.War == true then
  389. -- morph the item into a locust. This will always happen regardless if the player has it or not
  390. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_WRATH, false)
  391. -- elseif roomData.IsConquestsRoom == true then
  392. elseif roomContains.Conquest == true then
  393. -- morph the item into a locust. This will always happen regardless if the player has it or not
  394. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_LOCUST_OF_CONQUEST, false)
  395. end
  396. end
  397. morphItem = true -- the item is already morphed
  398.  
  399. elseif (item.SubType == CollectibleType.COLLECTIBLE_POLARIOD -- spawned from the Krampus fight
  400. or item.SubType == CollectibleType.COLLECTIBLE_NEGATIVE) then
  401. -- get mom's "pool"
  402. local pool = {69} -- Faded Polariod
  403. -- morph the item to the picked trinket
  404. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool, false)
  405.  
  406. morphItem = true -- the item is already morphed
  407.  
  408. -- elseif item.SubType == CollectibleType.COLLECTIBLE_SKATOLE then -- shell game
  409. -- get the shell game trinket "pool"
  410. -- local pool = {2,93} -- Petrified Poop, Used Diaper
  411. -- local poolBackwards = {93,2}
  412.  
  413. -- trinket pool stuff
  414. -- TrinketPools(item, pool, poolBackwards)
  415.  
  416. elseif item.SubType == CollectibleType.COLLECTIBLE_DOLLAR then -- slot machine
  417. -- get the slot machine trinket "pool"
  418. local pool = {121}
  419. -- morph the item to the picked trinket
  420. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool, false)
  421.  
  422. morphItem = true -- the item is already morphed
  423.  
  424. elseif item.SubType == CollectibleType.COLLECTIBLE_CRYSTAL_BALL then -- fortune teeler
  425. -- get the fortune teller trinket "pool"
  426. local pool = {102} -- Fragmented Card
  427. -- morph the item to the picked trinket
  428. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, pool, false)
  429.  
  430. morphItem = true -- the item is already morphed
  431.  
  432. end
  433.  
  434. if waitForBeggar == false -- the item wasn't spawned by a beggar
  435. and morphItem == false then -- item hasn't morphed yet
  436. -- go through the different room types
  437. if roomType == RoomType.ROOM_TREASURE
  438. or roomType == RoomType.ROOM_DUNGEON then
  439. -- get the treasure room pool
  440. local pool = {5,8,14,16,25,30,31,33,53,54,55,57,60,68,70,71,77,81,86,90,93,95,97,98,99,127}
  441. local poolBackwards = {127,99,98,97,95,93,90,86,81,77,71,70,68,60,57,55,54,53,33,31,30,25,16,14,8,5}
  442.  
  443. -- trinket pool stuff
  444. TrinketPools(item, pool, poolBackwards)
  445.  
  446.  
  447. -- if item:GetData().ThereIsOptions == nil then
  448. -- item:GetData().ThereIsOptions = true
  449. -- end
  450.  
  451. elseif roomType == RoomType.ROOM_SHOP
  452. or roomType == RoomType.ROOM_BLACK_MARKET then
  453. -- get the shop room pool
  454. local pool = {3,29,34,36,41,44,59,62,63,72,73,74,76,78,82,89,94,103,106,109,120,125}
  455. local poolBackwards = {125,120,109,106,103,94,89,82,78,76,74,73,72,63,62,59,44,41,36,34,29,3}
  456.  
  457. -- trinket pool stuff
  458. TrinketPools(item, pool, poolBackwards)
  459.  
  460. -- asign data to the entity to make it a shop item later down the line
  461. item:GetData().ShopTrinket = true
  462. item:GetData().NeedsNewPrize = true
  463.  
  464.  
  465. elseif roomType == RoomType.ROOM_LIBRARY then
  466. -- get the library room pool
  467. local pool = {9,10,11,12,21,23,26,27,45,48,64,65,66,96,102}
  468. local poolBackwards = {102,96,66,65,64,48,45,27,26,23,21,12,11,10,9}
  469.  
  470. -- trinket pool stuff
  471. TrinketPools(item, pool, poolBackwards)
  472.  
  473. elseif roomType == RoomType.ROOM_BOSS
  474. or roomType == RoomType.ROOM_MINIBOSS then
  475. if roomContains.Famine == true then -- the boss room contains the Fallen
  476. -- get the devil room pool
  477. local pool = {13,17,20,22,35,80,111,118}
  478. local poolBackwards = {118,111,80,35,22,20,17,13}
  479.  
  480. -- trinket pool stuff
  481. TrinketPools(item, pool, poolBackwards)
  482. else
  483. -- get the boss room pool
  484. local pool = {37,39,42,46,58,101,104,105,108,119}
  485. local poolBackwards = {119,108,105,104,101,58,46,42,39,37}
  486.  
  487. -- trinket pool stuff
  488. TrinketPools(item, pool, poolBackwards)
  489. end
  490.  
  491. elseif roomType == RoomType.ROOM_SECRET
  492. or roomType == RoomType.ROOM_SUPERSECRET then
  493. -- get the secret room pool
  494. local pool = {15,28,32,83,84,91}
  495. local poolBackwards = {91,84,83,32,28,15}
  496.  
  497. -- trinket pool stuff
  498. TrinketPools(item, pool, poolBackwards)
  499.  
  500. elseif roomType == RoomType.ROOM_DEVIL then
  501. -- get the secret room pool
  502. local pool = {13,17,20,22,35,80,111,118}
  503. local poolBackwards = {118,111,80,35,22,20,17,13}
  504.  
  505. -- trinket pool stuff
  506. TrinketPools(item, pool, poolBackwards)
  507.  
  508. elseif roomType == RoomType.ROOM_ANGEL
  509. or roomType == RoomType.ROOM_SACRIFICE then
  510. -- get the secret room pool
  511. local pool = {7,18,38,85,87,92,100,110,121}
  512. local poolBackwards = {121,110,100,92,87,85,38,18,7}
  513.  
  514. -- trinket pool stuff
  515. TrinketPools(item, pool, poolBackwards)
  516.  
  517. elseif roomType == RoomType.ROOM_CURSE then
  518. -- get the secret room pool
  519. local pool = {40,43,61,107,128}
  520. local poolBackwards = {128,107,61,43,40}
  521.  
  522. -- trinket pool stuff
  523. TrinketPools(item, pool, poolBackwards)
  524.  
  525. elseif roomType == RoomType.ROOM_ISAACS
  526. or roomType == RoomType.ROOM_BARREN then
  527. -- get the secret room pool
  528. local pool = {8,46,54,63,67,99}
  529. local poolBackwards = {99,67,63,54,46,8}
  530.  
  531. -- trinket pool stuff
  532. TrinketPools(item, pool, poolBackwards)
  533.  
  534. elseif roomType == RoomType.ROOM_CHALLENGE then
  535. -- get the secret room pool
  536. local pool = {6,40,58}
  537. local poolBackwards = {58,40,6}
  538.  
  539. -- trinket pool stuff
  540. TrinketPools(item, pool, poolBackwards)
  541.  
  542. elseif roomType == RoomType.ROOM_ERROR then
  543. -- get the secret room pool
  544. local pool = {4,6,67,75,79,92}
  545. local poolBackwards = {92,79,75,67,6,4}
  546.  
  547. -- trinket pool stuff
  548. TrinketPools(item, pool, poolBackwards)
  549.  
  550. elseif roomType == RoomType.ROOM_BOSSRUSH
  551. or roomType == RoomType.ROOM_DEFAULT then
  552. Isaac.ConsoleOutput("s,rjzgqp")
  553. -- morph the item into a random trinket. This will always happen regardless if the player has it or not
  554. item:ToPickup():Morph(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_TRINKET, TrinketType.TRINKET_NULL, false)
  555. end
  556. end
  557. morphItem = false
  558.  
  559. elseif entities.Variant == PickupVariant.PICKUP_TRINKET then -- look for trinkets
  560. local trinket = entities
  561. local sprite = trinket:GetSprite()
  562. local data = trinket:GetData()
  563.  
  564. -- check for There's Options trinkets
  565. if roomType == RoomType.ROOM_TREASURE then
  566. if (player.Position - trinket.Position):Length() < player.Size + trinket.Size then
  567.  
  568. -- Isaac.ConsoleOutput("Collect") -- gets collected
  569. if data.Picked == nil -- hasn't been picked up yet
  570. and data.ThereIsOptions == nil then -- one of the trinkets where you have a choice
  571.  
  572. -- Isaac.ConsoleOutput("Yeahhh")
  573. data.Picked = true
  574. data.ThereIsOptions = false
  575.  
  576. -- look for the other There Is Options trinket
  577. for _, entitis in pairs(Isaac.GetRoomEntities()) do
  578. if entitis.Type == EntityType.ENTITY_PICKUP
  579. and entitis.Variant == PickupVariant.PICKUP_TRINKET
  580. and entitis.SpawnerType ~= EntityType.ENTITY_PLAYER -- the trinket isn't the one dropped by the player
  581. and entitis:GetData().Picked == nil
  582. and entitis ~= trinket then -- isn't the trinket which is picked up
  583. entitis:Remove() -- remove the other trinket
  584. end
  585. end
  586. end
  587. end
  588.  
  589. -- check if the trinket is in the shop
  590. elseif roomType == RoomType.ROOM_SHOP then
  591. local price = 10
  592. if data.ShopTrinket == true then -- it's a shop trinket
  593. if data.NeedsNewPrize == true then -- is just spawned
  594. -- give it a new cost/price
  595. trinket:ToPickup().Price = price
  596. data.Price = price
  597.  
  598. -- doesn't need a new price anymore
  599. data.NeedsNewPrize = false
  600. end
  601. end
  602. elseif roomType == RoomType.ROOM_DEVIL then
  603. if (player.Position - trinket.Position):Length() < player.Size + trinket.Size then
  604. -- if sprite:IsPlaying("Collect") -- gets collected
  605. if data.Picked == nil
  606. and trinket.SpawnerType ~= EntityType.ENTITY_PLAYER then -- the trinket isn't the one dropped by the player -- hasn't been picked up yet
  607. player:TakeDamage(1, 0, EntityRef(player), 1)
  608. -- Isaac.ConsoleOutput("Yeahhh")
  609. data.Picked = true
  610. end
  611. end
  612. end
  613. end
  614. end
  615. end
  616. end
  617. end
  618. Mod:AddCallback(ModCallbacks.MC_POST_PEFFECT_UPDATE, Mod.OnUpdate)
  619.  
  620. function Mod:onAchievementPopup(effect)
  621. local sprite = effect:GetSprite()
  622.  
  623. effect.RenderZOffset = 4900 -- 1300 is enough for most obstacles, but not for the player
  624.  
  625. if not sprite:Play("Appear")
  626. and effect:GetData().Init == nil then
  627. -- Isaac.ConsoleOutput("Appear ")
  628. sprite:Play("Appear")
  629. effect:GetData().Init = true
  630. end
  631. end
  632. Mod:AddCallback(ModCallbacks.MC_POST_EFFECT_INIT, Mod.onAchievementPopup, EffectVariant.COSTUM_ACHIEVEMENT_PAPER)
  633.  
  634.  
  635. function Mod:onAchievementUpdate(effect)
  636.  
  637. local sprite = effect:GetSprite()
  638. local data = effect:GetData()
  639.  
  640. effect.RenderZOffset = 4900
  641. -- sprite:ReplaceSpritesheet(3, "gfx/effects/first_challenge_won.png")
  642.  
  643. if sprite:IsFinished("Appear") then
  644. -- Isaac.ConsoleOutput("Idle ")
  645. sprite:Play("Idle", true)
  646.  
  647. end
  648. if sprite:IsFinished("Idle") then
  649. -- Isaac.ConsoleOutput("Go away ")
  650. sprite:Play("Dissapear", false)
  651. end
  652. end
  653. Mod:AddCallback(ModCallbacks.MC_POST_EFFECT_UPDATE, Mod.onAchievementUpdate, EffectVariant.COSTUM_ACHIEVEMENT_PAPER)
  654.  
  655. function Mod.onNewRoom(_)
  656. local player = Isaac.GetPlayer(0)
  657. local roomType = game:GetRoom():GetType()
  658.  
  659. -- check if the player plays the challenge
  660. if game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then
  661.  
  662. if game:GetRoom():IsFirstVisit() == true then
  663. -- Isaac.ConsoleOutput("Roooom")
  664. if roomType == RoomType.ROOM_TREASURE then
  665.  
  666. -- check for items
  667. for _, entities in pairs(Isaac.GetRoomEntities()) do
  668. if entities.Type == EntityType.ENTITY_PICKUP then
  669. if entities.Variant == PickupVariant.PICKUP_COLLECTIBLE then -- it's an item!
  670. local item = entities
  671. -- get the treasure room pool
  672. local pool = {5,8,14,16,25,30,31,33,53,54,55,57,60,68,70,71,77,81,86,90,93,95,97,98,99,127}
  673. local poolBackwards = {127,99,98,97,95,93,90,86,81,77,71,70,68,60,57,55,54,53,33,31,30,25,16,14,8,5}
  674.  
  675. -- trinket pool stuff
  676. TrinketPools(item, pool, poolBackwards)
  677. elseif entities.Variant == PickupVariant.PICKUP_TRINKET then -- it's a trinket!
  678. end
  679. end
  680. end
  681. elseif roomType == RoomType.ROOM_BOSS then
  682. -- look for the boss in the boss room
  683. for _, entitis in pairs(Isaac.GetRoomEntities()) do
  684. if entitis.Type == EntityType.ENTITY_FAMINE then
  685. if roomContains.Famine == false then
  686. roomContains.Famine = true
  687. end
  688. elseif entitis.Type == EntityType.ENTITY_PESTILENCE then
  689. if roomContains.Pestilence == false then
  690. roomContains.Pestilence = true
  691. end
  692. elseif entitis.Type == EntityType.ENTITY_WAR then
  693. if entitis.Variant == 1 then -- it's Conquest
  694. if roomContains.Conquest == false then
  695. roomContains.Conquest = true
  696. end
  697. else -- it's War
  698. if roomContains.War == false then
  699. roomContains.War = true
  700. end
  701. end
  702. elseif entitis.Type == EntityType.ENTITY_DEATH then
  703. if roomContains.Death == false then
  704. roomContains.Death = true
  705. end
  706. elseif entitis.Type == EntityType.ENTITY_FALLEN then
  707. if roomContains.Fallen == false then
  708. roomContains.Fallen = true
  709. end
  710. else
  711. -- it is none of them so the variables should be reset to false
  712. roomContains.Famine = false
  713. roomContains.Pestilence = false
  714. roomContains.War = false
  715. roomContains.Death = false
  716. roomContains.Conquest = false
  717. roomContains.Fallen = false
  718. end
  719. end
  720. end
  721. end
  722. end
  723.  
  724. end
  725. Mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, Mod.onNewRoom)
  726.  
  727. function Mod:onHeartKill(entity)
  728. -- Isaac.ConsoleOutput("Heart?")
  729. local data = entity:GetData()
  730. if entity:IsDead() -- is it dead?
  731. and data.Died == nil then -- did it already die?
  732. data.Died = true -- well now it is dead
  733. if game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then
  734.  
  735. -- increase the kill counter
  736. if data.CounterUpdate == nil then
  737. GameState.HeartKill = GameState.HeartKill + 1
  738.  
  739. -- reevaluate the custom achievements
  740. reevaluateCustomAchievements = true
  741.  
  742. -- Isaac.ConsoleOutput("Diiiiie!!")
  743. Isaac.SaveModData(Mod, json.encode(GameState)) -- encodes the data
  744.  
  745. data.CounterUpdate = true
  746. end
  747. end
  748. end
  749. end
  750. Mod:AddCallback(ModCallbacks.MC_NPC_UPDATE, Mod.onHeartKill, EntityType.ENTITY_MOMS_HEART)
  751. -- Mod:AddCallback(ModCallbacks.MC_NPC_UPDATE, Mod.onHeartKill, EntityType.ENTITY_IT_LIVES)
  752.  
  753. function Mod:onSatanKill(entity)
  754. local data = entity:GetData()
  755. if entity:IsDead() -- is it dead?
  756. and not data.Died then -- did it already die?
  757. data.Died = true -- well now it is dead
  758. if game.Challenge == Challenges.CHALLENGE_ONLY_TRINKETS then -- will be replaced with hard
  759. -- increase the kill counter
  760. GameState.HeartKill = GameState.HeartKill + 1 -- in case the player skips the second womb floor
  761.  
  762. -- reevaluate the custom achievements
  763. reevaluateCustomAchievements = true
  764.  
  765. Isaac.SaveModData(Mod, json.encode(GameState)) -- encodes the data
  766. end
  767. end
  768. end
  769. Mod:AddCallback(ModCallbacks.MC_NPC_UPDATE, Mod.onSatanKill, EntityType.ENTITY_SATAN)
  770.  
  771. function Mod:onExit(save)
  772. Isaac.SaveModData(Mod, json.encode(GameState)) -- encodes the data
  773. end
  774. Mod:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, Mod.onExit)
  775. Mod:AddCallback(ModCallbacks.MC_PRE_GAME_EXIT, Mod.onExit)
  776. Mod:AddCallback(ModCallbacks.MC_POST_GAME_END, Mod.onExit)
Advertisement
Add Comment
Please, Sign In to add comment