From 4529adf22c9f32bc0e3ba647d54f56fcd2ad4f9f Mon Sep 17 00:00:00 2001 From: Deysh <61760541+Deysh@users.noreply.github.com> Date: Sat, 20 Jul 2024 16:41:50 -0400 Subject: [PATCH 1/5] [eherbs]v2.0.9 code consolidation mostly an update to determining inventory and the use_herb method. Combines the blood only option and removed that stand alone method as well. Also put the injury results in the escort method into a hash. No change in functionality (least none was intended. --- scripts/eherbs.lic | 765 +++++++++++++++------------------------------ 1 file changed, 244 insertions(+), 521 deletions(-) diff --git a/scripts/eherbs.lic b/scripts/eherbs.lic index 26dd98da4..be0276d10 100644 --- a/scripts/eherbs.lic +++ b/scripts/eherbs.lic @@ -14,7 +14,12 @@ game: Gemstone tags: healing, herbs requires: Lich >= 4.6.0 - version: 2.0.8 + version: 2.0.9 + 2.0.9 (2024-07-20) + - use quiet command for _injury 2 + - consolidate inventory check methods + - general code consolidation + - change log added to wiki 2.0.8 (2024-07-12) - pause script ego2 if running 2.0.7 (2024-07-12) @@ -32,117 +37,9 @@ 2.0.1 (2023-11-10) - bugfix to use id instead of name for distiller - added setting output for debugging ;eherbs settings + Previous change logs can be found on the wiki: https://gswiki.play.net/Lich:Script_Eherbs =end -=begin - Version Semantics: - Major_change.feature_addition.bugfix - 2.0.0 (2023-09-21) - - added heal down for bleeding deaders ;eherbs - - added note support when stocking herb kits - - will exit script if herbsack is full and trying to stock - - typo in available herbs - - correct FWI herb names - - corrected the logic to prioritize correctly based on UI selection - - bugfix for Lich Room# 0 go2 pathing - - bugfix for eating herbs with knife in left hand, special messaging. - 1.5.18 (2023-09-21) - - Bugfix for matching change in wealth output. - 1.5.17 (2023-06-11) - - change to 650 implementation - 1.5.16 (2023-06-01) - - bugfix added word boundary to regex for finding similarly named containers - 1.5.15 (2023-05-31) - - bugfix for stocking with similarly named containers - - added support for using the basket under the bench in RR - - bugfix for UI not greying out sigil of mending, 650, 1035 unless known - - bugfix for UI saving when x-ing out. Only saves with close button - 1.5.14 (2023-04-27) - - added support for survival kit distiller - - added support for using the basket under the bench in RR - - bugfix for UI not greying out sigil of mending, 650, 1035 unless known - - bugfix for UI saving when x-ing out. Only saves with close button - 1.5.13 (2023-03-17) - - bugfix for sigil of mending - - bugfix for leaving people at the bank - - bugfix for opening/closing containers - - added option stock survival kit as combined total of herbs and potions - 1.5.12 (2023-03-15): Tysong: remove $infomon_cutthroat reference for cutthroat? reference - 1.5.11 (2023-03-07): Deysh: Update to drinkable regex - 1.5.10 (2023-03-05): Deysh: bugfix in UI that didn't grey out 650 or 1035 if not known - 1.5.9 (2023-03-05): Deysh: urchin guide was not returning to same herbalist after silver withdraw - 1.5.8 (2023-03-03): Deysh: old UI file was used in last submission - 1.5.7 (2023-02-26): Deysh: fixed the 'in,on,under,behind' options, added some additional inventory handling, added check for casting spells; added toggle for depositing silver - 1.5.6 (2023-02-25): Deysh: Update herb identification to use noun instead of name; bugfix for stock entry in UI; added a wait until healed for cutthroat - 1.5.5 (2023-02-22): Deysh: Update fragrant woth flower in FWI dosage from 2 to 3; misc typo fix - 1.5.4 (2023-02-20): Xanlin: typo fix, old compat fixes - 1.5.3 (2023-02-20): Deysh: fix to CLI bug, UI not keeping settings, checks on 650 - 1.5.2 (2023-02-20): Deysh: bug fixes for exec_string monitor of measuring; stop coin deposit unless buying - 1.5.1 (2023-02-19): Deysh: bug fixes for skip_scars and Utility.set_preferences; Clean up of stocking routine - 1.5.0 (2023-02-17): Deysh: Added support for survival kits. - 1.4.7 (2023-01-23): Xanlin: winterberry order fix - 1.4.6 (2022-12-16): Xanlin: revert 1.4.4, restores override for cli options - 1.4.5 (2022-12-11): Deysh: Added UI - 1.4.4 (2022-11-29): Tysong: Fix to exit after setting change from CLI - 1.4.3 (2022-09-22): Xanlin: Fix override behavior - 1.4.2 (2022-09-18): Xanlin: River's Rest winterberry brew - 1.4.1 (2022-09-17): Xanlin: update instance variable when preferences set. Changed internal name for skip-scars to skip_scars and use-mending to use_mending. - 1.4.0 (2022-09-12): Xanlin: added ;eherbs check, fixed under and behind containers, - converted to module, replaced version check with shims, refactored procs to methods. - 1.3.0 (2022-07-16): - Updated River's Rest herbs, removed minor head wound from available herbs - in River's Rest. - Refactored stock function to count appropriately and track stocking measures - Added feature to stock specifc herb type (;eherbs stock major head wound) - Added feature to get blood only (;eherbs blood) and ignore wounds - Improved (;eherbs list) to accept herb type (;eherbs list major head wound) - this feature also accepts partials (;eherbs list minor) - 1.2.0 (2022-05-23): - Fix for gambling kit open/close/get/put regex. - 1.1.3 (2022-05-19): - Fix for gambling kit open/close/get/put regex. - 1.1.2 (2022-04-06): - Fix for a/an ordering from menus - 1.1.1 (2022-04-04): - Add LICH_VERSION check - 1.1.0 (2022-04-03): - Rewrote fill and stock functions to detect those regions that only - sell tinctures, tarts and various assorted non-bundling type herbs - Corrected multiple errors in initial data tables for locations / herbs - 1.0.0 (2022-02-27): - Global RENAME to ;eherbs - Rewrote stock function to work at any herbalist - Rewrote stock function to account for any 'type' of herb, so for example - acantha leaf, acantha tea, Bloody Krolvin ale all count towards - total doses of 'blood' herb. - - Previously as ;useherbs - 0.14 (2022-01-25): - fix for handedness and herbs (mistaken stick for sticky and so on) - 0.13 (2021-12-17): - updated for KF herbs - 0.12 (2020-10-10): - response message for buying herbs now has commas - 0.11 (2020-10-07): - changed fill function to go to closest herbalist instead of a single hardcoded one, update for commas - 0.10 (2017-09-30): - add feature to fill your herbsack with herbs (;useherbs stock herbs) - 0.9 (2017-03-04): - remove 506 from the script, since it doesn't affect eating herbs anymore - 0.8 (2017-01-14): - withdraw @silvers first when using the "stock potions" command - 0.7 (2015-04-26): - fix for working with hidden containers, like the basket in Ta'Vaalor - 0.6 (2015-03-28): - remember to look on/under/behind a container instead of "in" if a second look is required - fix bug with finding a herbsack given on the command line - 0.5 (2015-02-23): - better method of finding container from herbsack setting - 0.4 (2014-12-12): - make "stock potions" track potion use instead of measuring every time - 0.3 (2014-11-14): - set herbsack with ;useherbs set herbsack -=end # FIXME: escort healing doesn't heal blood # fixme: garland of sovyn cloves @@ -292,7 +189,6 @@ module EHerbs } settings_hash[:note] = nil - settings_hash[:note_names] = ['salt-stained kraken chit', 'Icemule promissory note', 'Borthuum Mining Company scrip', "Wehnimer's promissory note", 'Torren promissory note', 'mining chit', 'City-States promissory note', 'Vornavis promissory note', 'Mist Harbor promissory note'] settings_hash[:open_regex] = Regexp.union( /You throw back/i, @@ -984,78 +880,6 @@ module EHerbs end module Actions - def self.blood_only - return unless (checkhealth + 7) < maxhealth - drinkable = false - - if EHerbs.data[:herb_sack].nil? - EHerbs.data[:herb_sack] = Utility.find_herbsack - Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) - end - - if EHerbs.data[:survival_kit] - if EHerbs.data[:use_yaba] - contents = Inventory.survival_contents(EHerbs.data[:herb_sack]) - herb = contents.find_all { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) and h[:type] == 'blood' } } - yaba = herb.find { |h| h.name =~ /yabathilium/ } - herb = yaba - end - if EHerbs.data[:use_potions] && herb.nil? - contents = Inventory.survival_contents(EHerbs.data[:herb_sack], 'drinkable') - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) and h[:type] == 'blood' } } - end - if !EHerbs.data[:use_potions] && herb.nil? - contents = Inventory.survival_contents(EHerbs.data[:herb_sack], 'edible') - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) and h[:type] == 'blood' } } - end - if herb.nil? - contents = Inventory.survival_contents(EHerbs.data[:herb_sack]) - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) and h[:type] == 'blood' } } - end - - else - if EHerbs.data[:use_yaba] - herb = EHerbs.data[:herb_sack].contents.find_all { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) and h[:type] == 'blood' } } - yaba = herb.find { |h| h.name =~ /yabathilium/ } - herb = yaba.nil? ? herb.first : yaba - end - if EHerbs.data[:use_potions] && herb.nil? - herb = EHerbs.data[:herb_sack].contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) and h[:type] == 'blood' and i.name =~ EHerbs.data[:drinkable] } } - end - if !EHerbs.data[:use_potions] && herb.nil? - herb = EHerbs.data[:herb_sack].contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) and h[:type] == 'blood' and i.name !~ EHerbs.data[:drinkable] } } - end - if herb.nil? - herb ||= EHerbs.data[:herb_sack].contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) and h[:type] == 'blood' } } - end - end - - if herb - Inventory.stow_herb - unless EHerbs.data[:no_get] && (herb.name !~ EHerbs.data[:drinkable]) - drinkable = Inventory.drag_to_hand(herb) - end - - Actions.cast_spells - - use_cmd = (herb.name =~ EHerbs.data[:drinkable] || drinkable) ? "drink ##{herb.id}" : "eat ##{herb.id}" - - while (checkhealth + 7) < maxhealth - use_result = dothistimeout use_cmd, 5, /^You (?:manage to )?take a (?:bite|drink)|Using your/ - if use_result.nil? - echo 'fixme 5' - exit - else - EHerbs.data[:used_herbs].push(herb.id) unless EHerbs.data[:used_herbs].include?(herb.id) - Utility.wait_rt - end - end - else - EHerbs.data[:skippable].push 'blood' if herb_type == 'blood' - respond "\nMissing herb for #{herb_type}.\n\n #{EHerbs.known_herbs.find_all { |h| h[:type] == 'blood' }.collect { |h| h[:name] }.join(', ')}\n\n" - end - end - def self.bundle_all(herb = nil) EHerbs.data[:herb_sack] = Utility.find_herbsack if EHerbs.data[:herb_sack].nil? return if EHerbs.data[:survival_kit] @@ -1184,7 +1008,8 @@ module EHerbs herb_name = EHerbs.data[:herb_shop_menu].keys.find { |name| EHerbs.known_herbs.any? { |h| (h[:type] == herb_type) and (name == h[:name] || name == h[:short_name]) } } unless (order_number = EHerbs.data[:herb_shop_menu][herb_name]) _respond - _respond Msg.monsterbold(" error: failed to find a herb for #{herb_type} in the menu") + _respond Msg.monsterbold(" error: failed to find #{herb_name} for #{herb_type} in the menu") + _respond "shop menu: #{EHerbs.data[:herb_shop_menu]}" _respond exit end @@ -1335,7 +1160,6 @@ module EHerbs if EHerbs.data[:herb_sack].nil? EHerbs.data[:herb_sack] = Utility.find_herbsack - Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) end empty_right_hand @@ -1364,14 +1188,9 @@ module EHerbs herb = GameObj.left_hand else Inventory.stow_herb + contents = Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) - if EHerbs.data[:survival_kit] - contents = Inventory.survival_contents(EHerbs.data[:herb_sack], 'drinkable') - else - contents = Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) - end - - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type && h[:name] =~ EHerbs.data[:drinkable] } } + herb = contents[:drinkable].find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type } } unless herb.nil? EHerbs.data[:used_herbs].push(herb.id) unless EHerbs.data[:used_herbs].include?(herb.id) @@ -1381,7 +1200,7 @@ module EHerbs dothistimeout "close ##{EHerbs.data[:herb_sack].id}", 5, EHerbs.data[:close_regex] if EHerbs.data[:close_herbsack] exit elsif get_result =~ /^You need a free hand for that\./ - echo 'fixme 28382' + echo 'fixme no freehand in self.deader(character)' dothistimeout "close ##{EHerbs.data[:herb_sack].id}", 5, EHerbs.data[:close_regex] if EHerbs.data[:close_herbsack] exit end @@ -1430,148 +1249,39 @@ module EHerbs elsif look_result =~ /^(?:She|He) appears to be in good shape\./ echo 'nothing to do' elsif look_result =~ /^(?:She|He) has/ + injury_patterns = { + /severe head trauma and bleeding from the ears/ => ['major head wound', 'major head wound', 'minor head wound'], + /minor lacerations about the head and a possible mild concussion/ => ['major head wound', 'minor head wound'], + /snapped bones and serious bleeding from the neck/ => ['major head wound', 'major head wound', 'minor head wound'], + /moderate bleeding from (?:his|her) neck/ => ['major head wound', 'minor head wound'], + /deep gashes and serious bleeding from (?:his|her) chest/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) chest/ => ['major organ wound', 'minor organ wound'], + /deep gashes and serious bleeding from (?:his|her) abdomen/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) abdomen/ => ['major organ wound', 'minor organ wound'], + /deep gashes and serious bleeding from (?:his|her) back/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) back/ => ['major organ wound', 'minor organ wound'], + /a blinded (right|left) eye/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /a swollen (right|left) eye/ => ['major organ wound', 'minor organ wound'], + /a completely severed (right|left) leg|arm|hand/ => ['major limb wound', 'major limb wound', 'minor limb wound'], + /a fractured and bleeding (right|left) leg|arm|hand/ => ['major limb wound', 'minor limb wound'], + /a case of uncontrollable convulsions|a case of sporadic convulsions/ => ['major nerve wound', 'minor nerve wound'], + /minor bruises about the head/ => ['minor head wound'], + /minor bruises on (?:his|her) neck/ => ['minor head wound'], + /minor cuts and bruises on (?:his|her) chest/ => ['minor organ wound'], + /minor cuts and bruises on (?:his|her) abdomen/ => ['minor organ wound'], + /minor cuts and bruises on (?:his|her) back/ => ['minor organ wound'], + /a bruised (right|left) eye/ => ['minor organ wound'], + /some minor cuts and bruises on (?:his|her) (right|left) leg|arm|hand/ => ['minor limb wound'], + /a strange case of muscle twitching/ => ['minor nerve wound'] + } + escort_injuries = [] - if look_result =~ /severe head trauma and bleeding from the ears/ - escort_injuries.push('major head wound') - escort_injuries.push('major head wound') - escort_injuries.push('minor head wound') - end - if look_result =~ /minor lacerations about the head and a possible mild concussion/ - escort_injuries.push('major head wound') - escort_injuries.push('minor head wound') - end - if look_result =~ /snapped bones and serious bleeding from the neck/ - escort_injuries.push('major head wound') - escort_injuries.push('major head wound') - escort_injuries.push('minor head wound') - end - if look_result =~ /moderate bleeding from (?:his|her) neck/ - escort_injuries.push('major head wound') - escort_injuries.push('minor head wound') - end - if look_result =~ /deep gashes and serious bleeding from (?:his|her) chest/ - escort_injuries.push('major organ wound') - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /deep lacerations across (?:his|her) chest/ - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /deep gashes and serious bleeding from (?:his|her) abdomen/ - escort_injuries.push('major organ wound') - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /deep lacerations across (?:his|her) abdomen/ - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /deep gashes and serious bleeding from (?:his|her) back/ - escort_injuries.push('major organ wound') - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /deep lacerations across (?:his|her) back/ - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /a blinded right eye/ - # escort_injuries.push('missing eye') - escort_injuries.push('major organ wound') - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /a blinded left eye/ - # escort_injuries.push('missing eye') - escort_injuries.push('major organ wound') - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /a swollen right eye/ - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /a swollen left eye/ - escort_injuries.push('major organ wound') - escort_injuries.push('minor organ wound') - end - if look_result =~ /a completely severed right leg/ - escort_injuries.push('major limb wound') - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a completely severed left leg/ - escort_injuries.push('major limb wound') - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a completely severed right arm/ - escort_injuries.push('major limb wound') - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a completely severed left arm/ - escort_injuries.push('major limb wound') - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a completely severed right hand/ - escort_injuries.push('major limb wound') - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a completely severed left hand/ - escort_injuries.push('major limb wound') - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a fractured and bleeding right leg/ - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a fractured and bleeding left leg/ - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a fractured and bleeding right arm/ - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a fractured and bleeding left arm/ - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a fractured and bleeding right hand/ - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a fractured and bleeding left hand/ - escort_injuries.push('major limb wound') - escort_injuries.push('minor limb wound') - end - if look_result =~ /a case of uncontrollable convulsions/ - escort_injuries.push('major nerve wound') - escort_injuries.push('minor nerve wound') - end - if look_result =~ /a case of sporadic convulsions/ - escort_injuries.push('major nerve wound') - escort_injuries.push('minor nerve wound') - end - escort_injuries.push('minor head wound') if look_result =~ /minor bruises (about the head)/ - escort_injuries.push('minor head wound') if look_result =~ /minor bruises on (?:his|her) neck/ - escort_injuries.push('minor organ wound') if look_result =~ /minor cuts and bruises on (?:his|her) chest/ - escort_injuries.push('minor organ wound') if look_result =~ /minor cuts and bruises on (?:his|her) abdomen/ - escort_injuries.push('minor organ wound') if look_result =~ /minor cuts and bruises on (?:his|her) back/ - escort_injuries.push('minor organ wound') if look_result =~ /a bruised right eye/ - escort_injuries.push('minor organ wound') if look_result =~ /a bruised left eye/ - escort_injuries.push('minor limb wound') if look_result =~ /some minor cuts and bruises on (?:his|her) right leg/ - escort_injuries.push('minor limb wound') if look_result =~ /some minor cuts and bruises on (?:his|her) left leg/ - escort_injuries.push('minor limb wound') if look_result =~ /some minor cuts and bruises on (?:his|her) right arm/ - escort_injuries.push('minor limb wound') if look_result =~ /some minor cuts and bruises on (?:his|her) left arm/ - escort_injuries.push('minor limb wound') if look_result =~ /some minor cuts and bruises on (?:his|her) right hand/ - escort_injuries.push('minor limb wound') if look_result =~ /some minor cuts and bruises on (?:his|her) left hand/ - escort_injuries.push('minor nerve wound') if look_result =~ /a strange case of muscle twitching/ + + injury_patterns.each do |pattern, injuries| + if look_result =~ pattern + escort_injuries.concat(injuries) + end + end # echo escort_injuries.inspect empty_right_hand @@ -1584,9 +1294,9 @@ module EHerbs herb = GameObj.left_hand else Inventory.stow_herb - contents = EHerbs.data[:survival_kit] ? Inventory.survival_contents(EHerbs.data[:herb_sack]) : EHerbs.data[:herb_sack].contents + contents = Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) - if (herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] == i.name) && h[:type] == herb_type } }) + if (herb = contents[:all].find { |i| EHerbs.known_herbs.find { |h| (h[:name] == i.name) && h[:type] == herb_type } }) EHerbs.data[:used_herbs].push(herb.id) unless EHerbs.data[:used_herbs].include?(herb.id) get_result = dothistimeout "get ##{herb.id}", 5, EHerbs.data[:get_regex] if get_result.nil? || (get_result =~ /^Get what\?/) @@ -1594,7 +1304,7 @@ module EHerbs dothistimeout "close ##{EHerbs.data[:herb_sack].id}", 5, EHerbs.data[:close_regex] if EHerbs.data[:close_herbsack] exit elsif get_result =~ /^You need a free hand for that\./ - echo 'fixme 28382' + echo 'fixme no freehand in escort' dothistimeout "close ##{EHerbs.data[:herb_sack].id}", 5, EHerbs.data[:close_regex] if EHerbs.data[:close_herbsack] exit end @@ -1626,12 +1336,12 @@ module EHerbs Utility.store_herb(item) end - contents = EHerbs.data[:survival_kit] ? Inventory.survival_contents(EHerbs.data[:herb_sack]) : EHerbs.data[:herb_sack].contents + contents = Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) herb_type_fill = [] types = ['blood', 'major head wound', 'minor head wound', 'major head scar', 'minor head scar', 'major organ wound', 'minor organ wound', 'major organ scar', 'minor organ scar', 'missing eye', 'major limb wound', 'minor limb wound', 'major limb scar', 'minor limb scar', 'severed limb', 'major nerve wound', 'minor nerve wound', 'major nerve scar', 'minor nerve scar'] types.each do |kind| - herb_type_fill.push(kind) unless contents.any? { |obj| EHerbs.known_herbs.any? { |herb| (herb[:name] =~ /#{obj.name}/ || herb[:short_name] =~ /#{obj.name}/) && herb[:type] == kind } } + herb_type_fill.push(kind) unless contents[:all].any? { |obj| EHerbs.known_herbs.any? { |herb| (herb[:name] =~ /#{obj.name}/ || herb[:short_name] =~ /#{obj.name}/) && herb[:type] == kind } } end unless herb_type_fill.empty? @@ -1655,14 +1365,8 @@ module EHerbs fill_hands end - if did_something - msg = ' Done - you have one of each herb available at this location.' - else - msg = ' Nothing to do - you have one of each herb available at this location.' - end - _respond - _respond Msg.monsterbold(msg) + _respond Msg.monsterbold("#{did_something ? 'Done' : 'Nothing to do'} - you have one of each herb available at this location.") _respond exit end @@ -1836,57 +1540,67 @@ module EHerbs return item end + def self.find_herb(contents, herb_type) + known_herbs = EHerbs.known_herbs + + # Find yabathilium if the type is 'blood' and use_yaba is enabled + return contents[:all].find { |i| i.name =~ /yabathilium/ } if herb_type == 'blood' && EHerbs.data[:use_yaba] + + # Find an edible herb of the specified type + unless EHerbs.data[:use_potions] + herb = contents[:edible].find { |i| known_herbs.any? { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type } } + return herb if herb + end + + # Find a drinkable herb of the specified type + if EHerbs.data[:use_potions] + herb = contents[:drinkable].find { |i| known_herbs.any? { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type } } + return herb if herb + end + + # Find any herb of the specified type + contents[:all].find { |i| known_herbs.any? { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type } } + end + + def self.track_missing(herb_type) + case herb_type + when /head/ + EHerbs.data[:skippable].push 'head' + EHerbs.data[:skippable].push 'neck' + when /organ|missing eye/ + EHerbs.data[:skippable].push 'torso' + when /limb/ + EHerbs.data[:skippable].push 'limbs' + when /nerve/ + EHerbs.data[:skippable].push 'nerves' + when 'blood' + EHerbs.data[:skippable].push 'blood' + else + EHerbs.data[:skippable].push herb_type + end + respond "\nMissing herb for #{herb_type}.\n\n #{EHerbs.known_herbs.find_all { |h| h[:type] == herb_type }.collect { |h| h[:name] }.join(', ')}\n\n" + end + def self.use_herbs drinkable = false + herb = nil if EHerbs.data[:herb_sack].nil? EHerbs.data[:herb_sack] = Utility.find_herbsack - Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) end - while (herb_type = Utility.next_herb_type) - herb = nil - if EHerbs.known_herbs.any? { |h| h[:type] == herb_type && (h[:name] =~ /#{GameObj.right_hand.name}/ || (h[:short_name] =~ /#{GameObj.right_hand.name}/)) } - herb = GameObj.right_hand - elsif EHerbs.known_herbs.any? { |h| h[:type] == herb_type && (h[:name] =~ /#{GameObj.left_hand.name}/ || (h[:short_name] && h[:short_name] =~ /#{GameObj.left_hand.name}/)) } - herb = GameObj.left_hand - elsif [Wounds.leftArm, Wounds.rightArm].min < 3 - Utility.go2(EHerbs.data[:start_room].id.to_s) if EHerbs.data[:return_to_stow] - if EHerbs.data[:survival_kit] - if herb_type == 'blood' && EHerbs.data[:use_yaba] && herb.nil? - contents = Inventory.survival_contents(EHerbs.data[:herb_sack]) - herb = contents.find_all { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type } } - yaba = herb.find { |h| h.name =~ /yabathilium/ } - herb = yaba - end - if !EHerbs.data[:use_potions] && herb.nil? - contents = Inventory.survival_contents(EHerbs.data[:herb_sack], 'edible') - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type } } - end - if EHerbs.data[:use_potions] && herb.nil? - contents = Inventory.survival_contents(EHerbs.data[:herb_sack], 'drinkable') - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type } } - end - if herb.nil? - contents = Inventory.survival_contents(EHerbs.data[:herb_sack]) - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) && h[:type] == herb_type } } - end - else - contents = Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) - if herb_type == 'blood' && EHerbs.data[:use_yaba] && herb.nil? - herb = contents.find_all { |i| EHerbs.known_herbs.find { |h| (h[:name] == i.name || h[:short_name] == i.name) && h[:type] == herb_type } } - yaba = herb.find { |h| h.name =~ /yabathilium/ } - herb = yaba.nil? ? herb.first : yaba - end - if !EHerbs.data[:use_potions] && herb.nil? - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] == i.name || h[:short_name] == i.name) && h[:type] == herb_type && i.name !~ EHerbs.data[:drinkable] } } - end - if EHerbs.data[:use_potions] && herb.nil? - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] == i.name || h[:short_name] == i.name) && h[:type] == herb_type && i.name =~ EHerbs.data[:drinkable] } } - end - if herb.nil? - herb = contents.find { |i| EHerbs.known_herbs.find { |h| (h[:name] == i.name || h[:short_name] == i.name) && h[:type] == herb_type } } - end + while (herb_type = EHerbs.data[:blood_only] ? 'blood' : Utility.next_herb_type) + break if (checkhealth + 7) >= maxhealth && EHerbs.data[:blood_only] + herb = [GameObj.right_hand, GameObj.left_hand].find do |i| + EHerbs.known_herbs.any? do |h| + h[:type] == herb_type && (h[:name] =~ /#{i.name}/ || h[:short_name] =~ /#{i.name}/) end + end + + if [Wounds.leftArm, Wounds.rightArm].min < 3 && herb.nil? + Utility.go2(EHerbs.data[:start_room].id.to_s) if EHerbs.data[:return_to_stow] + contents = Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) + herb = Actions.find_herb(contents, herb_type) + if herb Inventory.stow_herb unless EHerbs.data[:no_get] && (herb.name !~ EHerbs.data[:drinkable]) @@ -1895,7 +1609,7 @@ module EHerbs end end - if EHerbs.data[:buy_missing] == true && herb.nil? + if EHerbs.data[:buy_missing] && herb.nil? && !EHerbs.data[:blood_only] Inventory.stow_herb EHerbs.data[:silvers] = Utility.check_silver unless EHerbs.data[:silvers] Actions.withdraw unless EHerbs.data[:silvers] > 4000 @@ -1936,22 +1650,7 @@ module EHerbs exit end else - case herb_type - when /head/ - EHerbs.data[:skippable].push 'head' - EHerbs.data[:skippable].push 'neck' - when /organ|missing eye/ - EHerbs.data[:skippable].push 'torso' - when /limb/ - EHerbs.data[:skippable].push 'limbs' - when /nerve/ - EHerbs.data[:skippable].push 'nerves' - when 'blood' - EHerbs.data[:skippable].push 'blood' - else - EHerbs.data[:skippable].push herb_type - end - respond "\nMissing herb for #{herb_type}.\n\n #{EHerbs.known_herbs.find_all { |h| h[:type] == herb_type }.collect { |h| h[:name] }.join(', ')}\n\n" + Actions.track_missing(herb_type) end end end @@ -1978,7 +1677,7 @@ module EHerbs exit end - EHerbs.data[:note] = [GameObj.right_hand, GameObj.left_hand].find { |i| EHerbs.data[:note_names].any? { |s| s.include?(i.name) } } + EHerbs.data[:note] = [GameObj.right_hand, GameObj.left_hand].find { |i| i.noun =~ /^(?:note|scrip|chit)$/ } Inventory.drag_to_container(EHerbs.data[:note].id, EHerbs.data[:herb_sack].id) fill_hand @@ -2109,9 +1808,6 @@ module EHerbs result_contents.scan(%r{(:?) (.*?) \((.*?)\)}).each do |_, exist, _noun, _name, count| $eherbs_measure[exist] = count.to_i end - - contents = Inventory.survival_contents(EHerbs.data[:herb_sack], type) - else type = nil EHerbs.data[:herb_sack].contents.each do |obj| @@ -2121,11 +1817,10 @@ module EHerbs dothistimeout "measure ##{obj.id}", 10, /^The .*? left/ dothistimeout "put ##{obj.id} in ##{EHerbs.data[:herb_sack].id}", 10, EHerbs.data[:put_regex] end - - contents = EHerbs.data[:herb_sack].contents - end + contents = Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) + seek_type_list.each do |bippity| # Check if the type of herb we want is available. herb_type = case type @@ -2143,11 +1838,11 @@ module EHerbs herb_list_items = case type when 'drinkable' - contents.find_all { |obj| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{obj.name}/ || h[:short_name] =~ /#{obj.name}/ || h[:short_name].include?(obj.name.sub('elixir', ''))) && h[:type] == bippity && h[:name] =~ EHerbs.data[:drinkable] } } + contents[:drinkable].find_all { |obj| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{obj.name}/ || h[:short_name] =~ /#{obj.name}/ || h[:short_name].include?(obj.name.sub('elixir', ''))) && h[:type] == bippity && h[:name] =~ EHerbs.data[:drinkable] } } when 'edible' - contents.find_all { |obj| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{obj.name}/ || h[:short_name] =~ /#{obj.name}/ || h[:short_name].include?(obj.name.sub('elixir', ''))) && h[:type] == bippity && h[:name] !~ EHerbs.data[:drinkable] } } + contents[:edible].find_all { |obj| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{obj.name}/ || h[:short_name] =~ /#{obj.name}/ || h[:short_name].include?(obj.name.sub('elixir', ''))) && h[:type] == bippity && h[:name] !~ EHerbs.data[:drinkable] } } else - contents.find_all { |obj| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{obj.name}/ || h[:short_name] =~ /#{obj.name}/ || h[:short_name].include?(obj.name.sub('elixir', ''))) && h[:type] == bippity } } + contents[:all].find_all { |obj| EHerbs.known_herbs.find { |h| (h[:name] =~ /#{obj.name}/ || h[:short_name] =~ /#{obj.name}/ || h[:short_name].include?(obj.name.sub('elixir', ''))) && h[:type] == bippity } } end total_doses = 0 @@ -2176,6 +1871,7 @@ module EHerbs end def self.herb_container_contents_load(container = nil) + contents = nil under_contents = behind_contents = on_contents = in_contents = nil # If passed a string check if its part of the inventory @@ -2194,89 +1890,109 @@ module EHerbs if EHerbs.data[:survival_kit] return Inventory.survival_contents(container) else - return EHerbs.data[:herb_sack].contents + contents = EHerbs.data[:herb_sack].contents + #return EHerbs.data[:herb_sack].contents end - end + else - # If still here then the container is still a string - lets find it - EHerbs.data[:herb_sack] = (GameObj.room_desc.to_a + GameObj.loot.to_a).find { |obj| obj.name =~ /#{container}/ } + # If still here then the container is still a string - lets find it + EHerbs.data[:herb_sack] = (GameObj.room_desc.to_a + GameObj.loot.to_a).find { |obj| obj.name =~ /#{container}/ } - if EHerbs.data[:herb_sack].nil? - _respond Msg.monsterbold(" Not able to find a #{container}. Exiting...") - exit - end + if EHerbs.data[:herb_sack].nil? + _respond Msg.monsterbold(" Not able to find a #{container}. Exiting...") + exit + end - unless EHerbs.data[:herb_sack].instance_of?(GameObj) - (GameObj.room_desc.to_a + GameObj.loot.to_a).each { |thing| - ["in", "on", "under", "behind"].each { |preposition| - result = Utility.get_lines("look #{preposition} #{thing}", %r{(.*?)<\/a>/) - matches.each do |match| - if match[1] =~ /#{container}/ || match[2] =~ /#{container}/ - EHerbs.data[:herb_sack] = GameObj.new(match[0], match[1], match[2]) - break + unless EHerbs.data[:herb_sack].instance_of?(GameObj) + (GameObj.room_desc.to_a + GameObj.loot.to_a).each { |thing| + ["in", "on", "under", "behind"].each { |preposition| + result = Utility.get_lines("look #{preposition} #{thing}", %r{(.*?)<\/a>/) + matches.each do |match| + if match[1] =~ /#{container}/ || match[2] =~ /#{container}/ + EHerbs.data[:herb_sack] = GameObj.new(match[0], match[1], match[2]) + break + end end - end + break if EHerbs.data[:herb_sack] + } break if EHerbs.data[:herb_sack] } - break if EHerbs.data[:herb_sack] - } - end + end - EHerbs.data[:preposition] = EHerbs.data[:preposition].nil? ? 'in' : EHerbs.data[:preposition] + EHerbs.data[:preposition] = EHerbs.data[:preposition].nil? ? 'in' : EHerbs.data[:preposition] - loop do - result = Utility.get_lines("look #{EHerbs.data[:preposition]} ##{EHerbs.data[:herb_sack].id}", %r{(In|On|Under|Behind) .*?exist="(-?\d+)" noun="(.*?)">(.*?)(.*?)(.*?)(?::| you see )(.*?)$} - under_contents = Regexp.last_match(4) - break - when %r{Behind .*?exist="(-?\d+)" noun="(.*?)">(.*?)(?::| you see )(.*?)$} - behind_contents = Regexp.last_match(4) - break - when %r{On .*?exist="(-?\d+)" noun="(.*?)">(.*?)(?::| you see )(.*?)$} - on_contents = Regexp.last_match(4) - break - when %r{In .*?exist="(-?\d+)" noun="(.*?)">(.*?)(?::| you see )(.*?)$} - in_contents = Regexp.last_match(4) - break - when %r{That is closed.} - unless EHerbs.data[:preposition] == 'in' + case result + when %r{Under .*?exist="(-?\d+)" noun="(.*?)">(.*?)(?::| you see )(.*?)$} + under_contents = Regexp.last_match(4) break - end + when %r{Behind .*?exist="(-?\d+)" noun="(.*?)">(.*?)(?::| you see )(.*?)$} + behind_contents = Regexp.last_match(4) + break + when %r{On .*?exist="(-?\d+)" noun="(.*?)">(.*?)(?::| you see )(.*?)$} + on_contents = Regexp.last_match(4) + break + when %r{In .*?exist="(-?\d+)" noun="(.*?)">(.*?)(?::| you see )(.*?)$} + in_contents = Regexp.last_match(4) + break + when %r{That is closed.} + unless EHerbs.data[:preposition] == 'in' + break + end - result = Inventory.open_single_container(EHerbs.data[:herb_sack]) - if result == 'locked' - _respond Msg.monsterbold(" Not able to look in #{container}. It's locked. Exiting...") - exit + result = Inventory.open_single_container(EHerbs.data[:herb_sack]) + if result == 'locked' + _respond Msg.monsterbold(" Not able to look in #{container}. It's locked. Exiting...") + exit + end + else + break end - else - break end - end - case EHerbs.data[:preposition] - when 'under' - result_contents = under_contents - when 'behind' - result_contents = behind_contents - when 'on' - result_contents = on_contents - when 'in' - result_contents = in_contents - end + case EHerbs.data[:preposition] + when 'under' + result_contents = under_contents + when 'behind' + result_contents = behind_contents + when 'on' + result_contents = on_contents + when 'in' + result_contents = in_contents + end - contents = [] - result_contents.scan(%r{(.*?)}).each do |exist, noun, name| - contents.push(GameObj.new_inv(exist, noun, name, EHerbs.data[:herb_sack].id.to_s)) + contents = [] + result_contents.scan(%r{(.*?)}).each do |exist, noun, name| + contents.push(GameObj.new_inv(exist, noun, name, EHerbs.data[:herb_sack].id.to_s)) + end + + contents = contents.dup.reject do |obj| + found_herb = EHerbs.known_herbs.find { |herb| herb[:name] =~ /#{obj.name}/ } + next true unless found_herb + end end - contents = contents.dup.reject do |obj| - found_herb = EHerbs.known_herbs.find { |herb| herb[:name] =~ /#{obj.name}/ } - next true unless found_herb + # Now that we have the contensts lets seperate by edible/drinkable + items = { + drinkable: [], + edible: [], + all: [] + } + + contents.each do |h| + next unless h.type == 'herb' + if h.name =~ EHerbs.data[:drinkable] + items[:drinkable].push(h) + else + items[:edible].push(h) + end + items[:all].push(h) end - contents + + return items end def self.open_single_container(sack) @@ -2324,21 +2040,36 @@ module EHerbs def self.survival_contents(container, type = nil) result = Utility.get_lines("look in ##{container.id}", %r{(In|On|Under|Behind) .*?exist="(-?\d+)" noun="(.*?)">(.*?)(.*?) contains DOSEs (.*?)\.} - liquid_result_contents = Regexp.last_match(5) if result =~ %r{^(.*?)The.*?exist="(-?\d+)" noun="(.*?)">(.*?) contains TINCTUREs (.*?)\.} + # Initialize the contents hash with drinkable and edible arrays + contents = { + drinkable: [], + edible: [], + all: [] + } - result_contents = case type - when 'drinkable' - liquid_result_contents.to_s - when 'edible' - edible_result_contents.to_s - else - liquid_result_contents.to_s + edible_result_contents.to_s - end + # Extract contents for edible and drinkable items + if result =~ %r{^(.*?)The.*?exist="(-?\d+)" noun="(.*?)">(.*?) contains DOSEs (.*?)\.} + edible_result_contents = Regexp.last_match(5) + end - contents = [] - result_contents.scan(%r{(:?) (.*?) (\(\d+\))}).each do |_what, exist, noun, name| - contents.push(GameObj.new_inv(exist, noun, name, EHerbs.data[:herb_sack].id.to_s)) + if result =~ %r{^(.*?)The.*?exist="(-?\d+)" noun="(.*?)">(.*?) contains TINCTUREs (.*?)\.} + liquid_result_contents = Regexp.last_match(5) + end + + # If edible_result_contents is not nil, parse and add items to the edible array + if edible_result_contents + edible_result_contents.scan(%r{(:?) (.*?) (\(\d+\))}).each do |_what, exist, noun, name| + contents[:edible].push(GameObj.new_inv(exist, noun, name, EHerbs.data[:herb_sack].id.to_s)) + contents[:all].push(GameObj.new_inv(exist, noun, name, EHerbs.data[:herb_sack].id.to_s)) + end + end + + # If liquid_result_contents is not nil, parse and add items to the drinkable array + if liquid_result_contents + liquid_result_contents.scan(%r{(:?) (.*?) (\(\d+\))}).each do |_what, exist, noun, name| + contents[:drinkable].push(GameObj.new_inv(exist, noun, name, EHerbs.data[:herb_sack].id.to_s)) + contents[:all].push(GameObj.new_inv(exist, noun, name, EHerbs.data[:herb_sack].id.to_s)) + end end contents @@ -2365,19 +2096,6 @@ module EHerbs container = Script.current.vars[0] container = EHerbs.data[:herb_container] if container.nil? && !EHerbs.data[:herb_container].to_s.empty? - - if container == EHerbs.data[:herb_container] - need_bundle = false - Inventory.herb_container_contents_load(container) - EHerbs.data[:herb_sack].contents.each { |herb| - next unless herb.type =~ /herb/ - unless $eherbs_measure.key?(herb.id.to_s) - need_bundle = true - end - } - Actions.bundle_all if need_bundle - end - contents = Inventory.herb_container_contents_load(container) if contents.nil? || contents.empty? @@ -2386,16 +2104,20 @@ module EHerbs end if container == EHerbs.data[:herb_container] - contents.each do |obj| - h = EHerbs.known_herbs.find { |herb| (herb[:name] =~ /#{obj.name}/) } - next unless h - - $eherbs_measure = {} unless $eherbs_measure.key?(obj.id.to_s) + need_bundle = false + contents = Inventory.herb_container_contents_load(container) + contents[:all].each do |herb| + next unless herb.type =~ /herb/ + need_bundle = true unless $eherbs_measure.key?(herb.id.to_s) + $eherbs_measure = {} unless $eherbs_measure.key?(herb.id.to_s) end + Actions.bundle_all if need_bundle end herb_types = ['poison', 'disease', 'blood', 'minor head wound', 'major head wound', 'minor head scar', 'major head scar', 'minor nerve wound', 'major nerve wound', 'minor nerve scar', 'major nerve scar', 'minor organ wound', 'major organ wound', 'minor organ scar', 'major organ scar', 'missing eye', 'minor limb wound', 'major limb wound', 'minor limb scar', 'major limb scar', 'severed limb'] EHerbs.known_herbs.each { |h| herb_types << h[:type] unless herb_types.include?(h[:type]) } + + # Fixme Inventory.get_current_stock(herb_types, nil) if container == EHerbs.data[:herb_container] check_list = {} @@ -2405,7 +2127,7 @@ module EHerbs # Check for Terminal-table have_terminal_table = Utility.check_terminal_table - contents.each do |obj| + contents[:all].each do |obj| matching_herb = EHerbs.known_herbs.find { |herb| (herb[:name] =~ /#{obj.name}/) } next unless matching_herb @@ -2416,7 +2138,7 @@ module EHerbs if container == EHerbs.data[:herb_container] check_list[t][:amount] = 0 - multiple_herbs = contents.find_all { |herb| herb.name =~ /#{obj.name}/ } + multiple_herbs = contents[:all].find_all { |herb| herb.name =~ /#{obj.name}/ } multiple_herbs.each { |item| check_list[t][:amount] += $eherbs_measure[item.id.to_s] } @@ -3141,7 +2863,12 @@ module EHerbs def self.test # Method to test pieces of code - Actions.check_prices + if EHerbs.data[:herb_sack].nil? + EHerbs.data[:herb_sack] = Utility.find_herbsack + end + + echo Utility.test_survival_contents(EHerbs.data[:herb_sack]) + exit end @@ -3240,7 +2967,7 @@ module EHerbs end # refresh XML display of wounds/scars incase missing an injury - Game.puts '_injury 2' + EHerbs::Utility.get_lines('_injury 2', / Date: Sat, 20 Jul 2024 16:47:59 -0400 Subject: [PATCH 2/5] rubocop cleanup --- scripts/eherbs.lic | 50 ++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/scripts/eherbs.lic b/scripts/eherbs.lic index be0276d10..1229276cf 100644 --- a/scripts/eherbs.lic +++ b/scripts/eherbs.lic @@ -40,7 +40,6 @@ Previous change logs can be found on the wiki: https://gswiki.play.net/Lich:Script_Eherbs =end - # FIXME: escort healing doesn't heal blood # fixme: garland of sovyn cloves # fixme: skip more better @@ -1250,29 +1249,29 @@ module EHerbs echo 'nothing to do' elsif look_result =~ /^(?:She|He) has/ injury_patterns = { - /severe head trauma and bleeding from the ears/ => ['major head wound', 'major head wound', 'minor head wound'], - /minor lacerations about the head and a possible mild concussion/ => ['major head wound', 'minor head wound'], - /snapped bones and serious bleeding from the neck/ => ['major head wound', 'major head wound', 'minor head wound'], - /moderate bleeding from (?:his|her) neck/ => ['major head wound', 'minor head wound'], - /deep gashes and serious bleeding from (?:his|her) chest/ => ['major organ wound', 'major organ wound', 'minor organ wound'], - /deep lacerations across (?:his|her) chest/ => ['major organ wound', 'minor organ wound'], - /deep gashes and serious bleeding from (?:his|her) abdomen/ => ['major organ wound', 'major organ wound', 'minor organ wound'], - /deep lacerations across (?:his|her) abdomen/ => ['major organ wound', 'minor organ wound'], - /deep gashes and serious bleeding from (?:his|her) back/ => ['major organ wound', 'major organ wound', 'minor organ wound'], - /deep lacerations across (?:his|her) back/ => ['major organ wound', 'minor organ wound'], - /a blinded (right|left) eye/ => ['major organ wound', 'major organ wound', 'minor organ wound'], - /a swollen (right|left) eye/ => ['major organ wound', 'minor organ wound'], - /a completely severed (right|left) leg|arm|hand/ => ['major limb wound', 'major limb wound', 'minor limb wound'], - /a fractured and bleeding (right|left) leg|arm|hand/ => ['major limb wound', 'minor limb wound'], - /a case of uncontrollable convulsions|a case of sporadic convulsions/ => ['major nerve wound', 'minor nerve wound'], - /minor bruises about the head/ => ['minor head wound'], - /minor bruises on (?:his|her) neck/ => ['minor head wound'], - /minor cuts and bruises on (?:his|her) chest/ => ['minor organ wound'], - /minor cuts and bruises on (?:his|her) abdomen/ => ['minor organ wound'], - /minor cuts and bruises on (?:his|her) back/ => ['minor organ wound'], - /a bruised (right|left) eye/ => ['minor organ wound'], - /some minor cuts and bruises on (?:his|her) (right|left) leg|arm|hand/ => ['minor limb wound'], - /a strange case of muscle twitching/ => ['minor nerve wound'] + /severe head trauma and bleeding from the ears/ => ['major head wound', 'major head wound', 'minor head wound'], + /minor lacerations about the head and a possible mild concussion/ => ['major head wound', 'minor head wound'], + /snapped bones and serious bleeding from the neck/ => ['major head wound', 'major head wound', 'minor head wound'], + /moderate bleeding from (?:his|her) neck/ => ['major head wound', 'minor head wound'], + /deep gashes and serious bleeding from (?:his|her) chest/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) chest/ => ['major organ wound', 'minor organ wound'], + /deep gashes and serious bleeding from (?:his|her) abdomen/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) abdomen/ => ['major organ wound', 'minor organ wound'], + /deep gashes and serious bleeding from (?:his|her) back/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) back/ => ['major organ wound', 'minor organ wound'], + /a blinded (right|left) eye/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /a swollen (right|left) eye/ => ['major organ wound', 'minor organ wound'], + /a completely severed (right|left) leg|arm|hand/ => ['major limb wound', 'major limb wound', 'minor limb wound'], + /a fractured and bleeding (right|left) leg|arm|hand/ => ['major limb wound', 'minor limb wound'], + /a case of uncontrollable convulsions|a case of sporadic convulsions/ => ['major nerve wound', 'minor nerve wound'], + /minor bruises about the head/ => ['minor head wound'], + /minor bruises on (?:his|her) neck/ => ['minor head wound'], + /minor cuts and bruises on (?:his|her) chest/ => ['minor organ wound'], + /minor cuts and bruises on (?:his|her) abdomen/ => ['minor organ wound'], + /minor cuts and bruises on (?:his|her) back/ => ['minor organ wound'], + /a bruised (right|left) eye/ => ['minor organ wound'], + /some minor cuts and bruises on (?:his|her) (right|left) leg|arm|hand/ => ['minor limb wound'], + /a strange case of muscle twitching/ => ['minor nerve wound'] } escort_injuries = [] @@ -1891,7 +1890,6 @@ module EHerbs return Inventory.survival_contents(container) else contents = EHerbs.data[:herb_sack].contents - #return EHerbs.data[:herb_sack].contents end else @@ -2037,7 +2035,7 @@ module EHerbs Inventory.herb_container_contents_load(EHerbs.data[:herb_sack]) if %w[under behind].include?(EHerbs.data[:preposition]) && relook == true end - def self.survival_contents(container, type = nil) + def self.survival_contents(container) result = Utility.get_lines("look in ##{container.id}", %r{(In|On|Under|Behind) .*?exist="(-?\d+)" noun="(.*?)">(.*?) Date: Sat, 20 Jul 2024 16:51:24 -0400 Subject: [PATCH 3/5] and more rubocop --- scripts/eherbs.lic | 47 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/scripts/eherbs.lic b/scripts/eherbs.lic index 1229276cf..e30f87b9e 100644 --- a/scripts/eherbs.lic +++ b/scripts/eherbs.lic @@ -1249,31 +1249,32 @@ module EHerbs echo 'nothing to do' elsif look_result =~ /^(?:She|He) has/ injury_patterns = { - /severe head trauma and bleeding from the ears/ => ['major head wound', 'major head wound', 'minor head wound'], - /minor lacerations about the head and a possible mild concussion/ => ['major head wound', 'minor head wound'], - /snapped bones and serious bleeding from the neck/ => ['major head wound', 'major head wound', 'minor head wound'], - /moderate bleeding from (?:his|her) neck/ => ['major head wound', 'minor head wound'], - /deep gashes and serious bleeding from (?:his|her) chest/ => ['major organ wound', 'major organ wound', 'minor organ wound'], - /deep lacerations across (?:his|her) chest/ => ['major organ wound', 'minor organ wound'], - /deep gashes and serious bleeding from (?:his|her) abdomen/ => ['major organ wound', 'major organ wound', 'minor organ wound'], - /deep lacerations across (?:his|her) abdomen/ => ['major organ wound', 'minor organ wound'], - /deep gashes and serious bleeding from (?:his|her) back/ => ['major organ wound', 'major organ wound', 'minor organ wound'], - /deep lacerations across (?:his|her) back/ => ['major organ wound', 'minor organ wound'], - /a blinded (right|left) eye/ => ['major organ wound', 'major organ wound', 'minor organ wound'], - /a swollen (right|left) eye/ => ['major organ wound', 'minor organ wound'], - /a completely severed (right|left) leg|arm|hand/ => ['major limb wound', 'major limb wound', 'minor limb wound'], - /a fractured and bleeding (right|left) leg|arm|hand/ => ['major limb wound', 'minor limb wound'], - /a case of uncontrollable convulsions|a case of sporadic convulsions/ => ['major nerve wound', 'minor nerve wound'], - /minor bruises about the head/ => ['minor head wound'], - /minor bruises on (?:his|her) neck/ => ['minor head wound'], - /minor cuts and bruises on (?:his|her) chest/ => ['minor organ wound'], - /minor cuts and bruises on (?:his|her) abdomen/ => ['minor organ wound'], - /minor cuts and bruises on (?:his|her) back/ => ['minor organ wound'], - /a bruised (right|left) eye/ => ['minor organ wound'], - /some minor cuts and bruises on (?:his|her) (right|left) leg|arm|hand/ => ['minor limb wound'], - /a strange case of muscle twitching/ => ['minor nerve wound'] + /severe head trauma and bleeding from the ears/ => ['major head wound', 'major head wound', 'minor head wound'], + /minor lacerations about the head and a possible mild concussion/ => ['major head wound', 'minor head wound'], + /snapped bones and serious bleeding from the neck/ => ['major head wound', 'major head wound', 'minor head wound'], + /moderate bleeding from (?:his|her) neck/ => ['major head wound', 'minor head wound'], + /deep gashes and serious bleeding from (?:his|her) chest/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) chest/ => ['major organ wound', 'minor organ wound'], + /deep gashes and serious bleeding from (?:his|her) abdomen/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) abdomen/ => ['major organ wound', 'minor organ wound'], + /deep gashes and serious bleeding from (?:his|her) back/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /deep lacerations across (?:his|her) back/ => ['major organ wound', 'minor organ wound'], + /a blinded (right|left) eye/ => ['major organ wound', 'major organ wound', 'minor organ wound'], + /a swollen (right|left) eye/ => ['major organ wound', 'minor organ wound'], + /a completely severed (right|left) leg|arm|hand/ => ['major limb wound', 'major limb wound', 'minor limb wound'], + /a fractured and bleeding (right|left) leg|arm|hand/ => ['major limb wound', 'minor limb wound'], + /a case of uncontrollable convulsions|a case of sporadic convulsions/ => ['major nerve wound', 'minor nerve wound'], + /minor bruises about the head/ => ['minor head wound'], + /minor bruises on (?:his|her) neck/ => ['minor head wound'], + /minor cuts and bruises on (?:his|her) chest/ => ['minor organ wound'], + /minor cuts and bruises on (?:his|her) abdomen/ => ['minor organ wound'], + /minor cuts and bruises on (?:his|her) back/ => ['minor organ wound'], + /a bruised (right|left) eye/ => ['minor organ wound'], + /some minor cuts and bruises on (?:his|her) (right|left) leg|arm|hand/ => ['minor limb wound'], + /a strange case of muscle twitching/ => ['minor nerve wound'] } + escort_injuries = [] injury_patterns.each do |pattern, injuries| From 720312ce8fed0409f080c2cc74cce70e0ca49193 Mon Sep 17 00:00:00 2001 From: Deysh <61760541+Deysh@users.noreply.github.com> Date: Sat, 20 Jul 2024 16:53:07 -0400 Subject: [PATCH 4/5] 3 rubocops a charm --- scripts/eherbs.lic | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/eherbs.lic b/scripts/eherbs.lic index e30f87b9e..328a4dbe3 100644 --- a/scripts/eherbs.lic +++ b/scripts/eherbs.lic @@ -1274,16 +1274,13 @@ module EHerbs /a strange case of muscle twitching/ => ['minor nerve wound'] } - escort_injuries = [] - injury_patterns.each do |pattern, injuries| if look_result =~ pattern escort_injuries.concat(injuries) end end - # echo escort_injuries.inspect empty_right_hand escort_injuries.each do |herb_type| From e58b8d89b63fa4f83f8e5aa078db6e151c741ec6 Mon Sep 17 00:00:00 2001 From: Deysh <61760541+Deysh@users.noreply.github.com> Date: Mon, 29 Jul 2024 05:48:05 -0400 Subject: [PATCH 5/5] update change log with note change --- scripts/eherbs.lic | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/eherbs.lic b/scripts/eherbs.lic index 328a4dbe3..2fe7a54f8 100644 --- a/scripts/eherbs.lic +++ b/scripts/eherbs.lic @@ -16,6 +16,7 @@ requires: Lich >= 4.6.0 version: 2.0.9 2.0.9 (2024-07-20) + - change note variable to just use the noun instead of full name - use quiet command for _injury 2 - consolidate inventory check methods - general code consolidation