Module: Verbs

Defined in:
lib/Olib/core/verbs.rb

Constant Summary collapse

SOLD =
/([\d]+) silver/
WRONG_SHOP =
/That's not quite my field/
WORTHLESS =
/worthless/

Instance Method Summary collapse

Instance Method Details

#__verbs__Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/Olib/core/verbs.rb', line 2

def __verbs__
  @verbs = "open close analyze inspect weigh".split(" ").map(&:to_sym)
  singleton = (class << self; self end)
  @verbs.each do |verb|
    singleton.send :define_method, verb do
      fput "#{verb.to_s} ##{@id}"
      self
    end
  end
end

#_drag(target) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/Olib/core/verbs.rb', line 290

def _drag(target)
  Olib.wrap("_drag ##{id} ##{target.id}") { |line|
    # order of operations is important here for jars
    raise Errors::DoesntExist          if line =~ Dictionary.put[:failure][:ne]
    raise Errors::Mundane              if line =~ Dictionary.put[:success]
    
    if line =~ Dictionary.put[:failure][:full]
      tag "full"
      raise Errors::ContainerFull
    end
  }
  self
end

#_inspectObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/Olib/core/verbs.rb', line 57

def _inspect

  return self if has? "inspect"

  in_inspect = false

  Olib.wrap_stream(action "inspect") { |line|

    raise Errors::Mundane  if line =~ /^<prompt/ and in_inspect

    # skip first inspect line because it"s useless for info
    in_inspect = true if line =~ /You carefully inspect|You carefully count|goat/

    if in_inspect
      
      if line =~ /^You estimate that (?:.*?) can store (?:a|an|some) ([a-zA-Z -]+) amount with enough space for ([a-zA-Z ]+)/
        @props["space"]           = $1
        @props["number_of_items"] = $2
      end
        

      
      if line =~ /^You determine that you could wear the (.*?) ([a-zA-Z ]+)/
        @props["location"]= $2
      end
      
      if line =~ /allows you to conclude that it is ([a-zA-Z ]+)/

        if line =~ Dictionary.size
          @props["shield_type"] = $1
        else
          Dictionary.armors.each do |type, re| @props["armor_type"] = type if line =~ re end
        end
        
      end

      if line =~ /suitable for use in unarmed combat/
        @props["weapon_type"]= "uac"
      end

      if line =~ /requires skill in ([a-zA-Z ]+) to use effectively/
    
        @props["weapon_type"]= $1
        if line =~ /It appears to be a modified ([a-zA-Z -]+)/
          @props["weapon_base"]= $1
        else
          @props["weapon_base"]= @noun
        end
      end            
      
      if line =~ /^It looks like this item has been mainly crafted out of ([a-zA-Z -]+)./
        @props["material"]= $1
        raise Errors::Mundane
      end
      
      if line =~ /can hold liquids/
        @props["liquid_container"]=true
      end

    end
    
  }
  
  return self
end

#analyzeObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/Olib/core/verbs.rb', line 203

def analyze
  fput "analyze ##{id}"
  should_detect = false
  begin
    Timeout::timeout(1) do
      while(line = get)
        next                        if Dictionary.ignorable?(line)
        next                        if line =~ /sense that the item is free from merchant alteration restrictions|and sense that the item is largely free from merchant alteration restrictions|these can all be altered by a skilled merchant|please keep the messaging in mind when designing an alterations|there is no recorded information on that item|The creator has also provided the following information/
        @props["max_light"] = true  if line =~ /light as it can get/
        @props["max_deep"]  = true  if line =~ /pockets could not possibly get any deeper/
        @props["max_deep"]  = false if line =~ /pockets deepened/
        @props["max_light"] = false if line =~ /talented merchant lighten/
        if line =~ /Casting Elemental Detection/
          should_detect = true 
          next 
        end
        break                       if line =~ /pockets deepened|^You get no sense of whether|light as it can get|pockets could not possibly get any deeper|talented merchant lighten/
        @props["analyze"] = String.new unless @props["analyze"]
        @props["analyze"].concat line.strip
        @props["analyze"].concat " "
      end
    end
  
  rescue Timeout::Error
    # Silent
  end
  detect if should_detect
  temp_analysis = @props["analyze"].split(".").map(&:strip).map(&:downcase).reject {|ln| ln.empty? }
  @props["analyze"] = temp_analysis unless temp_analysis.empty?
  return self
end

#atObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/Olib/core/verbs.rb', line 13

def at
  Olib.wrap_stream("look at ##{@id}") { |line|
    if line =~ /You see nothing unusual|prompt time|You gaze through (.*?) and see...|written/
      raise Errors::Mundane
    end

    if line =~ /Looking at the (.*?), you see (?<nested>.*)/
      @nested = true

      @containers = line
        .match(/Looking at the (.*?), you see (?<nested>.*)/)[:nested]
        .scan(/<a exist="(?<id>.*?)" noun="(?<noun>.*?)">(?<name>.*?)<\/a>/)
        .map {|matches| Container.new GameObj.new *matches }
      raise Errors::Mundane
    end
    
  }
  self
end

#dropObject



270
271
272
273
274
# File 'lib/Olib/core/verbs.rb', line 270

def drop
  Script.log("#{Time.now} > dropped #{to_s}")
  fput action "drop"
  self
end

#inObject



52
53
54
55
# File 'lib/Olib/core/verbs.rb', line 52

def in
  fput "look in ##{@id}"
  self
end

#lookObject



33
34
35
# File 'lib/Olib/core/verbs.rb', line 33

def look
  self
end

#onObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/Olib/core/verbs.rb', line 37

def on
  return self unless @id
  Olib.wrap_stream("look on ##{@id}") { |line|
    raise Errors::Mundane if line =~ /There is nothing on there|prompt time/
    if line =~ /On the (.*?) you see/
      @ontop << line.match(Dictionary.contents)[:items]
        .scan(Dictionary.tag)
        .map {|matches| Item.new GameObj.new *matches }
      raise Errors::Mundane
    end
    next
  }
  self
end

#priceObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/Olib/core/verbs.rb', line 142

def price
  return self if(has? "price" or has? "info")
  Olib.wrap(action "get") { |line|

    if line =~ /(\d+) silvers/
      define "price", line.match(/(?<price>\d+) silvers/)[:price]
      raise Errors::Mundane
    end

    if line =~ /You can"t pick that up/
      define "info", true
      raise Errors::Mundane
    end

    Script.log "unmatched price: #{line}"
    
  }
  self
end

#readObject



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
# File 'lib/Olib/core/verbs.rb', line 162

def read
  return self if has? "read"
  scroll    = false
  multiline = false
  Olib.wrap_stream(action "read") {  |line|

    raise Errors::Mundane  if line =~ /^<prompt/ and (multiline or scroll)
    raise Errors::Mundane if line =~ /There is nothing there to read|You can"t do that./

    # if we are in a multiline state
    @props["read"] = @props["read"].concat line if multiline

    # capture spell
    if scroll && line =~ /\(([0-9]+)\) ([a-zA-Z"\s]+)/
        spell = OpenStruct.new(name: $2, num: $1.to_i)
        #Client.notify "Spell detected ... (#{$1}) #{$2}"
        @props["spells"].push spell

    # begin scroll
    elsif line =~ /It takes you a moment to focus on the/
      scroll = true
      @props["spells"] = Array.new 

    # open multiline
    elsif line =~ /^In the (.*?) language, it reads/
      multiline          = true
      @props["read"]     = "#{line}\n"
      @props["language"] = $1

    # alert to unknown
    elsif line =~ /but the language is not one you know.  It looks like it"s written in (.*?)./
      Script.log "Please find a friend that can read for #{$1} in #{XMLData.room_title}"
      echo "Please find a friend that can read for #{$1} in #{XMLData.room_title}"
      raise Errors::Mundane
    
    end
    
  }
  return self
end

#sellObject



280
281
282
283
284
285
286
287
288
# File 'lib/Olib/core/verbs.rb', line 280

def sell
  take
  case result = dothistimeout("sell ##{id}", 3, Regexp.union(SOLD, WRONG_SHOP, WORTHLESS))
  when SOLD        then [:sold, OpenStruct.new(name: self.name, price: $1.to_i)]
  when WRONG_SHOP  then [:wrong_shop, self]
  when WORTHLESS   then [:worthless, self]
  else                  [:unhandled_case, result]
  end
end

#takeObject



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/Olib/core/verbs.rb', line 235

def take
  return self if has? "cost"

  Olib.wrap(action "get") { |line|
    raise Errors::DoesntExist    if line=~ Dictionary.get[:failure][:ne]
    raise Errors::HandsFull      if line=~ Dictionary.get[:failure][:hands_full]
    raise Errors::TooHeavy       if line=~ Dictionary.get[:failure][:weight]
    
    if line=~ Dictionary.get[:success] 
      raise Errors::Mundane
    end  

    if line =~ Dictionary.get[:failure][:buy]
      define "cost", line.match(Dictionary.get[:failure][:buy])[:cost].to_i
      raise Errors::Mundane
    end

    if line =~ /let me help you with that/
      raise Errors::Mundane
    end

    if line=~ /You"ll have to buy it if you want it/
      tag "buyable"
      raise Errors::Mundane
    end

    if line=~ /You can PULL/
      tag "pullable"
      raise Errors::Mundane
    end

  }
  self
end

#tapObject



132
133
134
135
136
137
138
139
140
# File 'lib/Olib/core/verbs.rb', line 132

def tap
  return self if has? "description"
  Olib.wrap(action "tap") { |line|
    next unless line=~ /You tap (.*?) (on|in)/
    define "description", $1 
    raise Errors::Mundane         
  }
  self
end