#!/usr/bin/env ruby
# $Revision: 1.3 $
# $Date: 2003/12/04 22:18:34 $
# $Author: jefus $

# the Skill class will be used to help keep the main skill list, which holds
# skill names, their costs, professions who get 'em cheap, associated broad
# skills, and related ability scores.

# $skills = [] # should this be a global variable like it is, or
# 						 # a local System variable, which is accessible globally anyways?
# moved to System.skills

class Skill
	attr_accessor :name, :cost, :professions, :ability, :untrained, :broad

	# useful constants for skill checks, etc
	# Marginal = 0
	# Ordinary = 1
	# Good     = 2
	# Amazing  = 3
	# apparently ruby won't let me do this, so until i figure out a better
	# way, i'll just use methods

	def Skill.CriticalFailure
		return -2
	end

	def Skill.Failure
		return -1
	end
	
	def Skill.Marginal
		return 0
	end

	def Skill.Ordinary
		return 1
	end

	def Skill.Good
		return 2
	end

	def Skill.Amazing
		return 3
	end
	
	def initialize(name = "nil skill", cost = 0, professions = "-",
								 ability = "str", untrained = true, broad = nil)
		@name = name
		@cost = cost
		@professions = professions
		@ability = ability
		@untrained = untrained # most skills can be used untrained
		@broad = broad

		# automatically add skill to master list (this can be removed if necessary)
		$system.skills << self
		# some feedback is always nice
		# Logger.log("Skill '#{@name}' loaded.")
		# but not really important now.
	end

	# this is to make things a little clearer.
	# the "broad" variable of this class holds either nil or another skill...
	# if it holds another skill (is true), then it's a specialty skill, NOT
	# a broad skill. seems backwards, so broad? can be used to more clearly
	# query the broad/specialty status of a skill.
	def broad?
		if broad
			return false
		else
			return true
		end
	end

	# i know there's technically already an "untrained" method, but this is more
	# logical.
	def untrained?
		return @untrained
	end

	# returns a list of specialty skills associated with the given broad skill.
	def specialties 
		specialties = []
		$system.skills.each {|skill|	specialties << skill if skill.broad == self }
		return specialties
	end

	# this seems to be an appropriate place for this. a clean way to look up
	# a skill by name and get an object in return. will be needed by Mobile.
	def Skill.[](name)
		$system.skills.each {|skill| return skill if name == skill.name }
		return nil # in case nothing was found
	end
end



Logger.log("Skill code initialized.")