Olib 0.0.3 → 0.0.4
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/lib/Olib.rb +32 -0
- data/lib/Olib/container.rb +64 -48
- data/lib/Olib/creature.rb +143 -58
- data/lib/Olib/creatures.rb +32 -26
- data/lib/Olib/dictionary.rb +66 -31
- data/lib/Olib/errors.rb +82 -0
- data/lib/Olib/extender.rb +6 -5
- data/lib/Olib/help_menu.rb +159 -12
- data/lib/Olib/inventory.rb +77 -0
- data/lib/Olib/item.rb +451 -30
- data/lib/Olib/shops.rb +175 -0
- data/lib/Olib/transport.rb +79 -78
- data/lib/Olib/utils.rb +223 -0
- metadata +6 -2
data/lib/Olib/creatures.rb
CHANGED
@@ -2,46 +2,52 @@ require 'Olib/creature'
|
|
2
2
|
# a collection for managing all of the creatures in a room
|
3
3
|
module Olib
|
4
4
|
class Creatures
|
5
|
-
attr_accessor :untargetables, :ignore, :collection
|
6
|
-
def initialize(ignore=true)
|
7
|
-
@ignore = ignore
|
8
|
-
self
|
9
|
-
end
|
10
5
|
|
11
|
-
def first
|
6
|
+
def Creatures.first
|
12
7
|
all.first
|
13
8
|
end
|
14
9
|
|
15
|
-
def all
|
16
|
-
GameObj.npcs
|
10
|
+
def Creatures.all
|
11
|
+
GameObj.npcs
|
12
|
+
.map { |creature| Olib::Creature.new(creature) }
|
13
|
+
.select { |creature| !creature.dead? }
|
14
|
+
.select { |creature| !creature.ignorable? }
|
15
|
+
.select { |creature| !creature.tags.include?('animate') }
|
16
|
+
.select { |creature| !creature.gone? } || []
|
17
17
|
end
|
18
18
|
|
19
|
-
def each(&block)
|
19
|
+
def Creatures.each(&block)
|
20
20
|
all.each(&block)
|
21
21
|
end
|
22
22
|
|
23
|
-
def [](exp)
|
23
|
+
def Creatures.[](exp)
|
24
24
|
regexp = exp.class == String ? /#{exp}/ : exp
|
25
25
|
|
26
26
|
all.select { |creature| creature.name =~ regexp || creature.id == exp }
|
27
27
|
end
|
28
|
-
def bandits; all.select { |creature| creature.is?('bandit') } ;end;
|
29
|
-
def flying; all.select { |creature| creature.is?('flying') } ;end;
|
30
|
-
def living; all.select { |creature| creature.is?('living') } ;end;
|
31
|
-
def antimagic; all.select { |creature| creature.is?('antimagic') } ;end;
|
32
|
-
def undead; all.select { |creature| creature.is?('undead') } ;end;
|
33
|
-
|
34
|
-
def grimswarm; all.select { |creature| creature.is?('grimswarm') } ;end;
|
35
|
-
def invasion; all.select { |creature| creature.is?('invasion') } ;end;
|
36
|
-
def escortees; GameObj.npcs.map {|creature| Creature.new(creature) }.select {|creature| creature.is?('escortee') } ;end;
|
37
|
-
|
38
|
-
def stunned; all.select(&:stunned?) ;end;
|
39
|
-
def active; all.select(&:active?) ;end;
|
40
|
-
def dead; all.select(&:dead?) ;end;
|
41
|
-
def prone; all.select(&:prone?) ;end;
|
42
28
|
|
43
|
-
def
|
44
|
-
|
29
|
+
def Creatures.filter(&block);
|
30
|
+
all.select(&block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def Creatures.bandits; all.select { |creature| creature.is?('bandit') } ;end;
|
34
|
+
def Creatures.ignoreable; all.select { |creature| creature.is?('ignoreable') } ;end;
|
35
|
+
def Creatures.flying; all.select { |creature| creature.is?('flying') } ;end;
|
36
|
+
def Creatures.living; all.select { |creature| creature.is?('living') } ;end;
|
37
|
+
def Creatures.antimagic; all.select { |creature| creature.is?('antimagic') } ;end;
|
38
|
+
def Creatures.undead; all.select { |creature| creature.is?('undead') } ;end;
|
39
|
+
|
40
|
+
def Creatures.grimswarm; all.select { |creature| creature.is?('grimswarm') } ;end;
|
41
|
+
def Creatures.invasion; all.select { |creature| creature.is?('invasion') } ;end;
|
42
|
+
def Creatures.escortees; GameObj.npcs.map {|creature| Creature.new(creature) }.select {|creature| creature.is?('escortee') } ;end;
|
43
|
+
|
44
|
+
def Creatures.stunned; all.select(&:stunned?) ;end;
|
45
|
+
def Creatures.active; all.select(&:active?) ;end;
|
46
|
+
def Creatures.dead; all.select(&:dead?) ;end;
|
47
|
+
def Creatures.prone; all.select(&:prone?) ;end;
|
48
|
+
|
49
|
+
def Creatures.ambushed?
|
50
|
+
last_line = $_SERVERBUFFER_.reverse.find { |line| line =~ /<pushStream id='room'\/>|An? .*? fearfully exclaims, "It's an ambush!"|#{Olib::Dictionary.bandit_traps.values.join('|')}/ }
|
45
51
|
echo "detected ambush..." if !last_line.nil? && last_line !~ /pushStream id='room'/
|
46
52
|
|
47
53
|
!last_line.nil? && last_line !~ /pushStream id='room'/
|
data/lib/Olib/dictionary.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
module Olib
|
2
2
|
|
3
|
-
class
|
4
|
-
def
|
3
|
+
class Dictionary
|
4
|
+
def Dictionary.heirloom
|
5
5
|
re = {}
|
6
|
-
re[:
|
6
|
+
re[:is] = /are the initials ([A-Z]{2})./
|
7
7
|
re[:give] = /Excellent. I'm sure the person who lost this will be quite happy/
|
8
8
|
re
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def Dictionary.ignorable?(line)
|
12
|
+
line =~ /You feel less drained|You feel at full magical power again|\[LNet\]|GSIV|moving stealthily into the room|glides into view|soars out of sight|You notice (.*?) moving stealthily out|[A-Z][a-z]+ says, "|(removes|put) a (.*?) from in (his|her)|just opened (a|an)|just went|You gesture|Your spell is ready|just bit the dust|joins the adventure|just arrived|returns home from a hard day of adventuring|no longer effective|You sense that your attunement|You do not feel drained anymore|You feel the magic of your spell depart/
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def Dictionary.targetable
|
16
16
|
re = {}
|
17
17
|
re[:yes] = /^You are now targeting/
|
18
18
|
re[:no] = /^You can't target/
|
19
19
|
re
|
20
20
|
end
|
21
|
-
def
|
21
|
+
def Dictionary.bounty
|
22
22
|
re = {}
|
23
23
|
re[:herb] = /requires (?:a|an|some) ([a-zA-Z '-]+) found (?:in|on|around) ([a-zA-Z '-]+). These samples must be in pristine condition. You have been tasked to retrieve ([0-9]+)/
|
24
24
|
re[:escort] = /Go to the (.*?) and WAIT for (?:him|her|them) to meet you there. You must guarantee (?:his|her|their) safety to ([a-zA-Z '-]+) as soon as/
|
@@ -41,7 +41,7 @@ module Olib
|
|
41
41
|
re[:get_bounty] = /You are not currently assigned a task/
|
42
42
|
|
43
43
|
end
|
44
|
-
def
|
44
|
+
def Dictionary.bandit_traps
|
45
45
|
re = {}
|
46
46
|
re[:net] = /Suddenly, a carefully concealed net springs up from the ground, completely entangling you/
|
47
47
|
re[:jaws] = /large pair of carefully concealed metal jaws slam shut on your/
|
@@ -56,22 +56,8 @@ module Olib
|
|
56
56
|
re[:statue] = /A faint silvery light flickers from the shadows/
|
57
57
|
re
|
58
58
|
end
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
def Gemstone_Regex.bandits
|
63
|
-
/thief|rogue|bandit|mugger|outlaw|highwayman|marauder|brigand|thug|robber/
|
64
|
-
end
|
65
|
-
def Gemstone_Regex.undead
|
66
|
-
/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/
|
67
|
-
end
|
68
|
-
def Gemstone_Regex.antimagic
|
69
|
-
/lesser construct|Vvrael warlock|Vvrael witch/
|
70
|
-
end
|
71
|
-
def Gemstone_Regex.living
|
72
|
-
/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/
|
73
|
-
end
|
74
|
-
def Gemstone_Regex.shop
|
59
|
+
|
60
|
+
def Dictionary.shop
|
75
61
|
db = {}
|
76
62
|
db[:success] = /^You hand over|You place your/
|
77
63
|
db[:failure] = {}
|
@@ -81,7 +67,7 @@ module Olib
|
|
81
67
|
db[:failure][:own] = /^Buy your own merchandise?/
|
82
68
|
db
|
83
69
|
end
|
84
|
-
def
|
70
|
+
def Dictionary.gems
|
85
71
|
re = {}
|
86
72
|
# Expressions to match interaction with gems
|
87
73
|
re[:appraise] = {}
|
@@ -91,32 +77,81 @@ module Olib
|
|
91
77
|
re[:singularize] = proc{ |str| str.gsub(/ies$/, 'y').gsub(/zes$/,'z').gsub(/s$/,'').gsub(/large |medium |containing |small |tiny |some /, '').strip }
|
92
78
|
re
|
93
79
|
end
|
94
|
-
|
80
|
+
|
81
|
+
def Dictionary.get
|
95
82
|
re = {}
|
96
83
|
re[:failure] = {}
|
97
84
|
# Expressions to match `get` verb results
|
98
85
|
re[:failure][:weight] = /You are unable to handle the additional load/
|
99
86
|
re[:failure][:hands_full] = /^You need a free hand to pick that up/
|
100
87
|
re[:failure][:ne] = /^Get what/
|
101
|
-
re[:failure][:buy] =
|
88
|
+
re[:failure][:buy] = /(?<cost>[0-9]+) (silvers|coins)/
|
102
89
|
re[:failure][:pshop] = /^Looking closely/
|
103
90
|
re[:success] = /^You pick up|^You remove|^You rummage|^You draw|^You grab|^You reach|^You already/
|
104
91
|
re
|
105
92
|
end
|
106
|
-
|
93
|
+
|
94
|
+
def Dictionary.put
|
107
95
|
re = {}
|
108
96
|
re[:failure] = {}
|
109
|
-
re[:failure][:full] = /^won't fit in the
|
97
|
+
re[:failure][:full] = /^won't fit in the|is full!|filling it./
|
110
98
|
re[:failure][:ne] = /^I could not find what you were referring to/
|
111
|
-
re[:success] = /^You put
|
99
|
+
re[:success] = /^You put|^You tuck|^You sheathe|^You slip|^You roll up|^You tuck|^You add/
|
112
100
|
re
|
113
101
|
end
|
114
|
-
|
102
|
+
|
103
|
+
def Dictionary.jar(name=nil)
|
115
104
|
if name
|
116
105
|
return name.gsub(/large |medium |containing |small |tiny |some /, '').sub 'rubies', 'ruby'
|
117
106
|
else
|
118
107
|
return false
|
119
108
|
end
|
120
109
|
end
|
110
|
+
|
111
|
+
def Dictionary.armors
|
112
|
+
armors = Hash.new
|
113
|
+
armors['robes'] = /cloth armor/i
|
114
|
+
armors['light leather'] = /soft leather armor that covers the torso only./i
|
115
|
+
armors['full leather'] = /soft leather armor that covers the torso and arms./i
|
116
|
+
armors['reinforced leather'] = /soft leather armor that covers the torso, arms, and legs./i
|
117
|
+
armors['double leather'] = /soft leather armor that covers the torso, arms, legs, neck, and head./i
|
118
|
+
armors['leather breastplate'] = /rigid leather armor that covers the torso only./i
|
119
|
+
armors['cuirbouilli leather'] = /rigid leather armor that covers the torso and arms./i
|
120
|
+
armors['studded leather'] = /rigid leather armor that covers the torso, arms, and legs./i
|
121
|
+
armors['brigadine armor'] = /rigid leather armor that covers the torso, arms, legs, neck, and head./i
|
122
|
+
armors['chain mail'] = /chain armor that covers the torso only./i
|
123
|
+
armors['double chain'] = /chain armor that covers the torso and arms./i
|
124
|
+
armors['augmented chain'] = /chain armor that covers the torso, arms, and legs./i
|
125
|
+
armors['chain hauberk'] = /chain armor that covers the torso, arms, legs, neck, and head./i
|
126
|
+
armors['metal breastplate'] = /plate armor that covers the torso only./i
|
127
|
+
armors['augmented plate'] = /plate armor that covers the torso and arms./i
|
128
|
+
armors['half plate'] = /plate armor that covers the torso, arms, and legs./i
|
129
|
+
armors['full plate'] = /plate armor that covers the torso, arms, legs, neck, and head./i
|
130
|
+
armors['DB'] = /miscellaneous armor that protects the wearer in general/
|
131
|
+
armors
|
132
|
+
end
|
133
|
+
|
134
|
+
def Dictionary.size
|
135
|
+
/that it is a (?<size>.*) shield that protects/
|
136
|
+
end
|
137
|
+
|
138
|
+
def Dictionary.numbers
|
139
|
+
numbers = Hash.new
|
140
|
+
numbers['one'] = 1
|
141
|
+
numbers['two'] = 2
|
142
|
+
numbers['three'] = 3
|
143
|
+
numbers['four'] = 4
|
144
|
+
numbers['five'] = 5
|
145
|
+
numbers
|
146
|
+
end
|
147
|
+
|
148
|
+
def Dictionary.spiked
|
149
|
+
/You also notice that it is spiked./i
|
150
|
+
end
|
151
|
+
|
152
|
+
def Dictionary.fusion
|
153
|
+
/(?<orbs>.*?) spherical depressions adorn the (.*?), approximately the size and shape of a small gem/
|
154
|
+
end
|
155
|
+
|
121
156
|
end
|
122
157
|
end
|
data/lib/Olib/errors.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Olib
|
2
|
+
module Errors
|
3
|
+
|
4
|
+
# used internally to handle early thread execution and error bubbling
|
5
|
+
class Mundane < Exception
|
6
|
+
end
|
7
|
+
|
8
|
+
# used internally to insure threads died and error bubbling
|
9
|
+
class TimedOut < Exception
|
10
|
+
end
|
11
|
+
|
12
|
+
# used internally to handle early thread execution and error bubbling
|
13
|
+
class Prempt < Exception
|
14
|
+
end
|
15
|
+
|
16
|
+
# used to exit a thread early due to an error that Olib cannot resolve internally
|
17
|
+
class Fatal < Exception
|
18
|
+
def initialize(message=nil)
|
19
|
+
unless message
|
20
|
+
message = String.new
|
21
|
+
message.concat "\n\nAn Olib::Errors::Fatal was raised but not rescued in an Olib method"
|
22
|
+
message.concat "\nyou should rescue this error if it isn't fatal and you don't want your script to break"
|
23
|
+
end
|
24
|
+
super(message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# If you have a full container and a script/action depends on it, this is thrown
|
29
|
+
# rescue it for logic
|
30
|
+
class ContainerFull < Exception
|
31
|
+
def initialize(message=nil)
|
32
|
+
unless message
|
33
|
+
message = String.new
|
34
|
+
message.concat "\n\nYou tried to add stuff to a container that was full"
|
35
|
+
message.concat "\nyou should rescue this error if it isn't fatal and you don't want your script to break"
|
36
|
+
end
|
37
|
+
super(message)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class InsufficientFunds < Exception
|
42
|
+
def initialize(message=nil)
|
43
|
+
unless message
|
44
|
+
message = String.new
|
45
|
+
message.concat "\n\nYou tried to do something that costs more money that your character had on them"
|
46
|
+
message.concat "\nyou should rescue this error if it isn't fatal and you don't want your script to break"
|
47
|
+
end
|
48
|
+
super(message)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class HandsFull < Exception
|
53
|
+
def initialize
|
54
|
+
message = String.new
|
55
|
+
message.concat "\n\nYour hands were full!"
|
56
|
+
message.concat "\nyou should rescue this error if you don't want your script to break"
|
57
|
+
super(message)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class TooHeavy < Exception
|
62
|
+
def initialize
|
63
|
+
message = String.new
|
64
|
+
message.concat "\n\nYou were too heavy to do something!"
|
65
|
+
message.concat "\nyou should rescue this error if you don't want your script to break"
|
66
|
+
super(message)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class DoesntExist < Exception
|
71
|
+
def initialize(message=nil)
|
72
|
+
unless message
|
73
|
+
message = String.new
|
74
|
+
message.concat "\n\nYou tried to interact with something that no longer exists"
|
75
|
+
message.concat "\nyou should rescue this error if it isn't fatal and you don't want your script to break"
|
76
|
+
end
|
77
|
+
super(message)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/lib/Olib/extender.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
# used to wrap and extend a GameObj item
|
2
2
|
module Olib
|
3
3
|
class Gameobj_Extender
|
4
|
-
|
4
|
+
attr_accessor :type
|
5
5
|
def initialize(item)
|
6
|
-
|
7
|
-
|
6
|
+
self.__extend__(item)
|
7
|
+
@type = item.type
|
8
8
|
end
|
9
9
|
|
10
10
|
# This copies GameObj data to attributes so we can employ it for scripting
|
11
11
|
def __extend__(item)
|
12
|
-
item.instance_variables.each
|
12
|
+
item.instance_variables.each { |var|
|
13
13
|
s = var.to_s.sub('@', '')
|
14
14
|
(class << self; self end).class_eval do; attr_accessor "#{s}"; end
|
15
15
|
instance_variable_set "#{var}", item.send(s)
|
16
|
-
|
16
|
+
}
|
17
|
+
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/lib/Olib/help_menu.rb
CHANGED
@@ -1,19 +1,166 @@
|
|
1
1
|
module Olib
|
2
|
+
class HelpMenu
|
3
|
+
attr_accessor :script, :cmds, :last_added, :flags, :title, :padding, :cols, :max_column_width
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
5
|
+
def initialize
|
6
|
+
@script = $lich_char+Olib.script.to_s
|
7
|
+
@cmds = {}
|
8
|
+
@flags = {}
|
9
|
+
@padding = 5
|
10
|
+
@max_column_width = Vars.max_column_width.to_i || 50
|
11
|
+
@title = "#{@script} help menu".upcase
|
12
|
+
self
|
9
13
|
end
|
10
14
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
def flag(flag, info)
|
16
|
+
if @last_added
|
17
|
+
@cmds[@last_added][:flags][flag] = info
|
18
|
+
else
|
19
|
+
@flags[flag] = info
|
20
|
+
end
|
21
|
+
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def pad
|
26
|
+
[''] * @padding * ' '
|
27
|
+
end
|
28
|
+
|
29
|
+
def cmd(cmd, info)
|
30
|
+
@last_added = cmd
|
31
|
+
@cmds[cmd] = {}
|
32
|
+
@cmds[cmd][:info] = info
|
33
|
+
@cmds[cmd][:flags] = {}
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def width
|
38
|
+
return @cols if @cols
|
39
|
+
|
40
|
+
@cols = {}
|
41
|
+
@cols[:one] = @script.length+padding
|
42
|
+
|
43
|
+
# global flags and commands
|
44
|
+
@cols[:two] = @flags
|
45
|
+
.keys
|
46
|
+
.concat(@cmds.keys)
|
47
|
+
.map(&:strip)
|
48
|
+
.sort_by(&:length).last.length+padding
|
49
|
+
|
50
|
+
# flags
|
51
|
+
@cols[:three] = @cmds
|
52
|
+
.keys
|
53
|
+
.map { |cmd| @cmds[cmd][:flags].keys }
|
54
|
+
.flatten
|
55
|
+
.map(&:strip)
|
56
|
+
.sort_by(&:length).last.length+padding
|
57
|
+
|
58
|
+
# help text
|
59
|
+
@cols[:four] = @max_column_width+padding
|
60
|
+
|
61
|
+
@cols[:total] = @cols.values.reduce(&:+)
|
62
|
+
|
63
|
+
@cols
|
64
|
+
end
|
65
|
+
|
66
|
+
def center(str)
|
67
|
+
"%#{width.values.reduce(&:+)/3-str.length}s\n" % str
|
68
|
+
end
|
69
|
+
|
70
|
+
# offset the entire array of eles by n number of blank strings
|
71
|
+
def offset(n, *eles)
|
72
|
+
row *(eles.unshift *[''] * n)
|
73
|
+
end
|
74
|
+
|
75
|
+
def row(*columns)
|
76
|
+
"%#{width[:one]}s %#{width[:two]}s#{pad}%-#{width[:three]}s#{pad}%-#{width[:four]}s\n" % columns.map(&:strip)
|
77
|
+
#row2 *columns
|
78
|
+
end
|
79
|
+
|
80
|
+
def bar
|
81
|
+
"|\n".rjust(width[:total]+10,"-")
|
82
|
+
end
|
83
|
+
|
84
|
+
def n
|
85
|
+
"\n"
|
86
|
+
end
|
87
|
+
|
88
|
+
def chunker(content)
|
89
|
+
rows = ['']
|
90
|
+
|
91
|
+
content.split.each { |chunk|
|
92
|
+
if rows.last.length + chunk.length > @max_column_width then rows.push chunk else rows.last.concat " "+chunk end
|
93
|
+
}
|
94
|
+
|
95
|
+
rows
|
96
|
+
end
|
97
|
+
|
98
|
+
def write
|
99
|
+
m = []
|
100
|
+
m.push bar
|
101
|
+
m.push n
|
102
|
+
m.push " #{@title}".rjust(40)
|
103
|
+
m.push n
|
104
|
+
m.push n
|
105
|
+
m.push bar
|
106
|
+
unless @flags.keys.empty?
|
107
|
+
m.push offset 2, *["| flag", "| info"].map(&:upcase)
|
108
|
+
m.push bar
|
109
|
+
@flags.each { |flag, info|
|
110
|
+
if info.length > @max_column_width
|
111
|
+
chunks = chunker info
|
112
|
+
m.push row( @script, '', '--'+flag, chunks.shift )
|
113
|
+
chunks.each { |chunk| m.push offset 3, chunk }
|
114
|
+
m.push n
|
115
|
+
else
|
116
|
+
m.push row(@script, '', '--'+flag, info)
|
117
|
+
m.push n
|
118
|
+
end
|
119
|
+
|
120
|
+
}
|
121
|
+
end
|
122
|
+
m.push n
|
123
|
+
unless @cmds.keys.empty?
|
124
|
+
m.push bar
|
125
|
+
m.push row *['', "| cmd", "| flag", "| info"].map(&:upcase)
|
126
|
+
m.push bar
|
127
|
+
@cmds.keys.each { |cmd|
|
128
|
+
# add top level command
|
129
|
+
m.push n
|
130
|
+
if @cmds[cmd][:info].length > @max_column_width
|
131
|
+
chunks = chunker @cmds[cmd][:info]
|
132
|
+
m.push row(@script, cmd, '', chunks.shift)
|
133
|
+
chunks.each { |chunk| m.push offset 3, chunk }
|
134
|
+
m.push n
|
135
|
+
else
|
136
|
+
m.push row(@script, cmd, '', @cmds[cmd][:info])
|
137
|
+
m.push n
|
138
|
+
end
|
139
|
+
|
140
|
+
# add flags for command
|
141
|
+
@cmds[cmd][:flags].keys.each {|flag|
|
142
|
+
if @cmds[cmd][:flags][flag].length > @max_column_width
|
143
|
+
chunks = chunker @cmds[cmd][:flags][flag]
|
144
|
+
m.push row( @script, cmd, '--'+flag, chunks.shift )
|
145
|
+
chunks.each { |chunk| m.push offset 3, chunk }
|
146
|
+
m.push n
|
147
|
+
else
|
148
|
+
m.push row(@script, cmd, '--'+flag, @cmds[cmd][:flags][flag] )
|
149
|
+
m.push n
|
150
|
+
end
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
m.push bar
|
155
|
+
m.push n
|
156
|
+
end
|
157
|
+
respond m.join('')
|
16
158
|
end
|
17
159
|
end
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
18
166
|
|
19
|
-
end
|