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
File without changes
@@ -1,3 +1,3 @@
1
1
  module Olib
2
- VERSION = "0.1.2"
2
+ VERSION = "2.0.0-rc.1"
3
3
  end
@@ -0,0 +1,43 @@
1
+ ##
2
+ ## XML utils
3
+ ##
4
+ module XML
5
+ def self.xml_on
6
+ Script.current.want_downstream_xml = true
7
+ end
8
+
9
+ def self.xml_off
10
+ Script.current.want_downstream_xml = false
11
+ end
12
+
13
+ def self.tap
14
+ xml_on
15
+ result = yield
16
+ xml_off
17
+ result
18
+ end
19
+
20
+ def self.cmd(cmd)
21
+ XML.tap do
22
+ fput(cmd)
23
+ while line = get
24
+ yield(line)
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.lines(**opts, &block)
30
+ XML.tap do
31
+ while line = get
32
+ result = block.call(line)
33
+ break if result == :halt
34
+ end
35
+ end
36
+ end
37
+
38
+ def self.match(cmd, patt, timeout: 5)
39
+ XML.tap do
40
+ dothistimeout(cmd, timeout, patt)
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Olib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 2.0.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondreian Shamsiel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-12 00:00:00.000000000 Z
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Useful Lich extensions for Gemstone IV including hostile creature management,
14
14
  group management, syntactically pleasing movement, locker management, etc
@@ -32,16 +32,27 @@ files:
32
32
  - lib/Olib/character/stance.rb
33
33
  - lib/Olib/combat/creature.rb
34
34
  - lib/Olib/combat/creatures.rb
35
+ - lib/Olib/core/action.rb
35
36
  - lib/Olib/core/container.rb
37
+ - lib/Olib/core/containers.rb
36
38
  - lib/Olib/core/errors.rb
37
- - lib/Olib/core/extender.rb
39
+ - lib/Olib/core/exist.rb
38
40
  - lib/Olib/core/item.rb
41
+ - lib/Olib/core/kinds.rb
42
+ - lib/Olib/core/rummage.rb
43
+ - lib/Olib/core/transaction.rb
39
44
  - lib/Olib/core/use.rb
40
45
  - lib/Olib/core/utils.rb
46
+ - lib/Olib/core/verbs.rb
41
47
  - lib/Olib/dictionary/dictionary.rb
48
+ - lib/Olib/ext/hash.rb
49
+ - lib/Olib/ext/matchdata.rb
50
+ - lib/Olib/ext/string.rb
51
+ - lib/Olib/ext/symbol.rb
42
52
  - lib/Olib/go2.rb
43
- - lib/Olib/interface/queryable.rb
44
- - lib/Olib/npcs.rb
53
+ - lib/Olib/loot.rb
54
+ - lib/Olib/npcs/npc.rb
55
+ - lib/Olib/npcs/npcs.rb
45
56
  - lib/Olib/objects/box.rb
46
57
  - lib/Olib/objects/clothing.rb
47
58
  - lib/Olib/objects/herb.rb
@@ -51,16 +62,18 @@ files:
51
62
  - lib/Olib/objects/scroll.rb
52
63
  - lib/Olib/objects/uncommon.rb
53
64
  - lib/Olib/objects/wand.rb
54
- - lib/Olib/pattern.rb
65
+ - lib/Olib/pattern_matching/any.rb
66
+ - lib/Olib/pattern_matching/err.rb
67
+ - lib/Olib/pattern_matching/ok.rb
68
+ - lib/Olib/pattern_matching/outcome.rb
69
+ - lib/Olib/pattern_matching/pattern_matching.rb
70
+ - lib/Olib/pattern_matching/result.rb
71
+ - lib/Olib/pattern_matching/rill.rb
72
+ - lib/Olib/pattern_matching/where.rb
55
73
  - lib/Olib/shops.rb
56
- - lib/Olib/storage/app_data.rb
57
74
  - lib/Olib/supervisor/supervisor.rb
58
- - lib/Olib/try/try.rb
59
- - lib/Olib/utils/cli.rb
60
- - lib/Olib/utils/help_menu.rb
61
- - lib/Olib/utils/monsterbold.rb
62
- - lib/Olib/utils/vbulletin.rb
63
75
  - lib/Olib/version.rb
76
+ - lib/Olib/xml.rb
64
77
  homepage: https://github.com/ondreian/Olib
65
78
  licenses:
66
79
  - MIT
@@ -76,12 +89,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
89
  version: '0'
77
90
  required_rubygems_version: !ruby/object:Gem::Requirement
78
91
  requirements:
79
- - - ">="
92
+ - - ">"
80
93
  - !ruby/object:Gem::Version
81
- version: '0'
94
+ version: 1.3.1
82
95
  requirements: []
83
96
  rubyforge_project:
84
- rubygems_version: 2.6.12
97
+ rubygems_version: 2.7.6
85
98
  signing_key:
86
99
  specification_version: 4
87
100
  summary: Useful Lich extensions for Gemstone IV
@@ -1,29 +0,0 @@
1
- # TODO:
2
- # this should be refactored to use a mixin pattern
3
- module Olib
4
- class Gameobj_Extender
5
- attr_accessor :type
6
- def initialize(item)
7
- self.__extend__(item)
8
- @type = item.type
9
- end
10
-
11
- # This copies GameObj data to attributes so we can employ it for scripting
12
- def __extend__(item)
13
- item.instance_variables.each { |var|
14
- s = var.to_s.sub('@', '')
15
- (class << self; self end).class_eval do; attr_accessor "#{s}"; end
16
- instance_variable_set "#{var}", item.send(s)
17
- }
18
- end
19
-
20
- def echo
21
- respond self
22
- self
23
- end
24
-
25
- def at
26
- fput "look at ##{@id}"
27
- end
28
- end
29
- end
@@ -1,50 +0,0 @@
1
- module Interface
2
- class Queryable
3
- def self.fetch
4
- []
5
- end
6
-
7
- def self.each(&block)
8
- fetch.each &block
9
- end
10
-
11
- def self.map(&block)
12
- fetch.map &block
13
- end
14
-
15
- def self.find(&block)
16
- fetch.find &block
17
- end
18
-
19
- def self.sort(&block)
20
- fetch.sort &block
21
- end
22
-
23
- def self.select(&block)
24
- fetch.select &block
25
- end
26
-
27
- def self.reject(&block)
28
- fetch.reject &block
29
- end
30
-
31
- def self.where(**conds)
32
- end
33
-
34
- def self.first
35
- fetch.first
36
- end
37
-
38
- def self.sample(n = 1)
39
- fetch.sample n
40
- end
41
-
42
- def self.empty?
43
- (fetch || []).empty?
44
- end
45
-
46
- def self.size
47
- fetch.size
48
- end
49
- end
50
- end
@@ -1,5 +0,0 @@
1
- class NPCS
2
- def self.[](query)
3
- GameObj.npcs.select { |npc| npc.name =~ /#{query}/ }
4
- end
5
- end
@@ -1,34 +0,0 @@
1
- ##
2
- ## @brief pattern matching for Ruby
3
- ##
4
- class Pattern
5
- attr_accessor :cases
6
-
7
- def initialize(cases)
8
- @cases = cases
9
- end
10
-
11
- def match(str)
12
- found = @cases.each_pair.find do |exp, handler|
13
- str =~ exp
14
- end
15
-
16
- if !found
17
- raise Exception.new [
18
- "Error: inexhaustive pattern",
19
- "counterexample: #{str}",
20
- ].join("\n")
21
- end
22
-
23
- exp, handler = found
24
-
25
- handler.call exp.match(str).to_struct
26
- end
27
-
28
- def to_proc
29
- patt = self
30
- Proc.new do |str|
31
- patt.match str
32
- end
33
- end
34
- end
@@ -1,32 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Olib
4
- class App
5
- FOLDER = ".olib"
6
- APP_DIR = File.join Dir.home, FOLDER
7
- ##
8
- ## setup app dir
9
- ##
10
- FileUtils.mkdir_p APP_DIR
11
-
12
- def self.app_file(path)
13
- File.join APP_DIR, path
14
- end
15
-
16
- def self.open(file)
17
- File.open(app_file(file), 'a', &block)
18
- end
19
-
20
- def self.write_json(file, data)
21
- open(file) do |f|
22
- JSON.dump(data)
23
- end
24
- end
25
-
26
- def self.read(file, &block)
27
- open(file) do |file|
28
- yield
29
- end
30
- end
31
- end
32
- end
@@ -1,58 +0,0 @@
1
- class Try
2
- attr_accessor :result, :task
3
-
4
- def self.of(&task)
5
- Proc.new do
6
- Try.new task
7
- end
8
- end
9
-
10
- def initialize(&task)
11
- @task = task
12
- run!
13
- end
14
-
15
- private def run!
16
- begin
17
- result = @task.call
18
- # handle recursives
19
- if result.is_a?(Try)
20
- @result = result.result
21
- else
22
- @result = result
23
- end
24
- rescue Exception => e
25
- @result = e
26
- end
27
- end
28
-
29
- def failed?
30
- @result.class.ancestors.include? Exception
31
- end
32
-
33
- def success?
34
- !failed?
35
- end
36
-
37
- def recover
38
- Try.new { yield @result } if failed?
39
- end
40
-
41
- def then
42
- Try.new { yield @result } if success?
43
- end
44
-
45
- def match?(exp)
46
- if failed?
47
- @result.message.match(exp)
48
- elsif @result.respond_to?(:match)
49
- @result.match(exp)
50
- else
51
- raise Exception.new "cannot match class #{@result.class}"
52
- end
53
- end
54
- end
55
-
56
- def try(&block)
57
- Try.new &block
58
- end
@@ -1,81 +0,0 @@
1
- module Olib
2
- class ScriptVars
3
- attr_accessor :opts
4
- def initialize
5
- opts = {}
6
- opts[:flags] = {}
7
- return opts if Script.current.vars.empty?
8
- list = Script.current.vars.map(&:downcase).last(Script.current.vars.length-1)
9
-
10
- unless list.first.start_with?('--')
11
- opts[:cmd] = list.shift
12
- end
13
-
14
- # iterate over list for flag values
15
- flags = list.compact.join(' ').split('--')
16
- flags.shift
17
- flags.each { |flag|
18
- segments = flag.split(' ')
19
- name = symbolize(segments.shift)
20
- opts[:flags][name] = true
21
- if !segments.empty?
22
- value = segments.join(' ').strip
23
- if value =~ /[\d]+/
24
- value = value.to_i
25
- end
26
- opts[:flags][name] = value
27
- end
28
- }
29
-
30
- @opts = opts
31
- self
32
- end
33
-
34
- def cmd
35
- @opts[:cmd]
36
- end
37
-
38
- def empty?(flag)
39
- opts[:flags][flag].class == TrueClass || opts[:flags][flag].class == NilClass
40
- end
41
-
42
- def cmd?(action)
43
- cmd == action
44
- end
45
-
46
- def symbolize(flag)
47
- flag.gsub('--', '').gsub('-', '_').to_sym
48
- end
49
-
50
- def help?
51
- cmd =~ /help/
52
- end
53
-
54
- def flags
55
- opts[:flags].keys
56
- end
57
-
58
- def to_s
59
- @opts.to_s
60
- end
61
-
62
- def flag
63
- self
64
- end
65
-
66
- def flag?(f)
67
- opts[:flags][ symbolize(f) ]
68
- end
69
-
70
- def method_missing(arg1, arg2=nil)
71
- @opts[:flags][arg1]
72
- end
73
-
74
- end
75
- end
76
-
77
- module Olib
78
- def Olib.CLI
79
- Olib::ScriptVars.new
80
- end
81
- end
@@ -1,166 +0,0 @@
1
- module Olib
2
- class HelpMenu
3
- attr_accessor :script, :cmds, :last_added, :flags, :title, :padding, :cols, :max_column_width
4
-
5
- def initialize
6
- @script = $lich_char+Olib.script.to_s
7
- @cmds = {}
8
- @flags = {}
9
- @padding = 5
10
- @max_column_width = Vars.max_column_width.to_i || 100
11
- @title = "#{@script} help menu".upcase
12
- self
13
- end
14
-
15
- def flag(flag, info)
16
- if @last_added
17
- @cmds[@last_added][:flags][flag] = info
18
- else
19
- @flags[flag] = info
20
- end
21
-
22
- self
23
- end
24
-
25
- def pad
26
- [''] * @padding * ' '
27
- end
28
-
29
- def cmd(cmd, info)
30
- @last_added = cmd
31
- @cmds[cmd] = {}
32
- @cmds[cmd][:info] = info
33
- @cmds[cmd][:flags] = {}
34
- self
35
- end
36
-
37
- def width
38
- return @cols if @cols
39
-
40
- @cols = {}
41
- @cols[:one] = @script.length+padding
42
-
43
- # global flags and commands
44
- @cols[:two] = @flags
45
- .keys
46
- .concat(@cmds.keys)
47
- .map(&:strip)
48
- .sort_by(&:length).last.length+padding
49
-
50
- # flags
51
- @cols[:three] = @cmds
52
- .keys
53
- .map { |cmd| @cmds[cmd][:flags].keys }
54
- .flatten
55
- .map(&:strip)
56
- .sort_by(&:length).last.length+padding
57
-
58
- # help text
59
- @cols[:four] = @max_column_width+padding
60
-
61
- @cols[:total] = @cols.values.reduce(&:+)
62
-
63
- @cols
64
- end
65
-
66
- def center(str)
67
- "%#{width.values.reduce(&:+)/3-str.length}s\n" % str
68
- end
69
-
70
- # offset the entire array of eles by n number of blank strings
71
- def offset(n, *eles)
72
- row *(eles.unshift *[''] * n)
73
- end
74
-
75
- def row(*columns)
76
- "%#{width[:one]}s %#{width[:two]}s#{pad}%-#{width[:three]}s#{pad}%-#{width[:four]}s\n" % columns.map(&:strip)
77
- #row2 *columns
78
- end
79
-
80
- def bar
81
- "|\n".rjust(width[:total]+10,"-")
82
- end
83
-
84
- def n
85
- "\n"
86
- end
87
-
88
- def chunker(content)
89
- rows = ['']
90
-
91
- content.split.each { |chunk|
92
- if rows.last.length + chunk.length > @max_column_width then rows.push chunk else rows.last.concat " "+chunk end
93
- }
94
-
95
- rows
96
- end
97
-
98
- def write
99
- m = []
100
- m.push bar
101
- m.push n
102
- m.push "#{@title}:"
103
- m.push n
104
- m.push n
105
- m.push bar
106
- unless @flags.keys.empty?
107
- m.push *["global flags:", "", "", ""].map(&:upcase)
108
- m.push bar
109
- @flags.each { |flag, info|
110
- if info.length > @max_column_width
111
- chunks = chunker info
112
- m.push row( @script, '', '--'+flag, chunks.shift )
113
- chunks.each { |chunk| m.push offset 3, chunk }
114
- m.push n
115
- else
116
- m.push row(@script, '', '--'+flag, info)
117
- m.push n
118
- end
119
-
120
- }
121
- end
122
- m.push n
123
- unless @cmds.keys.empty?
124
- m.push bar
125
- m.push row *['', "| cmd", "| flag", "| info"].map(&:upcase)
126
- m.push bar
127
- @cmds.keys.each { |cmd|
128
- # add top level command
129
- m.push n
130
- if @cmds[cmd][:info].length > @max_column_width
131
- chunks = chunker @cmds[cmd][:info]
132
- m.push row(@script, cmd, '', chunks.shift)
133
- chunks.each { |chunk| m.push offset 3, chunk }
134
- m.push n
135
- else
136
- m.push row(@script, cmd, '', @cmds[cmd][:info])
137
- m.push n
138
- end
139
-
140
- # add flags for command
141
- @cmds[cmd][:flags].keys.each {|flag|
142
- if @cmds[cmd][:flags][flag].length > @max_column_width
143
- chunks = chunker @cmds[cmd][:flags][flag]
144
- m.push row( @script, cmd, '--'+flag, chunks.shift )
145
- chunks.each { |chunk| m.push offset 3, chunk }
146
- m.push n
147
- else
148
- m.push row(@script, cmd, '--'+flag, @cmds[cmd][:flags][flag] )
149
- m.push n
150
- end
151
- }
152
-
153
- }
154
- m.push bar
155
- m.push n
156
- end
157
- respond m.join('')
158
- end
159
- end
160
- end
161
-
162
-
163
-
164
-
165
-
166
-