Class: Gemwarrior::Player

Inherits:
Creature show all
Includes:
Formatting, PlayerLevels
Defined in:
lib/gemwarrior/entities/player.rb

Constant Summary collapse

LEVEL_UP_TEXT =

CONSTANTS

'** LEVEL UP! **'
REST_FULL_TEXT =
'** HMMMM **'
REST_NOT_FULL_TEXT =
'** ZZZZZ **'

Instance Attribute Summary collapse

Attributes inherited from Creature

#atk_hi, #atk_lo, #defense, #dexterity, #face, #hands, #hp_cur, #hp_max, #inventory, #level, #mood, #rox, #speak, #use, #xp

Attributes inherited from Entity

#consumable, #describe, #describe_detailed, #description, #display_shopping_cart, #equippable, #equipped, #name, #name_display, #number_of_uses, #takeable, #talkable, #useable, #useable_battle, #used, #used_again

Instance Method Summary collapse

Methods included from Formatting

#to_hooch, upstyle

Methods included from PlayerLevels

check_level, get_ability_description, get_level_stats

Methods inherited from Creature

#describe, #describe_detailed, #initialize

Methods inherited from Entity

#initialize, #puts, #use

Constructor Details

This class inherits a constructor from Gemwarrior::Creature

Instance Attribute Details

#bosses_killedObject

Returns the value of attribute bosses_killed.



23
24
25
# File 'lib/gemwarrior/entities/player.rb', line 23

def bosses_killed
  @bosses_killed
end

#cur_coordsObject

Returns the value of attribute cur_coords.



23
24
25
# File 'lib/gemwarrior/entities/player.rb', line 23

def cur_coords
  @cur_coords
end

#deathsObject

Returns the value of attribute deaths.



23
24
25
# File 'lib/gemwarrior/entities/player.rb', line 23

def deaths
  @deaths
end

#items_takenObject

Returns the value of attribute items_taken.



23
24
25
# File 'lib/gemwarrior/entities/player.rb', line 23

def items_taken
  @items_taken
end

#monsters_killedObject

Returns the value of attribute monsters_killed.



23
24
25
# File 'lib/gemwarrior/entities/player.rb', line 23

def monsters_killed
  @monsters_killed
end

#movements_madeObject

Returns the value of attribute movements_made.



23
24
25
# File 'lib/gemwarrior/entities/player.rb', line 23

def movements_made
  @movements_made
end

#rests_takenObject

Returns the value of attribute rests_taken.



23
24
25
# File 'lib/gemwarrior/entities/player.rb', line 23

def rests_taken
  @rests_taken
end

#special_abilitiesObject

Returns the value of attribute special_abilities.



23
24
25
# File 'lib/gemwarrior/entities/player.rb', line 23

def special_abilities
  @special_abilities
end

Instance Method Details

#at_full_hp?Boolean

Returns:

  • (Boolean)


361
362
363
# File 'lib/gemwarrior/entities/player.rb', line 361

def at_full_hp?
  self.hp_cur == self.hp_max
end

#attack(world, monster, is_ambush = false) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/gemwarrior/entities/player.rb', line 257

def attack(world, monster, is_ambush = false)
  if monster.is_dead
    { type: 'message', data: 'That monster is now dead forever and cannot be attacked. You must have done them a good one.' }
  else
    battle = Battle.new(world: world, player: self, monster: monster)
    result = battle.start(false, is_ambush)
    if result.eql?('death')
      return 'death'
    elsif result.eql?('exit')
      return 'exit'
    else
      return result
    end
  end
end

#check_self(show_pic = true) ⇒ Object



48
49
50
51
52
53
54
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
95
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 48

def check_self(show_pic = true)
  unless show_pic == false
    print_char_pic
  end

  weapon_slot     = '(unarmed)'
  armor_slot      = '(unarmored)'
  base_atk_lo     = self.atk_lo
  base_atk_hi     = self.atk_hi
  base_defense    = self.defense
  base_dexterity  = self.dexterity
  net_atk_lo      = nil
  net_atk_hi      = nil
  net_defense     = nil
  net_dexterity   = nil

  # juice the weapon display
  if has_weapon_equipped?
    weapon_slot = self.inventory.weapon.name
    net_atk_lo = base_atk_lo + self.inventory.weapon.atk_lo
    net_atk_hi = base_atk_hi + self.inventory.weapon.atk_hi
    net_dexterity = base_dexterity + self.inventory.weapon.dex_mod
  end

  # juice the armor display
  if has_armor_equipped?
    armor_slot = inventory.armor.name
    net_defense = base_defense + inventory.armor.defense
  end

  abilities = ''
  if special_abilities.empty?
    abilities = " none...yet(?)\n"
  else
    abilities << "\n"
    special_abilities.each do |sp|
      abilities << "  #{Formatting.upstyle(sp.to_s).ljust(15).colorize(:yellow)}: #{PlayerLevels.get_ability_description(sp)}\n"
    end
  end

  self_text =  "\n"
  self_text << "NAME      : #{self.name.colorize(:green)}\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 << "WEAPON    : #{weapon_slot}\n"
  self_text << "ARMOR     : #{armor_slot}\n"
  self_text << "ATTACK    : #{base_atk_lo}-#{base_atk_hi}"
  self_text << " (#{net_atk_lo}-#{net_atk_hi} w/ #{weapon_slot})".colorize(:yellow) unless net_atk_lo.nil?
  self_text << "\n"
  self_text << "DEFENSE   : #{base_defense}"
  self_text << " (#{net_defense} w/ #{armor_slot})".colorize(:yellow) unless net_defense.nil?
  self_text << "\n"
  self_text << "DEXTERITY : #{self.dexterity}"
  self_text << " (#{net_dexterity} w/ #{weapon_slot})".colorize(:yellow) unless net_dexterity.nil?
  self_text << "\n"
  self_text << "ABILITIES :"
  self_text << "#{abilities}"
  self_text << "INVENTORY : #{self.inventory.contents}\n"

  if GameOptions.data['debug_mode']
    self_text << "\n"
    self_text << "[DEBUG STUFF]\n"
    self_text << ">> POSITION       : #{self.cur_coords.values.to_a}\n"
    self_text << ">> GOD_MODE       : #{GameOptions.data['god_mode']}\n"
    self_text << ">> BEAST_MODE     : #{GameOptions.data['beast_mode']}\n"
    self_text << ">> MONSTERS_KILLED: #{self.monsters_killed}\n"
    self_text << ">> BOSSES_KILLED  : #{self.bosses_killed}\n"
    self_text << ">> ITEMS_TAKEN    : #{self.items_taken}\n"
    self_text << ">> MOVEMENTS_MADE : #{self.movements_made}\n"
    self_text << ">> RESTS_TAKEN    : #{self.rests_taken}\n"
    self_text << ">> DEATHS         : #{self.deaths}\n"
  end

  self_text << "\n"

  self_text << "[#{"Your Story".colorize(:yellow)}]\n#{self.description}"

  self_text << "\n\n"

  self_text << "[#{"Current Status".colorize(:yellow)}]\nBreathing, non-naked, with a #{self.face.colorize(:yellow)} face, #{self.hands.colorize(:yellow)} hands, and feeling, generally, #{self.mood.colorize(:yellow)}."

  self_text << "\n"
end

#cur_weapon_nameObject



281
282
283
284
285
286
287
# File 'lib/gemwarrior/entities/player.rb', line 281

def cur_weapon_name
  if has_weapon_equipped?
    return " with your #{inventory.weapon.name}"
  else
    return nil
  end
end

#generate_faceObject



36
37
38
# File 'lib/gemwarrior/entities/player.rb', line 36

def generate_face
  WordList.new('adjective').get_random_value
end

#generate_handsObject



40
41
42
# File 'lib/gemwarrior/entities/player.rb', line 40

def generate_hands
  WordList.new('adjective').get_random_value
end

#generate_moodObject



44
45
46
# File 'lib/gemwarrior/entities/player.rb', line 44

def generate_mood
  WordList.new('adjective').get_random_value
end

#generate_nameObject



32
33
34
# File 'lib/gemwarrior/entities/player.rb', line 32

def generate_name
  NameGenerator.new('fantasy').generate_name
end

#go(world, direction) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
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
# File 'lib/gemwarrior/entities/player.rb', line 215

def go(world, direction)
  case direction
  when 'north', 'n'
    self.cur_coords = {
      x: cur_coords[:x],
      y: cur_coords[:y]+1,
      z: cur_coords[:z]
    }
    direction_cue = :player_travel_north
    direction_text = '^^^'
  when 'east', 'e'
    self.cur_coords = {
      x: cur_coords[:x]+1,
      y: cur_coords[:y],
      z: cur_coords[:z]
    }
    direction_cue = :player_travel_east
    direction_text = '>>>'
  when 'south', 's'
    self.cur_coords = {
      x: cur_coords[:x],
      y: cur_coords[:y]-1,
      z: cur_coords[:z]
    }
    direction_cue = :player_travel_south
    direction_text = 'vvv'
  when 'west', 'w'
    self.cur_coords = {
      x: cur_coords[:x]-1,
      y: cur_coords[:y],
      z: cur_coords[:z]
    }
    direction_cue = :player_travel_west
    direction_text = '<<<'
  end
  world.location_by_coords(self.cur_coords).visited = true
  print_traveling_text(direction_cue, direction_text)

  # stats
  self.movements_made += 1
end

#has_armor_equipped?Boolean

Returns:

  • (Boolean)


277
278
279
# File 'lib/gemwarrior/entities/player.rb', line 277

def has_armor_equipped?
  self.inventory.armor
end

#has_weapon_equipped?Boolean

Returns:

  • (Boolean)


273
274
275
# File 'lib/gemwarrior/entities/player.rb', line 273

def has_weapon_equipped?
  self.inventory.weapon
end

#heal_damage(dmg) ⇒ Object



297
298
299
300
301
302
# File 'lib/gemwarrior/entities/player.rb', line 297

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_inventoryObject



211
212
213
# File 'lib/gemwarrior/entities/player.rb', line 211

def list_inventory
  inventory.list_contents
end

#modify_nameObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/gemwarrior/entities/player.rb', line 196

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
    self.name = Formatting::upstyle(new_name)
    return "New name, '#{name}', accepted."
  end
end

#rest(world, tent_uses = 0, ensure_fight = false) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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 133

def rest(world, tent_uses = 0, ensure_fight = false)
  if ensure_fight
    battle = Battle.new(world: world, player: self, monster: GameMonsters.data[rand(0..GameMonsters.data.length-1)].clone)
    result = battle.start(is_arena = false, is_event = true)
    if result.eql?('death')
      return 'death'
    else
      return
    end
  end

  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)].clone)
      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'

  if tent_uses > 0
    if self.at_full_hp?
      Animation.run(phrase: REST_FULL_TEXT)
      return 'Despite feeling just fine, health-wise, you decide to set up camp for the ni--well, actually, after a few minutes you realize you don\'t need to sleep and pack things up again, ready to go.'
    else
      Animation.run(phrase: REST_NOT_FULL_TEXT)
      self.hp_cur = self.hp_max

      status_text = "You brandish the 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.\n"
      status_text << ">> You regain all of your hit points.".colorize(:green)

      return status_text
    end
  else
    if self.at_full_hp?
      Animation.run(phrase: REST_FULL_TEXT)
      return 'You sit down on the ground, make some notes on the back of your hand, test the air, and then return to standing, back at it all again.'
    else
      Animation.run(phrase: REST_NOT_FULL_TEXT)
      self.hp_cur = self.hp_cur.to_i + rand(3..5)
      self.hp_cur = self.hp_max if self.hp_cur > self.hp_max

      status_text = "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('noun-plural').get_random_value}.\n"
      status_text << ">> You regain a few hit points.".colorize(:green)

      return status_text
    end
  end
end

#take_damage(dmg) ⇒ Object



289
290
291
292
293
294
295
# File 'lib/gemwarrior/entities/player.rb', line 289

def take_damage(dmg)
  self.hp_cur = self.hp_cur - dmg.to_i

  if hp_cur <= 0
    return player_death
  end
end

#update_stats(trigger) ⇒ Object



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/gemwarrior/entities/player.rb', line 304

def update_stats(trigger)
  old_player_level = PlayerLevels::check_level(self.xp)

  case
  when trigger[:reason].eql?(:monster)
    monster = trigger[:value]
    self.xp += monster.xp
    self.rox += monster.rox

    monster_items = monster.inventory.items
    unless monster_items.nil?
      self.inventory.items.concat monster_items unless monster_items.empty?
    end
  when trigger[:reason].eql?(:xp)
    self.xp += trigger[:value]
  when trigger[:reason].eql?(:level_bump)
    next_player_level = old_player_level + trigger[:value]
    self.xp = PlayerLevels::get_level_stats(next_player_level)[:xp_start]
  end

  new_player_level = PlayerLevels::check_level(self.xp)

  # how many levels did we go up, if any?
  level_climb = new_player_level - old_player_level

  if level_climb >= 1
    level_to_get = old_player_level

    level_climb.times do
      level_to_get += 1
      Audio.play_synth(:player_level_up)
      Animation.run(phrase: LEVEL_UP_TEXT)
      new_stats = PlayerLevels::get_level_stats(level_to_get)

      self.level = new_stats[:level]
      puts "You are now level #{self.level.to_s.colorize(:green)}!"
      self.hp_cur = new_stats[:hp_max]
      self.hp_max = new_stats[:hp_max]
      puts "You now have #{self.hp_max.to_s.colorize(:green)} hit 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.to_s.colorize(:green)}-#{self.atk_hi.to_s.colorize(:green)}!"
      self.defense = new_stats[:defense]
      puts "You now have #{self.defense.to_s.colorize(:green)} defensive points!"
      self.dexterity = new_stats[:dexterity]
      puts "You now have #{self.dexterity.to_s.colorize(:green)} 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: #{Formatting::upstyle(new_stats[:special_abilities]).colorize(:green)}!"
        end
      end
      STDIN.getc
    end
  end
end