summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/activity.rb2
-rw-r--r--app/models/character.rb8
-rw-r--r--app/models/concerns/has_whatnot.rb9
-rw-r--r--app/models/item.rb2
-rw-r--r--app/models/location.rb2
-rw-r--r--app/models/skill.rb2
6 files changed, 21 insertions, 4 deletions
diff --git a/app/models/activity.rb b/app/models/activity.rb
index be5b573..fb99e1d 100644
--- a/app/models/activity.rb
+++ b/app/models/activity.rb
@@ -1,4 +1,6 @@
class Activity < ApplicationRecord
+ include HasWhatnot
+
belongs_to :location
validates :gid, :name, :description, presence: true
end
diff --git a/app/models/character.rb b/app/models/character.rb
index df4938d..7df48e8 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -29,12 +29,12 @@ class Character < ApplicationRecord
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_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 = [duration, duration_data[:minimum]].max
duration - (Time.now - self.activity_started_at)
end
diff --git a/app/models/concerns/has_whatnot.rb b/app/models/concerns/has_whatnot.rb
new file mode 100644
index 0000000..a4dcfa0
--- /dev/null
+++ b/app/models/concerns/has_whatnot.rb
@@ -0,0 +1,9 @@
+module HasWhatnot
+ extend ActiveSupport::Concern
+
+ included do
+ def whatnot
+ @whatnot ||= super.is_a?(Hash) ? super.deep_symbolize_keys! : nil
+ end
+ end
+end
diff --git a/app/models/item.rb b/app/models/item.rb
index 71482f5..d42460b 100644
--- a/app/models/item.rb
+++ b/app/models/item.rb
@@ -1,4 +1,6 @@
class Item < ApplicationRecord
+ include HasWhatnot
+
enum equip_slot: [:mainhand, :offhand, :head, :neck, :back, :torso, :grip,
:left_ring, :right_ring, :waist, :legs, :feet, :curio]
validates :gid, :name, :description, presence: true
diff --git a/app/models/location.rb b/app/models/location.rb
index e35e5e7..b7c5bf5 100644
--- a/app/models/location.rb
+++ b/app/models/location.rb
@@ -1,4 +1,6 @@
class Location < ApplicationRecord
+ include HasWhatnot
+
has_many :activities
validates :gid, :name, presence: true
end
diff --git a/app/models/skill.rb b/app/models/skill.rb
index b77165b..f97bb39 100644
--- a/app/models/skill.rb
+++ b/app/models/skill.rb
@@ -1,3 +1,5 @@
class Skill < ApplicationRecord
+ include HasWhatnot
+
validates :gid, :name, :description, presence: true
end