Olib 0.1.2 → 2.0.0.pre.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/Olib.gemspec +1 -1
  3. data/README.md +0 -0
  4. data/TODOS.md +0 -0
  5. data/lib/Olib.rb +6 -79
  6. data/lib/Olib/actor/actor.rb +0 -0
  7. data/lib/Olib/area.rb +22 -37
  8. data/lib/Olib/bounty.rb +8 -10
  9. data/lib/Olib/character/char.rb +64 -68
  10. data/lib/Olib/character/disk.rb +31 -9
  11. data/lib/Olib/character/group.rb +122 -40
  12. data/lib/Olib/character/inventory.rb +0 -0
  13. data/lib/Olib/character/mind.rb +0 -0
  14. data/lib/Olib/character/stance.rb +0 -0
  15. data/lib/Olib/combat/creature.rb +77 -128
  16. data/lib/Olib/combat/creatures.rb +52 -36
  17. data/lib/Olib/core/action.rb +8 -0
  18. data/lib/Olib/core/container.rb +32 -236
  19. data/lib/Olib/core/containers.rb +42 -0
  20. data/lib/Olib/core/errors.rb +69 -71
  21. data/lib/Olib/core/exist.rb +88 -0
  22. data/lib/Olib/core/item.rb +43 -598
  23. data/lib/Olib/core/kinds.rb +6 -0
  24. data/lib/Olib/core/rummage.rb +42 -0
  25. data/lib/Olib/core/transaction.rb +53 -0
  26. data/lib/Olib/core/use.rb +2 -5
  27. data/lib/Olib/core/utils.rb +25 -123
  28. data/lib/Olib/core/verbs.rb +304 -0
  29. data/lib/Olib/dictionary/dictionary.rb +150 -150
  30. data/lib/Olib/ext/hash.rb +7 -0
  31. data/lib/Olib/ext/matchdata.rb +14 -0
  32. data/lib/Olib/ext/string.rb +9 -0
  33. data/lib/Olib/ext/symbol.rb +13 -0
  34. data/lib/Olib/go2.rb +48 -112
  35. data/lib/Olib/loot.rb +44 -0
  36. data/lib/Olib/npcs/npc.rb +4 -0
  37. data/lib/Olib/npcs/npcs.rb +45 -0
  38. data/lib/Olib/objects/box.rb +1 -1
  39. data/lib/Olib/objects/clothing.rb +1 -1
  40. data/lib/Olib/objects/herb.rb +1 -1
  41. data/lib/Olib/objects/jar.rb +0 -0
  42. data/lib/Olib/objects/jewel.rb +7 -7
  43. data/lib/Olib/objects/jewelry.rb +1 -1
  44. data/lib/Olib/objects/scroll.rb +1 -1
  45. data/lib/Olib/objects/uncommon.rb +1 -1
  46. data/lib/Olib/objects/wand.rb +1 -1
  47. data/lib/Olib/pattern_matching/any.rb +11 -0
  48. data/lib/Olib/pattern_matching/err.rb +4 -0
  49. data/lib/Olib/pattern_matching/ok.rb +4 -0
  50. data/lib/Olib/pattern_matching/outcome.rb +35 -0
  51. data/lib/Olib/pattern_matching/pattern_matching.rb +5 -0
  52. data/lib/Olib/pattern_matching/result.rb +80 -0
  53. data/lib/Olib/pattern_matching/rill.rb +43 -0
  54. data/lib/Olib/pattern_matching/where.rb +4 -0
  55. data/lib/Olib/shops.rb +147 -155
  56. data/lib/Olib/supervisor/supervisor.rb +0 -0
  57. data/lib/Olib/version.rb +1 -1
  58. data/lib/Olib/xml.rb +43 -0
  59. metadata +28 -15
  60. data/lib/Olib/core/extender.rb +0 -29
  61. data/lib/Olib/interface/queryable.rb +0 -50
  62. data/lib/Olib/npcs.rb +0 -5
  63. data/lib/Olib/pattern.rb +0 -34
  64. data/lib/Olib/storage/app_data.rb +0 -32
  65. data/lib/Olib/try/try.rb +0 -58
  66. data/lib/Olib/utils/cli.rb +0 -81
  67. data/lib/Olib/utils/help_menu.rb +0 -166
  68. data/lib/Olib/utils/monsterbold.rb +0 -5
  69. data/lib/Olib/utils/vbulletin.rb +0 -101
@@ -1,168 +1,168 @@
1
1
  require "ostruct"
2
2
 
3
- module Olib
4
- class Dictionary < OpenStruct
5
- def Dictionary.heirloom
6
- re = {}
7
- re[:is] = /are the initials ([A-Z]{2})./
8
- re[:give] = /Excellent. I'm sure the person who lost this will be quite happy/
9
- re
10
- end
11
3
 
12
- def Dictionary.tag
13
- /<a exist="(?<id>.*?)" noun="(?<noun>.*?)">(?<name>.*?)<\/a>/
14
- end
4
+ class Dictionary < OpenStruct
5
+ def Dictionary.heirloom
6
+ re = {}
7
+ re[:is] = /are the initials ([A-Z]{2})./
8
+ re[:give] = /Excellent. I'm sure the person who lost this will be quite happy/
9
+ re
10
+ end
15
11
 
16
- def Dictionary.contents
17
- /(On|In) the (.*?) you see (?<items>.*)/
18
- end
12
+ def Dictionary.tag
13
+ /<a exist="(?<id>.*?)" noun="(?<noun>.*?)">(?<name>.*?)<\/a>/
14
+ end
19
15
 
20
- def Dictionary.ignorable?(line)
21
- line =~ /You feel less drained|You feel at full magical power again|\[LNet\]|GSIV|moving stealthily into the room|glides into view|soars out of sight|You notice (.*?) moving stealthily out|[A-Z][a-z]+ says, "|(removes|put) a (.*?) from in (his|her)|just opened (a|an)|just went|You gesture|Your spell is ready|just bit the dust|joins the adventure|just arrived|returns home from a hard day of adventuring|no longer effective|You sense that your attunement|You do not feel drained anymore|You feel the magic of your spell depart/
22
- end
16
+ def Dictionary.contents
17
+ /(On|In) the (.*?) you see (?<items>.*)/
18
+ end
23
19
 
24
- def Dictionary.targetable
25
- re = {}
26
- re[:yes] = /^You are now targeting/
27
- re[:no] = /^You can't target/
28
- re
29
- end
30
- def Dictionary.bounty
31
- re = {}
32
- re[:herb] = /requires (?:a|an|some) ([a-zA-Z '-]+) found (?:in|on|around) ([a-zA-Z '-]+). These samples must be in pristine condition. You have been tasked to retrieve ([0-9]+)/
33
- re[:escort] = /Go to the (.*?) and WAIT for (?:him|her|them) to meet you there. You must guarantee (?:his|her|their) safety to ([a-zA-Z '-]+) as soon as/
34
- re[:gem] = /has received orders from multiple customers requesting (?:a|an|some) ([a-zA-Z '-]+). You have been tasked to retrieve ([0-9]+)/
35
- re[:heirloom] = /You have been tasked to recover ([a-zA-Z '-]+) that an unfortunate citizen lost after being attacked by (a|an|some) ([a-zA-Z '-]+) (in|on|around|near|by) ([a-zA-Z '-]+)./
36
- re[:heirloom_found] = /^You have located the heirloom and should bring it back to/
37
- re[:turn_in] = /You have succeeded in your task and can return to the Adventurer's Guild to receive your reward/
38
- re[:guard_turn_in] = /^You succeeded in your task and should report back to/
39
- re[:guard_bounty] = /Go report to ([a-zA-Z ]+) to find out more/
40
- re[:cull] = /^You have been tasked to suppress (^((?!bandit).)*$) activity (?:in|on) (?:the )? (.*?)(?: near| between| under|\.) ([a-zA-Z' ]+). You need to kill ([0-9]+)/
41
- re[:bandits] = /^You have been tasked to suppress bandit activity (?:in |on )(?:the )(.*?)(?: near| between| under) ([a-zA-Z' ]+). You need to kill ([0-9]+)/
42
- re[:dangerous] = /You have been tasked to hunt down and kill a particularly dangerous (.*) that has established a territory (?:in|on) (?:the )?(.*?)(?: near| between| under|\.)/
43
- re[:get_skin_bounty] = /The local furrier/
44
- re[:get_herb_bounty] = /local herbalist|local healer|local alchemist/
45
- re[:get_gem_bounty] = /The local gem dealer, ([a-zA-Z ]+), has an order to fill and wants our help/
46
- re[:creature_problem] = /It appears they have a creature problem they\'d like you to solve/
47
- re[:rescue] = /A local divinist has had visions of the child fleeing from (?:a|an) (.*) (?:in|on) (?:the )?(.*?)(?: near| between| under|\.)/
20
+ def Dictionary.ignorable?(line)
21
+ line =~ /You feel less drained|You feel at full magical power again|\[LNet\]|GSIV|moving stealthily into the room|glides into view|soars out of sight|You notice (.*?) moving stealthily out|[A-Z][a-z]+ says, "|(removes|put) a (.*?) from in (his|her)|just opened (a|an)|just went|You gesture|Your spell is ready|just bit the dust|joins the adventure|just arrived|returns home from a hard day of adventuring|no longer effective|You sense that your attunement|You do not feel drained anymore|You feel the magic of your spell depart/
22
+ end
48
23
 
49
- re[:failed_bounty] = /You have failed in your task/
50
- re[:get_bounty] = /You are not currently assigned a task/
51
-
52
- end
53
- def Dictionary.bandit_traps
54
- re = {}
55
- re[:net] = /Suddenly, a carefully concealed net springs up from the ground, completely entangling you/
56
- re[:jaws] = /large pair of carefully concealed metal jaws slam shut on your/
57
- re[:wire] = /stumbled right into a length of nearly invisible razor wire/
58
- re[:pouch] = /of air as you realize you've just stepped on a carefully concealed inflated pouch/
59
- re[:rope] = /wrapping around your ankle and tossing you up into the air/
60
- re[:spikes] = /from under you as you fall into a shallow pit filled with tiny spikes/
61
- re[:net] = /completely entangling you/
62
- re[:net_end] = /The net entangling you rips and falls apart/
63
- re[:hidden] = /You hear a voice shout|leaps|flies from the shadows toward you/
64
- re[:fail] = /You spy/
65
- re[:statue] = /A faint silvery light flickers from the shadows/
66
- re
67
- end
24
+ def Dictionary.targetable
25
+ re = {}
26
+ re[:yes] = /^You are now targeting/
27
+ re[:no] = /^You can't target/
28
+ re
29
+ end
30
+
31
+ def Dictionary.bounty
32
+ re = {}
33
+ re[:herb] = /requires (?:a|an|some) ([a-zA-Z '-]+) found (?:in|on|around) ([a-zA-Z '-]+). These samples must be in pristine condition. You have been tasked to retrieve ([0-9]+)/
34
+ re[:escort] = /Go to the (.*?) and WAIT for (?:him|her|them) to meet you there. You must guarantee (?:his|her|their) safety to ([a-zA-Z '-]+) as soon as/
35
+ re[:gem] = /has received orders from multiple customers requesting (?:a|an|some) ([a-zA-Z '-]+). You have been tasked to retrieve ([0-9]+)/
36
+ re[:heirloom] = /You have been tasked to recover ([a-zA-Z '-]+) that an unfortunate citizen lost after being attacked by (a|an|some) ([a-zA-Z '-]+) (in|on|around|near|by) ([a-zA-Z '-]+)./
37
+ re[:heirloom_found] = /^You have located the heirloom and should bring it back to/
38
+ re[:turn_in] = /You have succeeded in your task and can return to the Adventurer's Guild to receive your reward/
39
+ re[:guard_turn_in] = /^You succeeded in your task and should report back to/
40
+ re[:guard_bounty] = /Go report to ([a-zA-Z ]+) to find out more/
41
+ re[:cull] = /^You have been tasked to suppress (^((?!bandit).)*$) activity (?:in|on) (?:the )? (.*?)(?: near| between| under|\.) ([a-zA-Z' ]+). You need to kill ([0-9]+)/
42
+ re[:bandits] = /^You have been tasked to suppress bandit activity (?:in |on )(?:the )(.*?)(?: near| between| under) ([a-zA-Z' ]+). You need to kill ([0-9]+)/
43
+ re[:dangerous] = /You have been tasked to hunt down and kill a particularly dangerous (.*) that has established a territory (?:in|on) (?:the )?(.*?)(?: near| between| under|\.)/
44
+ re[:get_skin_bounty] = /The local furrier/
45
+ re[:get_herb_bounty] = /local herbalist|local healer|local alchemist/
46
+ re[:get_gem_bounty] = /The local gem dealer, ([a-zA-Z ]+), has an order to fill and wants our help/
47
+ re[:creature_problem] = /It appears they have a creature problem they\'d like you to solve/
48
+ re[:rescue] = /A local divinist has had visions of the child fleeing from (?:a|an) (.*) (?:in|on) (?:the )?(.*?)(?: near| between| under|\.)/
49
+
50
+ re[:failed_bounty] = /You have failed in your task/
51
+ re[:get_bounty] = /You are not currently assigned a task/
68
52
 
69
- def Dictionary.shop
70
- db = {}
71
- db[:success] = /^You hand over|You place your/
72
- db[:failure] = {}
73
- db[:failure][:missing] = /^There is nobody here to buy anything from/
74
- db[:failure][:silvers] = /^The merchant frowns and says/
75
- db[:failure][:full] = /^There's no more room for anything else/
76
- db[:failure][:own] = /^Buy your own merchandise?/
77
- db
78
- end
79
- def Dictionary.gems
80
- re = {}
81
- # Expressions to match interaction with gems
82
- re[:appraise] = {}
83
- re[:appraise][:gemshop] = /inspects it carefully before saying, "I'll give you ([0-9]+) for it if you want to sell/
84
- re[:appraise][:player] = /You estimate that the ([a-zA-Z '-]+) is of ([a-zA-Z '-]+) quality and worth approximately ([0-9]+) silvers/
85
- re[:appraise][:failure] = /As best you can tell, the ([a-zA-Z '-]+) is of average quality/
86
- re[:singularize] = Proc.new do |str|
87
- str.gsub(/ies$/, 'y').gsub(/zes$/,'z').gsub(/s$/,'').gsub(/large |medium |containing |small |tiny |some /, '').strip
88
- end
89
- re
90
- end
53
+ end
54
+ def Dictionary.bandit_traps
55
+ re = {}
56
+ re[:net] = /Suddenly, a carefully concealed net springs up from the ground, completely entangling you/
57
+ re[:jaws] = /large pair of carefully concealed metal jaws slam shut on your/
58
+ re[:wire] = /stumbled right into a length of nearly invisible razor wire/
59
+ re[:pouch] = /of air as you realize you've just stepped on a carefully concealed inflated pouch/
60
+ re[:rope] = /wrapping around your ankle and tossing you up into the air/
61
+ re[:spikes] = /from under you as you fall into a shallow pit filled with tiny spikes/
62
+ re[:net] = /completely entangling you/
63
+ re[:net_end] = /The net entangling you rips and falls apart/
64
+ re[:hidden] = /You hear a voice shout|leaps|flies from the shadows toward you/
65
+ re[:fail] = /You spy/
66
+ re[:statue] = /A faint silvery light flickers from the shadows/
67
+ re
68
+ end
91
69
 
92
- def Dictionary.get
93
- re = {}
94
- re[:failure] = {}
95
- # Expressions to match `get` verb results
96
- re[:failure][:weight] = /You are unable to handle the additional load/
97
- re[:failure][:hands_full] = /^You need a free hand to pick that up/
98
- re[:failure][:ne] = /^Get what/
99
- re[:failure][:buy] = /(is|for|be) (?<cost>[0-9]+) (silvers|coins)/
100
- re[:failure][:race] = /be (?<cost>[0-9]+) (silvers|coins) for someone like you/
101
- re[:failure][:pshop] = /^Looking closely/
102
- re[:success] = /^You carefully|^You unsheathe|^You shield|^You discreetly|^You gather|^You pick up|^You remove|^You rummage|^You draw|^You grab|^You reach|^You already|^You gather/
103
- re
104
- end
70
+ def Dictionary.shop
71
+ db = {}
72
+ db[:success] = /^You hand over|You place your/
73
+ db[:failure] = {}
74
+ db[:failure][:missing] = /^There is nobody here to buy anything from/
75
+ db[:failure][:silvers] = /^The merchant frowns and says/
76
+ db[:failure][:full] = /^There's no more room for anything else/
77
+ db[:failure][:own] = /^Buy your own merchandise?/
78
+ db
79
+ end
80
+ def Dictionary.gems
81
+ re = {}
82
+ # Expressions to match interaction with gems
83
+ re[:appraise] = {}
84
+ re[:appraise][:gemshop] = /inspects it carefully before saying, "I'll give you ([0-9]+) for it if you want to sell/
85
+ re[:appraise][:player] = /You estimate that the ([a-zA-Z '-]+) is of ([a-zA-Z '-]+) quality and worth approximately ([0-9]+) silvers/
86
+ re[:appraise][:failure] = /As best you can tell, the ([a-zA-Z '-]+) is of average quality/
87
+ re[:singularize] = Proc.new do |str|
88
+ str.gsub(/ies$/, 'y').gsub(/zes$/,'z').gsub(/s$/,'').gsub(/large |medium |containing |small |tiny |some /, '').strip
89
+ end
90
+ re
91
+ end
92
+
93
+ def Dictionary.get
94
+ re = {}
95
+ re[:failure] = {}
96
+ # Expressions to match `get` verb results
97
+ re[:failure][:weight] = /You are unable to handle the additional load/
98
+ re[:failure][:hands_full] = /^You need a free hand to pick that up/
99
+ re[:failure][:ne] = /^Get what/
100
+ re[:failure][:buy] = /(is|for|be) (?<cost>[0-9]+) (silvers|coins)/
101
+ re[:failure][:race] = /be (?<cost>[0-9]+) (silvers|coins) for someone like you/
102
+ re[:failure][:pshop] = /^Looking closely/
103
+ re[:success] = /^You carefully|^You unsheathe|^You shield|^You discreetly|^You gather|^You pick up|^You remove|^You rummage|^You draw|^You grab|^You reach|^You already|^You gather/
104
+ re
105
+ end
106
+
107
+ def Dictionary.put
108
+ re = {}
109
+ re[:failure] = {}
110
+ re[:failure][:full] = /^won't fit in the|is full!|filling it./
111
+ re[:failure][:ne] = /^I could not find what you were referring to/
112
+ re[:success] = /^Your bundle|^You attempt to shield|^As you place|^You wipe off the blade|^You discreetly|^You toss|^You carefully|^You give|^You untie your|^You put|^You absent|^You tuck|^You sheathe|^You slip|^You roll up|^You tuck|^You add|^You place/
113
+ re
114
+ end
105
115
 
106
- def Dictionary.put
107
- re = {}
108
- re[:failure] = {}
109
- re[:failure][:full] = /^won't fit in the|is full!|filling it./
110
- re[:failure][:ne] = /^I could not find what you were referring to/
111
- re[:success] = /^Your bundle|^You attempt to shield|^As you place|^You wipe off the blade|^You discreetly|^You toss|^You carefully|^You give|^You untie your|^You put|^You absent|^You tuck|^You sheathe|^You slip|^You roll up|^You tuck|^You add|^You place/
112
- re
113
- end
114
-
115
- def Dictionary.jar(name=nil)
116
- if name
117
- return name.gsub(/large |medium |containing |small |tiny |some /, '').sub 'rubies', 'ruby'
118
- else
119
- return false
120
- end
116
+ def Dictionary.jar(name=nil)
117
+ if name
118
+ return name.gsub(/large |medium |containing |small |tiny |some /, '').sub 'rubies', 'ruby'
119
+ else
120
+ return false
121
121
  end
122
+ end
122
123
 
123
- def Dictionary.armors
124
- armors = Hash.new
125
- armors['robes'] = /cloth armor/i
126
- armors['light leather'] = /soft leather armor that covers the torso only./i
127
- armors['full leather'] = /soft leather armor that covers the torso and arms./i
128
- armors['reinforced leather'] = /soft leather armor that covers the torso, arms, and legs./i
129
- armors['double leather'] = /soft leather armor that covers the torso, arms, legs, neck, and head./i
130
- armors['leather breastplate'] = /rigid leather armor that covers the torso only./i
131
- armors['cuirbouilli leather'] = /rigid leather armor that covers the torso and arms./i
132
- armors['studded leather'] = /rigid leather armor that covers the torso, arms, and legs./i
133
- armors['brigadine armor'] = /rigid leather armor that covers the torso, arms, legs, neck, and head./i
134
- armors['chain mail'] = /chain armor that covers the torso only./i
135
- armors['double chain'] = /chain armor that covers the torso and arms./i
136
- armors['augmented chain'] = /chain armor that covers the torso, arms, and legs./i
137
- armors['chain hauberk'] = /chain armor that covers the torso, arms, legs, neck, and head./i
138
- armors['metal breastplate'] = /plate armor that covers the torso only./i
139
- armors['augmented plate'] = /plate armor that covers the torso and arms./i
140
- armors['half plate'] = /plate armor that covers the torso, arms, and legs./i
141
- armors['full plate'] = /plate armor that covers the torso, arms, legs, neck, and head./i
142
- armors['DB'] = /miscellaneous armor that protects the wearer in general/
143
- armors
144
- end
124
+ def Dictionary.armors
125
+ armors = Hash.new
126
+ armors['robes'] = /cloth armor/i
127
+ armors['light leather'] = /soft leather armor that covers the torso only./i
128
+ armors['full leather'] = /soft leather armor that covers the torso and arms./i
129
+ armors['reinforced leather'] = /soft leather armor that covers the torso, arms, and legs./i
130
+ armors['double leather'] = /soft leather armor that covers the torso, arms, legs, neck, and head./i
131
+ armors['leather breastplate'] = /rigid leather armor that covers the torso only./i
132
+ armors['cuirbouilli leather'] = /rigid leather armor that covers the torso and arms./i
133
+ armors['studded leather'] = /rigid leather armor that covers the torso, arms, and legs./i
134
+ armors['brigadine armor'] = /rigid leather armor that covers the torso, arms, legs, neck, and head./i
135
+ armors['chain mail'] = /chain armor that covers the torso only./i
136
+ armors['double chain'] = /chain armor that covers the torso and arms./i
137
+ armors['augmented chain'] = /chain armor that covers the torso, arms, and legs./i
138
+ armors['chain hauberk'] = /chain armor that covers the torso, arms, legs, neck, and head./i
139
+ armors['metal breastplate'] = /plate armor that covers the torso only./i
140
+ armors['augmented plate'] = /plate armor that covers the torso and arms./i
141
+ armors['half plate'] = /plate armor that covers the torso, arms, and legs./i
142
+ armors['full plate'] = /plate armor that covers the torso, arms, legs, neck, and head./i
143
+ armors['DB'] = /miscellaneous armor that protects the wearer in general/
144
+ armors
145
+ end
145
146
 
146
- def Dictionary.size
147
- /that it is a (?<size>.*) shield that protects/
148
- end
147
+ def Dictionary.size
148
+ /that it is a (?<size>.*) shield that protects/
149
+ end
149
150
 
150
- def Dictionary.numbers
151
- numbers = Hash.new
152
- numbers['one'] = 1
153
- numbers['two'] = 2
154
- numbers['three'] = 3
155
- numbers['four'] = 4
156
- numbers['five'] = 5
157
- numbers
158
- end
151
+ def Dictionary.numbers
152
+ numbers = Hash.new
153
+ numbers['one'] = 1
154
+ numbers['two'] = 2
155
+ numbers['three'] = 3
156
+ numbers['four'] = 4
157
+ numbers['five'] = 5
158
+ numbers
159
+ end
159
160
 
160
- def Dictionary.spiked
161
- /You also notice that it is spiked./i
162
- end
161
+ def Dictionary.spiked
162
+ /You also notice that it is spiked./i
163
+ end
163
164
 
164
- def Dictionary.fusion
165
- /(?<orbs>.*?) spherical depressions adorn the (.*?), approximately the size and shape of a small gem/
166
- end
165
+ def Dictionary.fusion
166
+ /(?<orbs>.*?) spherical depressions adorn the (.*?), approximately the size and shape of a small gem/
167
167
  end
168
168
  end
@@ -0,0 +1,7 @@
1
+ require "ostruct"
2
+
3
+ class Hash
4
+ def to_struct
5
+ OpenStruct.new self
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ require "ostruct"
2
+ require "Olib/ext/string"
3
+
4
+ class MatchData
5
+ def to_struct
6
+ OpenStruct.new to_hash
7
+ end
8
+
9
+ def to_h
10
+ Hash[self.names.map(&:to_sym).zip(self.captures.map(&:strip).map do |capture|
11
+ if capture.is_i? then capture.to_i else capture end
12
+ end)]
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class String
2
+ def is_i?
3
+ !!(self =~ /\A[-+]?[0-9]+\z/)
4
+ end
5
+
6
+ def methodize
7
+ self.downcase.strip.gsub(/-|\s+|'|"/, "_").to_sym
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class Symbol
2
+ def to_game
3
+ self.to_s.gsub("_", " ")
4
+ end
5
+
6
+ def ok?
7
+ self.eql?(:ok)
8
+ end
9
+
10
+ def err?
11
+ self.eql?(:err)
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ require "Olib/ext/string"
2
+
1
3
  class Integer
2
4
  def go2
3
5
  Go2.room self
@@ -10,127 +12,61 @@ class String
10
12
  end
11
13
  end
12
14
 
13
- module Olib
15
+ class Go2
14
16
  ##
15
- ## @brief ;go2 wrapper class
17
+ ## @brief returns the filtered relevant Map db tags
16
18
  ##
17
- class Go2
18
- @@teleporter = {}
19
- @@routines = {}
20
- ##
21
- ## @brief returns the filtered relevant Map db tags
22
- ##
23
- ## @return Array
24
- ##
25
- def Go2.tags
26
- Map.tags
27
- .select { |tag| !tag.include? "=" }
28
- end
29
-
30
- ##
31
- ## dynamically assign all of our Go2#methods
32
- ##
33
- Go2.tags.each { |tag|
34
- method = Olib.methodize tag
35
-
36
- Go2.define_singleton_method(method.to_sym) do
37
- Go2.room tag
38
- end
39
- }
19
+ ## @return Array
20
+ ##
21
+ def Go2.tags
22
+ Map.tags.select { |tag| !tag.include? "=" }
23
+ end
40
24
 
41
- def Go2.room(roomid)
42
- unless Room.current.id == roomid || Room.current.tags.include?(roomid)
43
- Char.unhide if hidden
44
- start_script "go2", [roomid, "_disable_confirm_"]
45
- wait_while { running? "go2" };
46
- end
47
- Go2
48
- end
25
+ ##
26
+ ## dynamically assign all of our Go2#methods
27
+ ##
28
+ Go2.tags.each do |tag|
29
+ Go2.define_singleton_method(tag.methodize) do Go2.room(tag) end
30
+ end
49
31
 
50
- def Go2.origin
51
- Go2.room @@origin[:roomid]
52
- Char.hide if @@origin[:hidden]
53
- Go2
32
+ def Go2.room(roomid)
33
+ unless Room.current.id == roomid || Room.current.tags.include?(roomid)
34
+ Char.unhide if hidden
35
+ start_script "go2", [roomid, "_disable_confirm_"]
36
+ wait_while { running? "go2" };
54
37
  end
38
+ Go2
39
+ end
55
40
 
56
- def Go2.fwi
57
- unless Char.fwi_teleporter
58
- echo "Error: No teleport defined ;var set teleporter=<teleporter>"
59
- exit
60
- end
61
-
62
- unless Inventory.fwi_teleporter
63
- echo "Error: Your teleporter could not be found #{Go2.teleporter}"
64
- exit
65
- end
66
-
67
- last = Room.current.id
68
- teleporter = Inventory.fwi_teleporter
69
- if teleporter.worn?
70
- teleporter.turn
71
- else
72
- teleporter.take.turn.stash
73
- end
74
-
75
- if Room.current.id == last
76
- echo "Error: You tried to teleport to FWI in a room that does not allow that"
77
- end
78
-
79
- Go2
80
- end
81
-
82
- def Go2.rebase
83
- @@origin = {}
84
- @@origin[:roomid] = Room.current.id
85
- @@origin[:hidden] = hiding?
86
- @@origin[:location] = Room.current.location
87
- Olib.debug "rebasing to #{@@origin}"
88
- Go2
89
- end
41
+ def Go2.origin
42
+ Go2.room @@origin[:roomid]
43
+ Char.hide if @@origin[:hidden]
44
+ Go2
45
+ end
90
46
 
91
- Go2.rebase
47
+ def Go2.rebase
48
+ @@origin = {}
49
+ @@origin[:roomid] = Room.current.id
50
+ @@origin[:hidden] = hiding?
51
+ @@origin[:location] = Room.current.location
52
+ Go2
53
+ end
92
54
 
93
- # Thanks Tillmen
94
- def Go2.cost(to)
95
- cost = 0
96
- Map.findpath(Room.current.id, to).each { |id|
97
- Room[id].tags.each { |tag|
98
- if tag =~ /^silver-cost:#{id-1}:(.*)$/
99
- cost_string = $1
100
- if cost_string =~ /^[0-9]+$/
101
- cost += cost_string.to_i
102
- else
103
- cost = StringProc.new(cost_string).call.to_i
104
- end
55
+ # Thanks Tillmen
56
+ def Go2.cost(to)
57
+ cost = 0
58
+ Map.findpath(Room.current.id, to).each { |id|
59
+ Room[id].tags.each { |tag|
60
+ if tag =~ /^silver-cost:#{id-1}:(.*)$/
61
+ cost_string = $1
62
+ if cost_string =~ /^[0-9]+$/
63
+ cost += cost_string.to_i
64
+ else
65
+ cost = StringProc.new(cost_string).call.to_i
105
66
  end
106
- }
67
+ end
107
68
  }
108
- cost
109
- end
110
-
111
- # use the teleporter variable to locate your teleporter and teleport
112
- # naive of where you are
113
- def Go2.fwi_teleport
114
- Go2.fwi
115
- end
116
-
117
- # TODO
118
- # create a dictionary of house lockers and the logic to enter a locker
119
- # insure locker is closed before scripting away from it
120
- def Go2.locker
121
- echo "the go2_locker method currently does not function properly..."
122
- self
123
- end
124
-
125
-
126
- end
127
-
128
- def Olib.Go2
129
- Olib::Go2
69
+ }
70
+ cost
130
71
  end
131
-
132
- end
133
-
134
- class Go2 < Olib::Go2
135
- # expose on the global scope
136
72
  end