Class: Lich::DragonRealms::EquipmentManager
- Inherits:
-
Object
- Object
- Lich::DragonRealms::EquipmentManager
- Defined in:
- documented/dragonrealms/commons/equipmanager.rb
Overview
Manages equipment for the DragonRealms game. This class handles the initialization, wearing, and removing of equipment.
Instance Method Summary collapse
-
#desc_to_items(descs) ⇒ Array<Item>
Converts descriptions to items.
-
#empty_hands ⇒ void
Empties the hands by returning held gear or stowing hands.
-
#get_combat_items ⇒ Array<String>
Retrieves the list of combat items currently worn.
-
#get_item?(item) ⇒ Boolean
Checks if an item can be retrieved from the inventory.
-
#get_item_helper(item, type) ⇒ Boolean
Helper method to retrieve an item based on its type.
-
#initialize(settings = nil) ⇒ EquipmentManager
constructor
Initializes a new EquipmentManager instance.
-
#is_listed_item?(desc) ⇒ Item?
Checks if a description matches a listed item.
-
#item_by_desc(description) ⇒ Item?
Finds an item by its description.
-
#items(settings = nil) ⇒ Array<Item>
Retrieves the list of items managed by the equipment manager.
-
#notify_missing(lost_items) ⇒ void
Notifies the user of missing items.
-
#remove_gear_by(&_block) ⇒ Array<Item>
Removes gear based on a given condition.
-
#remove_item(item) ⇒ Boolean
Removes a specific item from the inventory.
-
#remove_unmatched_items(combat_items, worn_items) ⇒ Array<Item>
Removes items from combat inventory that do not match worn items.
-
#return_held_gear(gear_set = 'standard') ⇒ Boolean
Returns held gear to the specified gear set.
-
#stow_helper(action, weapon_name, *accept_strings) ⇒ void
Helper method to assist in stowing a weapon.
-
#stow_weapon(description = nil) ⇒ void
Stows a weapon in the inventory.
-
#swap_to_skill?(noun, skill) ⇒ Boolean
Swaps a weapon to a specified skill.
-
#turn_to_weapon?(old_noun, new_noun) ⇒ Boolean
Turns a weapon from one type to another.
-
#unload_weapon(name) ⇒ void
Unloads a weapon from the inventory.
-
#verb_data(item) ⇒ Hash
Retrieves verb data for a specific item.
-
#wear_equipment_set?(set_name) ⇒ Boolean
Wears a set of equipment by name.
-
#wear_item?(item) ⇒ Boolean
Wears a specific item if it is available.
-
#wear_items(items_list) ⇒ void
Wears a list of items.
-
#wear_missing_items(worn_items, combat_items) ⇒ Array<Item>
Wears items that are missing from the combat inventory.
-
#wield_weapon(description, skill = nil) ⇒ Boolean
Wields a weapon in the main hand.
- #wield_weapon?(description, skill = nil) ⇒ Boolean
-
#wield_weapon_offhand(description, skill = nil) ⇒ Boolean
Wields a weapon in the offhand.
- #wield_weapon_offhand?(description, skill = nil) ⇒ Boolean
-
#worn_items(list) ⇒ Array<Item>
Filters the worn items based on a given list.
Constructor Details
#initialize(settings = nil) ⇒ EquipmentManager
Initializes a new EquipmentManager instance.
11 12 13 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 11 def initialize(settings = nil) items(settings) end |
Instance Method Details
#desc_to_items(descs) ⇒ Array<Item>
Converts descriptions to items.
81 82 83 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 81 def desc_to_items(descs) descs.map { |description| item_by_desc(description) }.compact end |
#empty_hands ⇒ void
This method returns an undefined value.
Empties the hands by returning held gear or stowing hands.
359 360 361 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 359 def empty_hands return_held_gear || DRCI.stow_hands end |
#get_combat_items ⇒ Array<String>
Retrieves the list of combat items currently worn.
143 144 145 146 147 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 143 def get_combat_items snapshot = Lich::Util.issue_command("inv combat", /All of your worn combat|You aren't wearing anything like that/, /Use INVENTORY HELP for more options/, usexml: false, include_end: false) .map(&:strip) snapshot - ["All of your worn combat equipment:", "You aren't wearing anything like that."] end |
#get_item?(item) ⇒ Boolean
Checks if an item can be retrieved from the inventory.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 295 def get_item?(item) return true if DRCI.in_hands?(item) if item.wield case DRC.bput("wield my #{item.short_name}", 'You draw', 'You deftly remove', 'You slip', 'With a flick of your wrist you stealthily unsheathe', 'Wield what', 'Your right hand is too injured', 'Your left hand is too injured') when 'Your right hand is too injured', 'Your left hand is too injured', 'Wield what' return false else return true end elsif item.transforms_to item = item_by_desc(item.transforms_to) item.worn ? get_item_helper(item, :worn) : get_item_helper(item, :stowed) get_item_helper(item, :transform) elsif (item.tie_to && get_item_helper(item, :tied)) || (item.worn && get_item_helper(item, :worn)) || (item.container && DRCI.get_item(item.short_name, item.container)) || get_item_helper(item, :stowed) true else echo("Could not find #{item.short_name} anywhere.") false end end |
#get_item_helper(item, type) ⇒ Boolean
Helper method to retrieve an item based on its type.
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 419 def get_item_helper(item, type) return false unless item data = verb_data(item)[type] snapshot = [DRC.left_hand, DRC.right_hand] waitrt? response = DRC.bput("#{data[:verb]} my #{item.short_name}", *data[:matches]) waitrt? # Handle empty/nil response (bput timeout) as failure if response.nil? || response.empty? DRC.("*** No response from game for '#{data[:verb]} my #{item.short_name}' - command may have been lost ***") return false end case response when 'You are already holding' return true when *data[:exhausted] return false when *data[:failures] data[:failure_recovery].call(item.name, item, response) else # Wait for hands to change with a timeout to prevent infinite loop timeout = Time.now + 5 pause 0.05 while snapshot == [DRC.left_hand, DRC.right_hand] && Time.now < timeout if snapshot == [DRC.left_hand, DRC.right_hand] DRC.("*** Hands did not change after '#{data[:verb]} my #{item.short_name}' - item may not have been retrieved ***") return false end return true end end |
#is_listed_item?(desc) ⇒ Item?
Checks if a description matches a listed item.
320 321 322 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 320 def is_listed_item?(desc) items.find { |item| item.short_regex =~ desc } end |
#item_by_desc(description) ⇒ Item?
Finds an item by its description.
88 89 90 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 88 def item_by_desc(description) items.find { |item| item.short_regex =~ description } end |
#items(settings = nil) ⇒ Array<Item>
Retrieves the list of items managed by the equipment manager.
20 21 22 23 24 25 26 27 28 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 20 def items(settings = nil) return @items if @items settings ||= get_settings @gear_sets = {} settings.gear_sets.each { |set_name, gear_list| @gear_sets[set_name] = gear_list.flatten.uniq } @sort_head = settings.sort_auto_head @items = settings.gear.map { |item| DRC::Item.new(name: item[:name], leather: item[:is_leather], hinders_locks: item[:hinders_lockpicking], worn: item[:is_worn], swappable: item[:swappable], tie_to: item[:tie_to], adjective: item[:adjective], bound: item[:bound], wield: item[:wield], transforms_to: item[:transforms_to], transform_verb: item[:transform_verb], transform_text: item[:transform_text], lodges: item[:lodges], ranged: item[:ranged], needs_unloading: item[:needs_unloading], skip_repair: item[:skip_repair], container: item[:container]) } end |
#notify_missing(lost_items) ⇒ void
This method returns an undefined value.
Notifies the user of missing items.
95 96 97 98 99 100 101 102 103 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 95 def notify_missing(lost_items) return unless lost_items && !lost_items.empty? DRC.beep echo 'MISSING EQUIPMENT: Please verify these items are in a closed container and not lost:' echo lost_items.map(&:short_name).join(', ').to_s pause DRC.beep end |
#remove_gear_by(&_block) ⇒ Array<Item>
Removes gear based on a given condition.
33 34 35 36 37 38 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 33 def remove_gear_by(&_block) combat_items = get_combat_items gear = desc_to_items(combat_items).select { |item| yield(item) } gear.each { |item| remove_item(item) } gear end |
#remove_item(item) ⇒ Boolean
Removes a specific item from the inventory.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 161 def remove_item(item) result = DRC.bput("remove my #{item.short_name}", "You .*#{item.name}", 'The leather gauntlets slide', 'Without any effort', 'you manage to loosen', "You need a free hand for that", "You'll need both hands free to do that", "then constricts tighter around your") waitrt? case result when /then constricts tighter around your/ # Items that auto-repair, like exoskeletal armor, # may have a timer on them that prevents you removing them. DRC.("The #{item.short_name} is not ready to be removed yet. Try again later.") return false when /You need a free hand for that/, /You'll need both hands free to do that/ # We may need to empty our hands to remove the item. # For example, exoskeletal armor requires two hands. temp_left_item = DRC.left_hand temp_right_item = DRC.right_hand # Lower the items because that preserves loaded bows. # Stowing them in a container would require unloading. did_lower = [temp_left_item, temp_right_item].compact.all? { |item_in_hand| DRCI.lower_item?(item_in_hand) } if did_lower remove_item(item) else DRC.("*** Unable to empty your hands to remove #{item.short_name} ***") end # Pick up the items in reverse order you lowered them # so that they end up in the correct hands again. DRCI.get_item_if_not_held?(temp_right_item) DRCI.get_item_if_not_held?(temp_left_item) # In case they end up in different hands, swap. DRC.bput('swap', /You move/, /^Will alone cannot conquer the paralysis/) if (DRC.left_hand != temp_left_item || DRC.right_hand != temp_right_item) else # If removing item transforms it (e.g. exoskeletal armor => orb) then continue with the transformed item. if item.transforms_to && DRCI.in_hands?(item.transforms_to) item = item_by_desc(item.transforms_to) end if item.tie_to stow_helper("tie my #{item.short_name} to my #{item.tie_to}", item.short_name, *DRCI::TIE_ITEM_SUCCESS_PATTERNS, *DRCI::TIE_ITEM_FAILURE_PATTERNS) elsif item.wield stow_helper("sheath my #{item.short_name}", item.short_name, 'Sheathing', 'You sheathe', 'You .* unload', 'You secure your', 'You slip', 'You hang', 'You .* strap', "Sheathe your .* where?") elsif item.container stow_helper("put my #{item.short_name} into my #{item.container}", item.short_name, *DRCI::PUT_AWAY_ITEM_SUCCESS_PATTERNS, *DRCI::PUT_AWAY_ITEM_FAILURE_PATTERNS) elsif /more room|too long to fit/ =~ DRC.bput("stow my #{item.short_name}", 'You put', 'You should unload', 'You easily strap', 'You secure your', 'There isn\'t any more room', 'straps have all been used', 'is too long to fit') wear_item?(item) end end waitrt? end |
#remove_unmatched_items(combat_items, worn_items) ⇒ Array<Item>
Removes items from combat inventory that do not match worn items.
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 128 def remove_unmatched_items(combat_items, worn_items) if UserVars.equipmanager_debug echo('removing unmatched items between these two sets') echo(combat_items.join(',').to_s) echo(worn_items.map(&:short_name).join(',').to_s) end combat_items .reject { |description| worn_items.find { |item| item.short_regex =~ description } } .map { |description| items.find { |item| item.short_regex =~ description } } .compact .each { |item| remove_item(item) } end |
#return_held_gear(gear_set = 'standard') ⇒ Boolean
Returns held gear to the specified gear set.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 327 def return_held_gear(gear_set = 'standard') return unless DRC.right_hand || DRC.left_hand todo = [DRC.left_hand, DRC.right_hand].compact worn_items = desc_to_items(@gear_sets[gear_set]) todo.all? do |held_item| if (info = worn_items.find { |item| item.short_regex =~ held_item }) unload_weapon(info.short_name) if info.needs_unloading stow_helper("wear my #{info.short_name}", info.short_name, 'You sling', 'You attach', 'You .* unload', 'You strap', 'You slide', 'You work your way into', 'You spin', '^You ', 'You carefully loop', 'slide effortlessly onto your', 'You slip', /^A brisk chill rushes through you/) true elsif (info = items.find { |item| item.short_regex =~ held_item }) unload_weapon(info.short_name) if info.needs_unloading if info.tie_to stow_helper("tie my #{info.short_name} to #{info.tie_to}", info.short_name, 'You attach', 'you tie', 'You are a little too busy', 'Your wounds hinder your ability to do that') elsif info.wield stow_helper("sheath my #{info.short_name}", info.short_name, 'Sheathing', 'You sheathe', 'You .* unload', 'You secure your', 'You slip', 'You hang', 'You .* strap') elsif info.container stow_helper("put my #{info.short_name} into my #{info.container}", info.short_name, *DRCI::PUT_AWAY_ITEM_SUCCESS_PATTERNS, *DRCI::PUT_AWAY_ITEM_FAILURE_PATTERNS) else stow_helper("stow my #{info.short_name}", info.short_name, 'You put', 'You should unload', 'You easily strap', 'You secure your') end true else false end end end |
#stow_helper(action, weapon_name, *accept_strings) ⇒ void
This method returns an undefined value.
Helper method to assist in stowing a weapon.
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 619 def stow_helper(action, weapon_name, *accept_strings) case DRC.bput(action, accept_strings) when /unload/ unload_weapon(weapon_name) stow_helper(action, weapon_name, accept_strings) when /close the fan/ fput("close my #{weapon_name}") stow_helper(action, weapon_name, accept_strings) when /You are a little too busy/ DRC.retreat stow_helper(action, weapon_name, accept_strings) when /You don't seem to be able to move/ pause 1 stow_helper(action, weapon_name, accept_strings) when /is too small to hold that/ fput("swap my #{weapon_name}") stow_helper(action, weapon_name, accept_strings) when /Your wounds hinder your ability to do that/, /Sheathe your .* where/ stow_helper("stow my #{weapon_name}", weapon_name, 'You put', 'You should unload', 'You easily strap', 'You secure your') end end |
#stow_weapon(description = nil) ⇒ void
This method returns an undefined value.
Stows a weapon in the inventory.
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 582 def stow_weapon(description = nil) unless description return unless DRC.right_hand || DRC.left_hand stow_weapon(DRC.right_hand) if DRC.right_hand stow_weapon(DRC.left_hand) if DRC.left_hand return end weapon = item_by_desc(description) return unless weapon # Is this a weapon that needs to be unloaded before it is put away? # This is an optimization attempt so that the script # isn't trying to unload every weapon that gets put away. # Would be silly to try "unload my scimitar" wouldn't it? :grins: unload_weapon(weapon.short_name) if weapon.needs_unloading if weapon.wield stow_helper("sheath my #{weapon.short_name}", weapon.short_name, 'Sheathing', 'You sheathe', 'You .* unload', 'close the fan', 'You secure your', 'You slip', 'You hang', 'You strap', "You don't seem to be able to move", 'You easily strap', 'is too small to hold that', 'is too wide to fit', 'With a flick of your wrist you stealthily sheathe', '^The .* slides easily', "There's no room", "Sheathe your .* where?", 'Your (left|right) hand is too injured') elsif weapon.worn stow_helper("wear my #{weapon.short_name}", weapon.short_name, 'You sling', 'You attach', 'You .* unload', 'You slide', 'You place', 'close the fan', 'You hang', 'You spin', 'You strap', 'You put', 'You carefully loop', "You don't seem to be able to move", "You are already wearing", "You work your way into", 'slide effortlessly onto your', "You can't wear") elsif !weapon.tie_to.nil? stow_helper("tie my #{weapon.short_name} to my #{weapon.tie_to}", weapon.short_name, 'You attach', 'close the fan', 'you tie', 'You are a little too busy', "You don't seem to be able to move", 'Your wounds hinder your ability to do that', 'You must be holding') elsif weapon.transforms_to stow_helper("#{weapon.transform_verb} my #{weapon.short_name}", weapon.short_name, weapon.transform_text) stow_weapon(weapon.transforms_to) elsif weapon.container stow_helper("put my #{weapon.short_name} in my #{weapon.container}", weapon.short_name, "You put .*#{weapon.name}", *DRCI::PUT_AWAY_ITEM_SUCCESS_PATTERNS, *DRCI::PUT_AWAY_ITEM_FAILURE_PATTERNS) else stow_helper("stow my #{weapon.short_name}", weapon.short_name, "You put .*#{weapon.name}", 'You .* unload', 'close the fan', 'You easily strap', "You don't seem to be able to move", 'You secure', 'is too small to hold that', 'is too wide to fit', 'You hang', '^The .* slides easily', "There's no room") end end |
#swap_to_skill?(noun, skill) ⇒ Boolean
Swaps a weapon to a specified skill.
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 474 def swap_to_skill?(noun, skill) if noun =~ /\bfan\b/i command = skill =~ /edged/i ? 'open' : 'close' DRC.bput("#{command} my fan", 'you snap', 'already') return true end proper_skill = case skill when /^he$|heavy edge|large edge|one-handed/i 'heavy edged' when /^2he$|^the$|twohanded edge|two-handed edge/i 'two-handed edged' when /^hb$|heavy blunt|large blunt/i 'heavy blunt' when /^2hb$|^thb$|twohanded blunt|two-handed blunt/i 'two-handed blunt' when /^se$|small edged|light edge|medium edge/i '(light edged|medium edged)' when /^sb$|small blunt|light blunt|medium blunt/i '(light blunt|medium blunt)' when /^lt$|light thrown/i 'light thrown' when /^ht$|heavy thrown/i 'heavy thrown' when /stave/i '(short|quarter) staff' when /polearms/i '(halberd|pike)' when /^ow$|offhand weapon/i return true # just use weapon in your left hand else DRC.("Unsupported weapon swap: #{noun} to #{skill}. Please report this to https://github.com/elanthia-online/dr-scripts/issues") return false end # All possible weapon skills to swap into. weapon_skills = [ 'light edged', 'medium edged', 'heavy edged', 'two-handed edged', 'light blunt', 'medium blunt', 'heavy blunt', 'two-handed blunt', 'light thrown', 'heavy thrown', 'short staff', 'quarter staff', 'halberd', 'pike' ] failure_matches = [ /You have nothing to swap/, /Your (left|right) hand is too injured/, /Will alone cannot conquer the paralysis that has wracked your body/, /^You move a .* to your (left|right) hand/ ] # The spaces in the regex are deliberate skill_match = / #{proper_skill} /i swapped_count = 0 loop do pause 0.25 # Avoid infinite loop where weapon can't swap to desired skill. return false if swapped_count > weapon_skills.length # Try to swap weapon to desired skill. case DRC.bput("swap my #{noun}", skill_match, /\b#{noun}\b.*(#{weapon_skills.join('|')})/, "You must have two free hands", *failure_matches) when /You must have two free hands/ fput('stow left') if DRC.left_hand && DRC.left_hand !~ /#{noun}/i fput('stow right') if DRC.right_hand && DRC.right_hand !~ /#{noun}/i next when *failure_matches return false when skill_match return true end swapped_count = swapped_count + 1 end end |
#turn_to_weapon?(old_noun, new_noun) ⇒ Boolean
Turns a weapon from one type to another.
457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 457 def turn_to_weapon?(old_noun, new_noun) return true if old_noun == new_noun result = DRC.bput("turn my #{old_noun} to #{new_noun}", /^Turn what?/i, /^Which weapon did you want to pull out/i, /^Your .*\b#{old_noun}.* shifts .*/i) waitrt? # turning may incur roundtime case result when /^Your .*\b#{old_noun}.* shifts .* before resolving itself into .*\b#{new_noun}/i true else false end end |
#unload_weapon(name) ⇒ void
This method returns an undefined value.
Unloads a weapon from the inventory.
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 556 def unload_weapon(name) # Phrases to match: # (hidden) You remain concealed by your surroundings, convinced that your unloading of the <weapon> went unobserved. # (hidden) You unload your <weapon> while blended in with your surroundings, but cannot shake the feeling that you drew attention to yourself. # (one hand empty) You unload the <weapon>. # (hands full) Your <ammo> falls from your <weapon> to your feet. case DRC.bput("unload my #{name}", /^You unload/, /^Your .* fall.*to your feet\.$/, 'As you release the string', /^You .* unloading/, 'But your .* isn\'t loaded', 'You can\'t unload such a weapon', 'You don\'t have a ranged weapon to unload', 'You must be holding the weapon to do that') when /^(?:Your .*?\b(?<ammo>[\w]+)\b fall.* from your .* to your feet\.)$/ # Ammo fell to ground because hands are full. # Lower weapon, stow ammo, then pick it back up. ammo = Regexp.last_match[:ammo] DRC.bput("lower ground left", "You lower") if DRCI.in_left_hand?(name) DRC.bput("lower ground right", "You lower") if DRCI.in_right_hand?(name) DRCI.put_away_item?(ammo) DRC.bput("get my #{name}", "You get", "You pick") when /^(You unload|You .* unloading)/ # Ammo is in hand, stow whichever hand isn't holding the weapon. DRC.bput("stow left", "You put") unless DRCI.in_left_hand?(name) DRC.bput("stow right", "You put") unless DRCI.in_right_hand?(name) end waitrt? end |
#verb_data(item) ⇒ Hash
Retrieves verb data for a specific item.
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 366 def verb_data(item) { worn: { verb: 'remove', matches: [/^You .*#{item.short_regex}/, /^You (get|sling|pull|work|loosen|slide|remove|yank|unbuckle).*#{item.name}/, 'you tug', 'Remove what', "You aren't wearing that", 'slide themselves off of your', 'you manage to loosen', 'you ready the', /^A brisk chill leaves you as you/], failures: [/^You (get|sling|pull|work|slide|remove|yank|unbuckle) $/], failure_recovery: proc { |noun| DRC.bput("wear my #{noun}", '^You ') }, exhausted: ['Remove what', "You aren't wearing that"] }, tied: { verb: 'untie', matches: [/^You .*#{item.short_regex}/, "^You remove.*#{item.name}", /^.*you untie your .*#{item.short_regex} from it./, '^What were you referring', '^Untie what', '^You are a little too busy', '^You are a bit too busy'], failures: ['You remove', /^You are a little too busy/, /^You are a bit too busy/], failure_recovery: proc { |_noun, item_to_recover, *matches| case matches when ['You are a little too busy'] DRC.retreat get_item?(item_to_recover) when ['You are a bit too busy'] DRC. get_item?(item_to_recover) else stow_weapon end }, exhausted: ['What were you referring', 'Untie what'] }, stowed: { verb: 'get', matches: [/^You .*#{item.short_regex}/, "^You .*#{item.name}", '^The.* slides easily out', '^What were you referring', 'But that is already', 'You are already'], failures: ['You get', /But that is already/], failure_recovery: proc { |noun| DRC.bput("stow my #{noun}", 'You put', 'But that is already in') }, exhausted: ['What were you referring'] }, transform: { verb: item.transform_verb, matches: [item.transform_text], failures: ["You'll need a free hand to do that!", "You don't seem to be holding"], failure_recovery: proc do |noun| fput('stow left') if DRC.left_hand && DRC.left_hand !~ /#{noun}/i fput('stow right') if DRC.right_hand && DRC.right_hand !~ /#{noun}/i item.worn ? DRC.bput("remove my #{noun}", '^You') : DRC.bput("get my #{noun}", '^You') DRC.bput("#{item.transform_verb} my #{item.short_name}", verb_data(item)[:matches]) end, exhausted: ['What were you referring'] } } end |
#wear_equipment_set?(set_name) ⇒ Boolean
Wears a set of equipment by name.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 56 def wear_equipment_set?(set_name) return false unless set_name worn_items = desc_to_items(@gear_sets[set_name]) echo("expected worn items:#{worn_items.map(&:short_name).join(',')}") if UserVars.equipmanager_debug unless worn_items echo("Could not find gear set #{set_name}") return false end combat_items = get_combat_items remove_unmatched_items(combat_items, worn_items) lost_items = wear_missing_items(worn_items, combat_items) notify_missing(lost_items) DRC.bput('sort auto head', /^Your inventory is now arranged/) if @sort_head lost_items.empty? end |
#wear_item?(item) ⇒ Boolean
Wears a specific item if it is available.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 210 def wear_item?(item) if item.nil? echo("failed to match an item, try turning on debugging with #{$clean_lich_char}e UserVars.equipmanager_debug = true") return false end if get_item?(item) DRCI.wear_item?(item.short_name) return true end return false end |
#wear_items(items_list) ⇒ void
This method returns an undefined value.
Wears a list of items.
45 46 47 48 49 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 45 def wear_items(items_list) items_list.each { |item| wear_item?(item) } DRC.bput('sort auto head', /^Your inventory is now arranged/) if @sort_head end |
#wear_missing_items(worn_items, combat_items) ⇒ Array<Item>
Wears items that are missing from the combat inventory.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 109 def wear_missing_items(worn_items, combat_items) if UserVars.equipmanager_debug echo('wearing missing items between these two sets') echo(combat_items.join(',').to_s) echo(worn_items.map(&:short_name).join(',').to_s) end missing_items = worn_items .reject { |item| combat_items.find { |c_item| item.short_regex =~ c_item } } .reject { |item| [DRC.right_hand, DRC.left_hand].grep(item.short_regex).any? ? (stow_weapon(item.short_name) || true) : false } echo("wear missing items #{missing_items}") if !missing_items.empty? && UserVars.equipmanager_debug missing_items.reject { |item| wear_item?(item) } end |
#wield_weapon(description, skill = nil) ⇒ Boolean
Wields a weapon in the main hand.
258 259 260 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 258 def wield_weapon(description, skill = nil) wield_weapon?(description, skill) end |
#wield_weapon?(description, skill = nil) ⇒ Boolean
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 262 def wield_weapon?(description, skill = nil) return unless description && !description.empty? offhand = skill == 'Offhand Weapon' weapon = item_by_desc(description) unless weapon DRC.("Failed to match a weapon for #{description}:#{skill}") return false end if [DRC.left_hand, DRC.right_hand].grep(weapon.short_regex).any? stow_weapon end if get_item?(weapon) swap_to_skill?(weapon.name, skill) if skill && weapon.swappable if offhand && DRC.right_hand case DRC.bput('swap', /^You move/, /^Will alone cannot conquer the paralysis/) when /^You move/ return true else return false end end end return false end |
#wield_weapon_offhand(description, skill = nil) ⇒ Boolean
Wields a weapon in the offhand.
226 227 228 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 226 def wield_weapon_offhand(description, skill = nil) wield_weapon_offhand?(description, skill) end |
#wield_weapon_offhand?(description, skill = nil) ⇒ Boolean
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 230 def wield_weapon_offhand?(description, skill = nil) return unless description && !description.empty? weapon = item_by_desc(description) unless weapon DRC.("Failed to match a weapon for #{description}:#{skill}") return false end if get_item?(weapon) swap_to_skill?(weapon.name, skill) if skill && weapon.swappable if DRCI.in_right_hand?(weapon) case DRC.bput('swap', /^You move/, /^Will alone cannot conquer the paralysis/) when /^You move/ return true else return false end end end return false end |
#worn_items(list) ⇒ Array<Item>
Filters the worn items based on a given list.
152 153 154 155 156 |
# File 'documented/dragonrealms/commons/equipmanager.rb', line 152 def worn_items(list) filter_gear = desc_to_items(list) gear = desc_to_items(get_combat_items) gear.select { |x| filter_gear.include?(x) } end |