Olib 2.0.0.pre.rc.5 → 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.
- checksums.yaml +4 -4
- data/Olib.gemspec +1 -1
- data/lib/Olib/bounty.rb +16 -23
- data/lib/Olib/character/group.rb +2 -2
- data/lib/Olib/combat/attack.rb +60 -0
- data/lib/Olib/combat/creature.rb +31 -54
- data/lib/Olib/combat/creatures.json +1770 -0
- data/lib/Olib/combat/creatures.rb +0 -19
- data/lib/Olib/combat/metadata.rb +13 -0
- data/lib/Olib/core/container.rb +1 -1
- data/lib/Olib/core/exist.rb +4 -12
- data/lib/Olib/core/item.rb +7 -0
- data/lib/Olib/core/scroll.rb +37 -0
- data/lib/Olib/core/transaction.rb +15 -3
- data/lib/Olib/go2.rb +1 -2
- data/lib/Olib/log.rb +42 -0
- data/lib/Olib/pattern_matching/rill.rb +4 -1
- data/lib/Olib/version.rb +1 -1
- metadata +7 -4
- data/lib/Olib/objects/scroll.rb +0 -42
@@ -1,11 +1,8 @@
|
|
1
|
-
require 'net/http'
|
2
1
|
require 'json'
|
3
2
|
# a collection for managing all of the creatures in a room
|
4
3
|
|
5
4
|
class Creatures
|
6
5
|
include Enumerable
|
7
|
-
|
8
|
-
METADATA_URL = "https://cdn.rawgit.com/ondreian/gemstone_data_project/c40a5dfb/creatures.json"
|
9
6
|
|
10
7
|
ARCHETYPES = %i[
|
11
8
|
undead living weak
|
@@ -22,22 +19,6 @@ class Creatures
|
|
22
19
|
|
23
20
|
KINDS = ARCHETYPES + STATES
|
24
21
|
|
25
|
-
def self.fetch_metadata()
|
26
|
-
begin
|
27
|
-
JSON.parse Net::HTTP.get URI METADATA_URL
|
28
|
-
rescue
|
29
|
-
puts $!
|
30
|
-
puts $!.backtrace[0..1]
|
31
|
-
[]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
METADATA = fetch_metadata()
|
36
|
-
BY_NAME = METADATA.reduce(Hash.new) do |by_name, record|
|
37
|
-
by_name[record["name"]] = record
|
38
|
-
by_name
|
39
|
-
end
|
40
|
-
|
41
22
|
ALL = -> creature { true }
|
42
23
|
|
43
24
|
attr_reader :predicate
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Creatures
|
2
|
+
module Metadata
|
3
|
+
@repo = JSON.parse File.read File.join(__dir__, "creatures.json")
|
4
|
+
|
5
|
+
def self.put(name:, level:, tags: [])
|
6
|
+
@repo[name.downcase] = {name: name, level: level, tags: tags}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.get(name)
|
10
|
+
@repo.fetch(name.downcase) do {name: name, level: Char.level, tags: []} end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/Olib/core/container.rb
CHANGED
data/lib/Olib/core/exist.rb
CHANGED
@@ -79,17 +79,9 @@ class Exist
|
|
79
79
|
inspect()
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
val = send(prop)
|
87
|
-
acc = "#{acc} #{prop}=#{val.inspect}" unless val.nil? or val.empty?
|
88
|
-
acc
|
89
|
-
end.strip
|
90
|
-
|
91
|
-
body = "#{body} contents=[#{contents.map {|i| i.inspect(depth + 1)}.join}]" unless contents.to_a.empty?
|
92
|
-
|
93
|
-
%[#{indent}#{self.class.name}(#{body})]
|
82
|
+
def deconstruct_keys(keys)
|
83
|
+
keys.each_with_object({}) do |key, acc|
|
84
|
+
acc[key] = self.send(key)
|
85
|
+
end
|
94
86
|
end
|
95
87
|
end
|
data/lib/Olib/core/item.rb
CHANGED
@@ -2,6 +2,7 @@ require "ostruct"
|
|
2
2
|
require "Olib/core/exist"
|
3
3
|
require "Olib/core/use"
|
4
4
|
require "Olib/core/transaction"
|
5
|
+
require "Olib/core/scroll"
|
5
6
|
|
6
7
|
class GameObj
|
7
8
|
def to_item
|
@@ -12,6 +13,12 @@ end
|
|
12
13
|
# this is the structure for a base Object
|
13
14
|
# wraps an instance of GameObj and adds the ability for tags, queries
|
14
15
|
class Item < Exist
|
16
|
+
def self.of(item, container = nil)
|
17
|
+
return Scroll.new(item, container) if item.type.include?("scroll")
|
18
|
+
return Item.new(item, container)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
15
22
|
def self.fetch(id)
|
16
23
|
new Exist.fetch(id)
|
17
24
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Scroll < Exist
|
2
|
+
SPELL = %r[\((?<num>\d+)\)\s(?<name>(\w|\s)+)$]
|
3
|
+
|
4
|
+
def initialize(obj, container = nil)
|
5
|
+
super(obj.id)
|
6
|
+
@knowledge = nil
|
7
|
+
@container = container
|
8
|
+
end
|
9
|
+
|
10
|
+
def spells()
|
11
|
+
@_spells ||= _read()
|
12
|
+
end
|
13
|
+
|
14
|
+
def knowledge?
|
15
|
+
spells
|
16
|
+
@knowledge.eql?(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def _read()
|
20
|
+
Script.current.want_downstream_xml = true
|
21
|
+
dothistimeout("read ##{id}", 5, /It takes you a moment to focus on the/)
|
22
|
+
spells = []
|
23
|
+
@knowledge = false
|
24
|
+
while line = get
|
25
|
+
@knowledge = true if line.include?(%[in vibrant ink])
|
26
|
+
break if line =~ %r[<prompt]
|
27
|
+
_parse_spell(spells, line.strip)
|
28
|
+
end
|
29
|
+
Script.current.want_downstream_xml = false
|
30
|
+
return spells
|
31
|
+
end
|
32
|
+
|
33
|
+
def _parse_spell(spells, line)
|
34
|
+
return unless line =~ SPELL
|
35
|
+
spells << OpenStruct.new(line.match(SPELL).to_h)
|
36
|
+
end
|
37
|
+
end
|
@@ -5,6 +5,7 @@ class Transaction < Exist
|
|
5
5
|
start: %[to appraise (?:a |an |)<a exist="{{id}}"],
|
6
6
|
close: Regexp.union(
|
7
7
|
%r[I already appraised that],
|
8
|
+
%r[Sorry, #{Char.name}, I'm not buying anything this valuable today\.],
|
8
9
|
%r[(I'll give you|How's|I'll offer you|worth at least) (?<value>\d+)],
|
9
10
|
%r[(?<value>\d+) silvers])
|
10
11
|
)
|
@@ -14,6 +15,9 @@ class Transaction < Exist
|
|
14
15
|
close: Regexp.union(
|
15
16
|
%r[(hands you|for) (?<value>\d+)],
|
16
17
|
%r[No #{Char.name}, I won't buy that],
|
18
|
+
%r[I'm sorry, #{Char.name}, but I have no use for that\.],
|
19
|
+
%r[He hands it back to you],
|
20
|
+
%r[Nope #{Char.name}, I ain't buying that\.],
|
17
21
|
%r[basically worthless here, #{Char.name}])
|
18
22
|
)
|
19
23
|
|
@@ -33,9 +37,13 @@ class Transaction < Exist
|
|
33
37
|
def appraise()
|
34
38
|
return self unless @value.nil?
|
35
39
|
take
|
36
|
-
(match,
|
40
|
+
(_, match, lines) = Appraise.capture(self.to_h,
|
37
41
|
"appraise \#{{id}}")
|
38
|
-
|
42
|
+
if lines.any? {|line| line.include?(%[Sorry, Pixelia, I'm not buying anything this valuable today.])}
|
43
|
+
@value = Float::INFINITY
|
44
|
+
else
|
45
|
+
@value = match[:value].to_i
|
46
|
+
end
|
39
47
|
self
|
40
48
|
end
|
41
49
|
|
@@ -46,8 +54,12 @@ class Transaction < Exist
|
|
46
54
|
transaction: self,
|
47
55
|
reason: "Value[#{@value}] is over Threshold[#{@threshold}]"]
|
48
56
|
end
|
49
|
-
|
57
|
+
|
58
|
+
(_, match, _lines) = Sell.capture(self.to_h,
|
50
59
|
"sell \#{{id}}")
|
60
|
+
|
61
|
+
|
62
|
+
match[:value] = 0 unless match[:value].is_a?(Integer)
|
51
63
|
Ok[**match]
|
52
64
|
end
|
53
65
|
end
|
data/lib/Olib/go2.rb
CHANGED
@@ -32,8 +32,7 @@ class Go2
|
|
32
32
|
def Go2.room(roomid)
|
33
33
|
unless Room.current.id == roomid || Room.current.tags.include?(roomid)
|
34
34
|
Char.unhide if hidden
|
35
|
-
|
36
|
-
wait_while { running? "go2" };
|
35
|
+
Script.run("go2", "#{roomid} _disable_confirm_")
|
37
36
|
end
|
38
37
|
Go2
|
39
38
|
end
|
data/lib/Olib/log.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Preset
|
2
|
+
def self.as(kind, body)
|
3
|
+
%[<preset id="#{kind}">#{body}</preset>\r\n]
|
4
|
+
end
|
5
|
+
end
|
6
|
+
##
|
7
|
+
## contextual logging
|
8
|
+
##
|
9
|
+
module Log
|
10
|
+
require "cgi"
|
11
|
+
def self.out(msg, label: :debug)
|
12
|
+
return _write _view(msg, label) unless msg.is_a?(Exception)
|
13
|
+
## pretty-print exception
|
14
|
+
_write _view(msg.message, label)
|
15
|
+
msg.backtrace.to_a.slice(0..5).each do |frame| _write _view(frame, label) end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self._write(line)
|
19
|
+
if Script.current.vars.include?("--headless") or not defined?(:_respond)
|
20
|
+
$stdout.write(line + "\n")
|
21
|
+
elsif line.include?("<") and line.include?(">")
|
22
|
+
respond(line)
|
23
|
+
else
|
24
|
+
_respond Preset.as(:debug, CGI.escapeHTML(line))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self._view(msg, label)
|
29
|
+
label = [Script.current.name, label].flatten.compact.join(".")
|
30
|
+
safe = msg.inspect
|
31
|
+
#safe = safe.gsub("<", "<").gsub(">", ">") if safe.include?("<") and safe.include?(">")
|
32
|
+
"[#{label}] #{safe}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.pp(msg, label = :debug)
|
36
|
+
respond _view(msg, label)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.dump(*args)
|
40
|
+
pp(*args)
|
41
|
+
end
|
42
|
+
end
|
@@ -38,7 +38,10 @@ class Rill
|
|
38
38
|
if (result = (line.match(begin_pattern) or line.match(end_pattern)))
|
39
39
|
matches.merge!(result.to_h)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
|
+
if (line.match(end_pattern) and state.eql?(:open))
|
43
|
+
return [:ok, matches, lines]
|
44
|
+
end
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
data/lib/Olib/version.rb
CHANGED
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.
|
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,7 +64,6 @@ 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
|
65
69
|
- lib/Olib/opts.rb
|
@@ -94,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
98
|
- !ruby/object:Gem::Version
|
95
99
|
version: 1.3.1
|
96
100
|
requirements: []
|
97
|
-
|
98
|
-
rubygems_version: 2.7.6
|
101
|
+
rubygems_version: 3.1.0.pre1
|
99
102
|
signing_key:
|
100
103
|
specification_version: 4
|
101
104
|
summary: Useful Lich extensions for Gemstone IV
|
data/lib/Olib/objects/scroll.rb
DELETED
@@ -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
|