Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- sell-loot.lic new yaml settings: lootsack_noun(container), sell_loot_materials(bolean), materials_sack(container), and force_loot_town(town name)
- =end
- custom_require.call(%w[common common-items common-money common-travel drinfomon equipmanager])
- class SellLoot
- include DRC
- include DRCI
- include DRCM
- include DRCT
- def initialize
- EquipmentManager.new.empty_hands
- Flags.add('tip-accepted', '.* accepts your tip and slips it away with a smile')
- Flags.add('tip-declined', '.* declines your tip offer')
- Flags.add('tip-expired', 'Your tip offer to .* has expired')
- @settings = get_settings
- town_data = get_data('town')
- if @settings.force_loot_town
- @character_hometown = @settings.force_loot_town
- @hometown = town_data[@settings.force_loot_town]
- else
- @character_hometown = @settings.hometown
- @hometown = town_data[@settings.hometown]
- end
- @bankbot_name = @settings.bankbot_name
- @bankbot_room_id = @settings.bankbot_room_id
- @bankbot_deposit_threshold = @settings.bankbot_deposit_threshold
- @bankbot_enabled = @settings.bankbot_enabled
- @local_currency = town_data[@character_hometown]['currency']
- skip_bank = @settings.sell_loot_skip_bank
- skip_exchange = @settings.sell_loot_skip_exchange
- keep_money_by_currency = @settings.sell_loot_money_on_hand
- sell_materials("#{@settings.materials_sack}") if @settings.sell_loot_materials
- ls_sell_materials("#{@settings.lootsack_noun}") if @settings.sell_loot_materials
- sell_gems("#{@settings.gem_pouch_adjective} #{@settings.gem_pouch_noun}") if @settings.sell_loot_pouch
- check_spare_pouch(@settings.spare_gem_pouch_container, @settings.gem_pouch_adjective) if @settings.spare_gem_pouch_container
- ls_sell_gems("#{@settings.lootsack_noun}") if @settings.sell_loot_pouch
- sell_bundle if @settings.sell_loot_bundle
- return if skip_bank && !@bankbot_enabled
- return if @bankbot_enabled && (@bankbot_name.nil? || @bankbot_room_id.nil?)
- keep_coppers_bank = parse(keep_money_by_currency.split(' '))
- if skip_bank && @bankbot_enabled
- $CURRENCIES.each do |currency|
- give_money_to_bankbot(currency, currency =~ /#{@local_currency}/i ? @bankbot_deposit_threshold : 0)
- end
- return
- end
- exchange_coins unless skip_exchange
- if @bankbot_enabled
- give_money_to_bankbot(@local_currency, @bankbot_deposit_threshold)
- else
- deposit_coins(keep_coppers_bank)
- end
- end
- def parse(setting)
- arg_definitions = [
- [
- { name: 'amount', regex: /\d+/i, variable: true, description: 'Number of coins to keep' },
- { name: 'type', regex: /\w+/i, variable: true, description: 'Type of coins to keep' }
- ],
- []
- ]
- args = parse_args(arg_definitions)
- keep_amount = args.amount || setting[0] || 3
- keep_type = args.type || setting[1] || 'silver'
- convert_to_copper(keep_amount, keep_type)
- end
- def exchange_coins
- walk_to @hometown['exchange']['id']
- release_invisibility
- exchange_to = @hometown['currency']
- $CURRENCIES
- .reject { |currency| currency =~ /#{exchange_to}/i }
- .each { |currency| fput "exchange all #{currency} for #{exchange_to}" }
- end
- def deposit_coins(keep_copper)
- walk_to @hometown['deposit']['id']
- release_invisibility
- bput('wealth', 'Wealth:')
- case bput('deposit all', 'you drop all your', 'drop your coins inside', 'You hand the clerk some coins', "You don't have any", 'There is no teller here', 'reached the maximum balance I can permit', "We don't serve necromancers or sorcerers here.")
- when 'There is no teller here', "We don't serve necromancers or sorcerers here."
- return
- end
- minimize_coins(keep_copper).each { |amount| withdraw_exact_amount?(amount, @settings) }
- bput('check balance', 'your current balance is', 'As expected, there are')
- end
- def give_money_to_bankbot(currency, keep)
- copper_on_hand = check_wealth(currency)
- deposit_amount = copper_on_hand - keep
- return if deposit_amount <= 0
- walk_to @bankbot_room_id
- return unless DRRoom.pcs.include?(@bankbot_name)
- Flags.reset('tip-accepted')
- Flags.reset('tip-expired')
- Flags.reset('tip-declined')
- case bput("tip #{@bankbot_name} #{deposit_amount} #{currency}", 'You offer', "I don't know who", 'you really should keep every bronze you can get your hands on', 'You already have a tip offer outstanding', 'already has a tip offer pending', "But you don't have that much!")
- when "I don't know who"
- echo '***Bankbot not found, skipping deposit***'
- return
- when 'You already have a tip offer outstanding'
- echo '***You already have a tip offer outstanding, skipping deposit***'
- return
- when 'you really should keep every bronze you can get your hands on'
- echo '***ERROR*** UNABLE TO TIP DUE TO LOW CIRCLE, EXITING'
- return
- when 'already has a tip offer pending'
- echo '***Bankbot is busy, skipping deposit***'
- return
- when "But you don't have that much!"
- echo '***Error calculating tip amount, please post a log on GitHub***'
- return
- end
- pause 0.5 until Flags['tip-accepted'] || Flags['tip-expired'] || Flags['tip-declined']
- end
- def sell_bundle
- return unless exists?('bundle')
- return unless walk_to @hometown['tannery']['id']
- return if bput('remove my bundle', 'You remove', 'You sling', 'Remove what','You take') == 'Remove what'
- release_invisibility
- bput('sell my bundle', 'ponders over the bundle', 'sorts through it', 'gives it a close inspection', 'takes the bundle')
- bput('stow rope', 'You put')
- end
- def check_spare_pouch(container, adj)
- fput("open my #{container}")
- return if inside?("#{adj} pouch", container)
- walk_to @hometown['gemshop']['id']
- clerk = which_clerk(@hometown['gemshop']['name'])
- release_invisibility
- fput("ask #{clerk} for #{adj} pouch")
- fput("put my pouch in my #{container}")
- end
- def which_clerk(clerks)
- clerks.is_a?(String) ? clerks : clerks.find { |clerk| DRRoom.npcs.include?(clerk) }
- end
- def sell_materials(container)
- release_invisibility
- case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
- when 'has been tied off', 'What were you referring to'
- return
- end
- materials = get_materials(container)
- unless materials.empty?
- return unless walk_to @hometown['gemshop']['id']
- clerk = which_clerk(@hometown['gemshop']['name'])
- materials.each do |material|
- fput "get my #{material} from my #{container}"
- fput "sell my #{material} to #{clerk}"
- end
- end
- end
- def ls_sell_materials(container)
- release_invisibility
- case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
- when 'has been tied off', 'What were you referring to'
- return
- end
- materials = get_materials(container)
- unless materials.empty?
- return unless walk_to @hometown['gemshop']['id']
- clerk = which_clerk(@hometown['gemshop']['name'])
- materials.each do |material|
- fput "get my #{material} from my #{container}"
- fput "sell my #{material} to #{clerk}"
- end
- end
- end
- def sell_gems(container)
- release_invisibility
- case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
- when 'has been tied off', 'What were you referring to'
- return
- end
- gems = get_gems(container)
- unless gems.empty?
- return unless walk_to @hometown['gemshop']['id']
- clerk = which_clerk(@hometown['gemshop']['name'])
- gems.each do |gem|
- fput "get my #{gem} from my #{container}"
- fput "sell my #{gem} to #{clerk}"
- end
- end
- fput "close my #{container}" unless @settings.sell_loot_skip_pouch_close
- end
- def ls_sell_gems(container)
- release_invisibility
- case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
- when 'has been tied off', 'What were you referring to'
- return
- end
- gems = get_gems(container)
- unless gems.empty?
- return unless walk_to @hometown['gemshop']['id']
- clerk = which_clerk(@hometown['gemshop']['name'])
- gems.each do |gem|
- fput "get my #{gem} from my #{container}"
- fput "sell my #{gem} to #{clerk}"
- end
- end
- end
- before_dying do
- Flags.delete('tip-accepted')
- Flags.delete('tip-declined')
- Flags.delete('tip-expired')
- end
- end
- SellLoot.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement