Class: Gemwarrior::Player
- Includes:
- PlayerLevels
- Defined in:
- lib/gemwarrior/entities/player.rb
Instance Attribute Summary collapse
-
#beast_mode ⇒ Object
Returns the value of attribute beast_mode.
-
#cur_coords ⇒ Object
Returns the value of attribute cur_coords.
-
#god_mode ⇒ Object
Returns the value of attribute god_mode.
-
#items_taken ⇒ Object
Returns the value of attribute items_taken.
-
#monsters_killed ⇒ Object
Returns the value of attribute monsters_killed.
-
#movements_made ⇒ Object
Returns the value of attribute movements_made.
-
#rests_taken ⇒ Object
Returns the value of attribute rests_taken.
-
#special_abilities ⇒ Object
Returns the value of attribute special_abilities.
-
#stam_cur ⇒ Object
Returns the value of attribute stam_cur.
-
#stam_max ⇒ Object
Returns the value of attribute stam_max.
-
#use_wordnik ⇒ Object
Returns the value of attribute use_wordnik.
Attributes inherited from Creature
#atk_hi, #atk_lo, #defense, #dexterity, #face, #hands, #hp_cur, #hp_max, #inventory, #level, #mood, #rox, #xp
Attributes inherited from Entity
Instance Method Summary collapse
- #attack(world, monster) ⇒ Object
- #check_self(debug_mode = false, show_pic = true) ⇒ Object
- #cur_weapon_name ⇒ Object
- #go(locations, direction, sound) ⇒ Object
- #has_weapon_equipped? ⇒ Boolean
- #heal_damage(dmg) ⇒ Object
-
#initialize(options) ⇒ Player
constructor
A new instance of Player.
- #list_inventory ⇒ Object
- #modify_name ⇒ Object
- #rest(world) ⇒ Object
- #stamina_dec ⇒ Object
- #take_damage(dmg) ⇒ Object
- #update_stats(monster) ⇒ Object
Methods included from PlayerLevels
Methods inherited from Entity
Constructor Details
#initialize(options) ⇒ Player
Returns a new instance of Player.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gemwarrior/entities/player.rb', line 18 def initialize() self.name = generate_name self.description = .fetch(:description) self.use_wordnik = .fetch(:use_wordnik) self.face = generate_face(use_wordnik) self.hands = generate_hands(use_wordnik) self.mood = generate_mood(use_wordnik) self.level = .fetch(:level) self.xp = .fetch(:xp) self.hp_cur = .fetch(:hp_cur) self.hp_max = .fetch(:hp_max) self.atk_lo = .fetch(:atk_lo) self.atk_hi = .fetch(:atk_hi) self.defense = .fetch(:defense) self.dexterity = .fetch(:dexterity) self.inventory = .fetch(:inventory) self.rox = .fetch(:rox) self.stam_cur = .fetch(:stam_cur) self.stam_max = .fetch(:stam_max) self.cur_coords = .fetch(:cur_coords) self.god_mode = .fetch(:god_mode) self.beast_mode = .fetch(:beast_mode) self.special_abilities = [] self.monsters_killed = 0 self.items_taken = 0 self.movements_made = 0 self.rests_taken = 0 end |
Instance Attribute Details
#beast_mode ⇒ Object
Returns the value of attribute beast_mode.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def beast_mode @beast_mode end |
#cur_coords ⇒ Object
Returns the value of attribute cur_coords.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def cur_coords @cur_coords end |
#god_mode ⇒ Object
Returns the value of attribute god_mode.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def god_mode @god_mode end |
#items_taken ⇒ Object
Returns the value of attribute items_taken.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def items_taken @items_taken end |
#monsters_killed ⇒ Object
Returns the value of attribute monsters_killed.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def monsters_killed @monsters_killed end |
#movements_made ⇒ Object
Returns the value of attribute movements_made.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def movements_made @movements_made end |
#rests_taken ⇒ Object
Returns the value of attribute rests_taken.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def rests_taken @rests_taken end |
#special_abilities ⇒ Object
Returns the value of attribute special_abilities.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def special_abilities @special_abilities end |
#stam_cur ⇒ Object
Returns the value of attribute stam_cur.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def stam_cur @stam_cur end |
#stam_max ⇒ Object
Returns the value of attribute stam_max.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def stam_max @stam_max end |
#use_wordnik ⇒ Object
Returns the value of attribute use_wordnik.
14 15 16 |
# File 'lib/gemwarrior/entities/player.rb', line 14 def use_wordnik @use_wordnik end |
Instance Method Details
#attack(world, monster) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/gemwarrior/entities/player.rb', line 196 def attack(world, monster) battle = Battle.new({:world => world, :player => self, :monster => monster}) result = battle.start if result.eql?('death') return 'exit' end end |
#check_self(debug_mode = false, show_pic = true) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gemwarrior/entities/player.rb', line 55 def check_self(debug_mode = false, show_pic = true) unless show_pic == false print_char_pic end weapon_slot = '' if has_weapon_equipped? weapon_slot = inventory.weapon.name self.atk_lo = inventory.weapon.atk_lo self.atk_hi = inventory.weapon.atk_hi else weapon_slot = '(unarmed)' end abilities = '' if special_abilities.empty? abilities = 'none' else abilities = special_abilities.join(', ') end self_text = "NAME : #{self.name}\n" self_text << "POSITION : #{self.cur_coords.values.to_a}\n" self_text << "WEAPON : #{weapon_slot}\n" self_text << "LEVEL : #{self.level}\n" self_text << "EXPERIENCE: #{self.xp}\n" self_text << "HIT POINTS: #{self.hp_cur}/#{self.hp_max}\n" self_text << "ATTACK : #{self.atk_lo}-#{self.atk_hi}\n" self_text << "DEXTERITY : #{self.dexterity}\n" self_text << "DEFENSE : #{self.defense}\n" self_text << "ABILITIES : #{abilities}\n" if debug_mode self_text << "GOD_MODE : #{self.god_mode}\n" self_text << "BEAST_MODE: #{self.beast_mode}\n" end self_text << "\n#{self.description}\n\n" self_text << "Current status - breathing, wearing clothing, and with a few other specific characteristics: face is #{self.face}, hands are #{self.hands}, and general mood is #{self.mood}.\n" end |
#cur_weapon_name ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/gemwarrior/entities/player.rb', line 208 def cur_weapon_name if has_weapon_equipped? return " with your #{inventory.weapon.name}" else return nil end end |
#go(locations, direction, sound) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/gemwarrior/entities/player.rb', line 159 def go(locations, direction, sound) case direction when 'north', 'n' self.cur_coords = { :x => cur_coords[:x], :y => cur_coords[:y]+1, :z => cur_coords[:z] } direction_text = '^^^' when 'east', 'e' self.cur_coords = { :x => cur_coords[:x]+1, :y => cur_coords[:y], :z => cur_coords[:z] } direction_text = '>>>' when 'south', 's' self.cur_coords = { :x => cur_coords[:x], :y => cur_coords[:y]-1, :z => cur_coords[:z] } direction_text = 'vvv' when 'west', 'w' self.cur_coords = { :x => cur_coords[:x]-1, :y => cur_coords[:y], :z => cur_coords[:z] } direction_text = '<<<' end print_traveling_text(direction_text, sound) # stats self.movements_made += 1 end |
#has_weapon_equipped? ⇒ Boolean
204 205 206 |
# File 'lib/gemwarrior/entities/player.rb', line 204 def has_weapon_equipped? self.inventory.weapon end |
#heal_damage(dmg) ⇒ Object
224 225 226 227 228 229 |
# File 'lib/gemwarrior/entities/player.rb', line 224 def heal_damage(dmg) self.hp_cur = self.hp_cur + dmg.to_i if self.hp_cur > self.hp_max self.hp_cur = self.hp_max end end |
#list_inventory ⇒ Object
155 156 157 |
# File 'lib/gemwarrior/entities/player.rb', line 155 def list_inventory inventory.list_contents end |
#modify_name ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/gemwarrior/entities/player.rb', line 137 def modify_name print "Enter new name: " new_name = gets.chomp! if new_name.length <= 0 return "You continue on as #{name}." elsif new_name.length < 3 || new_name.length > 10 return "'#{new_name}' is an invalid length. Make it between 3 and 10 characters, please." else name_to_add = "" name_to_add << new_name[0].upcase name_to_add << new_name[1..new_name.length-1].downcase self.name = name_to_add return "New name, '#{name}', accepted." end end |
#rest(world) ⇒ Object
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 123 124 125 126 127 128 129 130 131 |
# File 'lib/gemwarrior/entities/player.rb', line 96 def rest(world) cur_loc = world.location_by_coords(cur_coords) if cur_loc.should_spawn_monster? chance_of_ambush = rand(0..100) if chance_of_ambush < 25 battle = Battle.new({:world => world, :player => self, :monster => cur_loc.monsters_abounding[rand(0..cur_loc.monsters_abounding.length-1)]}) return battle.start(is_arena = false, is_event = true) end end # stats self.rests_taken += 1 hours = rand(1..23) minutes = rand(1..59) seconds = rand(1..59) hours_text = hours == 1 ? "hour" : "hours" mins_text = minutes == 1 ? "minute" : "minutes" secs_text = seconds == 1 ? "second" : "seconds" Animation::run({:phrase => '** Zzzzz **'}) if self.inventory.contains_item?('tent') || world.location_by_coords(cur_coords).has_item?('tent') self.hp_cur = self.hp_max return "You brandish your trusty magical canvas, and with a flick of the wrist your home for the evening is set up. Approximately #{hours} #{hours_text}, #{minutes} #{mins_text}, and #{seconds} #{secs_text} later, you wake up, fully rested, ready for adventure." else self.hp_cur = self.hp_cur.to_i + rand(10..15) self.hp_cur = self.hp_max if self.hp_cur > self.hp_max return "You lie down somewhere quasi-flat and after a few moments, due to extreme exhaustion, you fall into a deep, yet troubled, slumber. Approximately #{hours} #{hours_text}, #{minutes} #{mins_text}, and #{seconds} #{secs_text} later, you wake up with a start. Upon getting to your feet you look around, notice you feel somewhat better, and wonder why you dreamt about #{WordList.new(world.use_wordnik, 'noun-plural').get_random_value}." end end |
#stamina_dec ⇒ Object
133 134 135 |
# File 'lib/gemwarrior/entities/player.rb', line 133 def stamina_dec self.stam_cur = stam_cur - 1 end |
#take_damage(dmg) ⇒ Object
216 217 218 219 220 221 222 |
# File 'lib/gemwarrior/entities/player.rb', line 216 def take_damage(dmg) self.hp_cur = self.hp_cur - dmg.to_i if hp_cur <= 0 player_death end end |
#update_stats(monster) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/gemwarrior/entities/player.rb', line 231 def update_stats(monster) old_player_level = PlayerLevels::check_level(self.xp) self.xp = self.xp + monster.xp self.rox = self.rox + monster.rox monster_items = monster.inventory.items unless monster_items.nil? self.inventory.items.concat monster_items unless monster_items.empty? end new_player_level = PlayerLevels::check_level(self.xp) if new_player_level > old_player_level Animation::run({:phrase => '** LEVEL UP! **'}) new_stats = PlayerLevels::get_level_stats(new_player_level) self.level = new_stats[:level] puts "You are now level #{self.level}!" self.hp_cur = new_stats[:hp_max] self.hp_max = new_stats[:hp_max] puts "You now have #{self.hp_max} hit points!" self.stam_cur = new_stats[:stam_max] self.stam_max = new_stats[:stam_max] puts "You now have #{self.stam_max} stamina points!" self.atk_lo = new_stats[:atk_lo] self.atk_hi = new_stats[:atk_hi] puts "You now have an attack of #{self.atk_lo}-#{self.atk_hi}!" self.defense = new_stats[:defense] puts "You now have #{self.defense} defensive points!" self.dexterity = new_stats[:dexterity] puts "You now have #{self.dexterity} dexterity points!" unless new_stats[:special_abilities].nil? unless self.special_abilities.include?(new_stats[:special_abilities]) self.special_abilities.push(new_stats[:special_abilities]) puts "You learned a new ability: #{new_stats[:special_abilities]}!" end end end end |