diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index 1e75b63..aa434ef 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -19,6 +19,21 @@ class Character < ApplicationRecord end end + def skill_level(gid) + self.character_skills.find_by(skill: Skill.find_by_gid(gid.to_s)).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 + end + duration = [duration, duration_data["minimum"]].max + duration - (Time.now - self.activity_started_at) + end + private def create_skills Skill.all.each { |skill| self.character_skills.create(skill: skill, xp: 0) } |