Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- Documentation: https://elanthipedia.play.net/Lich_script_repository#smelt-deeds
- =end
- class SmeltDeeds
- def initialize
- arg_definitions = [
- [
- { name: 'material', regex: /\w+/i, optional: true, description: 'Single material to smelt' }
- ]
- ]
- args = parse_args(arg_definitions)
- alloys = %w[steel bronze pewter brass]
- all_metals = get_data('items').metal_types - alloys
- all_metals += [args.material] if args.material && alloys.include?(args.material)
- unless DRCI.search?('deed')
- echo '***NO DEEDS FOUND TO SMELT***'
- return
- end
- @equipment_manager = EquipmentManager.new
- @equipment_manager.empty_hands
- results = reget(100, 'A deed for')
- waitrt?
- results
- .each_with_object([]) { |line, array| array << line.match(/A deed for (.+) (.*) (.+) is in/)[2] }
- .each_with_object(Hash.new(0)) { |name, counts| counts[name] += 1 }
- .select { |metal, _count| all_metals.include?(metal) }
- .reject { |_metal, count| count <= 1 }
- .reject { |metal, _count| metal.nil? }
- .reject { |metal, _count| args.material && metal !~ /#{args.material}/i }
- .each_key { |metal| smelt(metal) }
- end
- def smelt(metal)
- settings = get_settings
- tools = settings.adjustable_tongs ? %w[rod bellows tongs] : %w[rod bellows shovel]
- unless tools.all? { |tool| DRCI.exists?(tool) }
- echo 'A TOOL WAS MISSING. FIND IT AND RESTART'
- exit
- end
- DRCC.find_empty_crucible(settings.hometown)
- prepare_crucible(metal)
- DRC.wait_for_script_to_complete('smelt')
- return unless packet?
- DRC.bput('push my ingot with my packet', 'You push')
- DRC.bput('stow my deed', 'You put')
- DRC.bput('stow my packet', 'You put') # TODO: What happens if that was your last deed in the packet?
- end
- def packet?
- case DRC.bput('get my packet', 'You get', 'What were you referring to')
- when 'What were you referring to'
- DRC.bput('stow my ingot', 'You put')
- return false
- end
- true
- end
- def prepare_crucible(metal)
- $ORDINALS.each do |ordinal|
- break unless more_deeds?(ordinal, metal)
- end
- end
- def more_deeds?(ordinal, metal)
- loop do
- return false unless deed?(ordinal, metal)
- return true unless tap_deed?
- return false unless load_crucible?(DRC.right_hand)
- return false unless load_crucible?(DRC.left_hand)
- end
- end
- def deed?(ordinal, metal)
- case DRC.bput("get my #{ordinal} #{metal} deed", 'You get', 'What were you referring to')
- when 'What were you referring to'
- return false
- end
- true
- end
- def tap_deed?
- case DRC.bput('tap my deed', /^You pick up/, /^The worker explains/, /^The ingot rests safely at your feet/)
- when 'The worker explains'
- DRC.bput('stow my deed', 'You put')
- return false
- when /The ingot rests safely at your feet/ # Anything heavy enough to not be picked up is almost certainly an ingot here
- DRC.bput('get my ingot', 'You pick up')
- waitrt?
- DRC.fix_standing
- end
- true
- end
- def load_crucible?(item)
- unless item.nil?
- case DRC.bput("put my #{item} in cruc", 'You put', 'at once would be dangerous')
- when 'at once would be dangerous'
- echo '***CRUCIBLE IS FULL***'
- @equipment_manager.empty_hands
- return false
- end
- end
- true
- end
- end
- SmeltDeeds.new
Advertisement
Add Comment
Please, Sign In to add comment