Class: Creature
- Inherits:
-
Object
- Object
- Creature
- Includes:
- Comparable
- Defined in:
- lib/Olib/combat/creature.rb
Constant Summary collapse
- WOUNDS =
[ :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( undead: /zombie|ghost|skele|ghoul|spectral|wight|shade/ | /spectre|revenant|apparition|bone|were|rotting/ | /spirit|soul|barghest|vruul|night|phant|naisirc/| /shrickhen|seraceris|n'ecare|vourkha|bendith/ | /baesrukha|lich|dybbuk|necrotic|flesh|waern|banshee/| /seeker|eidolon|decay|putrefied|vaespilon/, antimagic: /construct|Vvrael/, grimswarm: /grimswarm/, lowly: /kobold|rolton|velnalin|urgh/, trollish: /troll|csetari/ )
Instance Attribute Summary collapse
-
#can_cast ⇒ Object
Returns the value of attribute can_cast.
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
-
#legged ⇒ Object
Returns the value of attribute legged.
-
#limbed ⇒ Object
Returns the value of attribute limbed.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#targetable ⇒ Object
Returns the value of attribute targetable.
-
#wounds ⇒ Object
Returns the value of attribute wounds.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #alive? ⇒ Boolean
- #ambush(location = nil) ⇒ Object
- #can_cast? ⇒ Boolean
- #danger ⇒ Object
- #eql?(other) ⇒ Boolean
- #fetch ⇒ Object
- #fire(location = nil) ⇒ Object
- #gone? ⇒ Boolean
- #heal ⇒ Object
- #hurl(location = nil) ⇒ Object
-
#initialize(creature) ⇒ Creature
constructor
A new instance of Creature.
- #injuries ⇒ Object
- #kill ⇒ Object
- #kill_shot(order = [:left_eye, :right_eye, :head, :neck, :back], default = :chest) ⇒ Object
- #legged? ⇒ Boolean
- #level ⇒ Object
- #limbed? ⇒ Boolean
- #metadata ⇒ Object
- #mstrike ⇒ Object
- #prone? ⇒ Boolean
- #search ⇒ Object
- #skin ⇒ Object
- #status ⇒ Object
- #stunned? ⇒ Boolean
- #target ⇒ Object
- #targetable? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(creature) ⇒ Creature
Returns a new instance of Creature.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/Olib/combat/creature.rb', line 71 def initialize(creature) @id = creature.id @name = creature.name @wounds = {} = ((creature.type || "").gsub(",", " ").split(" ") + (["tags"] || []) ).map(&:to_sym) TAGS.each_pair do |tag, pattern| << tag if @name =~ pattern end heal end |
Instance Attribute Details
#can_cast ⇒ Object
Returns the value of attribute can_cast.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def can_cast @can_cast end |
#data ⇒ Object
Returns the value of attribute data.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def id @id end |
#legged ⇒ Object
Returns the value of attribute legged.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def legged @legged end |
#limbed ⇒ Object
Returns the value of attribute limbed.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def limbed @limbed end |
#name ⇒ Object
Returns the value of attribute name.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def name @name end |
#tags ⇒ Object
Returns the value of attribute tags.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def end |
#targetable ⇒ Object
Returns the value of attribute targetable.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def targetable @targetable end |
#wounds ⇒ Object
Returns the value of attribute wounds.
68 69 70 |
# File 'lib/Olib/combat/creature.rb', line 68 def wounds @wounds end |
Class Method Details
.tags(name) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/Olib/combat/creature.rb', line 61 def self.(name) TAGS.each_pair.reduce([]) do |is, pair| tag, pattern = pair name =~ pattern ? is + [tag] : is end end |
Instance Method Details
#<=>(other) ⇒ Object
200 201 202 |
# File 'lib/Olib/combat/creature.rb', line 200 def <=>(other) self.danger <=> other.danger end |
#==(other) ⇒ Object
189 190 191 |
# File 'lib/Olib/combat/creature.rb', line 189 def ==(other) @id.to_i == other.id.to_i end |
#alive? ⇒ Boolean
168 169 170 |
# File 'lib/Olib/combat/creature.rb', line 168 def alive? !dead? end |
#ambush(location = nil) ⇒ Object
233 234 235 236 237 238 239 240 241 242 |
# File 'lib/Olib/combat/creature.rb', line 233 def ambush(location=nil) until hidden? fput "hide" waitrt? end Char.aim(location) if location fput "ambush ##{@id}" waitrt? self end |
#can_cast? ⇒ Boolean
163 164 165 166 |
# File 'lib/Olib/combat/creature.rb', line 163 def can_cast? injuries @wounds[:right_arm] == 3 || @wounds[:head] == 3 end |
#danger ⇒ Object
194 195 196 197 198 |
# File 'lib/Olib/combat/creature.rb', line 194 def danger status .map do |state| Creatures::STATES.index(state) end .reduce(&:+) || -1 end |
#eql?(other) ⇒ Boolean
185 186 187 |
# File 'lib/Olib/combat/creature.rb', line 185 def eql?(other) self == other end |
#fetch ⇒ Object
90 91 92 |
# File 'lib/Olib/combat/creature.rb', line 90 def fetch GameObj[@id] end |
#fire(location = nil) ⇒ Object
258 259 260 261 262 263 264 |
# File 'lib/Olib/combat/creature.rb', line 258 def fire(location=nil) unless dead? Char.aim(location) if location fput "fire ##{@id}" end self end |
#gone? ⇒ Boolean
177 178 179 |
# File 'lib/Olib/combat/creature.rb', line 177 def gone? fetch.nil? ? true : false end |
#heal ⇒ Object
98 99 100 101 102 103 |
# File 'lib/Olib/combat/creature.rb', line 98 def heal WOUNDS.each do |location| @wounds[location] = 0 end self end |
#hurl(location = nil) ⇒ Object
266 267 268 269 270 271 272 |
# File 'lib/Olib/combat/creature.rb', line 266 def hurl(location=nil) unless dead? Char.aim(location) if location fput "hurl ##{@id}" end self end |
#injuries ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/Olib/combat/creature.rb', line 105 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
251 252 253 254 255 256 |
# File 'lib/Olib/combat/creature.rb', line 251 def kill unless dead? fput "kill ##{@id}" end self end |
#kill_shot(order = [:left_eye, :right_eye, :head, :neck, :back], default = :chest) ⇒ Object
208 209 210 211 212 213 |
# File 'lib/Olib/combat/creature.rb', line 208 def kill_shot(order = [:left_eye, :right_eye, :head, :neck, :back], default = :chest) wounds = injuries return (order .drop_while do |area| @wounds[area] == 3 end .first || default).to_game end |
#legged? ⇒ Boolean
158 159 160 161 |
# File 'lib/Olib/combat/creature.rb', line 158 def legged? injuries @wounds[:right_leg] == 3 || @wounds[:left_leg] == 3 end |
#level ⇒ Object
82 83 84 |
# File 'lib/Olib/combat/creature.rb', line 82 def level ["level"] end |
#limbed? ⇒ Boolean
172 173 174 175 |
# File 'lib/Olib/combat/creature.rb', line 172 def limbed? injuries @wounds[:right_leg] == 3 || @wounds[:left_leg] == 3 || @wounds[:right_arm] == 3 end |
#metadata ⇒ Object
86 87 88 |
# File 'lib/Olib/combat/creature.rb', line 86 def Creatures::BY_NAME[@name] || {} end |
#mstrike ⇒ Object
244 245 246 247 248 249 |
# File 'lib/Olib/combat/creature.rb', line 244 def mstrike unless dead? fput "mstrike ##{@id}" end self end |
#prone? ⇒ Boolean
181 182 183 |
# File 'lib/Olib/combat/creature.rb', line 181 def prone? status.include?(:lying) || status.include?(:prone) ? true : false end |
#search ⇒ Object
274 275 276 277 |
# File 'lib/Olib/combat/creature.rb', line 274 def search waitrt? fput "search ##{@id}" if dead? end |
#skin ⇒ Object
279 280 281 282 283 |
# File 'lib/Olib/combat/creature.rb', line 279 def skin waitrt? fput "skin ##{@id}" if dead? self end |
#status ⇒ Object
94 95 96 |
# File 'lib/Olib/combat/creature.rb', line 94 def status fetch.status.split(" ") end |
#stunned? ⇒ Boolean
204 205 206 |
# File 'lib/Olib/combat/creature.rb', line 204 def stunned? status.include?(:stunned) ? true : false end |
#target ⇒ Object
227 228 229 230 231 |
# File 'lib/Olib/combat/creature.rb', line 227 def target result = dothistimeout "target ##{@id}", 3, /#{Olib::Dictionary.targetable.values.join('|')}/ @targetable = result =~ Olib::Dictionary.targetable[:yes] ? true : false self end |
#targetable? ⇒ Boolean
215 216 217 218 |
# File 'lib/Olib/combat/creature.rb', line 215 def targetable? target if @targetable.nil? @targetable end |
#to_s ⇒ Object
285 286 287 |
# File 'lib/Olib/combat/creature.rb', line 285 def to_s "<#{fetch.name}:#{@id} @danger=#{danger} @tags=#{tags} @status=#{status}>" end |