Olib 2.0.0.pre.rc.1 → 2.0.0.pre.rc.6

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.
@@ -1,11 +0,0 @@
1
- require "Olib/pattern_matching/result"
2
-
3
- class Any < Result
4
- def self.===(*args)
5
- true
6
- end
7
-
8
- def ===(other)
9
- true
10
- end
11
- end
@@ -1,3 +1,6 @@
1
+
2
+ require "Olib/pattern_matching/any"
3
+
1
4
  class Result
2
5
  def self.included(ctx)
3
6
  ctx.include(Result::Constructors)
@@ -32,7 +35,9 @@ class Result
32
35
  expected.all? do |k, v|
33
36
  if this.respond_to?(k.to_sym)
34
37
  _compare_values(v, this.send(k.to_sym))
35
- elsif this.respond_to?(:[])
38
+ elsif this.is_a?(Array) and k.is_a?(Fixnum)
39
+ _compare_values(v, this[k.to_i])
40
+ elsif this.respond_to?(:[]) and not this.is_a?(Array)
36
41
  _compare_values(v, this[k.to_s]) or _compare_values(v, this[k.to_sym])
37
42
  else
38
43
  false
@@ -77,4 +82,14 @@ class Result
77
82
  Err[*args]
78
83
  end
79
84
  end
85
+ end
86
+
87
+ class Any < Result
88
+ def self.===(*args)
89
+ true
90
+ end
91
+
92
+ def ===(other)
93
+ true
94
+ end
80
95
  end
@@ -3,16 +3,21 @@ require "Olib/pattern_matching/outcome"
3
3
  require "Olib/ext/matchdata"
4
4
 
5
5
  class Rill
6
+ def self.union(*patterns)
7
+ patterns.join("|")
8
+ end
9
+
6
10
  PROMPT = /<prompt/
7
11
 
8
12
  include Enumerable
9
- attr_reader :close, :start, :mode
13
+ attr_reader :close, :start, :mode, :timeout
10
14
 
11
- def initialize(start: nil, close: PROMPT, mode: :xml)
15
+ def initialize(start: nil, close: PROMPT, mode: :xml, timeout: 5)
12
16
  fail "Rill.new() requires :start argument" if start.nil?
13
17
  @mode = mode
14
18
  @close = Outcome.new(close)
15
19
  @start = Outcome.new(start)
20
+ @timeout = timeout
16
21
  end
17
22
 
18
23
  def capture(obj, command_template)
@@ -27,13 +32,16 @@ class Rill
27
32
  state = :start
28
33
  lines = []
29
34
  matches = {}
30
- XML.cmd(command) do |line|
35
+ XML.cmd(command, pattern: begin_pattern, timeout: @timeout) do |line|
31
36
  state = :open if line.match(begin_pattern)
32
37
  lines << line if state.eql?(:open)
33
- if (result = (line.match(begin_pattern) || line.match(end_pattern)))
38
+ if (result = (line.match(begin_pattern) or line.match(end_pattern)))
34
39
  matches.merge!(result.to_h)
35
40
  end
36
- return [matches, lines] if (line.match(end_pattern) and state.eql?(:open))
41
+
42
+ if (line.match(end_pattern) and state.eql?(:open))
43
+ return [:ok, matches, lines]
44
+ end
37
45
  end
38
46
  end
39
47
 
@@ -1,3 +1,3 @@
1
1
  module Olib
2
- VERSION = "2.0.0-rc.1"
2
+ VERSION = "2.0.0-rc.6"
3
3
  end
@@ -17,11 +17,15 @@ module XML
17
17
  result
18
18
  end
19
19
 
20
- def self.cmd(cmd)
20
+ def self.cmd(cmd, timeout: 5, pattern:)
21
21
  XML.tap do
22
- fput(cmd)
22
+ result = dothistimeout(cmd, timeout, pattern)
23
+ return nil if result.nil?
24
+ yield(result)
25
+ ttl = Time.now + timeout
23
26
  while line = get
24
27
  yield(line)
28
+ break if Time.now > ttl
25
29
  end
26
30
  end
27
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Olib
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.rc.1
4
+ version: 2.0.0.pre.rc.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondreian Shamsiel
@@ -30,8 +30,11 @@ files:
30
30
  - lib/Olib/character/inventory.rb
31
31
  - lib/Olib/character/mind.rb
32
32
  - lib/Olib/character/stance.rb
33
+ - lib/Olib/combat/attack.rb
33
34
  - lib/Olib/combat/creature.rb
35
+ - lib/Olib/combat/creatures.json
34
36
  - lib/Olib/combat/creatures.rb
37
+ - lib/Olib/combat/metadata.rb
35
38
  - lib/Olib/core/action.rb
36
39
  - lib/Olib/core/container.rb
37
40
  - lib/Olib/core/containers.rb
@@ -40,6 +43,7 @@ files:
40
43
  - lib/Olib/core/item.rb
41
44
  - lib/Olib/core/kinds.rb
42
45
  - lib/Olib/core/rummage.rb
46
+ - lib/Olib/core/scroll.rb
43
47
  - lib/Olib/core/transaction.rb
44
48
  - lib/Olib/core/use.rb
45
49
  - lib/Olib/core/utils.rb
@@ -50,6 +54,7 @@ files:
50
54
  - lib/Olib/ext/string.rb
51
55
  - lib/Olib/ext/symbol.rb
52
56
  - lib/Olib/go2.rb
57
+ - lib/Olib/log.rb
53
58
  - lib/Olib/loot.rb
54
59
  - lib/Olib/npcs/npc.rb
55
60
  - lib/Olib/npcs/npcs.rb
@@ -59,9 +64,9 @@ files:
59
64
  - lib/Olib/objects/jar.rb
60
65
  - lib/Olib/objects/jewel.rb
61
66
  - lib/Olib/objects/jewelry.rb
62
- - lib/Olib/objects/scroll.rb
63
67
  - lib/Olib/objects/uncommon.rb
64
68
  - lib/Olib/objects/wand.rb
69
+ - lib/Olib/opts.rb
65
70
  - lib/Olib/pattern_matching/any.rb
66
71
  - lib/Olib/pattern_matching/err.rb
67
72
  - lib/Olib/pattern_matching/ok.rb
@@ -93,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
98
  - !ruby/object:Gem::Version
94
99
  version: 1.3.1
95
100
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.7.6
101
+ rubygems_version: 3.1.0.pre1
98
102
  signing_key:
99
103
  specification_version: 4
100
104
  summary: Useful Lich extensions for Gemstone IV
@@ -1,42 +0,0 @@
1
- class Scroll < Item
2
- @@whitelist = [
3
- 101, 102, 103, 107, 116, 120,
4
- 202, 211, 215, 219,
5
- 303, 307, 310, 313, 315,
6
- 401, 406, 414, 425, 430,
7
- 503, 507, 508, 509, 511, 513, 520,
8
- 601, 602, 606, 613, 617, 618, 625, 640,
9
- 712, 716,
10
- 905, 911, 913, 920,
11
- 1109, 1119, 1125, 1130,
12
- 1201, 1204,
13
- 1601, 1603, 1606, 1610, 1611, 1612, 1616,
14
- 1712, 1718
15
- ]
16
- attr_accessor :spells, :worthy, :whitelist
17
-
18
- def Scroll.whitelist
19
- @@whitelist
20
- end
21
-
22
- def Scroll.add_to_whitelist(*args)
23
- @@whitelist + args
24
- end
25
-
26
- def Scroll.remove_from_whitelist(*args)
27
- @@whitelist = @@whitelist - args
28
- end
29
-
30
- def initialize(item)
31
- super item
32
- @spells = []
33
- return self
34
- end
35
-
36
- def worthy?
37
- @worthy = false
38
- read unless @spells.length > 0
39
- @spells.each do |spell| @worthy = true if Scroll.whitelist.include? spell[:n] end
40
- @worthy
41
- end
42
- end