#
# file:: occupations.rb
# author:: Craig Smith
$:.unshift "lib" if !$:.include? "lib"
$:.unshift "vendor" if !$:.include? "vendor"
require 'yaml'
require 'utility/ternarytrie'
require 'utility/configuration'
require 'utility/log'
# The Command class encapsulates a TeensyMud command
class Occupation
attr_reader :name, :start_items, :start_skills
attr_accessor :start_location, :level_skill_bonus, :start_cash_bonus
logger
configuration
# Create an occupation
def initialize(name)
@name,@start_items,@start_skills,@start_location,@level_skill_bonus = name,start_items,start_skills,start_location,level_skill_bonus
end
# load builds a occupation lookup trie from the commands listed in a yaml
# config file and in the and then defines/redefines them on the GameObject
# classes.
# [+return+] A trie of commands (see TernaryTrie class)
def self.load
@log.info "Loading occupations..."
occtable = TernaryTrie.new
if options['occupations'] && !options['occupations'].empty?
options['occupations'].each do |i|
if FileTest.exists? "occupations/#{i}.yaml"
occs = YAML::load_file("occupations/#{i}.yaml")
if occs.has_key? "name"
occtable.insert(occs['name'], occs)
else
@log.error "No name field defined for #{i}"
end
else
@log.warn "No occupation file for #{i}."
end
end
end
@log.info "Done."
return occtable
rescue Exception
@log.error $!
end
# We need options at class level
def self.options
Configuration.instance.options
end
end