class Character
The Character
class represents a being that lives in the world. Human players and NPCs are both 'Character's.
Attributes
armour[RW]
cha[RW]
con[RW]
description[RW]
dex[RW]
height[RW]
hp[RW]
int[RW]
keywords[RW]
level[RW]
location[RW]
maxhp[RW]
name[RW]
state[RW]
str[RW]
weight[RW]
wis[RW]
xp[RW]
Public Class Methods
new(name="", initial_level=1, initial_location=3001, description="", keywords=Array.new)
click to toggle source
Create the character, which by default begins at level one and starts life at the temple (room 3001)
# File lib/skirmish/character.rb, line 17 def initialize(name="", initial_level=1, initial_location=3001, description="", keywords=Array.new) @state = :CREATING @name = name @description = description @keywords = keywords roll_stats initial_level @location = initial_location $world.move_character(self, 0, initial_location) end
Public Instance Methods
attack(num=1, size=10)
click to toggle source
Character's attack each time is calculated based on a roll of 1d10 * level, or as otherwise specified
# File lib/skirmish/character.rb, line 58 def attack(num=1, size=10) return roll_dice(num, size) * @level end
roll_stats(initial_level = 1)
click to toggle source
Roll stats for the character. This is based on the D&D 5e creation rules, with some tweaks.
# File lib/skirmish/character.rb, line 30 def roll_stats(initial_level = 1) size_roll = roll_dice(2, 10) @height = 60 + size_roll #inches @weight = 110 + roll_dice(2, 3) * size_roll #pounds # Roll 3d6 for each attribute and sort the rolls by size rolls = Array.new 6.times do rolls.push roll_dice(3,6) end rolls.sort! { |a, b| a <=> b } # Assign rolls in the standard order for a 'fighter' @str = rolls.pop() @con = rolls.pop() @dex = rolls.pop() @cha = rolls.pop() @wis = rolls.pop() @int = rolls.pop() @maxhp = @con + 10 @hp = @maxhp @xp = 0 @armour = @dex + 10 @level = initial_level end