module FTLTools::CharacterTools

CharacterTools implements modules for modifying Character objects. These methods are outside career data sets.

Constants

DATA_PATH

In theory this is where we keep the data.

Public Class Methods

increase_skill(options) click to toggle source

Takes a hash of Character object, skill, and optional level to increase. Returns the modified Character object. If the “skill” to be modified is a Stat, calls modify_stat.

# File lib/ftl_tools/character_tools.rb, line 27
def increase_skill(options)
                    # This should eventually change to not need the character object.
                    # Maybe.
  character = options['character']
  skill     = options['skill']
  level     = options.key?('level') ? options['level'] : 1
  if skill.split.length > 1
    stat_options                            = Hash.new
                            stat_options[:upp]  = character.upp
                            stat_options[:mod]  = skill
    modify_stat(stat_options)
  else
    if character.skills.key?(skill)
      character.skills[skill] += level
    else
      character.skills[skill] = level
    end
  end
end
modify_stat(options) click to toggle source

Takes a hash of the UPP and the modifier, for example “+2 Int”. Returns a hash of the modified UPP, within the game's 2-15 limits.

# File lib/ftl_tools/character_tools.rb, line 50
def modify_stat(options)
                    # havenwood, trying to remember why I used the ArgumentError.
                    # This one uses + and - input.
                    # Changing this completely, it needs the stat mod and UPP hash,
                    # returns UPP hash.
                    upp          = options[:upp]
                    mod          = options[:mod]
                    level        = mod.split[0].to_i
                    stat = mod.split[1].downcase.to_sym
                    upp[stat] = upp[stat] + level
                    upp[stat] = [upp[stat], 15].min
                    upp[stat] = [upp[stat], 2].max
                    upp
end

Public Instance Methods

generate_name(options) click to toggle source
# File lib/ftl_tools/character_tools.rb, line 20
def generate_name(options)
  Name.new(options).to_s
end
generate_plot() click to toggle source
# File lib/ftl_tools/character_tools.rb, line 66
def generate_plot
  [get_random_line_from_file('plots.txt'), rand(1..6)]
rescue SystemCallError
  ['Some drab plot', rand(1..6)]
end
generate_temperament() click to toggle source
# File lib/ftl_tools/character_tools.rb, line 72
def generate_temperament
                    # havenwood, fixed the return.
  begin
    temperament = get_random_line_from_file('temperaments.txt')
  rescue SystemCallError
    temperament = 'Boring'
  end
end
generate_traits() click to toggle source
# File lib/ftl_tools/character_tools.rb, line 14
def generate_traits
  traits = []
  traits << get_random_line_from_file('positive_traits.txt')
  traits << get_random_line_from_file('negative_traits.txt')
end
morale(options = '') click to toggle source

def self.morale(options = “”)

# File lib/ftl_tools/character_tools.rb, line 82
def morale(options = '')
  morale = roll_1
  if (options.class == Hash) && !options['character'].careers.empty?
    high_morales    = %w[Marine Army Firster]
    medium_morales  = %w[Navy Scout]
    options['character'].careers.each do |career, terms|
      morale += (1 * terms)      if high_morales.include?(career)
      morale += (0.5 * terms)    if medium_morales.include?(career)
    end
  end
  morale
end
skill_mod(skills, skill, assume_zero = false) click to toggle source
# File lib/ftl_tools/character_tools.rb, line 95
def skill_mod(skills, skill, assume_zero = false)
  skill_value = if skills.key?(skill)
                  skills[skill]
                elsif assume_zero
                  0
                else
                  -3
                end
  skill_value
end

Private Instance Methods

increase_skill(options) click to toggle source

Takes a hash of Character object, skill, and optional level to increase. Returns the modified Character object. If the “skill” to be modified is a Stat, calls modify_stat.

# File lib/ftl_tools/character_tools.rb, line 27
def increase_skill(options)
                    # This should eventually change to not need the character object.
                    # Maybe.
  character = options['character']
  skill     = options['skill']
  level     = options.key?('level') ? options['level'] : 1
  if skill.split.length > 1
    stat_options                            = Hash.new
                            stat_options[:upp]  = character.upp
                            stat_options[:mod]  = skill
    modify_stat(stat_options)
  else
    if character.skills.key?(skill)
      character.skills[skill] += level
    else
      character.skills[skill] = level
    end
  end
end
modify_stat(options) click to toggle source

Takes a hash of the UPP and the modifier, for example “+2 Int”. Returns a hash of the modified UPP, within the game's 2-15 limits.

# File lib/ftl_tools/character_tools.rb, line 50
def modify_stat(options)
                    # havenwood, trying to remember why I used the ArgumentError.
                    # This one uses + and - input.
                    # Changing this completely, it needs the stat mod and UPP hash,
                    # returns UPP hash.
                    upp          = options[:upp]
                    mod          = options[:mod]
                    level        = mod.split[0].to_i
                    stat = mod.split[1].downcase.to_sym
                    upp[stat] = upp[stat] + level
                    upp[stat] = [upp[stat], 15].min
                    upp[stat] = [upp[stat], 2].max
                    upp
end