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.
@@ -0,0 +1,28 @@
1
+ class Stance
2
+ OFFENSIVE = "offensive"
3
+ ADVANCE = "advance"
4
+ FORWARD = "forward"
5
+ NEUTRAL = "neutral"
6
+ GUARDED = "guarded"
7
+ DEFENSIVE = "defensive"
8
+
9
+ ENUM = [OFFENSIVE, ADVANCE, FORWARD, NEUTRAL, GUARDED, DEFENSIVE]
10
+
11
+ def self.change(stance)
12
+ waitcastrt?
13
+ waitrt?
14
+ fput "stance #{stance}" unless checkstance == stance
15
+ sleep 0.1
16
+ self
17
+ end
18
+
19
+ ENUM.each do |stance|
20
+ Stance.define_singleton_method((stance.to_s + "?").to_sym) do
21
+ checkstance == str
22
+ end
23
+
24
+ Stance.define_singleton_method(stance.to_sym) do
25
+ change stance
26
+ end
27
+ end
28
+ end
@@ -4,252 +4,286 @@
4
4
  # - add corporeal types
5
5
  # - add quadrapedal types
6
6
  # - add known spells/cmans/manuevers and algorithm for danger level by profession and skills
7
+ require "ostruct"
8
+ require "Olib/combat/creatures"
7
9
 
8
- module Olib
9
- class Creature < Olib::Gameobj_Extender
10
- def Creature.escortee(name)
11
- name =~ /^(?:traveller|magistrate|merchant|scribe|dignitary|official)$/
12
- end
10
+ class FalseClass
11
+ def to_i
12
+ 0
13
+ end
14
+ end
15
+ class TrueClass
16
+ def to_i
17
+ 1
18
+ end
19
+ end
13
20
 
14
- def Creature.bandit(name)
15
- name =~ /thief|rogue|bandit|mugger|outlaw|highwayman|marauder|brigand|thug|robber/
16
- end
17
-
18
- def Creature.undead(name)
19
- name =~ /zombie rolton|lesser ghoul|skeleton|lesser frost shade|lesser shade|phantom|moaning phantom|ghost|ice skeleton|greater ghoul|revenant|mist wraith|dark apparition|lesser mummy|firephantom|spectral fisherman|bone golem|snow spectre|death dirge|werebear|darkwoode|spectre|shadowy spectre|wraith|tomb wight|wolfshade|ghoul master|ghost wolf|ghostly warrior|dark assassin|rotting krolvin pirate|elder ghoul master|nedum vereri|arch wight|wood wight|ancient ghoul master|nonomino|zombie|crazed zombie|rotting woodsman|roa'ter wormling|carceris|spectral monk|tree spirit|monastic lich|skeletal lord|moaning spirit|elder tree spirit|krynch|skeletal ice troll|rotting corpse|rotting farmhand|ghostly mara|ghostly pooka|skeletal giant|rock troll zombie|skeletal soldier|spectral warrior|troll wraith|spectral shade|barghest|spectral woodsman|spectral lord|skeletal warhorse|lesser moor wight|shadow mare|shadow steed|vourkha|greater moor wight|forest bendith|spectral miner|bog wraith|phantasma|frozen corpse|baesrukha|night mare|gaunt spectral servant|bog wight|ice wraith|lesser vruul|rotting chimera|dybbuk|necrotic snake|waern|banshee|flesh golem|seeker|ethereal mage apprentice|nightmare steed|eidolon|decaying Citadel guardsman|rotting Citadel arbalester|putrefied Citadel herald|phantasmal bestial swordsman|wind wraith|soul golem|greater vruul|naisirc|shrickhen|seraceris|lich qyn'arj|n'ecare|lost soul|vaespilon|spectral triton defender|ethereal triton sentry/
20
- end
21
-
22
- def Creature.antimagic(name)
23
- name =~ /lesser construct|Vvrael warlock|Vvrael witch/
24
- end
25
-
26
- def Creature.living(name)
27
- name =~ /carrion worm|black rolton|black-winged daggerbeak|fanged rodent|kobold|mountain rolton|giant rat|slimy little grub|young grass snake|fire ant|rolton|spotted gnarp|giant ant|cave gnome|rabid squirrel|big ugly kobold|goblin|pale crab|fanged goblin|brown gak|thyril|spotted gak|sea nymph|Mistydeep siren|dark vysan|greater ice spider|fire salamander|cave nipper|kobold shepherd|relnak|striped relnak|cave gnoll|hobgoblin|Bresnahanini rolton|velnalin|spotted velnalin|striped gak|white vysan|mountain snowcat|troglodyte|black urgh|water moccasin|cobra|urgh|ridge orc|whiptail|spotted leaper|fanged viper|mongrel kobold|night golem|mongrel hobgoblin|bobcat|coyote|water witch|nasty little gremlin|monkey|spotted lynx|cockatrice|leaper|lesser orc|snowy cockatrice|blood eagle|lesser red orc|hobgoblin shaman|shelfae soldier|lesser burrow orc|greater kappa|greater spider|thrak|crystal crab|greater orc|greater burrow orc|albino tomb spider|mottled thrak|brown spinner|crocodile|manticore|rabid guard dog|great boar|raider orc|cave worm|gnoll worker|giant marmot|shelfae chieftain|Neartofar orc|wall guardian|crystal golem|dark orc|great stag|plumed cockatrice|tawny brindlecat|gnoll thief|deranged sentry|Agresh troll scout|forest troll|grey orc|silverback orc|great brown bear|brown boar|giant weasel|black boar|swamp troll|panther|ridgeback boar|luminescent arachnid|gnoll ranger|large ogre|puma|arctic puma|Neartofar troll|black leopard|humpbacked puma|black bear|Agresh troll warrior|mongrel wolfhound|plains orc warrior|cave troll|phosphorescent worm|hill troll|wind witch|fire guardian|mountain ogre|Agresh bear|mongrel troll|red bear|fire rat|banded rattlesnake|mountain troll|spiked cavern urchin|gnoll guard|giant veaba|plains ogre|forest ogre|mountain goat|black panther|dark shambler|plains orc scout|krolvin mercenary|cave lizard|war troll|fire cat|mountain lion|bighorn sheep|shelfae warlord|plains orc shaman|greenwing hornet|plains lion|thunder troll|krolvin warrior|steel golem|gnoll priest|ogre warrior|massive grahnk|major spider|Agresh troll chieftain|striped warcat|Arachne servant|cave bear|plains orc chieftain|cougar|warthog|crested basilisk|dark panther|centaur|fenghai|Arachne acolyte|tree viper|burly reiver|reiver|ice hound|wolverine|veteran reiver|arctic wolverine|giant albino scorpion|krolvin warfarer|gnoll jarl|jungle troll|Arachne priest|Arachne priestess|troll chieftain|cyclops|Grutik savage|lesser stone gargoyle|snow leopard|giant hawk-owl|fire ogre|dobrem|ki-lin|darken|pra'eda|Grutik shaman|ice troll|arctic manticore|scaly burgee|hooded figure|hisskra warrior|giant albino tomb spider|hunter troll|jungle troll chieftain|mammoth arachnid|ash hag|wild hound|caribou|wild dog|giant fog beetle|mezic|three-toed tegu|hisskra shaman|maw spore|moor hound|sand beetle|tundra giant|colossus vulture|hisskra chieftain|moor witch|cold guardian|lava troll|moor eagle|bog troll|shimmering fungus|water wyrd|snow crone|undertaker bat|dust beetle|krolvin slaver|fire giant|arctic titan|Sheruvian initiate|tusked ursian|huge mein golem|magru|mud wasp|grizzly bear|frost giant|wood sprite|krolvin corsair|vesperti|greater bog troll|stone gargoyle|storm giant|myklian|kiramon worker|lesser ice giant|Sheruvian monk|roa'ter|siren lizard|shan wizard|shan warrior|minor glacei|dark vortece|shan cleric|swamp hag|shan ranger|wasp nest|dreadnought raptor|forest trali shaman|firethorn shoot|polar bear|mastodonic leopard|lesser faeroth|kiramon defender|forest trali|cinder wasp|greater ice giant|major glacei|bog spectre|sand devil|warrior shade|horned vor'taz|red-scaled thrak|greater faeroth|snow madrinol|tomb troll|wooly mammoth|ice golem|lesser ice elemental|sabre-tooth tiger|stone sentinel|animated slush|skayl|tomb troll necromancer|stone troll|glacial morph|lava golem|stone giant|massive pyrothag|black forest viper|massive black boar|fire elemental|black forest ogre|stone mastiff|Illoke mystic|massive troll king|ice elemental|Sheruvian harbinger|grifflet|fire sprite|emaciated hierophant|red tsark|Illoke shaman|muscular supplicant|yeti|lesser griffin|hunch-backed dogmatist|krag yeti|fire mage|krag dweller|storm griffin|lesser minotaur|moulis|csetairi|minotaur warrior|farlook|raving lunatic|minotaur magus|dhu goleras|earth elemental|gnarled being|caedera|greater krynch|gremlock|Illoke elder|festering taint|aivren|greater earth elemental|Ithzir scout|Illoke jarl|Ithzir initiate|water elemental|Ithzir janissary|Ithzir herald|triton dissembler|greater construct|Ithzir adept|triton executioner|siren|Ithzir seer|triton combatant|triton radical|war griffin|triton magus|greater water elemental/
28
- end
21
+ class Regexp
22
+ def or(re)
23
+ Regexp.new self.to_s + "|" + re.to_s
24
+ end
25
+ # define union operator for regex instance
26
+ def |(re)
27
+ self.or(re)
28
+ end
29
+ end
29
30
 
30
- def Creature.invasion(name)
31
- name =~ /taladorian/i
32
- end
31
+ class Symbol
32
+ def to_game
33
+ self.to_s.gsub("_", " ")
34
+ end
35
+ end
33
36
 
34
- def Creature.grimswarm(name)
35
- name =~ /griswarm/i
36
- end
37
37
 
38
- def Creature.animate(name)
39
- name =~ /animated/
38
+ class Creature
39
+ include Comparable
40
+
41
+ WOUNDS = [
42
+ :right_leg, :left_leg, :right_arm,
43
+ :left_arm, :head, :neck, :chest,
44
+ :abdomen, :back, :left_eye, :right_eye,
45
+ :right_hand, :left_hand, :nerves,
46
+ ]
47
+
48
+ TAGS = OpenStruct.new(
49
+ undead: /zombie|ghost|skele|ghoul|spectral|wight|shade/ |
50
+ /spectre|revenant|apparition|bone|were|rotting/ |
51
+ /spirit|soul|barghest|vruul|night|phant|naisirc/|
52
+ /shrickhen|seraceris|n'ecare|vourkha|bendith/ |
53
+ /baesrukha|lich|dybbuk|necrotic|flesh|waern|banshee/|
54
+ /seeker|eidolon|decay|putrefied|vaespilon/,
55
+ antimagic: /construct|Vvrael/,
56
+ grimswarm: /grimswarm/,
57
+ lowly: /kobold|rolton|velnalin|urgh/,
58
+ trollish: /troll|csetari/
59
+ )
60
+
61
+ def self.tags(name)
62
+ TAGS.each_pair.reduce([]) do |is, pair|
63
+ tag, pattern = pair
64
+ name =~ pattern ? is + [tag] : is
40
65
  end
66
+ end
41
67
 
42
- def Creature.ignoreable(name)
43
- name =~ /kobold|rolton|velnalin|urgh/
44
- end
68
+ attr_accessor :wounds, :targetable, :can_cast, :tags,
69
+ :data, :legged, :limbed, :id, :name
45
70
 
46
- def Creature.self_healing?(name)
47
- name =~ /troll|csetari/ ? true : false
71
+ def initialize(creature)
72
+ @id = creature.id
73
+ @name = creature.name
74
+ @wounds = {}
75
+ @tags = ((creature.type || "").gsub(",", " ").split(" ") + (metadata["tags"] || []) ).map(&:to_sym)
76
+ TAGS.each_pair do |tag, pattern|
77
+ @tags << tag if @name =~ pattern
48
78
  end
79
+ heal
80
+ end
49
81
 
50
- def Creature.tag(name)
51
- Creature.tags.map { |type|
52
- Creature.send(type, name) ? type : nil
53
- }.compact
54
- end
82
+ def level
83
+ metadata["level"]
84
+ end
55
85
 
56
- def Creature.tags
57
- ['undead', 'living', 'antimagic', 'bandit', 'invasion', 'grimswarm', 'ignoreable', 'escortee', 'animate']
58
- end
86
+ def metadata
87
+ Creatures::BY_NAME[@name] || {}
88
+ end
59
89
 
60
- attr_accessor :wounds, :targetable, :can_cast, :tags, :data, :legged, :limbed
61
-
62
- def initialize(creature)
63
- @wounds = {}
64
- @data = {}
65
-
66
- tag('trollish') if Creature.self_healing?(creature.name)
67
- @data[:incapacitated] = false
68
- @data[:tags] = Creature.tag(creature.name)
69
-
70
- heal
71
- # call the Gameobj_Extender initialize method that copies the game properties to this class
72
- super(creature)
73
- end
90
+ def fetch
91
+ GameObj[@id]
92
+ end
74
93
 
75
- def tags
76
- @data[:tags]
77
- end
94
+ def status
95
+ fetch.status.split(" ")
96
+ end
78
97
 
79
- def tag(tag)
80
- @data[:tags].push(tag)
98
+ def heal
99
+ WOUNDS.each do |location|
100
+ @wounds[location] = 0
81
101
  end
102
+ self
103
+ end
104
+
105
+ def injuries
106
+ fput "look ##{@id}"
107
+ woundinfo = matchtimeout(2, /(he|she|it) (?:has|appears to be in good) .*/i)
108
+ if woundinfo =~ /appears to be in good shape/ then heal; return @wounds; end
109
+ if woundinfo =~ /some minor cuts and bruises on (his|her|its) right (?:hind )?leg/ then @wounds[:right_leg] = 1; end
110
+ if woundinfo =~ /some minor cuts and bruises on (his|her|its) left (?:hind )?leg/ then @wounds[:left_leg] = 1; end
111
+ if woundinfo =~ /some minor cuts and bruises on (his|her|its) (?:right arm|right foreleg)/ then @wounds[:right_arm] = 1; end
112
+ if woundinfo =~ /some minor cuts and bruises on (his|her|its) (?:left arm|left foreleg)/ then @wounds[:left_arm] = 1; end
113
+ if woundinfo =~ /minor bruises around (his|her|its) neck/ then @wounds[:neck] = 1; end
114
+ if woundinfo =~ /minor bruises around (his|her|its) head/ then @wounds[:head] = 1; end
115
+ if woundinfo =~ /minor cuts and bruises on (his|her|its) chest/ then @wounds[:chest] = 1; end
116
+ if woundinfo =~ /minor cuts and bruises on (his|her|its) abdomen/ then @wounds[:abdomen] = 1; end
117
+ if woundinfo =~ /minor cuts and bruises on (his|her|its) back/ then @wounds[:back] = 1; end
118
+ if woundinfo =~ /bruised left eye/ then @wounds[:left_eye] = 1; end
119
+ if woundinfo =~ /bruised right eye/ then @wounds[:right_eye] = 1; end
120
+ if woundinfo =~ /some minor cuts and bruises on (his|her|its) right (?:hand|paw|claw)/ then @wounds[:right_hand] = 1; end
121
+ if woundinfo =~ /some minor cuts and bruises on (his|her|its) left (?:hand|paw|claw)/ then @wounds[:left_hand] = 1; end
122
+ if woundinfo =~ /a strange case of muscle twitching/ then @wounds[:nerves] = 1; end
123
+ if woundinfo =~ /fractured and bleeding right (?:hind )?leg/ then @wounds[:right_leg] = 2; end
124
+ if woundinfo =~ /fractured and bleeding left (?:hind )?leg/ then @wounds[:left_leg] = 2; end
125
+ if woundinfo =~ /fractured and bleeding (?:right arm|right foreleg)/ then @wounds[:right_arm] = 2; end
126
+ if woundinfo =~ /fractured and bleeding (?:left arm|left foreleg)/ then @wounds[:left_arm] = 2; end
127
+ if woundinfo =~ /moderate bleeding from (his|her|its) neck/ then @wounds[:neck] = 2; end
128
+ if woundinfo =~ /minor lacerations about (his|her|its) head and a possible mild concussion/ then @wounds[:head] = 2; end
129
+ if woundinfo =~ /deep lacerations across (his|her|its) chest/ then @wounds[:chest] = 2; end
130
+ if woundinfo =~ /deep lacerations across (his|her|its) abdomen/ then @wounds[:abdomen] = 2; end
131
+ if woundinfo =~ /deep lacerations across (his|her|its) back/ then @wounds[:back] = 2; end
132
+ if woundinfo =~ /swollen left eye/ then @wounds[:left_eye] = 2; end
133
+ if woundinfo =~ /swollen right eye/ then @wounds[:right_eye] = 2; end
134
+ if woundinfo =~ /fractured and bleeding right (?:hand|paw|claw)/ then @wounds[:right_hand] = 2; end
135
+ if woundinfo =~ /fractured and bleeding left (?:hand|paw|claw)/ then @wounds[:left_hand] = 2; end
136
+ if woundinfo =~ /a case of sporadic convulsions/ then @wounds[:nerves] = 2; end
137
+ if woundinfo =~ /severed right (?:hind )?leg/ then @wounds[:right_leg] = 3; end
138
+ if woundinfo =~ /severed left (?:hind )?leg/ then @wounds[:left_leg] = 3; end
139
+ if woundinfo =~ /severed (?:right arm|right foreleg)/ then @wounds[:right_arm] = 3; end
140
+ if woundinfo =~ /severed (?:left arm|left foreleg)/ then @wounds[:left_arm] = 3; end
141
+ if woundinfo =~ /snapped bones and serious bleeding from (his|her|its) neck/ then @wounds[:neck] = 3; end
142
+ if woundinfo =~ /severe head trauma and bleeding from (his|her|its) ears/ then @wounds[:head] = 3; end
143
+ if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) chest/ then @wounds[:chest] = 3; end
144
+ if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) abdomen/ then @wounds[:abdomen] = 3; end
145
+ if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) back/ then @wounds[:back] = 3; end
146
+ if woundinfo =~ /blinded left eye/ then @wounds[:left_eye] = 3; end
147
+ if woundinfo =~ /blinded right eye/ then @wounds[:right_eye] = 3; end
148
+ if woundinfo =~ /severed right (?:hand|paw|claw)/ then @wounds[:right_hand] = 3; end
149
+ if woundinfo =~ /severed left (?:hand|paw|claw)/ then @wounds[:left_hand] = 3; end
150
+ if woundinfo =~ /a case of uncontrollable convulsions/ then @wounds[:nerves] = 3; end
151
+ @wounds
152
+ end
153
+
154
+ def status
155
+ GameObj[@id].status.split(" ").map(&:to_sym)
156
+ end
82
157
 
83
- def is?(t)
84
- tags.include?(t)
85
- end
158
+ def legged?
159
+ injuries
160
+ @wounds[:right_leg] == 3 || @wounds[:left_leg] == 3
161
+ end
86
162
 
87
- def bandit?
88
- tags.include?('bandit')
89
- end
163
+ def can_cast?
164
+ injuries
165
+ @wounds[:right_arm] == 3 || @wounds[:head] == 3
166
+ end
90
167
 
91
- def grimswarm?
92
- tags.include('grimswarm')
93
- end
168
+ def alive?
169
+ !dead?
170
+ end
94
171
 
95
- def heal
96
- [:right_leg, :left_leg, :right_arm, :left_arm, :head, :neck, :chest, :abdomen, :back, :left_eye, :right_eye, :right_hand, :left_hand, :nerves].each do |location| @wounds[location] = 0 end
97
- @wounds
98
- end
99
-
100
- def injuries
101
- fput "look ##{@id}"
102
- woundinfo = matchtimeout(2, /(he|she|it) (?:has|appears to be in good) .*/i)
103
- if woundinfo =~ /appears to be in good shape/ then heal; return @wounds; end
104
- if woundinfo =~ /some minor cuts and bruises on (his|her|its) right (?:hind )?leg/ then @wounds[:right_leg] = 1; end
105
- if woundinfo =~ /some minor cuts and bruises on (his|her|its) left (?:hind )?leg/ then @wounds[:left_leg] = 1; end
106
- if woundinfo =~ /some minor cuts and bruises on (his|her|its) (?:right arm|right foreleg)/ then @wounds[:right_arm] = 1; end
107
- if woundinfo =~ /some minor cuts and bruises on (his|her|its) (?:left arm|left foreleg)/ then @wounds[:left_arm] = 1; end
108
- if woundinfo =~ /minor bruises around (his|her|its) neck/ then @wounds[:neck] = 1; end
109
- if woundinfo =~ /minor bruises around (his|her|its) head/ then @wounds[:head] = 1; end
110
- if woundinfo =~ /minor cuts and bruises on (his|her|its) chest/ then @wounds[:chest] = 1; end
111
- if woundinfo =~ /minor cuts and bruises on (his|her|its) abdomen/ then @wounds[:abdomen] = 1; end
112
- if woundinfo =~ /minor cuts and bruises on (his|her|its) back/ then @wounds[:back] = 1; end
113
- if woundinfo =~ /bruised left eye/ then @wounds[:left_eye] = 1; end
114
- if woundinfo =~ /bruised right eye/ then @wounds[:right_eye] = 1; end
115
- if woundinfo =~ /some minor cuts and bruises on (his|her|its) right (?:hand|paw|claw)/ then @wounds[:right_hand] = 1; end
116
- if woundinfo =~ /some minor cuts and bruises on (his|her|its) left (?:hand|paw|claw)/ then @wounds[:left_hand] = 1; end
117
- if woundinfo =~ /a strange case of muscle twitching/ then @wounds[:nerves] = 1; end
118
- if woundinfo =~ /fractured and bleeding right (?:hind )?leg/ then @wounds[:right_leg] = 2; end
119
- if woundinfo =~ /fractured and bleeding left (?:hind )?leg/ then @wounds[:left_leg] = 2; end
120
- if woundinfo =~ /fractured and bleeding (?:right arm|right foreleg)/ then @wounds[:right_arm] = 2; end
121
- if woundinfo =~ /fractured and bleeding (?:left arm|left foreleg)/ then @wounds[:left_arm] = 2; end
122
- if woundinfo =~ /moderate bleeding from (his|her|its) neck/ then @wounds[:neck] = 2; end
123
- if woundinfo =~ /minor lacerations about (his|her|its) head and a possible mild concussion/ then @wounds[:head] = 2; end
124
- if woundinfo =~ /deep lacerations across (his|her|its) chest/ then @wounds[:chest] = 2; end
125
- if woundinfo =~ /deep lacerations across (his|her|its) abdomen/ then @wounds[:abdomen] = 2; end
126
- if woundinfo =~ /deep lacerations across (his|her|its) back/ then @wounds[:back] = 2; end
127
- if woundinfo =~ /swollen left eye/ then @wounds[:left_eye] = 2; end
128
- if woundinfo =~ /swollen right eye/ then @wounds[:right_eye] = 2; end
129
- if woundinfo =~ /fractured and bleeding right (?:hand|paw|claw)/ then @wounds[:right_hand] = 2; end
130
- if woundinfo =~ /fractured and bleeding left (?:hand|paw|claw)/ then @wounds[:left_hand] = 2; end
131
- if woundinfo =~ /a case of sporadic convulsions/ then @wounds[:nerves] = 2; end
132
- if woundinfo =~ /severed right (?:hind )?leg/ then @wounds[:right_leg] = 3; end
133
- if woundinfo =~ /severed left (?:hind )?leg/ then @wounds[:left_leg] = 3; end
134
- if woundinfo =~ /severed (?:right arm|right foreleg)/ then @wounds[:right_arm] = 3; end
135
- if woundinfo =~ /severed (?:left arm|left foreleg)/ then @wounds[:left_arm] = 3; end
136
- if woundinfo =~ /snapped bones and serious bleeding from (his|her|its) neck/ then @wounds[:neck] = 3; end
137
- if woundinfo =~ /severe head trauma and bleeding from (his|her|its) ears/ then @wounds[:head] = 3; end
138
- if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) chest/ then @wounds[:chest] = 3; end
139
- if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) abdomen/ then @wounds[:abdomen] = 3; end
140
- if woundinfo =~ /deep gashes and serious bleeding from (his|her|its) back/ then @wounds[:back] = 3; end
141
- if woundinfo =~ /blinded left eye/ then @wounds[:left_eye] = 3; end
142
- if woundinfo =~ /blinded right eye/ then @wounds[:right_eye] = 3; end
143
- if woundinfo =~ /severed right (?:hand|paw|claw)/ then @wounds[:right_hand] = 3; end
144
- if woundinfo =~ /severed left (?:hand|paw|claw)/ then @wounds[:left_hand] = 3; end
145
- if woundinfo =~ /a case of uncontrollable convulsions/ then @wounds[:nerves] = 3; end
146
- @wounds
147
- end
148
-
149
- def status
150
- GameObj[@id].status
151
- end
172
+ def limbed?
173
+ injuries
174
+ @wounds[:right_leg] == 3 || @wounds[:left_leg] == 3 || @wounds[:right_arm] == 3
175
+ end
152
176
 
153
- def trollish?
154
- @data[:trollish]
155
- end
177
+ def gone?
178
+ fetch.nil? ? true : false
179
+ end
156
180
 
157
- def ignorable?
158
- is?('ignoreable')
159
- end
181
+ def prone?
182
+ status.include?(:lying) || status.include?(:prone) ? true : false
183
+ end
160
184
 
161
- def legged?
162
- injuries
163
- trollish? ? false : @wounds[:right_leg] == 3 || @wounds[:left_leg] == 3 || dead? || gone?
164
- end
185
+ def eql?(other)
186
+ self == other
187
+ end
165
188
 
166
- def can_cast?
167
- injuries
168
- trollish? ? false : @wounds[:right_arm] == 3 || @wounds[:head] == 3 || dead? || gone?
169
- end
189
+ def ==(other)
190
+ @id.to_i == other.id.to_i
191
+ end
170
192
 
171
- def limbed?
172
- injuries
173
- trollish? ? false : @wounds[:right_leg] == 3 || @wounds[:left_leg] == 3 || @wounds[:right_arm] == 3 || dead? || gone?
174
- end
175
193
 
176
- def dead?
177
- status =~ /dead/ ? true : false
178
- end
194
+ def danger
195
+ status
196
+ .map do |state| Creatures::STATES.index(state) end
197
+ .reduce(&:+) || -1
198
+ end
179
199
 
180
- def active?
181
- !stunned?
182
- end
200
+ def <=>(other)
201
+ self.danger <=> other.danger
202
+ end
183
203
 
184
- def gone?
185
- GameObj[@id].nil? ? true : false
186
- end
204
+ def stunned?
205
+ status.include?(:stunned) ? true : false
206
+ end
187
207
 
188
- def prone?
189
- status =~ /lying|prone/ ? true : false
190
- end
208
+ def kill_shot(order = [:left_eye, :right_eye, :head, :neck, :back], default = :chest)
209
+ wounds = injuries
210
+ return (order
211
+ .drop_while do |area| @wounds[area] == 3 end
212
+ .first || default).to_game
213
+ end
191
214
 
192
- def stunned?
193
- status =~ /stunned/ ? true : false
194
- end
215
+ def targetable?
216
+ target if @targetable.nil?
217
+ @targetable
218
+ end
195
219
 
196
- def kill_shot
197
- wounds = injuries
198
- location = "left eye"
199
- location = "right eye" if @wounds[:left_eye] == 3
200
- location = "head" if @wounds[:right_eye] == 3
201
- location = "neck" if @wounds[:head] == 3
202
- location = "back" if @wounds[:neck] == 3
203
- location
220
+ [Creatures::ARCHETYPES, Creatures::STATES].flatten.each do |state|
221
+ define_method((state.to_s + "?").to_sym) do
222
+ [tags, status].flatten.include?(state)
204
223
  end
224
+ end
205
225
 
206
- def target
207
- result = dothistimeout "target ##{@id}", 3, /#{Olib::Dictionary.targetable.values.join('|')}/
208
- @targetable = result =~ Olib::Dictionary.targetable[:yes] ? true : false
209
- self
210
- end
211
226
 
212
- def search
213
- fput "search ##{@id}" if dead?
214
- end
227
+ def target
228
+ result = dothistimeout "target ##{@id}", 3, /#{Olib::Dictionary.targetable.values.join('|')}/
229
+ @targetable = result =~ Olib::Dictionary.targetable[:yes] ? true : false
230
+ self
231
+ end
215
232
 
216
- def ambush(location=nil)
217
- until hidden?
218
- fput "hide"
219
- waitrt?
220
- end
221
- fput "aim #{location}" if location
222
- fput "ambush ##{@id}"
233
+ def ambush(location=nil)
234
+ until hidden?
235
+ fput "hide"
223
236
  waitrt?
224
- self
225
237
  end
238
+ Char.aim(location) if location
239
+ fput "ambush ##{@id}"
240
+ waitrt?
241
+ self
242
+ end
226
243
 
227
- def mstrike
228
- fput "mstrike ##{@id}"
229
- waitrt?
230
- self
244
+ def mstrike
245
+ unless dead?
246
+ fput "mstrike ##{@id}"
231
247
  end
248
+ self
249
+ end
232
250
 
233
- def kill
251
+ def kill
252
+ unless dead?
234
253
  fput "kill ##{@id}"
235
- waitrt?
236
- self
237
254
  end
255
+ self
256
+ end
238
257
 
239
- def targetable?
240
- target if @targetable.nil?
241
- @targetable
258
+ def fire(location=nil)
259
+ unless dead?
260
+ Char.aim(location) if location
261
+ fput "fire ##{@id}"
242
262
  end
263
+ self
264
+ end
243
265
 
244
- def search
245
- waitrt?
246
- fput "search ##{id}"
266
+ def hurl(location=nil)
267
+ unless dead?
268
+ Char.aim(location) if location
269
+ fput "hurl ##{@id}"
247
270
  end
271
+ self
272
+ end
273
+
274
+ def search
275
+ waitrt?
276
+ fput "search ##{@id}" if dead?
248
277
  end
249
- end
250
278
 
251
- ##
252
- ## @brief alias for internal Olib Creature
253
- ##
254
- class Creature < Olib::Creature
279
+ def skin
280
+ waitrt?
281
+ fput "skin ##{@id}" if dead?
282
+ self
283
+ end
284
+
285
+ def to_s
286
+ "<#{fetch.name}:#{@id} @danger=#{danger} @tags=#{tags} @status=#{status}>"
287
+ end
255
288
  end
289
+