Kaesken

smelt-deeds

Sep 30th, 2025 (edited)
57
0
38 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. =begin
  2. Documentation: https://elanthipedia.play.net/Lich_script_repository#smelt-deeds
  3. =end
  4.  
  5. class SmeltDeeds
  6. def initialize
  7. arg_definitions = [
  8. [
  9. { name: 'material', regex: /\w+/i, optional: true, description: 'Single material to smelt' }
  10. ]
  11. ]
  12. args = parse_args(arg_definitions)
  13. alloys = %w[steel bronze pewter brass]
  14. all_metals = get_data('items').metal_types - alloys
  15. all_metals += [args.material] if args.material && alloys.include?(args.material)
  16.  
  17. unless DRCI.search?('deed')
  18. echo '***NO DEEDS FOUND TO SMELT***'
  19. return
  20. end
  21.  
  22. @equipment_manager = EquipmentManager.new
  23.  
  24. @equipment_manager.empty_hands
  25.  
  26. results = reget(100, 'A deed for')
  27. waitrt?
  28.  
  29. results
  30. .each_with_object([]) { |line, array| array << line.match(/A deed for (.+) (.*) (.+) is in/)[2] }
  31. .each_with_object(Hash.new(0)) { |name, counts| counts[name] += 1 }
  32. .select { |metal, _count| all_metals.include?(metal) }
  33. .reject { |_metal, count| count <= 1 }
  34. .reject { |metal, _count| metal.nil? }
  35. .reject { |metal, _count| args.material && metal !~ /#{args.material}/i }
  36. .each_key { |metal| smelt(metal) }
  37. end
  38.  
  39. def smelt(metal)
  40. settings = get_settings
  41.  
  42. tools = settings.adjustable_tongs ? %w[rod bellows tongs] : %w[rod bellows shovel]
  43. unless tools.all? { |tool| DRCI.exists?(tool) }
  44. echo 'A TOOL WAS MISSING. FIND IT AND RESTART'
  45. exit
  46. end
  47.  
  48. DRCC.find_empty_crucible(settings.hometown)
  49.  
  50. prepare_crucible(metal)
  51.  
  52. DRC.wait_for_script_to_complete('smelt')
  53.  
  54. return unless packet?
  55.  
  56. DRC.bput('push my ingot with my packet', 'You push')
  57. DRC.bput('stow my deed', 'You put')
  58. DRC.bput('stow my packet', 'You put') # TODO: What happens if that was your last deed in the packet?
  59. end
  60.  
  61. def packet?
  62. case DRC.bput('get my packet', 'You get', 'What were you referring to')
  63. when 'What were you referring to'
  64. DRC.bput('stow my ingot', 'You put')
  65. return false
  66. end
  67. true
  68. end
  69.  
  70. def prepare_crucible(metal)
  71. $ORDINALS.each do |ordinal|
  72. break unless more_deeds?(ordinal, metal)
  73. end
  74. end
  75.  
  76. def more_deeds?(ordinal, metal)
  77. loop do
  78. return false unless deed?(ordinal, metal)
  79. return true unless tap_deed?
  80. return false unless load_crucible?(DRC.right_hand)
  81. return false unless load_crucible?(DRC.left_hand)
  82. end
  83. end
  84.  
  85. def deed?(ordinal, metal)
  86. case DRC.bput("get my #{ordinal} #{metal} deed", 'You get', 'What were you referring to')
  87. when 'What were you referring to'
  88. return false
  89. end
  90. true
  91. end
  92.  
  93. def tap_deed?
  94. case DRC.bput('tap my deed', /^You pick up/, /^The worker explains/, /^The ingot rests safely at your feet/)
  95. when 'The worker explains'
  96. DRC.bput('stow my deed', 'You put')
  97. return false
  98. when /The ingot rests safely at your feet/ # Anything heavy enough to not be picked up is almost certainly an ingot here
  99. DRC.bput('get my ingot', 'You pick up')
  100. waitrt?
  101. DRC.fix_standing
  102. end
  103. true
  104. end
  105.  
  106. def load_crucible?(item)
  107. unless item.nil?
  108. case DRC.bput("put my #{item} in cruc", 'You put', 'at once would be dangerous')
  109. when 'at once would be dangerous'
  110. echo '***CRUCIBLE IS FULL***'
  111. @equipment_manager.empty_hands
  112. return false
  113. end
  114. end
  115. true
  116. end
  117. end
  118.  
  119. SmeltDeeds.new
Advertisement
Add Comment
Please, Sign In to add comment