Class: Creature
- Inherits:
-
Exist
show all
- Includes:
- Comparable
- Defined in:
- lib/Olib/combat/creature.rb
Constant Summary
collapse
- Search =
Rill.new(
timeout: 1,
start: Rill.union(%(You search the <pushBold/><a exist="{{id}}"),))
- Skin =
Rill.new(
start: Rill.union(%[You skinned the <pushBold/><a exist="{{id}}"],
%[You botched],
%[has already"]))
- WOUNDS =
%i[
right_leg left_leg right_arm
left_arm head neck chest
abdomen back left_eye right_eye
right_hand left_hand nerves
]
- TAGS =
OpenStruct.new(
antimagic: %r[construct|Vvrael],
lowly: %r[kobold|rolton|velnalin|urgh],
trollish: %r[troll|csetari],
)
Constants inherited
from Exist
Exist::GETTER, Exist::PATTERN
Instance Attribute Summary collapse
Attributes inherited from Exist
#gameobj, #id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Exist
#==, #deconstruct_keys, #effects, #exists?, #fetch, fetch, #gone?, #method_missing, normalize_type_data, #respond_to_missing?, scan, #to_h, #to_s
Constructor Details
#initialize(creature) ⇒ Creature
Returns a new instance of Creature.
57
58
59
60
61
62
63
64
|
# File 'lib/Olib/combat/creature.rb', line 57
def initialize(creature)
super(creature)
@wounds = {}
@tags = Exist.normalize_type_data(creature.type).map(&:to_sym)
TAGS.each_pair do |tag, pattern| @tags << tag if @name =~ pattern end
Creature.add_boss_type(self)
heal
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Exist
Instance Attribute Details
Returns the value of attribute tags.
56
57
58
|
# File 'lib/Olib/combat/creature.rb', line 56
def tags
@tags
end
|
#wounds ⇒ Object
Returns the value of attribute wounds.
56
57
58
|
# File 'lib/Olib/combat/creature.rb', line 56
def wounds
@wounds
end
|
Class Method Details
.add_boss_type(foe) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/Olib/combat/creature.rb', line 48
def self.add_boss_type(foe)
return if foe.tags.include?(:aggressive)
if GameObj.type_data["aggressive npc"][:name].match stem_name(foe)
foe.tags << :aggressive
foe.tags << :npc
end
end
|
.stem_name(foe) ⇒ Object
44
45
46
|
# File 'lib/Olib/combat/creature.rb', line 44
def self.stem_name(foe)
foe.name.split(" ").slice(1..-1).join(" ")
end
|
37
38
39
40
41
42
|
# File 'lib/Olib/combat/creature.rb', line 37
def self.tags(name)
TAGS.each_pair.reduce([]) do |is, pair|
tag, pattern = pair
name =~ pattern ? is + [tag] : is
end
end
|
Instance Method Details
#<=>(other) ⇒ Object
153
154
155
|
# File 'lib/Olib/combat/creature.rb', line 153
def <=>(other)
self.danger <=> other.danger
end
|
#alive? ⇒ Boolean
134
135
136
|
# File 'lib/Olib/combat/creature.rb', line 134
def alive?
not dead?
end
|
#ambush(location: nil, qstrike: 0) ⇒ Object
231
232
233
234
|
# File 'lib/Olib/combat/creature.rb', line 231
def ambush(location: nil, qstrike: 0)
Char.aim(location) if location
Attack.apply(self, :ambush)
end
|
#can_cast? ⇒ Boolean
129
130
131
132
|
# File 'lib/Olib/combat/creature.rb', line 129
def can_cast?
injuries
@wounds[:right_arm] == 3 || @wounds[:head] == 3
end
|
#cast ⇒ Object
217
218
219
|
# File 'lib/Olib/combat/creature.rb', line 217
def cast
Attack.apply(self, :cast)
end
|
#danger ⇒ Object
147
148
149
150
151
|
# File 'lib/Olib/combat/creature.rb', line 147
def danger
status
.map do |state| Creatures::STATES.index(state) end
.reduce(&:+) || -1
end
|
#dead? ⇒ Boolean
209
210
211
|
# File 'lib/Olib/combat/creature.rb', line 209
def dead?
status.include?(:dead)
end
|
#fire(location: nil, qstrike: 0) ⇒ Object
221
222
223
224
|
# File 'lib/Olib/combat/creature.rb', line 221
def fire(location: nil, qstrike: 0)
Char.aim(location) if location
Attack.apply(self, :fire)
end
|
#heal ⇒ Object
70
71
72
73
|
# File 'lib/Olib/combat/creature.rb', line 70
def heal
WOUNDS.each do |location| @wounds[location] = 0 end
self
end
|
#hurl(location: nil, qstrike: 0) ⇒ Object
226
227
228
229
|
# File 'lib/Olib/combat/creature.rb', line 226
def hurl(location: nil, qstrike: 0)
Char.aim(location) if location
Attack.apply(self, :hurl, qstrike: qstrike)
end
|
#injuries ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/Olib/combat/creature.rb', line 75
def injuries
fput "look ##{@id}"
woundinfo = matchtimeout(2, /(he|she|it) (?:has|appears to be in good) .*/i)
if woundinfo =~ /appears to be in good shape/ then heal; return @wounds; end
if woundinfo =~ /some minor cuts and bruises on (his|her|its) right (?:hind )?leg/ then @wounds[:right_leg] = 1; end
if woundinfo =~ /some minor cuts and bruises on (his|her|its) left (?:hind )?leg/ then @wounds[:left_leg] = 1; end
if woundinfo =~ /some minor cuts and bruises on (his|her|its) (?:right arm|right foreleg)/ then @wounds[:right_arm] = 1; end
if woundinfo =~ /some minor cuts and bruises on (his|her|its) (?:left arm|left foreleg)/ then @wounds[:left_arm] = 1; end
if woundinfo =~ /minor bruises around (his|her|its) neck/ then @wounds[:neck] = 1; end
if woundinfo =~ /minor bruises around (his|her|its) head/ then @wounds[:head] = 1; end
if woundinfo =~ /minor cuts and bruises on (his|her|its) chest/ then @wounds[:chest] = 1; end
if woundinfo =~ /minor cuts and bruises on (his|her|its) abdomen/ then @wounds[:abdomen] = 1; end
if woundinfo =~ /minor cuts and bruises on (his|her|its) back/ then @wounds[:back] = 1; end
if woundinfo =~ /bruised left eye/ then @wounds[:left_eye] = 1; end
if woundinfo =~ /bruised right eye/ then @wounds[:right_eye] = 1; end
if woundinfo =~ /some minor cuts and bruises on (his|her|its) right (?:hand|paw|claw)/ then @wounds[:right_hand] = 1; end
if woundinfo =~ /some minor cuts and bruises on (his|her|its) left (?:hand|paw|claw)/ then @wounds[:left_hand] = 1; end
if woundinfo =~ /a strange case of muscle twitching/ then @wounds[:nerves] = 1; end
if woundinfo =~ /fractured and bleeding right (?:hind )?leg/ then @wounds[:right_leg] = 2; end
if woundinfo =~ /fractured and bleeding left (?:hind )?leg/ then @wounds[:left_leg] = 2; end
if woundinfo =~ /fractured and bleeding (?:right arm|right foreleg)/ then @wounds[:right_arm] = 2; end
if woundinfo =~ /fractured and bleeding (?:left arm|left foreleg)/ then @wounds[:left_arm] = 2; end
if woundinfo =~ /moderate bleeding from (his|her|its) neck/ then @wounds[:neck] = 2; end
if woundinfo =~ /minor lacerations about (his|her|its) head and a possible mild concussion/ then @wounds[:head] = 2; end
if woundinfo =~ /deep lacerations across (his|her|its) chest/ then @wounds[:chest] = 2; end
if woundinfo =~ /deep lacerations across (his|her|its) abdomen/ then @wounds[:abdomen] = 2; end
if woundinfo =~ /deep lacerations across (his|her|its) back/ then @wounds[:back] = 2; end
if woundinfo =~ /swollen left eye/ then @wounds[:left_eye] = 2; end
if woundinfo =~ /swollen right eye/ then @wounds[:right_eye] = 2; end
if woundinfo =~ /fractured and bleeding right (?:hand|paw|claw)/ then @wounds[:right_hand] = 2; end
if woundinfo =~ /fractured and bleeding left (?:hand|paw|claw)/ then @wounds[:left_hand] = 2; end
if woundinfo =~ /a case of sporadic convulsions/ then @wounds[:nerves] = 2; end
if woundinfo =~ /severed right (?:hind )?leg/ then @wounds[:right_leg] = 3; end
if woundinfo =~ /severed left (?:hind )?leg/ then @wounds[:left_leg] = 3; end
if woundinfo =~ /severed (?:right arm|right foreleg)/ then @wounds[:right_arm] = 3; end
if woundinfo =~ /severed (?:left arm|left foreleg)/ then @wounds[:left_arm] = 3; end
if woundinfo =~ /snapped bones and serious bleeding from (his|her|its) neck/ then @wounds[:neck] = 3; end
if woundinfo =~ /severe head trauma and bleeding from (his|her|its) ears/ then @wounds[:head] = 3; end
if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) chest/ then @wounds[:chest] = 3; end
if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) abdomen/ then @wounds[:abdomen] = 3; end
if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) back/ then @wounds[:back] = 3; end
if woundinfo =~ /blinded left eye/ then @wounds[:left_eye] = 3; end
if woundinfo =~ /blinded right eye/ then @wounds[:right_eye] = 3; end
if woundinfo =~ /severed right (?:hand|paw|claw)/ then @wounds[:right_hand] = 3; end
if woundinfo =~ /severed left (?:hand|paw|claw)/ then @wounds[:left_hand] = 3; end
if woundinfo =~ /a case of uncontrollable convulsions/ then @wounds[:nerves] = 3; end
@wounds
end
|
#kill ⇒ Object
213
214
215
|
# File 'lib/Olib/combat/creature.rb', line 213
def kill
Attack.apply(self, :kill)
end
|
#kill_shot(order = %i(left_eye right_eye head neck back),, default = :chest) ⇒ Object
165
166
167
168
169
170
171
|
# File 'lib/Olib/combat/creature.rb', line 165
def kill_shot(order = %i(left_eye right_eye head neck back), default = :chest)
injuries
return (order
.drop_while do |area| @wounds[area] == 3 end
.first || default).to_game
end
|
#legged? ⇒ Boolean
124
125
126
127
|
# File 'lib/Olib/combat/creature.rb', line 124
def legged?
injuries
@wounds[:right_leg] == 3 || @wounds[:left_leg] == 3
end
|
#level ⇒ Object
182
183
184
|
# File 'lib/Olib/combat/creature.rb', line 182
def level()
metadata.level
end
|
#limbed? ⇒ Boolean
138
139
140
141
|
# File 'lib/Olib/combat/creature.rb', line 138
def limbed?
injuries
@wounds[:right_leg] == 3 || @wounds[:left_leg] == 3 || @wounds[:right_arm] == 3
end
|
178
179
180
|
# File 'lib/Olib/combat/creature.rb', line 178
def metadata()
OpenStruct.new Creatures::Metadata.get(name.gsub(/hanging|flying/, "").strip)
end
|
#mstrike ⇒ Object
198
199
200
201
202
203
|
# File 'lib/Olib/combat/creature.rb', line 198
def mstrike
unless dead?
fput "mstrike ##{@id}"
end
self
end
|
#prone? ⇒ Boolean
143
144
145
|
# File 'lib/Olib/combat/creature.rb', line 143
def prone?
status.include?(:lying) || status.include?(:prone) ? true : false
end
|
#search ⇒ Object
236
237
238
239
240
241
242
243
244
|
# File 'lib/Olib/combat/creature.rb', line 236
def search()
waitrt?
return unless dead?
(_, _, lines) = Search.capture(self.to_h, %[search \#{{id}}])
lines[1..-1]
.map do |line| Exist.scan(line) end
.flatten.compact.reject(&:gone?)
end
|
#skin ⇒ Object
246
247
248
249
250
251
252
253
254
|
# File 'lib/Olib/combat/creature.rb', line 246
def skin()
waitrt?
return unless dead?
(_, _, lines)= Skin.capture(self.to_h, %[skin \#{{id}}])
@skinned = true
lines
.map do |line| Exist.scan(line.split("yielding").last) end
.flatten.compact.reject(&:gone?)
end
|
#skin? ⇒ Boolean
161
162
163
|
# File 'lib/Olib/combat/creature.rb', line 161
def skin?
dead? && !@skinned && metadata.skin.is_a?(String)
end
|
#status ⇒ Object
205
206
207
|
# File 'lib/Olib/combat/creature.rb', line 205
def status()
super.split(",").map(&:to_sym)
end
|
#stunned? ⇒ Boolean
157
158
159
|
# File 'lib/Olib/combat/creature.rb', line 157
def stunned?
status.include?(:stunned)
end
|
#target ⇒ Object
192
193
194
195
196
|
# File 'lib/Olib/combat/creature.rb', line 192
def target
result = dothistimeout "target ##{@id}", 3, /#{Dictionary.targetable.values.join('|')}/
@targetable = (result =~ Dictionary.targetable[:yes])
self
end
|
#targetable? ⇒ Boolean
173
174
175
176
|
# File 'lib/Olib/combat/creature.rb', line 173
def targetable?
target if @targetable.nil?
@targetable
end
|