Class: Gemwarrior::Player

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

Instance Attribute Summary collapse

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

#description, #name

Instance Method Summary collapse

Methods included from PlayerLevels

check_level, get_level_stats

Methods inherited from Entity

#status

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
# File 'lib/gemwarrior/entities/player.rb', line 18

def initialize(options)
  self.name             = generate_name
  self.description      = options.fetch(:description)
  self.use_wordnik      = options.fetch(:use_wordnik)

  self.face             = generate_face(use_wordnik)
  self.hands            = generate_hands(use_wordnik)
  self.mood             = generate_mood(use_wordnik)

  self.level            = options.fetch(:level)
  self.xp               = options.fetch(:xp)
  self.hp_cur           = options.fetch(:hp_cur)
  self.hp_max           = options.fetch(:hp_max)
  self.atk_lo           = options.fetch(:atk_lo)
  self.atk_hi           = options.fetch(:atk_hi)

  self.defense          = options.fetch(:defense)
  self.dexterity        = options.fetch(:dexterity)

  self.inventory        = Inventory.new
  self.rox              = options.fetch(:rox)

  self.stam_cur         = options.fetch(:stam_cur)
  self.stam_max         = options.fetch(:stam_max)
  self.cur_coords       = options.fetch(:cur_coords)

  self.god_mode         = options.fetch(:god_mode)
  self.beast_mode       = options.fetch(:beast_mode)

  self.monsters_killed  = 0
  self.items_taken      = 0
  self.movements_made   = 0
  self.rests_taken      = 0
end

Instance Attribute Details

#beast_modeObject

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_coordsObject

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_modeObject

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_takenObject

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_killedObject

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_madeObject

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_takenObject

Returns the value of attribute rests_taken.



14
15
16
# File 'lib/gemwarrior/entities/player.rb', line 14

def rests_taken
  @rests_taken
end

#stam_curObject

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_maxObject

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_wordnikObject

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



186
187
188
189
# File 'lib/gemwarrior/entities/player.rb', line 186

def attack(world, monster)
  battle = Battle.new({:world => world, :player => self, :monster => monster})
  battle.start
end

#check_self(debug_mode = false, show_pic = true) ⇒ Object



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
# File 'lib/gemwarrior/entities/player.rb', line 53

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

  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"
  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_nameObject



195
196
197
198
199
200
201
# File 'lib/gemwarrior/entities/player.rb', line 195

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

#go(locations, direction, sound) ⇒ Object



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
# File 'lib/gemwarrior/entities/player.rb', line 149

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

Returns:

  • (Boolean)


191
192
193
# File 'lib/gemwarrior/entities/player.rb', line 191

def has_weapon_equipped?
  self.inventory.weapon
end

#heal_damage(dmg) ⇒ Object



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

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



145
146
147
# File 'lib/gemwarrior/entities/player.rb', line 145

def list_inventory
  inventory.list_contents
end

#modify_nameObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/gemwarrior/entities/player.rb', line 127

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



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
# File 'lib/gemwarrior/entities/player.rb', line 86

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_decObject



123
124
125
# File 'lib/gemwarrior/entities/player.rb', line 123

def stamina_dec
  self.stam_cur = stam_cur - 1
end

#take_damage(dmg) ⇒ Object



203
204
205
206
207
208
209
# File 'lib/gemwarrior/entities/player.rb', line 203

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

  if hp_cur <= 0
    player_death
  end
end