gemwarrior 0.15.10 → 0.15.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,191 +1,191 @@
1
- # lib/gemwarrior/game.rb
2
- # Main launching point for Gem Warrior
3
-
4
- require 'colorize'
5
- require 'matrext'
6
-
7
- require_relative 'entities/armor/iron_helmet'
8
- require_relative 'entities/items/herb'
9
- require_relative 'entities/weapons/dagger'
10
- require_relative 'misc/animation'
11
- require_relative 'misc/audio'
12
- require_relative 'misc/formatting'
13
- require_relative 'misc/hr'
14
- require_relative 'evaluator'
15
- require_relative 'game_assets'
16
- require_relative 'game_options'
17
- require_relative 'inventory'
18
- require_relative 'repl'
19
- require_relative 'world'
20
-
21
- module Gemwarrior
22
- class Game
23
- # CONSTANTS
24
- INVENTORY_DEFAULT = Inventory.new
25
- INVENTORY_DEBUG = Inventory.new([Herb.new, Herb.new, Herb.new])
26
- ROX_DEFAULT = 0
27
- ROX_DEBUG = 300
28
-
29
- attr_accessor :world,
30
- :evaluator,
31
- :repl,
32
- :monsters,
33
- :weapons
34
-
35
- def initialize(options)
36
- # set game options
37
- GameOptions.add 'beast_mode', options.fetch(:beast_mode)
38
- GameOptions.add 'debug_mode', options.fetch(:debug_mode)
39
- GameOptions.add 'god_mode', options.fetch(:god_mode)
40
- GameOptions.add 'sound_enabled', options.fetch(:sound_enabled)
41
- GameOptions.add 'sound_system', options.fetch(:sound_system)
42
- GameOptions.add 'sound_volume', options.fetch(:sound_volume)
43
- GameOptions.add 'use_wordnik', options.fetch(:use_wordnik)
44
- GameOptions.add 'fight_completion', options.fetch(:fight_completion)
45
-
46
- # add classes for creatures, monsters, people, items, weapons, and armor to game
47
- # also add them to the global GameAssets
48
- init_creatures
49
- init_monsters
50
- init_people
51
- init_items
52
- init_weapons
53
- init_armor
54
-
55
- # create new world based on default template
56
- self.world = init_world
57
-
58
- # update some player aspects to make more dynamic
59
- world.player.name = world.player.generate_name
60
- world.player.face = world.player.generate_face
61
- world.player.hands = world.player.generate_hands
62
- world.player.mood = world.player.generate_mood
63
- world.player.inventory = GameOptions.data['debug_mode'] ? INVENTORY_DEBUG : INVENTORY_DEFAULT
64
- world.player.rox = GameOptions.data['debug_mode'] ? ROX_DEBUG : ROX_DEFAULT
65
-
66
- # set some global variables
67
- world.duration = { mins: 0, secs: 0, ms: 0 }
68
- world.emerald_beaten = false
69
- world.shifty_to_jewel = false
70
- world.shifty_has_jeweled = false
71
-
72
- # spawn bosses
73
- ## Pain Quarry
74
- world.location_by_name('pain_quarry-southeast').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
75
- world.location_by_name('pain_quarry-east').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
76
- world.location_by_name('pain_quarry-central').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
77
- world.location_by_name('pain_quarry-south').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
78
- world.location_by_name('pain_quarry-west').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
79
- world.location_by_name('pain_quarry-northwest').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
80
- world.location_by_name('pain_quarry-north').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
81
- ## River Bridge
82
- world.location_by_name('river_bridge').bosses_abounding.push(Gemwarrior.const_get('Jaspern').new)
83
- ## Throne Room
84
- world.location_by_name('sky_tower-throne_room').bosses_abounding.push(Gemwarrior.const_get('Emerald').new)
85
-
86
- # mark home as visited
87
- world.location_by_name('home').visited = true
88
-
89
- # create options file if not existing
90
- update_options_file
91
-
92
- # require needed files for selected sound_system if sound_enabled
93
- if GameOptions.data['sound_enabled']
94
- Audio.init
95
- end
96
-
97
- # create the console
98
- self.evaluator = Evaluator.new(world)
99
- self.repl = Repl.new(self, world, evaluator)
100
-
101
- # enter Jool!
102
- repl.start('look', options.fetch(:extra_command), options.fetch(:new_skip), options.fetch(:resume_skip))
103
- end
104
-
105
- def update_options_file
106
- File.open(GameOptions.data['options_file_path'], 'w') do |f|
107
- f.puts "sound_enabled:#{GameOptions.data['sound_enabled']}"
108
- f.puts "sound_system:#{GameOptions.data['sound_system']}"
109
- f.puts "sound_volume:#{GameOptions.data['sound_volume']}"
110
- f.puts "use_wordnik:#{GameOptions.data['use_wordnik']}"
111
- f.puts "fight_completion:#{GameOptions.data['fight_completion']}"
112
- end
113
- end
114
-
115
- private
116
-
117
- # convert an entity filename to a class so it can be added to game asset singleton registry
118
- def file_to_class(filename)
119
- filename_to_string = Formatting.upstyle(filename.split('/').last.split('.')[0], no_space: true)
120
- Gemwarrior.const_get(filename_to_string).new
121
- end
122
-
123
- def init_creatures
124
- Dir.glob(File.expand_path('../entities/creatures/*.rb', __FILE__)).each do |creature|
125
- require_relative creature
126
- GameCreatures.add(file_to_class(creature))
127
- end
128
- end
129
-
130
- def init_monsters
131
- Dir.glob(File.expand_path('../entities/monsters/*.rb', __FILE__)).each do |monster|
132
- require_relative monster
133
- GameMonsters.add(file_to_class(monster))
134
- end
135
- Dir.glob(File.expand_path('../entities/monsters/bosses/*.rb', __FILE__)).each do |boss|
136
- require_relative boss
137
- GameMonsters.add(file_to_class(boss))
138
- end
139
- end
140
-
141
- def init_people
142
- Dir.glob(File.expand_path('../entities/people/*.rb', __FILE__)).each do |person|
143
- require_relative person
144
- GamePeople.add(file_to_class(person))
145
- end
146
- end
147
-
148
- def init_items
149
- Dir.glob(File.expand_path('../entities/items/*.rb', __FILE__)).each do |item|
150
- require_relative item
151
- GameItems.add(file_to_class(item))
152
- end
153
- end
154
-
155
- def init_weapons
156
- Dir.glob(File.expand_path('../entities/weapons/*.rb', __FILE__)).each do |weapon|
157
- require_relative weapon
158
- GameWeapons.add(file_to_class(weapon))
159
- end
160
- end
161
-
162
- def init_armor
163
- Dir.glob(File.expand_path('../entities/armor/*.rb', __FILE__)).each do |armor|
164
- require_relative armor
165
- GameArmor.add(file_to_class(armor))
166
- end
167
- end
168
-
169
- def init_world
170
- mode = GameOptions.data['save_file_mode']
171
-
172
- if mode.eql?('Y')
173
- if File.exist?(GameOptions.data['default_world_path_yaml'])
174
- File.open(GameOptions.data['default_world_path_yaml'], 'r') do |f|
175
- return YAML.load(f)
176
- end
177
- else
178
- puts "Error: cannot load #{GameOptions.data['default_world_path_yaml']}."
179
- end
180
- else
181
- if File.exist?(GameOptions.data['default_world_path_bin'])
182
- File.open(GameOptions.data['default_world_path_bin'], 'r') do |f|
183
- return Marshal.load(f)
184
- end
185
- else
186
- puts "Error: cannot load #{GameOptions.data['default_world_path_bin']}."
187
- end
188
- end
189
- end
190
- end
191
- end
1
+ # lib/gemwarrior/game.rb
2
+ # Main launching point for Gem Warrior
3
+
4
+ require 'colorize'
5
+ require 'matrext'
6
+
7
+ require_relative 'entities/armor/iron_helmet'
8
+ require_relative 'entities/items/herb'
9
+ require_relative 'entities/weapons/dagger'
10
+ require_relative 'misc/animation'
11
+ require_relative 'misc/audio'
12
+ require_relative 'misc/formatting'
13
+ require_relative 'misc/hr'
14
+ require_relative 'evaluator'
15
+ require_relative 'game_assets'
16
+ require_relative 'game_options'
17
+ require_relative 'inventory'
18
+ require_relative 'repl'
19
+ require_relative 'world'
20
+
21
+ module Gemwarrior
22
+ class Game
23
+ # CONSTANTS
24
+ INVENTORY_DEFAULT = Inventory.new
25
+ INVENTORY_DEBUG = Inventory.new([Herb.new, Herb.new, Herb.new])
26
+ ROX_DEFAULT = 0
27
+ ROX_DEBUG = 300
28
+
29
+ attr_accessor :world,
30
+ :evaluator,
31
+ :repl,
32
+ :monsters,
33
+ :weapons
34
+
35
+ def initialize(options)
36
+ # set game options
37
+ GameOptions.add 'beast_mode', options.fetch(:beast_mode)
38
+ GameOptions.add 'debug_mode', options.fetch(:debug_mode)
39
+ GameOptions.add 'god_mode', options.fetch(:god_mode)
40
+ GameOptions.add 'sound_enabled', options.fetch(:sound_enabled)
41
+ GameOptions.add 'sound_system', options.fetch(:sound_system)
42
+ GameOptions.add 'sound_volume', options.fetch(:sound_volume)
43
+ GameOptions.add 'use_wordnik', options.fetch(:use_wordnik)
44
+ GameOptions.add 'fight_completion', options.fetch(:fight_completion)
45
+
46
+ # add classes for creatures, monsters, people, items, weapons, and armor to game
47
+ # also add them to the global GameAssets
48
+ init_creatures
49
+ init_monsters
50
+ init_people
51
+ init_items
52
+ init_weapons
53
+ init_armor
54
+
55
+ # create new world based on default template
56
+ self.world = init_world
57
+
58
+ # update some player aspects to make more dynamic
59
+ world.player.name = world.player.generate_name
60
+ world.player.face = world.player.generate_face
61
+ world.player.hands = world.player.generate_hands
62
+ world.player.mood = world.player.generate_mood
63
+ world.player.inventory = GameOptions.data['debug_mode'] ? INVENTORY_DEBUG : INVENTORY_DEFAULT
64
+ world.player.rox = GameOptions.data['debug_mode'] ? ROX_DEBUG : ROX_DEFAULT
65
+
66
+ # set some global variables
67
+ world.duration = { mins: 0, secs: 0, ms: 0 }
68
+ world.emerald_beaten = false
69
+ world.shifty_to_jewel = false
70
+ world.shifty_has_jeweled = false
71
+
72
+ # spawn bosses
73
+ ## Pain Quarry
74
+ world.location_by_name('pain_quarry-southeast').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
75
+ world.location_by_name('pain_quarry-east').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
76
+ world.location_by_name('pain_quarry-central').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
77
+ world.location_by_name('pain_quarry-south').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
78
+ world.location_by_name('pain_quarry-west').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
79
+ world.location_by_name('pain_quarry-northwest').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
80
+ world.location_by_name('pain_quarry-north').bosses_abounding.push(Gemwarrior.const_get('Garynetty').new)
81
+ ## River Bridge
82
+ world.location_by_name('river_bridge').bosses_abounding.push(Gemwarrior.const_get('Jaspern').new)
83
+ ## Throne Room
84
+ world.location_by_name('sky_tower-throne_room').bosses_abounding.push(Gemwarrior.const_get('Emerald').new)
85
+
86
+ # mark home as visited
87
+ world.location_by_name('home').visited = true
88
+
89
+ # create options file if not existing
90
+ update_options_file
91
+
92
+ # require needed files for selected sound_system if sound_enabled
93
+ if GameOptions.data['sound_enabled']
94
+ Audio.init
95
+ end
96
+
97
+ # create the console
98
+ self.evaluator = Evaluator.new(world)
99
+ self.repl = Repl.new(self, world, evaluator)
100
+
101
+ # enter Jool!
102
+ repl.start('look', options.fetch(:extra_command), options.fetch(:new_skip), options.fetch(:resume_skip))
103
+ end
104
+
105
+ def update_options_file
106
+ File.open(GameOptions.data['options_file_path'], 'w') do |f|
107
+ f.puts "sound_enabled:#{GameOptions.data['sound_enabled']}"
108
+ f.puts "sound_system:#{GameOptions.data['sound_system']}"
109
+ f.puts "sound_volume:#{GameOptions.data['sound_volume']}"
110
+ f.puts "use_wordnik:#{GameOptions.data['use_wordnik']}"
111
+ f.puts "fight_completion:#{GameOptions.data['fight_completion']}"
112
+ end
113
+ end
114
+
115
+ private
116
+
117
+ # convert an entity filename to a class so it can be added to game asset singleton registry
118
+ def file_to_class(filename)
119
+ filename_to_string = Formatting.upstyle(filename.split('/').last.split('.')[0], no_space: true)
120
+ Gemwarrior.const_get(filename_to_string).new
121
+ end
122
+
123
+ def init_creatures
124
+ Dir.glob(File.expand_path('../entities/creatures/*.rb', __FILE__)).each do |creature|
125
+ require_relative creature
126
+ GameCreatures.add(file_to_class(creature))
127
+ end
128
+ end
129
+
130
+ def init_monsters
131
+ Dir.glob(File.expand_path('../entities/monsters/*.rb', __FILE__)).each do |monster|
132
+ require_relative monster
133
+ GameMonsters.add(file_to_class(monster))
134
+ end
135
+ Dir.glob(File.expand_path('../entities/monsters/bosses/*.rb', __FILE__)).each do |boss|
136
+ require_relative boss
137
+ GameMonsters.add(file_to_class(boss))
138
+ end
139
+ end
140
+
141
+ def init_people
142
+ Dir.glob(File.expand_path('../entities/people/*.rb', __FILE__)).each do |person|
143
+ require_relative person
144
+ GamePeople.add(file_to_class(person))
145
+ end
146
+ end
147
+
148
+ def init_items
149
+ Dir.glob(File.expand_path('../entities/items/*.rb', __FILE__)).each do |item|
150
+ require_relative item
151
+ GameItems.add(file_to_class(item))
152
+ end
153
+ end
154
+
155
+ def init_weapons
156
+ Dir.glob(File.expand_path('../entities/weapons/*.rb', __FILE__)).each do |weapon|
157
+ require_relative weapon
158
+ GameWeapons.add(file_to_class(weapon))
159
+ end
160
+ end
161
+
162
+ def init_armor
163
+ Dir.glob(File.expand_path('../entities/armor/*.rb', __FILE__)).each do |armor|
164
+ require_relative armor
165
+ GameArmor.add(file_to_class(armor))
166
+ end
167
+ end
168
+
169
+ def init_world
170
+ mode = GameOptions.data['save_file_mode']
171
+
172
+ if mode.eql?('Y')
173
+ if File.exist?(GameOptions.data['default_world_path_yaml'])
174
+ File.open(GameOptions.data['default_world_path_yaml'], 'r') do |f|
175
+ return YAML.load(f)
176
+ end
177
+ else
178
+ puts "Error: cannot load #{GameOptions.data['default_world_path_yaml']}."
179
+ end
180
+ else
181
+ if File.exist?(GameOptions.data['default_world_path_bin'])
182
+ File.open(GameOptions.data['default_world_path_bin'], 'r') do |f|
183
+ return Marshal.load(f)
184
+ end
185
+ else
186
+ puts "Error: cannot load #{GameOptions.data['default_world_path_bin']}."
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
@@ -1,100 +1,100 @@
1
- # lib/gemwarrior/game_assets.rb
2
- # Gem Warrior Global Assets
3
- ## Game Armor
4
- ## Game Creatures
5
- ## Game Items
6
- ## Game Monsters
7
- ## Game People
8
- ## Game Weapons
9
-
10
- module Gemwarrior
11
- module GameArmor
12
- def self.add obj
13
- @@data ||= []
14
- @@data.push(obj)
15
- end
16
-
17
- def self.data
18
- @@data ||= []
19
- end
20
-
21
- def self.get(name)
22
- self.data.find { |i| i.name.downcase == name.downcase }
23
- end
24
- end
25
-
26
- module GameCreatures
27
- def self.add obj
28
- @@data ||= []
29
- @@data.push(obj)
30
- end
31
-
32
- def self.data
33
- @@data ||= []
34
- end
35
-
36
- def self.get(name)
37
- self.data.find { |i| i.name.downcase == name.downcase }
38
- end
39
- end
40
-
41
- module GameItems
42
- def self.add obj
43
- @@data ||= []
44
- @@data.push(obj)
45
- end
46
-
47
- def self.data
48
- @@data ||= []
49
- end
50
-
51
- def self.get(name)
52
- self.data.find { |i| i.name.downcase == name.downcase }
53
- end
54
- end
55
-
56
- module GameMonsters
57
- def self.add obj
58
- @@data ||= []
59
- @@data.push(obj)
60
- end
61
-
62
- def self.data
63
- @@data ||= []
64
- end
65
-
66
- def self.get(name)
67
- self.data.find { |i| i.name.downcase == name.downcase }
68
- end
69
- end
70
-
71
- module GamePeople
72
- def self.add obj
73
- @@data ||= []
74
- @@data.push(obj)
75
- end
76
-
77
- def self.data
78
- @@data ||= []
79
- end
80
-
81
- def self.get(name)
82
- self.data.find { |i| i.name.downcase == name.downcase }
83
- end
84
- end
85
-
86
- module GameWeapons
87
- def self.add obj
88
- @@data ||= []
89
- @@data.push(obj)
90
- end
91
-
92
- def self.data
93
- @@data ||= []
94
- end
95
-
96
- def self.get(name)
97
- self.data.find { |i| i.name.downcase == name.downcase }
98
- end
99
- end
100
- end
1
+ # lib/gemwarrior/game_assets.rb
2
+ # Gem Warrior Global Assets
3
+ ## Game Armor
4
+ ## Game Creatures
5
+ ## Game Items
6
+ ## Game Monsters
7
+ ## Game People
8
+ ## Game Weapons
9
+
10
+ module Gemwarrior
11
+ module GameArmor
12
+ def self.add obj
13
+ @@data ||= []
14
+ @@data.push(obj)
15
+ end
16
+
17
+ def self.data
18
+ @@data ||= []
19
+ end
20
+
21
+ def self.get(name)
22
+ self.data.find { |i| i.name.downcase == name.downcase }
23
+ end
24
+ end
25
+
26
+ module GameCreatures
27
+ def self.add obj
28
+ @@data ||= []
29
+ @@data.push(obj)
30
+ end
31
+
32
+ def self.data
33
+ @@data ||= []
34
+ end
35
+
36
+ def self.get(name)
37
+ self.data.find { |i| i.name.downcase == name.downcase }
38
+ end
39
+ end
40
+
41
+ module GameItems
42
+ def self.add obj
43
+ @@data ||= []
44
+ @@data.push(obj)
45
+ end
46
+
47
+ def self.data
48
+ @@data ||= []
49
+ end
50
+
51
+ def self.get(name)
52
+ self.data.find { |i| i.name.downcase == name.downcase }
53
+ end
54
+ end
55
+
56
+ module GameMonsters
57
+ def self.add obj
58
+ @@data ||= []
59
+ @@data.push(obj)
60
+ end
61
+
62
+ def self.data
63
+ @@data ||= []
64
+ end
65
+
66
+ def self.get(name)
67
+ self.data.find { |i| i.name.downcase == name.downcase }
68
+ end
69
+ end
70
+
71
+ module GamePeople
72
+ def self.add obj
73
+ @@data ||= []
74
+ @@data.push(obj)
75
+ end
76
+
77
+ def self.data
78
+ @@data ||= []
79
+ end
80
+
81
+ def self.get(name)
82
+ self.data.find { |i| i.name.downcase == name.downcase }
83
+ end
84
+ end
85
+
86
+ module GameWeapons
87
+ def self.add obj
88
+ @@data ||= []
89
+ @@data.push(obj)
90
+ end
91
+
92
+ def self.data
93
+ @@data ||= []
94
+ end
95
+
96
+ def self.get(name)
97
+ self.data.find { |i| i.name.downcase == name.downcase }
98
+ end
99
+ end
100
+ end
@@ -1,15 +1,15 @@
1
- # lib/gemwarrior/game_options.rb
2
- # Gem Warrior Global Game Options
3
-
4
- module Gemwarrior
5
- module GameOptions
6
- def self.add key, value
7
- @@data ||= {}
8
- @@data[key] = value
9
- end
10
-
11
- def self.data
12
- @@data ||= {}
13
- end
14
- end
15
- end
1
+ # lib/gemwarrior/game_options.rb
2
+ # Gem Warrior Global Game Options
3
+
4
+ module Gemwarrior
5
+ module GameOptions
6
+ def self.add key, value
7
+ @@data ||= {}
8
+ @@data[key] = value
9
+ end
10
+
11
+ def self.data
12
+ @@data ||= {}
13
+ end
14
+ end
15
+ end