class WizardsCastle::Player

Constants

ARMORS
GENDERS
RACES
TREASURES
WEAPONS

Attributes

armor[R]
armor_health[R]
armor_value[R]
facing[R]
gender[R]
last_ate_turn[R]
location[R]
race[R]
weapon[R]
weapon_value[R]

Public Class Methods

new() click to toggle source
# File lib/wizards-castle/player.rb, line 53
def initialize
  @room_memory = Array.new(8*8*8,false) #true means visited
  @race = nil
  @gender = nil
  @gp = 60
  @flares = 0
  @has_lamp = false
  @location = [1,4,1]
  @str = 0
  @int = 0
  @dex = 0
  @custom_attribute_points = 0
  @armor = :nothing
  @armor_value = 0
  @armor_health = 0
  @weapon = :nothing
  @weapon_value = 0
  @treasures = []
  @runestaff = false
  @orb_of_zot = false
  @vendor_rage = false
  @turns = 1
  @last_ate_turn = 0
  @facing = :n  # needed by orb-of-zot shunt
  @teleported = false  # so orb-of-zot room knows how you entered it

  # afflictions
  @blind = false
  @stickybook = false
  @forgetful = false
  @leech = false
  @lethargic = false
end

Public Instance Methods

add_treasure(t) click to toggle source
# File lib/wizards-castle/player.rb, line 173
def add_treasure(t)
  raise "invalid treasure #{t.inspect}" unless TREASURES.include?(t)
  raise "already have treasure #{t.inspect}" if @treasures.include?(t)
  @treasures << t
end
blind?() click to toggle source

afflictions

# File lib/wizards-castle/player.rb, line 215
def blind?
  @blind
end
custom_attribute_points(n=0) click to toggle source
# File lib/wizards-castle/player.rb, line 165
def custom_attribute_points n=0
  @custom_attribute_points += n
end
dead?() click to toggle source
# File lib/wizards-castle/player.rb, line 87
def dead?
  @str<1 || @int<1 || @dex<1
end
dex(n=0) click to toggle source
# File lib/wizards-castle/player.rb, line 154
def dex n=0
  @dex += n.to_i
  @dex=0 if @dex<0
  @dex=18 if @dex>18
  @dex
end
flares(n=0) click to toggle source
# File lib/wizards-castle/player.rb, line 128
def flares n=0
  @flares += n.to_i
  @flares=0 if @flares<0
  @flares
end
forget_random_room() click to toggle source
# File lib/wizards-castle/player.rb, line 203
def forget_random_room
  loc = Castle.random_room
  idx = Castle.room_index(*loc)
  @room_memory[idx] = false
end
forgetful?() click to toggle source
# File lib/wizards-castle/player.rb, line 231
def forgetful?
  @forgetful
end
gp(n=0) click to toggle source
# File lib/wizards-castle/player.rb, line 134
def gp n=0
  @gp += n.to_i
  @gp=0 if @gp<0
  @gp
end
have_treasure?(t) click to toggle source
# File lib/wizards-castle/player.rb, line 185
def have_treasure?(t)
  raise "invalid treasure #{t.inspect}" unless TREASURES.include?(t)
  @treasures.include?(t)
end
int(n=0) click to toggle source
# File lib/wizards-castle/player.rb, line 147
def int n=0
  @int += n.to_i
  @int=0 if @int<0
  @int=18 if @int>18
  @int
end
knows_room?(col,row,floor) click to toggle source
# File lib/wizards-castle/player.rb, line 195
def knows_room?(col,row,floor)
  @room_memory[Castle.room_index(col,row,floor)]
end
lamp?() click to toggle source
# File lib/wizards-castle/player.rb, line 13
def lamp?
  @has_lamp
end
leech?() click to toggle source
# File lib/wizards-castle/player.rb, line 239
def leech?
  @leech
end
lethargic?() click to toggle source
# File lib/wizards-castle/player.rb, line 247
def lethargic?
  @lethargic
end
orb_of_zot?() click to toggle source
# File lib/wizards-castle/player.rb, line 37
def orb_of_zot?
  @orb_of_zot
end
random_treasure() click to toggle source
# File lib/wizards-castle/player.rb, line 190
def random_treasure
  return nil if treasure_count() < 1
  @treasures.sample
end
remember_room(col,row,floor) click to toggle source
# File lib/wizards-castle/player.rb, line 199
def remember_room(col,row,floor)
  @room_memory[Castle.room_index(col,row,floor)] = true
end
remove_treasure(t) click to toggle source
# File lib/wizards-castle/player.rb, line 179
def remove_treasure(t)
  raise "invalid treasure #{t.inspect}" unless TREASURES.include?(t)
  raise "don't have treasure #{t.inspect}" unless @treasures.include?(t)
  @treasures.delete(t)
end
runestaff?() click to toggle source
# File lib/wizards-castle/player.rb, line 29
def runestaff?
  @runestaff
end
set_armor(a) click to toggle source
# File lib/wizards-castle/player.rb, line 115
def set_armor a
  raise "Unrecognized armor parameter" unless ARMORS.include?(a)
  @armor = a
  @armor_value = ARMORS.index(a)
  @armor_health = @armor_value*7
end
set_blind(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 218
def set_blind(bool)
  check_bool(bool)
  @blind = bool
end
set_facing(f) click to toggle source
# File lib/wizards-castle/player.rb, line 98
def set_facing f
  raise "Illegal direction '#{f.inspect}'" unless [:n,:s,:w,:e].include?(f)
  @facing = f
end
set_forgetful(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 234
def set_forgetful(bool)
  check_bool(bool)
  @forgetful = bool
end
set_gender(g) click to toggle source
# File lib/wizards-castle/player.rb, line 109
def set_gender g
  #maybe in a future version I'll allow non-binary genders
  raise "Unrecognized gender parameter" unless GENDERS.include?(g)
  @gender = g
end
set_lamp(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 16
def set_lamp bool
  check_bool(bool)
  @has_lamp = bool
end
set_leech(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 242
def set_leech(bool)
  check_bool(bool)
  @leech = bool
end
set_lethargic(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 250
def set_lethargic(bool)
  check_bool(bool)
  @lethargic = bool
end
set_location(row,col,floor) click to toggle source
# File lib/wizards-castle/player.rb, line 91
def set_location(row,col,floor)
  if row<1 || row>8 || col<1 || col>8 || floor<1 || floor>8
    raise "Illegal location [#{row},#{col},#{floor}]"
  end
  @location = [row,col,floor]
end
set_orb_of_zot(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 40
def set_orb_of_zot(bool)
  check_bool(bool)
  @orb_of_zot = bool
end
set_race(r) click to toggle source
# File lib/wizards-castle/player.rb, line 104
def set_race r
  raise "Unrecognized race parameter '#{r.inspect}'" unless RACES.include?(r)
  @race = r
end
set_runestaff(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 32
def set_runestaff(bool)
  check_bool(bool)
  @runestaff = bool
end
set_stickybook(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 226
def set_stickybook(bool)
  check_bool(bool)
  @stickybook=bool
end
set_teleported(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 48
def set_teleported(bool)
  check_bool(bool)
  @teleported=bool
end
set_vendor_rage(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 24
def set_vendor_rage bool
  check_bool(bool)
  @vendor_rage = bool
end
set_weapon(w) click to toggle source
# File lib/wizards-castle/player.rb, line 122
def set_weapon w
  raise "Unrecognized weapon parameter" unless WEAPONS.include?(w)
  @weapon = w
  @weapon_value = WEAPONS.index(w)
end
stickybook?() click to toggle source
# File lib/wizards-castle/player.rb, line 223
def stickybook?
  @stickybook
end
str(n=0) click to toggle source
# File lib/wizards-castle/player.rb, line 140
def str n=0
  @str += n.to_i
  @str=0 if @str<0
  @str=18 if @str>18
  @str
end
take_a_hit!(n,printer=nil) click to toggle source

combat

# File lib/wizards-castle/player.rb, line 257
def take_a_hit!(n,printer=nil)
  if @armor==:nothing
    self.str(-n)
  else
    if n >= @armor_value
      loss = n-@armor_value
      self.str(-loss)
      @armor_health -= @armor_value
    else
      @armor_health -= n
    end

    if @armor_health<=0
      self.set_armor(:nothing)
      printer.armor_destroyed if printer
    end
  end
  nil
end
teleported?() click to toggle source
# File lib/wizards-castle/player.rb, line 45
def teleported?
  @teleported
end
treasure_count() click to toggle source
# File lib/wizards-castle/player.rb, line 169
def treasure_count
  @treasures.length
end
turns(n=0) click to toggle source
# File lib/wizards-castle/player.rb, line 161
def turns n=0
  @turns += n.to_i
end
update_last_ate_turn!() click to toggle source
# File lib/wizards-castle/player.rb, line 209
def update_last_ate_turn!
  @last_ate_turn = @turns
end
vendor_rage?() click to toggle source
# File lib/wizards-castle/player.rb, line 21
def vendor_rage?
  @vendor_rage
end

Private Instance Methods

check_bool(bool) click to toggle source
# File lib/wizards-castle/player.rb, line 279
def check_bool(bool)
  raise "Parameter is not a boolean: #{bool.inspect}" unless [true,false].include?(bool)
end