diff options
-rw-r--r-- | app/models/character.rb | 14 | ||||
-rw-r--r-- | data/activities.yml | 8 |
2 files changed, 16 insertions, 6 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) diff --git a/data/activities.yml b/data/activities.yml index 2395f82..e71485d 100644 --- a/data/activities.yml +++ b/data/activities.yml @@ -41,7 +41,9 @@ craft_pig_iron_ingot: base: 70 minimum: 35 scaling: - otherforge: 2 + - type: "skill" + gid: "otherforge" + scale_value: 2 cost: - type: "item" gid: "crude_iron_ore" @@ -58,7 +60,9 @@ quarry_floret_mines: base: 70 minimum: 35 scaling: - planequarry: 2 + - type: "skill" + gid: "planequarry" + scale_value: 2 results: - type: "item" chance: 1 |