From 73744a9c6840fb0ba6f285ca81f9fba75ec22d5f Mon Sep 17 00:00:00 2001 From: David Gay Date: Tue, 4 May 2021 17:55:28 -0400 Subject: Initial draft of timer setup, with results outputting and items being awarded --- app/models/character.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app/models/character.rb') 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) } -- cgit v1.2.3