diff options
author | David Gay <david@davidgay.org> | 2021-05-20 17:40:20 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-20 17:40:20 -0400 |
commit | fea8b6bb7aef2d69c0641b19abc0f05eb89e789e (patch) | |
tree | f257ea2954b4711e6b4ccf517bdd3c8fff62bf95 /app/models | |
parent | 9415011b5fd192f1bafeaa9b6eacbb7921382a00 (diff) |
Refactor activity scaling data format
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index 9a3569f..507548e 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -44,16 +44,22 @@ class Character < ApplicationRecord CharacterSkill.find_by(skill: skill).increment!(:xp, amount) end - def skill_level(gid) - self.character_skills.find_by(skill: Skill.find_by_gid(gid.to_s)).level + def skill_level(skill) + skill = Skill.find_by_gid(skill) if skill.is_a? String + self.character_skills.find_by(skill: skill).level end def activity_time_remaining return nil unless self.activity duration_data = self.activity.whatnot[:duration] duration = duration_data[:base] - duration_data[:scaling]&.each do |skill, scaling_amount| - duration -= self.skill_level(skill) * scaling_amount + duration_data[:scaling]&.each do |scaling_entry| + case scaling_entry[:type] + when "skill" + duration -= self.skill_level(scaling_entry[:gid]) * scaling_entry[:scale_value] + else + raise "Invalid scaling type." # TODO: Improve this + end end duration = [duration, duration_data[:minimum] || 10].max duration - (Time.now - self.activity_started_at) |