Olib 0.1.0 → 0.1.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.
@@ -1,6 +1,13 @@
1
1
  class Char
2
+ EMPATH = "Empath"
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
+
2
8
  @@silvers = 0
3
9
  @@routines = {}
10
+ @@aiming = nil
4
11
 
5
12
  def Char.hide
6
13
  while not hiding?
@@ -14,6 +21,48 @@ class Char
14
21
  Char
15
22
  end
16
23
 
24
+ def Char.arm
25
+ fput "gird"
26
+ self
27
+ end
28
+
29
+ def Char.unarm
30
+ fput "store both"
31
+ self
32
+ end
33
+
34
+ def Char.swap
35
+ fput "swap"
36
+ self
37
+ end
38
+
39
+ def Char.stand
40
+ unless standing?
41
+ fput "stand"
42
+ waitrt?
43
+ end
44
+ self
45
+ end
46
+
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)
59
+ unless @@aiming == location
60
+ fput "aim #{location}"
61
+ @@aiming = location
62
+ end
63
+ self
64
+ end
65
+
17
66
  def Char.fwi_teleporter
18
67
  Vars.teleporter || Vars.mapdb_fwi_trinket
19
68
  end
@@ -27,6 +76,10 @@ class Char
27
76
  Char
28
77
  end
29
78
 
79
+ def Char.in_town?
80
+ Room.current.location =~ /the Adventurer's Guild|kharam|teras|landing|sol|icemule trace|mist|vaalor|illistim|rest|cysaegir|logoth/i
81
+ end
82
+
30
83
  def Char.left
31
84
  GameObj.left_hand.name == "Empty" ? nil : Olib::Item.new(GameObj.left_hand)
32
85
  end
@@ -75,7 +128,7 @@ class Char
75
128
  end
76
129
 
77
130
  def Char.deplete_wealth(silvers)
78
- @@silvers = @@silvers - silvers
131
+ #@@silvers = @@silvers - silvers
79
132
  end
80
133
 
81
134
  def Char.smart_wealth
@@ -109,5 +162,22 @@ class Char
109
162
  @@silvers
110
163
  end
111
164
 
165
+ def Char.total_wound_severity
166
+ INJURIES
167
+ .reduce(0) do |sum, method| sum + Wounds.send(method) end
168
+ end
169
+
170
+ def Char.wounded?
171
+ total_wound_severity.gt(0)
172
+ end
173
+
174
+ def Char.empty_hands
175
+ hands = [Char.left, Char.right].compact
112
176
 
177
+ hands.each do |hand| Containers.Lootsack.add hand end
178
+
179
+ yield
180
+
181
+ hands.each(&:take)
182
+ end
113
183
  end
@@ -0,0 +1,19 @@
1
+ class Disk
2
+ attr_accessor :owner, :full
3
+
4
+ def initialize(owner)
5
+ @owner = owner
6
+ @full = false
7
+ GameObj.loot.find do |item|
8
+ item.name.downcase =~/#{owner.downcase}/
9
+ end
10
+ end
11
+
12
+ def add(item)
13
+
14
+ end
15
+
16
+ def full?
17
+ @full
18
+ end
19
+ end
@@ -1,69 +1,206 @@
1
- module Olib
2
- class Group
3
- @@characters = {}
4
- @@checked = false
5
- @@characters[Char.name] = true # YOU CAN NEVER ESCAPE YOURSELF (so your own disk won't fuck up)
6
- @@leader = Char.name
7
-
8
- # ran at the initialization of a script
9
- def Group.check
10
- @@characters = {}
11
-
12
-
13
- fput "group"
14
- while line=get
15
- break if line =~ /You are not currently in a group/
16
- Group.define($1) if line =~ /([a-zA-Z]+) (is following you|is also a member of your group|is the leader of your group)/
17
- @@leader = $1 if line =~ /([a-zA-Z]+) is the leader of your group/
18
- break if line =~ /^Your group status is/
19
- end
20
- @@checked = true
21
- @@characters
1
+ require "ostruct"
2
+
3
+
4
+ class String
5
+ def is_i?
6
+ !!(self =~ /\A[-+]?[0-9]+\z/)
7
+ end
8
+ end
9
+
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
+ module Group
30
+ class Members
31
+ include Enumerable
32
+ attr_accessor :leader, :members, :birth
33
+ def initialize
34
+ @birth = Time.now
35
+ @members = []
22
36
  end
23
37
 
24
- def Group.leader
25
- @@leader
38
+ def clear!
39
+ @members = []
40
+ @birth = Time.now
41
+ @leader = nil
26
42
  end
27
43
 
28
- def Group.leader?
29
- Group.check unless @@checked
30
- @@leader == Char.name
44
+ def size
45
+ @members.size
31
46
  end
32
47
 
33
- def Group.whisper(msg)
34
- fput "whisper group #{msg}" unless Group.members.empty?
48
+ def empty?
49
+ @members.empty?
35
50
  end
36
-
37
- def Group.add(char)
38
- fput "group #{char}"
39
- Group.define(char)
51
+
52
+ def add(pc, leader = false)
53
+ member = Member.new pc, leader
54
+ if leader
55
+ @leader = member
56
+ end
57
+ @members << member
40
58
  self
41
59
  end
42
60
 
43
- def Group.remove(char)
44
- fput "remove #{char}"
45
- @@characters.delete(char)
61
+ def each(&block)
62
+ @members.each { |char| yield char }
46
63
  self
47
64
  end
48
65
 
49
- def Group.nonmembers
50
- Group.check unless @@checked
51
- others = GameObj.pcs.map! {|char| char.noun } || []
52
- # find all the disks/hidden players too
53
- disk_owners = GameObj.loot.find_all { |obj| (obj.noun == 'disk') }.map{|disk| /([A-Z](?:[a-z]+))/.match(disk.name)[0].strip } || []
54
- [others, disk_owners].flatten.reject(&:nil?).uniq - @@characters.keys
66
+ def include?(pc)
67
+ select { |char| char.name == pc }
55
68
  end
56
69
 
57
- def Group.members
58
- Group.check unless @@checked
59
- @@characters.keys
70
+ def nonmembers
71
+ (GameObj.pcs || []).reject do |pc|
72
+ @members.include?(pc)
73
+ end
60
74
  end
61
75
 
62
- def Group.define(name)
63
- GameObj.pcs.detect do |pc| @@characters[name] = pc.dup if pc.noun == name end
76
+ def to_s
77
+ "<Members: [#{@members.join(" ")}]>"
64
78
  end
65
79
  end
66
- end
67
80
 
68
- class Group < Olib::Group
81
+ class Member
82
+ attr :id, :leader
83
+ def initialize(pc, leader = false)
84
+ @id = pc.id
85
+ @leader = leader
86
+ end
87
+
88
+ private def ref
89
+ GameObj[@id]
90
+ end
91
+
92
+ def leader?
93
+ @leader
94
+ end
95
+
96
+ def name
97
+ ref.name.split.pop
98
+ end
99
+
100
+ def status
101
+ (ref.status.split(" ") || []).map(&:to_sym)
102
+ end
103
+
104
+ def is(state)
105
+ status =~ state
106
+ end
107
+
108
+ def ==(other)
109
+ @id == other.id
110
+ end
111
+
112
+ def to_s
113
+ "<#{name}: @leader=#{leader?} @status=#{status}>"
114
+ end
115
+ end
116
+
117
+ MEMBERS = Members.new
118
+ OPEN = :open
119
+ CLOSED = :closed
120
+ CHECK_HOOK = self.name.to_s
121
+ NO_GROUP = /You are not currently in a group/
122
+ MEMBER = /<a exist="(?<id>.*?)" noun="(?<name>.*?)">(.*?)<\/a> is (?<type>(the leader|also a member) of your group|following you)\./
123
+ STATE = /^Your group status is currently (?<state>open|closed)\./
124
+ END_GROUP = /list of other options\./
125
+
126
+ PARSER = Proc.new do |line|
127
+
128
+ if line.strip.empty? || line =~ NO_GROUP
129
+ nil
130
+ elsif line =~ STATE
131
+ nil
132
+ elsif line =~ END_GROUP
133
+ Group.checked!
134
+ DownstreamHook.remove(CHECK_HOOK)
135
+ nil
136
+ elsif line =~ MEMBER
137
+ begin
138
+ pc = line.match(MEMBER).to_struct
139
+ Group::MEMBERS.add GameObj[pc.name], (line =~ /leader/ ? true : false)
140
+ if line =~ /following/
141
+ Group::MEMBERS.leader = OpenStruct.new(name: Char.name, leader: true)
142
+ end
143
+ nil
144
+ rescue Exception => e
145
+ respond e
146
+ respond e.backtrace
147
+ end
148
+ else
149
+ line
150
+ end
151
+ end
152
+
153
+ @@checked = false
154
+
155
+ def Group.checked?
156
+ @@checked
157
+ end
158
+
159
+ def Group.checked!
160
+ @@checked = true
161
+ self
162
+ end
163
+
164
+ def Group.empty?
165
+ MEMBERS.empty?
166
+ end
167
+
168
+ def Group.exists?
169
+ !empty?
170
+ end
171
+
172
+ def Group.members
173
+ maybe_check
174
+ MEMBERS
175
+ end
176
+
177
+ def Group.to_s
178
+ MEMBERS.to_s
179
+ end
180
+
181
+ # ran at the initialization of a script
182
+ def Group.check
183
+ @@checked = false
184
+ MEMBERS.clear!
185
+ DownstreamHook.add(CHECK_HOOK, PARSER)
186
+ Game._puts "<c>group\r\n"
187
+ wait_until { Group.checked? }
188
+ MEMBERS
189
+ end
190
+
191
+ def Group.maybe_check
192
+ Group.check unless checked?
193
+ end
194
+
195
+ def Group.nonmembers
196
+ members.nonmembers
197
+ end
198
+
199
+ def Group.leader
200
+ members.leader
201
+ end
202
+
203
+ def Group.leader?
204
+ leader && leader.name == Char.name
205
+ end
69
206
  end
@@ -1,80 +1,21 @@
1
- module Olib
2
- module Inventory
3
- Vars.Olib[:Inventory] ||= Hash.new
4
-
5
- @@checked = false
6
-
7
-
8
- def Inventory.containers
9
- Inventory.check
10
- GameObj.containers
11
- end
12
-
13
- def Inventory.to_s
14
- Inventory.items.map(&:to_s)
15
- end
16
-
17
- def Inventory.checked?
18
- @@checked
19
- end
20
-
21
- def Inventory.[](query)
22
- GameObj.inv.select { |item|
23
- item.name == query || item.id == query
24
- }
25
- end
26
-
27
- def Inventory.fwi_teleporter
28
- # check for worn teleporter
29
- candidates= GameObj.inv.select { |item|
30
- item.name == Char.fwi_teleporter
31
- }
32
-
33
- unless candidates.empty?
34
- return Item.new(candidates.first)
35
- end
36
-
37
- # check in containers
38
- Inventory.items.select { |item|
39
- item.is? "teleporter"
40
- }.first
41
- end
42
-
43
- def Inventory.items
44
- Inventory.containers.map { |id, contents| contents.map {|item|
45
- Item.new(item).define("container", id)
46
- }
47
- }.flatten
48
- end
49
-
50
- def Inventory.check
51
- return self if Inventory.checked?
52
- GameObj.inv.select{ |item|
53
- !item.name.include?('tattoo')
54
- }.each {|item|
55
- if item.contents.nil?
56
- Olib.wrap("look in ##{item.id}") { |line|
57
- respond line =~ /Shadow engulf/
1
+ module Inventory
2
+ def Inventory.containers
3
+ GameObj.containers
4
+ end
58
5
 
59
- raise Olib::Errors::Mundane if line =~ /There is nothing in there.|Total|^In the (.*).$|prompt|^Shadows engulf/
6
+ def Inventory.to_s
7
+ Inventory.items.map(&:to_s)
8
+ end
60
9
 
61
- if line =~ /That is closed./
62
- Olib.wrap("open ##{item.id}") { |line|
63
- if line =~ /You open/
64
- multifput "look in ##{item.id}", "close ##{item.id}"
65
- end
66
- }
67
- end
68
- }
69
- end
70
- }
71
- @@checked = true
72
- return self
73
- end
74
-
10
+ def Inventory.[](query)
11
+ GameObj.inv.select { |item|
12
+ item.name == query || item.id == query
13
+ }
75
14
  end
76
15
 
77
- def Olib.Inventory
78
- Olib::Inventory
16
+ def Inventory.items
17
+ containers.map do |id, contents|
18
+ contents.map(&:to_item)
19
+ end.flatten
79
20
  end
80
21
  end