Class: PfrpgCore::Character

Inherits:
Object
  • Object
show all
Includes:
Bonus, Derived::CombatBonuses, Derived::Magic, Derived::Misc
Defined in:
lib/pfrpg_core/character.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Derived::Misc

#calc_speed, #explode_levels, #get_caster_level, #get_class_level, #gets_companion?, #gets_familiar?, #hit_dice, #hit_die, #hit_points, #initiative, #level_string, #misc_json, #parse_speed_bonuses, #size, #speed, #total_level

Methods included from Derived::Magic

#arcane_school, #bloodline, #can_arcane?, #can_divine?, #empty_spells, #filter, #filter_for_high_level, #filter_for_max_attribute, #gets_companion?, #gets_familiar?, #known_sorcerer_spells, #spells_per_level, #valid_spell?

Methods included from Derived::CombatBonuses

#armor_speed_penalty, #get_ac_penalty, #get_armor_modifier, #get_attack_filters, #get_damage_reduction, #get_deflection_modifier, #get_dodge_modifier, #get_highest_attack_bonus, #get_max_dex_bonus, #get_natural_armor, #get_size_modifier, #get_spell_resistance

Methods included from Bonus

#get_bonus

Constructor Details

#initialize(params) ⇒ Character

Returns a new instance of Character.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pfrpg_core/character.rb', line 14

def initialize(params)
  @character_uuid = params[:uuid]
  @character_id   = params[:id]
  # TODO: Refactor client to remove @character
  # computed by calling objects
  @character      = params[:character]
  @avatar         = params[:avatar]
  @demographics   = params[:demographics]
  @race           = params[:race][:race]
  @racial_bonuses = params[:race][:bonuses]
  prime_bonuses_with_racial_stats
  @attributes     = PfrpgCore::Attributes.new(params[:attributes], @bonuses)
  @levels         = params[:levels][:latest].map { |x| PfrpgCore::Level.new(x) }
  @latest_levels  = params[:levels][:latest]
  @alignment      = params[:alignment]
  @feats          = params[:feats]
  @class_features = FeatureDuplicator.filter_duplicates(params[:features])
  @inventory      = params[:inventory]
  @base_skills    = params[:base_skills]
  @spellbooks     = params[:spellbooks]
  # uncomputable until bonuses are calculated
  apply_bonuses
  @attributes.set_bonuses(@bonuses)
  @attributes.max_dex = self.get_max_dex_bonus
  @saves          = SavingThrows.new(params[:saves], @bonuses, @attributes)
  @combat         = PfrpgCore::Combat.new(self)
  @skills         = PfrpgCore::Skills.new(self)
  @spells         = PfrpgCore::SpellBooks.new(self)
end

Instance Attribute Details

#alignmentObject

Returns the value of attribute alignment.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def alignment
  @alignment
end

#attributesObject

Returns the value of attribute attributes.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def attributes
  @attributes
end

#avatarObject

Returns the value of attribute avatar.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def avatar
  @avatar
end

#base_skillsObject

Returns the value of attribute base_skills.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def base_skills
  @base_skills
end

#bonusesObject

Returns the value of attribute bonuses.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def bonuses
  @bonuses
end

#character_idObject

Returns the value of attribute character_id.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def character_id
  @character_id
end

#character_uuidObject

Returns the value of attribute character_uuid.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def character_uuid
  @character_uuid
end

#class_featuresObject

Returns the value of attribute class_features.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def class_features
  @class_features
end

#combatObject

Returns the value of attribute combat.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def combat
  @combat
end

#demographicsObject

Returns the value of attribute demographics.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def demographics
  @demographics
end

#effectsObject

Returns the value of attribute effects.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def effects
  @effects
end

#featsObject

Returns the value of attribute feats.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def feats
  @feats
end

#inventoryObject

Returns the value of attribute inventory.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def inventory
  @inventory
end

#latest_levelsObject

Returns the value of attribute latest_levels.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def latest_levels
  @latest_levels
end

#levelsObject

Returns the value of attribute levels.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def levels
  @levels
end

#raceObject

Returns the value of attribute race.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def race
  @race
end

#racial_bonusesObject

Returns the value of attribute racial_bonuses.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def racial_bonuses
  @racial_bonuses
end

#savesObject

Returns the value of attribute saves.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def saves
  @saves
end

#skillsObject

Returns the value of attribute skills.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def skills
  @skills
end

#spellbooksObject

Returns the value of attribute spellbooks.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def spellbooks
  @spellbooks
end

#spellsObject

Returns the value of attribute spells.



8
9
10
# File 'lib/pfrpg_core/character.rb', line 8

def spells
  @spells
end

Instance Method Details

#apply_bonusesObject



49
50
51
# File 'lib/pfrpg_core/character.rb', line 49

def apply_bonuses
  apply_effects(PfrpgCore::EffectTotaler.new(self).effects)
end

#apply_effects(effects) ⇒ Object



53
54
55
56
57
58
# File 'lib/pfrpg_core/character.rb', line 53

def apply_effects(effects)
  e = PfrpgCore::EffectProcessor.new(self, effects)
  e.process_effects.each do |effect|
    effect.apply(self)
  end
end

#as_json(options = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pfrpg_core/character.rb', line 64

def as_json(options={})
  p = {
      :id           => @character_id,
      :uuid         => @character_uuid,
      :character    => @character,
      :demographics => @demographics,
      :attributes   => @attributes,
      :combat       => @combat,
      :saves        => @saves,
      :misc         => misc_json,
      :skills       => @skills,
      :spells       => @spells,
      :inventory    => @inventory
  }
  p[:avatar] = AvatarURL.new(@avatar) if @avatar
  p
end

#nameObject



60
61
62
# File 'lib/pfrpg_core/character.rb', line 60

def name
  @demographics.character_name
end

#prime_bonuses_with_racial_statsObject



44
45
46
47
# File 'lib/pfrpg_core/character.rb', line 44

def prime_bonuses_with_racial_stats
  @bonuses = PfrpgCore::Bonuses.new
  apply_effects(@racial_bonuses.map { |x| x.get_effects }.flatten)
end