loot.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. local critical_loot = {
  2. -- The main problem with the `surface` challenge is keeping it from being too easy.
  3. -- This is especially due to travel being very swift, and too much food can go a long way.
  4. ["surface"] = {
  5. {item="default:stick", min=5, max=20},
  6. {item="farming:bread", min=5, max=20},
  7. {item="default:steel_ingot", min=5, max=20},
  8. {item="default:diamond", min=3, max=9},
  9. {item="bones:bones_type2", min=9, max=27},
  10. {item="torches:torch_floor", min=10, max=30},
  11. {item="bucket:bucket_water", min=1, max=4},
  12. {item="default:dirt", min=6, max=12},
  13. },
  14. -- The challenge of `cave` mode is building a farm to make food and keep going.
  15. -- Finding sources of iron and coal are critical. Farm supplies have to be provided
  16. -- right away because otherwise the gamemode would probably be impossible.
  17. ["cave"] = {
  18. {item="default:stick", min=10, max=30},
  19. {item="farming:bread", min=10, max=50},
  20. {item="basictrees:tree_apple", min=10, max=50},
  21. {item="pumpkin:bread", min=10, max=30},
  22. {item="default:steel_ingot", min=30, max=64},
  23. {item="default:coal_lump", min=30, max=64},
  24. {item="bones:bones_type2", min=10, max=40},
  25. {item="default:dirt", min=6, max=12},
  26. {item="torches:torch_floor", min=10, max=30},
  27. {item="bucket:bucket_water", min=4, max=12},
  28. {item="default:grass_dummy", min=5, max=20},
  29. {item="moreblocks:super_glow_glass", min=6, max=20},
  30. {item="rackstone:dauthsand", min=3, max=6},
  31. {item="firetree:sapling", min=2, max=3},
  32. {item="griefer:grieferstone", min=2, max=4},
  33. {item="titanium:crystal", min=3, max=16},
  34. },
  35. -- Like `cave` mode, in this gamemode building a farm and finding sources of iron and coal are critical.
  36. ["nether"] = {
  37. {item="default:stick", min=10, max=30},
  38. {item="farming:bread", min=10, max=50},
  39. {item="basictrees:tree_apple", min=10, max=50},
  40. {item="default:steel_ingot", min=30, max=64},
  41. {item="default:coal_lump", min=30, max=64},
  42. {item="gems:ruby_gem", min=3, max=13},
  43. {item="torches:kalite_torch_floor", min=10, max=25},
  44. {item="moreblocks:super_glow_glass", min=6, max=20},
  45. {item="rackstone:dauthsand", min=3, max=12},
  46. {item="firetree:sapling", min=2, max=3},
  47. {item="default:flint", min=3, max=5},
  48. {item="bluegrass:seed", min=3, max=16},
  49. {item="griefer:grieferstone", min=2, max=4},
  50. {item="titanium:crystal", min=3, max=16},
  51. {item="default:cobble", min=1, max=64},
  52. {item="default:cobble", min=1, max=64},
  53. {item="default:cobble", min=1, max=64},
  54. -- Nether challenge must have bed, because otherwise it is too
  55. -- difficult/impossible to craft one.
  56. {item="beds:fancy_bed_bottom", min=3, max=5},
  57. },
  58. }
  59. local bonus_loot = {
  60. {item="farming:seed_wheat", min=2, max=6, chance=40},
  61. {item="farming:seed_cotton", min=2, max=6, chance=40},
  62. {item="potatoes:seed", min=2, max=6, chance=40},
  63. {item="default:junglegrass", min=2, max=6, chance=40},
  64. {item="default:cactus", min=2, max=6, chance=40},
  65. {item="bandages:bandage_3", min=5, max=30, chance=40},
  66. {item="carbon_steel:ingot", min=5, max=30, chance=40},
  67. {item="default:mese_crystal", min=5, max=30, chance=40},
  68. }
  69. function survivalist.fill_loot_chest(inv, gamemode)
  70. if not inv then
  71. return
  72. end
  73. local loot = {}
  74. local critical = critical_loot[gamemode]
  75. if not critical then
  76. return
  77. end
  78. loot = table.copy(critical)
  79. table.shuffle(loot)
  80. local positions = {}
  81. local listsize = inv:get_size("main")
  82. for i = 1, listsize, 1 do
  83. positions[#positions + 1] = i
  84. end
  85. table.shuffle(positions)
  86. -- Add loot.
  87. for k, v in ipairs(loot) do
  88. local min = math.floor(v.min)
  89. local max = math.ceil(v.max)
  90. if max >= min then
  91. local count = math.floor(math.random(min, max))
  92. if count > 0 and #positions > 0 then
  93. local idx = positions[#positions]
  94. positions[#positions] = nil
  95. inv:set_stack("main", idx, ItemStack(v.item .. " " .. count))
  96. end
  97. end
  98. end
  99. local bonus = table.copy(bonus_loot)
  100. table.shuffle(bonus)
  101. -- Add bonus loot.
  102. for k, v in ipairs(bonus) do
  103. local min = math.floor(v.min)
  104. local max = math.ceil(v.max)
  105. if max >= min then
  106. local count = math.floor(math.random(min, max))
  107. local chance = math.random(0, 100)
  108. if count > 0 and #positions > 0 and chance < v.chance then
  109. local idx = positions[#positions]
  110. positions[#positions] = nil
  111. inv:set_stack("main", idx, ItemStack(v.item .. " " .. count))
  112. end
  113. end
  114. end
  115. end