Guest User

Untitled

a guest
Dec 12th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. -- 测试反人类卡+点金术生成金大便概率
  2.  
  3. local game = Game();
  4. local mod = RegisterMod("count_gridentity", 1);
  5. local counts = {}
  6. local room = game:GetRoom()
  7. local gridsize = room:GetGridSize()
  8. local last_time = -1
  9. local sum = 0
  10.  
  11. function mod:handler_game_start()
  12. local player = Isaac.GetPlayer(1)
  13. player:AddCollectible(CollectibleType.COLLECTIBLE_MIDAS_TOUCH, 0) -- 添加点金术
  14. counts = {}
  15. last_time = -1
  16. sum = 0
  17. end
  18.  
  19. function mod:handler_change_room()
  20. -- 更新房间大小
  21. room = game:GetRoom()
  22. if room ~= nil then
  23. gridsize = room:GetGridSize()
  24. end
  25. end
  26.  
  27. function add_count(is_gold)
  28. --辅助函数: is_gold, 0表示不是,1表示是金大便
  29. sum = sum + 1
  30. luck = Isaac.GetPlayer(1).Luck
  31. if counts[luck] then
  32. counts[luck][1] = counts[luck][1] + 1
  33. counts[luck][2] = counts[luck][2] + is_gold
  34. else
  35. counts[luck] = {1, is_gold}
  36. end
  37. end
  38.  
  39. function mod:update()
  40. -- 生成文字
  41. for i in pairs(counts) do
  42. Isaac.RenderScaledText('Luck ' .. i .. ': ' .. string.format("%d/%d=%.4f%%", counts[i][2], counts[i][1], 100*counts[i][2]/counts[i][1]) , 100, 40+i*5, 0.5, 0.5, 255, 255, 255, 255);
  43. end
  44.  
  45. if game:IsPaused() or game.TimeCounter < 30 then
  46. return
  47. end
  48.  
  49. player = Isaac.GetPlayer(1)
  50. luck = player.Luck
  51. if luck < 20 then
  52. -- 自动使用道具 1 次
  53. player:UseActiveItem(CollectibleType.COLLECTIBLE_POOP,false,false,false,false)
  54. if counts[luck]~= nil and counts[luck][1] >= 10000 then -- 测试一万次,加幸运
  55. Isaac.GetPlayer(1):AddCollectible(CollectibleType.COLLECTIBLE_LUCKY_FOOT, 0)
  56. end
  57. end
  58. end
  59.  
  60.  
  61. function mod:remove()
  62. -- 统计金大便数并移除
  63. for i = 1, gridsize do
  64. gridentity = room:GetGridEntity(i)
  65. if gridentity ~= nil then
  66. etype = gridentity:GetType()
  67. -- 判断是否是大便
  68. if etype == GridEntityType.GRID_POOP then
  69. vari = gridentity:GetVariant()
  70. if vari == 0 then -- 普通大便
  71. add_count(0)
  72. elseif vari == 3 then -- 金大便
  73. add_count(1)
  74. end
  75. room:RemoveGridEntity(i,0,false) -- 立即摧毁大便
  76. end
  77. end
  78. end
  79. end
  80.  
  81. mod:AddCallback(ModCallbacks.MC_PRE_USE_ITEM , mod.remove);
  82. mod:AddCallback(ModCallbacks.MC_POST_RENDER, mod.update);
  83. mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, mod.handler_change_room);
  84. mod:AddCallback(ModCallbacks.MC_POST_GAME_STARTED , mod.handler_game_start);
Add Comment
Please, Sign In to add comment