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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6e3a63b873937a4644f53fcfea7a335e3b0d2cc6
4
- data.tar.gz: 851ef4add8178845dbd0db6bd61ae42db530af57
2
+ SHA256:
3
+ metadata.gz: a3847ae46163103e49356d4e6fcc43badaa3b4ddd29a9ea3ad48c509203b5eb7
4
+ data.tar.gz: 6ff8a42a9ca26c9cf394bd311ff7095052b7a507005b34aa42d73d63f9701a79
5
5
  SHA512:
6
- metadata.gz: 8c9ba056450555b6de96ae48ef41d84d5ea670de5cee5b01fcba3acb3672d3c3f4d8b19424db236fc19532f0358a091b0758f58d1378877b52aac5771c8932b2
7
- data.tar.gz: dd6dc889f09910d1f4faf264cdb405f32d59c34e4319c8a3fe9f91efb511b9715872951c0c39550550a4f96ba85977027b9649f021a6ec03156650256b22688b
6
+ metadata.gz: eb34b92ed44adeab5c1b15e7ae65f73124d7557af2c613bef5113c7efe76607e362807553076d52f51f05b95787b93adbf65cb3893343962af82485f008098d0
7
+ data.tar.gz: c89d3853c1d5569f7ed375269a047cf7eee943dde1f5ad8b11eb9c2ffb0e1abd29bdf9df8893491afb1cd4f0b29fb1c3df440d3559fc133f8db4119d390a8856
@@ -5,7 +5,7 @@ require "Olib/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "Olib"
7
7
  s.version = Olib::VERSION
8
- s.date = "2014-09-12"
8
+ s.date = "2018-01-04"
9
9
  s.summary = "Useful Lich extensions for Gemstone IV"
10
10
  s.description = "Useful Lich extensions for Gemstone IV including hostile creature management, group management, syntactically pleasing movement, locker management, etc"
11
11
  s.authors = ["Ondreian Shamsiel"]
data/README.md CHANGED
File without changes
data/TODOS.md CHANGED
File without changes
@@ -1,83 +1,10 @@
1
- require 'net/http'
2
- require 'json'
3
1
  require "ostruct"
4
2
 
5
- class String
6
- def is_i?
7
- !!(self =~ /\A[-+]?[0-9]+\z/)
8
- end
9
- end
10
-
11
- class MatchData
12
- def to_struct
13
- OpenStruct.new to_hash
14
- end
15
-
16
- def to_hash
17
- Hash[self.names.zip(self.captures.map(&:strip).map do |capture|
18
- if capture.is_i? then capture.to_i else capture end
19
- end)]
20
- end
21
- end
22
-
23
- class Hash
24
- def to_struct
25
- OpenStruct.new self
26
- end
27
- end
28
-
29
- class Regexp
30
- def or(re)
31
- Regexp.new self.to_s + "|" + re.to_s
32
- end
33
- # define union operator for regex instance
34
- def |(re)
35
- self.or(re)
36
- end
37
- end
38
-
39
3
  module Olib
40
-
41
- def Olib.update_notifier
42
- begin
43
- response = JSON.parse Net::HTTP.get URI('https://rubygems.org/api/v1/gems/Olib.json')
44
- # check version
45
- if Gem.loaded_specs["Olib"].version < Gem::Version.new(response['version'])
46
- puts "<pushBold/>You need to update the Olib gem with a `gem install Olib`<popBold/>"
47
- end
48
- rescue
49
- echo $!
50
- puts $!.backtrace[0..1]
51
- end
52
- end
53
-
54
- def Olib.methodize(str)
55
- str.to_s.downcase.strip.gsub(/-|\s+|'|"/, "_").to_sym
56
- end
57
-
58
- # load core first
59
- Dir[File.dirname(__FILE__) + '/Olib/core/**/*.rb'].each {|file|
60
- require file
61
- }
62
-
4
+ # load ext first
5
+ Dir[File.dirname(__FILE__) + '/Olib/ext/**/*.rb'].each do |file| require(file) end
6
+ # load core next
7
+ Dir[File.dirname(__FILE__) + '/Olib/core/**/*.rb'].each do |file| require(file) end
63
8
  # load things that depend on core extensions
64
- Dir[File.dirname(__FILE__) + '/Olib/**/*.rb'].each {|file|
65
- require file
66
- }
67
-
68
- # invoke update notifier immediately
69
- # Olib.update_notifier
70
-
71
- def Olib.do(action, re)
72
- dothistimeout action, 5, re
73
- end
74
-
75
- def Olib.run(script, *args)
76
- start_script script, args
77
- wait_while { running? script }
78
- end
79
-
80
- Vars.Olib ||= Hash.new
81
-
82
-
83
- end
9
+ Dir[File.dirname(__FILE__) + '/Olib/**/*.rb'].each do |file| require(file) end
10
+ end
File without changes
@@ -1,48 +1,35 @@
1
- class Area < Olib::Container
2
- def self.contents
3
- GameObj.loot.map { |obj| Olib::Item.new(obj) }
4
- end
5
-
6
- def each
7
- self.contents.each { |item|
8
- yield item
9
- }
10
- end
11
-
12
- class << self
13
- Olib::Item.type_methods.each { |method, tag|
14
- exp = /#{tag}/
15
- define_method(method.to_sym) do
16
- GameObj.loot
17
- .select { |obj| obj.type =~ exp }
18
- .map { |obj| Olib::Item.new(obj) }
19
- end
20
- }
1
+ class Area
2
+ include Enumerable
3
+ def self.method_missing(method, *args, &block)
4
+ if respond_to?(method)
5
+ Area.new.send(method, *args, &block)
6
+ else
7
+ super(method, *args, &block)
8
+ end
21
9
  end
22
10
 
23
- def Area.deep
24
- Area.new
11
+ def self.respond_to?(method)
12
+ return super(method) unless Area.new.respond_to?(method)
13
+ return true
25
14
  end
26
15
 
27
- attr_accessor :room, :objects
16
+ attr_reader :room, :autoid, :objects
28
17
 
29
18
  def initialize
30
19
  @room = Room.current
31
- @objects = [ GameObj.loot, GameObj.room_desc ]
32
- .flatten
33
- .compact
34
- .map { |thing| thing.id }
35
- .uniq # sometimes objects exist in both loot & room_desc
36
- .map { |id| Olib::Container.new id }
20
+ @auto = XMLData.room_count
21
+ @objects = [ GameObj.loot, GameObj.room_desc ].map(&:to_a).flatten.compact.map(&:to_container)
37
22
  end
38
23
 
39
- def contents
24
+ def each(&block)
25
+ @objects.each(&block)
26
+ end
27
+
28
+ def deep
40
29
  items = []
41
- @objects
42
- .reject { |container| container.name =~ /[A-Z][a-z]+ disk/ }
43
- .each { |container|
30
+ @objects.reject { |container| container.name =~ /[A-Z][a-z]+ disk/ }.each { |container|
44
31
  check_container container
45
- item = Olib::Item.new container
32
+ item = Item.new container
46
33
  unless container.nested?
47
34
  container.contents.each { |item|
48
35
  item.container = container
@@ -58,7 +45,7 @@ class Area < Olib::Container
58
45
  end
59
46
  end
60
47
  }
61
- items.compact
48
+ items.compact.each do |item| yield(item) end
62
49
  end
63
50
 
64
51
  def check_container(container)
@@ -66,6 +53,4 @@ class Area < Olib::Container
66
53
  container.look.at.on
67
54
  end
68
55
  end
69
-
70
-
71
56
  end
@@ -35,7 +35,7 @@ class Bounty
35
35
  none: /You are not currently assigned a task/,
36
36
  skin: /^You have been tasked to retrieve (?<number>\d+) (?<skin>.*?) of at least (?<quality>.*?) quality for (?<buyer>.*?) in (?<realm>.*?)\.\s+You can SKIN them off the corpse of (a|an|some) (?<creature>.*?) or/,
37
37
 
38
- help_bandits: /You have been tasked to help (?<partner>.*?) suppress bandit activity (in|on|around) (?<area>.*?)(| near (?<realm>.*?)). You need to kill (?<number>[0-9]+)/
38
+ help_bandits: /You have been tasked to help (?<partner>.*?) suppress bandit activity (?:in|on|around) (?<area>.*?) (?:near|between|under) (?<realm>.*?). You need to kill (?<number>[0-9]+)/
39
39
  )
40
40
 
41
41
  # convenience list to get all types of bounties
@@ -59,7 +59,7 @@ class Bounty
59
59
  def Bounty.parse(str)
60
60
  type, patt = Bounty.match str
61
61
  unless patt
62
- raise Exception.new "could not match Bounty: #{str}\nplease notify Ondreian"
62
+ return OpenStruct.new
63
63
  else
64
64
  bounty = patt.match(str).to_struct
65
65
  bounty[:type] = type
@@ -159,13 +159,13 @@ class Bounty
159
159
  end
160
160
 
161
161
  def Bounty.cooldown?
162
- Spell[9003].active?
162
+ not XMLData.active_spells["Next Bounty"].nil?
163
163
  end
164
164
 
165
165
  def Bounty.cooldown!
166
166
  if Bounty.cooldown?
167
167
  Go2.origin
168
- wait_until { !Bounty.cooldown? }
168
+ wait_while { Bounty.cooldown? }
169
169
  end
170
170
  Bounty
171
171
  end
@@ -179,9 +179,9 @@ class Bounty
179
179
  msg.concat " # do something\n"
180
180
  msg.concat " }\n"
181
181
  msg.concat " \n"
182
- msg.concat "or rescue this error (Olib::Errors::Fatal) gracefully\n"
182
+ msg.concat "or rescue this error (Errors::Fatal) gracefully\n"
183
183
  msg.concat " \n"
184
- raise Olib::Errors::Fatal.new msg
184
+ raise Errors::Fatal.new msg
185
185
  end
186
186
 
187
187
  def Bounty.dispatch(listener=nil)
@@ -205,14 +205,12 @@ class Bounty
205
205
  def Bounty.find_guard
206
206
  Go2.advguard
207
207
  if Bounty.npc.nil? then Go2.advguard2 end
208
- if Bounty.npc.nil? then
209
- throw Olib::Errors::Fatal.new "could not find guard"
210
- end
208
+ throw Errors::Fatal.new "could not find guard" if Bounty.npc.nil?
211
209
  return Bounty
212
210
  end
213
211
 
214
212
  def Bounty.npc
215
- GameObj.npcs.find { |npc| npc.name =~ NPCS } ||
213
+ GameObj.npcs.find { |npc| npc.name =~ NPCS } or
216
214
  GameObj.room_desc.find { |npc| npc.name =~ NPCS }
217
215
  end
218
216
  end
@@ -1,42 +1,50 @@
1
1
  class Char
2
- EMPATH = "Empath"
2
+ INJURIES = Wounds.singleton_methods.map(&:to_s).select do |m| m.downcase == m and not m.include?("_") end.map(&:to_sym)
3
3
  Duration = Struct.new(:seconds, :minutes, :hours)
4
- INJURIES = Wounds.singleton_methods
5
- .map(&:to_s)
6
- .select do |m| m.downcase == m && m !~ /_/ end.map(&:to_sym)
7
-
8
4
  @@silvers = 0
9
- @@routines = {}
10
5
  @@aiming = nil
11
6
 
12
- def Char.hide
13
- while not hiding?
14
- waitrt?
15
- if @@routines[:hiding]
16
- @@routines[:hiding].call
17
- else
18
- fput 'hide'
19
- end
20
- end
21
- Char
7
+ def Char.spell(num)
8
+ hour, minutes, seconds = Spell[num].remaining.split(":").map(&:to_f)
9
+ total_seconds = seconds + (minutes * 60.00) + (hour * 60.00 * 60.00)
10
+
11
+ Duration.new(
12
+ total_seconds,
13
+ total_seconds/60,
14
+ total_seconds/60/60,
15
+ )
22
16
  end
23
17
 
24
- def Char.arm
18
+ def self.hide()
19
+ return unless visible?
20
+ fput "hide"
21
+ waitrt?
22
+ self
23
+ end
24
+
25
+ def self.unhide()
26
+ return if visible?
27
+ fput "unhide"
28
+ wait_until do visible? end
29
+ self
30
+ end
31
+
32
+ def self.arm
25
33
  fput "gird"
26
34
  self
27
35
  end
28
36
 
29
- def Char.unarm
37
+ def self.unarm
30
38
  fput "store both"
31
39
  self
32
40
  end
33
41
 
34
- def Char.swap
42
+ def self.swap
35
43
  fput "swap"
36
44
  self
37
45
  end
38
46
 
39
- def Char.stand
47
+ def self.stand
40
48
  unless standing?
41
49
  fput "stand"
42
50
  waitrt?
@@ -44,18 +52,7 @@ class Char
44
52
  self
45
53
  end
46
54
 
47
- def Char.spell(num)
48
- hour, minutes, seconds = Spell[num].remaining.split(":").map(&:to_f)
49
- total_seconds = seconds + (minutes * 60.00) + (hour * 60.00 * 60.00)
50
-
51
- Duration.new(
52
- total_seconds,
53
- total_seconds/60,
54
- total_seconds/60/60,
55
- )
56
- end
57
-
58
- def Char.aim(location)
55
+ def self.aim(location)
59
56
  unless @@aiming == location
60
57
  fput "aim #{location}"
61
58
  @@aiming = location
@@ -63,32 +60,24 @@ class Char
63
60
  self
64
61
  end
65
62
 
66
- def Char.fwi_teleporter
67
- Vars.teleporter || Vars.mapdb_fwi_trinket
68
- end
69
63
 
70
- def Char.visible?
71
- hiding? || invisible?
72
- end
73
-
74
- def Char.hiding_routine(procedure)
75
- @@routines[:hiding] = procedure
76
- Char
64
+ def self.visible?
65
+ hiding? or invisible?
77
66
  end
78
67
 
79
- def Char.in_town?
68
+ def self.in_town?
80
69
  Room.current.location =~ /the Adventurer's Guild|kharam|teras|landing|sol|icemule trace|mist|vaalor|illistim|rest|cysaegir|logoth/i
81
70
  end
82
71
 
83
- def Char.left
84
- GameObj.left_hand.name == "Empty" ? nil : Olib::Item.new(GameObj.left_hand)
72
+ def self.left
73
+ GameObj.left_hand.name == "Empty" ? nil : Item.new(GameObj.left_hand)
85
74
  end
86
75
 
87
- def Char.right
88
- GameObj.right_hand.name == "Empty" ? nil : Olib::Item.new(GameObj.right_hand)
76
+ def self.right
77
+ GameObj.right_hand.name == "Empty" ? nil : Item.new(GameObj.right_hand)
89
78
  end
90
79
 
91
- def Char.withdraw(amount)
80
+ def self.withdraw(amount)
92
81
  Go2.bank
93
82
  result = Olib.do "withdraw #{amount} silvers", /I'm sorry|hands you/
94
83
  if result =~ /I'm sorry/
@@ -100,15 +89,15 @@ class Char
100
89
  return self
101
90
  end
102
91
 
103
- def Char.deposit_all
92
+ def self.deposit_all
104
93
  Go2.bank
105
- fput "unhide" if invisible? || hidden?
94
+ fput "unhide" unless visible?
106
95
  fput "deposit all"
107
96
  @@silvers = 0
108
97
  return self
109
98
  end
110
99
 
111
- def Char.deposit(amt)
100
+ def self.deposit(amt)
112
101
  wealth
113
102
  if wealth >= amt
114
103
  Go2.bank
@@ -120,28 +109,28 @@ class Char
120
109
 
121
110
  # naive share
122
111
  # does not check if you're actually in a group or not
123
- def Char.share
112
+ def self.share
124
113
  wealth
125
114
  fput "share #{@silvers}"
126
115
  wealth
127
116
  self
128
117
  end
129
118
 
130
- def Char.deplete_wealth(silvers)
119
+ def self.deplete_wealth(silvers)
131
120
  #@@silvers = @@silvers - silvers
132
121
  end
133
122
 
134
- def Char.smart_wealth
123
+ def self.smart_wealth
135
124
  return @@silvers if @@silvers
136
125
  Char.wealth
137
126
  end
138
127
 
139
- def Char.unhide
128
+ def self.unhide
140
129
  fput 'unhide' if Spell[916].active? or hidden?
141
130
  self
142
131
  end
143
132
 
144
- def Char.hide
133
+ def self.hide
145
134
  if Spell[916].known? && Spell[916].affordable?
146
135
  Spell[916].cast
147
136
  else
@@ -149,29 +138,36 @@ class Char
149
138
  end
150
139
  end
151
140
 
152
- def Char.wealth
153
- fput "info"
154
- while(line=get)
155
- next if line =~ /^\s*Name\:|^\s*Gender\:|^\s*Normal \(Bonus\)|^\s*Strength \(STR\)\:|^\s*Constitution \(CON\)\:|^\s*Dexterity \(DEX\)\:|^\s*Agility \(AGI\)\:|^\s*Discipline \(DIS\)\:|^\s*Aura \(AUR\)\:|^\s*Logic \(LOG\)\:|^\s*Intuition \(INT\)\:|^\s*Wisdom \(WIS\)\:|^\s*Influence \(INF\)\:/
156
- if line =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
157
- @@silvers= $1.to_i
158
- break
141
+ def self.wealth
142
+ silvers = nil
143
+ DownstreamHook.add("Olib_check_silvers", Proc.new do |server_string|
144
+ if server_string =~ /^\s*Name\:|^\s*Gender\:|^\s*Normal \(Bonus\)|^\s*Strength \(STR\)\:|^\s*Constitution \(CON\)\:|^\s*Dexterity \(DEX\)\:|^\s*Agility \(AGI\)\:|^\s*Discipline \(DIS\)\:|^\s*Aura \(AUR\)\:|^\s*Logic \(LOG\)\:|^\s*Intuition \(INT\)\:|^\s*Wisdom \(WIS\)\:|^\s*Influence \(INF\)\:/
145
+ nil
146
+ elsif server_string =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
147
+ silvers = $1.to_i
148
+ DownstreamHook.remove("Olib_check_silvers")
149
+ nil
150
+ else
151
+ server_string
159
152
  end
160
- sleep 0.1
161
- end
153
+ end)
154
+ $_SERVER_.puts "#{$cmd_prefix}info\n"
155
+ wait_until { silvers }
156
+ silvers
157
+ @@silvers = silvers
162
158
  @@silvers
163
159
  end
164
160
 
165
- def Char.total_wound_severity
161
+ def self.total_wound_severity
166
162
  INJURIES
167
163
  .reduce(0) do |sum, method| sum + Wounds.send(method) end
168
164
  end
169
165
 
170
- def Char.wounded?
166
+ def self.wounded?
171
167
  total_wound_severity.gt(0)
172
168
  end
173
169
 
174
- def Char.empty_hands
170
+ def self.empty_hands
175
171
  hands = [Char.left, Char.right].compact
176
172
 
177
173
  hands.each do |hand| Containers.Lootsack.add hand end