Olib 2.0.0.pre.rc.1 → 2.0.0.pre.rc.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3847ae46163103e49356d4e6fcc43badaa3b4ddd29a9ea3ad48c509203b5eb7
4
- data.tar.gz: 6ff8a42a9ca26c9cf394bd311ff7095052b7a507005b34aa42d73d63f9701a79
3
+ metadata.gz: 59092281655cf2bb6035a9bf6117a4cd1b88539c2eb971041d13910f4d319f55
4
+ data.tar.gz: 26d0a65a8edfeba5077b6e9efc0887d8bdbcad394fa4b29af015a9281ab00f12
5
5
  SHA512:
6
- metadata.gz: eb34b92ed44adeab5c1b15e7ae65f73124d7557af2c613bef5113c7efe76607e362807553076d52f51f05b95787b93adbf65cb3893343962af82485f008098d0
7
- data.tar.gz: c89d3853c1d5569f7ed375269a047cf7eee943dde1f5ad8b11eb9c2ffb0e1abd29bdf9df8893491afb1cd4f0b29fb1c3df440d3559fc133f8db4119d390a8856
6
+ metadata.gz: '038216104dd7f79a3d45d181a759b56256ed6bf611dfcece8f8c777886f6a5371c2476381af7ecc447567169265e9299275973f18fd492d32f37ba5573d86a7d'
7
+ data.tar.gz: 1638f640f0540fc425937dd963a4914e0d44cbb391cc77f2417bb9a9e99b6c4107733818ad4448b1c3858149c803fa9933d164307070040593ecd3d6768de2a0
@@ -95,6 +95,7 @@ module Group
95
95
  "<#{name}: @leader=#{leader?} @status=#{status}>"
96
96
  end
97
97
  end
98
+
98
99
  MEMBERS = Members.new
99
100
  OPEN = :open
100
101
  CLOSED = :closed
@@ -156,9 +157,7 @@ module Group
156
157
 
157
158
  def Group.disks
158
159
  return [Disk.find_by_name(Char.name)].compact unless Group.leader?
159
- members.map(&:name).map do |name|
160
- Disk.find_by_name(name)
161
- end.compact
160
+ members.map(&:name).map do |name| Disk.find_by_name(name) end.compact
162
161
  end
163
162
 
164
163
  def Group.to_s
@@ -199,13 +198,15 @@ module Group
199
198
  # <a exist="-10467645" noun="Oreh">Oreh</a> joins your group.
200
199
  # You add <a exist="-10467645" noun="Oreh">Oreh</a> to your group.
201
200
  # You remove <a exist="-10467645" noun="Oreh">Oreh</a> from the group.
202
- JOIN = %r{^<a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> joins your group.$}
203
- LEAVE = %r{^<a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> leaves your group.$}
204
- ADD = %r{^You add <a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> to your group.$}
205
- REMOVE = %r{^You remove <a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> from the group.$}
206
- NOOP = %r{^But <a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> is already a member of your group!$}
207
- EXIST = %r{<a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a>}
208
- ANY = Regexp.union(JOIN, LEAVE, ADD, REMOVE, NOOP)
201
+ # You disband your group.
202
+ JOIN = %r{^<a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> joins your group.$}
203
+ LEAVE = %r{^<a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> leaves your group.$}
204
+ ADD = %r{^You add <a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> to your group.$}
205
+ REMOVE = %r{^You remove <a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> from the group.$}
206
+ NOOP = %r{^But <a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a> is already a member of your group!$}
207
+ EXIST = %r{<a exist="(?<id>[\d-]+)" noun="(?<noun>[A-Za-z]+)">(?<name>\w+?)</a>}
208
+ DISBAND = %r{^You disband your group}
209
+ ANY = Regexp.union(JOIN, LEAVE, ADD, REMOVE, NOOP)
209
210
  end
210
211
 
211
212
  GROUP_OBSERVER = -> line {
@@ -283,6 +284,10 @@ module Group
283
284
  end
284
285
 
285
286
  def self.broken?
286
- (GameObj.pcs.to_a.map(&:noun) & Group.members.map(&:noun)).size.eql?(Group.members.size)
287
- end
287
+ if Group.leader?
288
+ (GameObj.pcs.map(&:noun) & Group.members.map(&:noun)).size < Group.members.size
289
+ else
290
+ GameObj.pcs.find do |pc| pc.noun.eql?(Group.leader.noun) end.nil?
291
+ end
292
+ end
288
293
  end
@@ -7,29 +7,39 @@
7
7
  require "ostruct"
8
8
  require "Olib/combat/creatures"
9
9
  require "Olib/core/exist"
10
+ require "Olib/pattern_matching/rill"
10
11
 
11
12
  class Creature < Exist
12
13
  include Comparable
13
14
 
14
- WOUNDS = [
15
- :right_leg, :left_leg, :right_arm,
16
- :left_arm, :head, :neck, :chest,
17
- :abdomen, :back, :left_eye, :right_eye,
18
- :right_hand, :left_hand, :nerves,
15
+ Search = Rill.new(
16
+ timeout: 1,
17
+ start: Rill.union(%(You search the <pushBold/><a exist="{{id}}"),))
18
+
19
+ Skin = Rill.new(
20
+ start: Rill.union(%[You skinned the <pushBold/><a exist="{{id}}"],
21
+ %[You botched],
22
+ %[has already"]))
23
+
24
+ Attack = Rill.new(
25
+ timeout: 2,
26
+ start: Rill.union(%[You (.*?) at <pushBold/>(a|an|some) <a exist="{{id}}],
27
+ %[A little bit late],
28
+ %[already dead],
29
+ %[I could not find what you were referring to],
30
+ %[What were you referring to?]))
31
+
32
+ WOUNDS = %i[
33
+ right_leg left_leg right_arm
34
+ left_arm head neck chest
35
+ abdomen back left_eye right_eye
36
+ right_hand left_hand nerves
19
37
  ]
20
38
 
21
39
  TAGS = OpenStruct.new(
22
- antimagic: /construct|Vvrael/,
23
- grimswarm: /grimswarm/,
24
- lowly: /kobold|rolton|velnalin|urgh/,
25
- trollish: /troll|csetari/,
26
- undead: Regexp.union(
27
- /zombie|ghost|skele|ghoul|spectral|wight|shade/,
28
- /spectre|revenant|apparition|bone|were|rotting/,
29
- /spirit|soul|barghest|vruul|night|phant|naisirc/,
30
- /shrickhen|seraceris|n'ecare|vourkha|bendith/,
31
- /baesrukha|lich|dybbuk|necrotic|flesh|waern|banshee/,
32
- /seeker|eidolon|decay|putrefied|vaespilon/),
40
+ antimagic: %r[construct|Vvrael],
41
+ lowly: %r[kobold|rolton|velnalin|urgh],
42
+ trollish: %r[troll|csetari],
33
43
  )
34
44
 
35
45
  def self.tags(name)
@@ -201,38 +211,56 @@ class Creature < Exist
201
211
  status.include?(:dead)
202
212
  end
203
213
 
214
+ def block(method)
215
+ return {err: :dead} if dead?
216
+ Kernel.send(method)
217
+ return {err: :dead} if dead?
218
+ yield if block_given?
219
+ end
220
+
204
221
  def kill
205
- unless dead?
206
- fput "kill ##{@id}"
222
+ block(:waitrt?) do
223
+ Attack.capture(self.to_h, %[kill \#{{id}}])
224
+ end
225
+ end
226
+
227
+ def cast
228
+ block(:waitcastrt?) do
229
+ Attack.capture(self.to_h, %[cast \#{{id}}])
207
230
  end
208
- self
209
231
  end
210
232
 
211
233
  def fire(location=nil)
212
- unless dead?
213
- Char.aim(location) if location
214
- fput "fire ##{@id}"
234
+ Char.aim(location) if location
235
+ block(:waitrt?) do
236
+ Attack.capture(self.to_h, %[fire \#{{id}}])
215
237
  end
216
- self
217
238
  end
218
239
 
219
240
  def hurl(location=nil)
220
- unless dead?
221
- Char.aim(location) if location
222
- fput "hurl ##{@id}"
241
+ Char.aim(location) if location
242
+ block(:waitrt?) do
243
+ Attack.capture(self.to_h, %[hurl \#{{id}}])
223
244
  end
224
- self
225
245
  end
226
246
 
227
- def search
247
+ def search()
228
248
  waitrt?
229
- fput "search ##{@id}" if dead?
249
+ return unless dead?
250
+ (_, lines) = Search.capture(self.to_h, %[search \#{{id}}])
251
+ # the first line containers a creature id we want to avoid capturing
252
+ lines[1..-1]
253
+ .map do |line| Exist.scan(line) end
254
+ .flatten.compact.reject(&:gone?)
230
255
  end
231
256
 
232
- def skin
257
+ def skin()
233
258
  waitrt?
234
- fput "skin ##{@id}" if dead?
235
- self
259
+ return unless dead?
260
+ (_, lines) = Skin.capture(self.to_h, %[skin \#{{id}}])
261
+ lines
262
+ .map do |line| Exist.scan(line.split("yielding").last) end
263
+ .flatten.compact.reject(&:gone?)
236
264
  end
237
265
  end
238
266
 
@@ -2,7 +2,8 @@
2
2
  require "Olib/core/action"
3
3
 
4
4
  class Exist
5
- GETTER = %r[\w$]
5
+ GETTER = %r[\w$]
6
+ PATTERN = %r(<a exist=(?:'|")(?<id>.*?)(?:'|") noun=(?:'|")(?<noun>.*?)(?:'|")>(?<name>.*?)</a>)
6
7
 
7
8
  def self.fetch(id)
8
9
  [ GameObj.inv, GameObj.containers.values,
@@ -12,8 +13,12 @@ class Exist
12
13
  .find do |item| item.id.to_s.eql?(id.to_s) end
13
14
  end
14
15
 
16
+ def self.scan(str)
17
+ str.scan(PATTERN).map do |matches| Item.new(GameObj.new(*matches)) end
18
+ end
19
+
15
20
  def self.normalize_type_data(type)
16
- (type or "").gsub(",", " ").split(" ")
21
+ (type or "").gsub(",", " ").split(" ").compact
17
22
  end
18
23
 
19
24
  attr_reader :id, :gameobj
@@ -35,6 +40,8 @@ class Exist
35
40
  end
36
41
 
37
42
  def method_missing(method, *args)
43
+ return nil if fetch.nil?
44
+
38
45
  if respond_to_missing?(method)
39
46
  fetch.send(method, *args)
40
47
  else
@@ -51,7 +58,7 @@ class Exist
51
58
  end
52
59
 
53
60
  def tags
54
- Exist.normalize_type_data(type).map(&:to_sym)
61
+ Exist.normalize_type_data("#{type},#{sellable}").map(&:to_sym)
55
62
  end
56
63
 
57
64
  def effects
@@ -53,6 +53,10 @@ class Item < Exist
53
53
  Transaction.new(take, **args)
54
54
  end
55
55
 
56
+ def appraise(**args)
57
+ transaction(**args).appraise()
58
+ end
59
+
56
60
  def sell(**args)
57
61
  transaction(**args).sell()
58
62
  end
@@ -3,7 +3,7 @@ require "Olib/ext/string"
3
3
 
4
4
  class MatchData
5
5
  def to_struct
6
- OpenStruct.new to_hash
6
+ OpenStruct.new to_h
7
7
  end
8
8
 
9
9
  def to_h
@@ -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,13 @@ 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
+ return {ok: 1, matches: matches, lines: lines} if (line.match(end_pattern) and state.eql?(:open))
37
42
  end
38
43
  end
39
44
 
@@ -1,3 +1,3 @@
1
1
  module Olib
2
- VERSION = "2.0.0-rc.1"
2
+ VERSION = "2.0.0-rc.2"
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondreian Shamsiel