summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-20 18:39:20 -0400
committerDavid Gay <david@davidgay.org>2021-05-20 18:39:20 -0400
commitb0998224427594acda8e4e8419a945c20c062568 (patch)
tree8da46effc1122281f4349f4800a12fd5076352d5 /app
parentc25a079be25cc0aadf85119d97d8e1b9395b15fb (diff)
Implement learned activities
Diffstat (limited to 'app')
-rw-r--r--app/models/activity.rb2
-rw-r--r--app/models/character.rb2
-rw-r--r--app/models/learned_activity.rb6
3 files changed, 10 insertions, 0 deletions
diff --git a/app/models/activity.rb b/app/models/activity.rb
index b8eeed7..7272a3b 100644
--- a/app/models/activity.rb
+++ b/app/models/activity.rb
@@ -4,6 +4,8 @@ class Activity < ApplicationRecord
belongs_to :location, optional: true
validates :gid, :name, :description, presence: true
+ attribute :innate, :boolean, default: false
+
def cost_string
requirements = []
self.whatnot[:cost].each do |cost|
diff --git a/app/models/character.rb b/app/models/character.rb
index 507548e..41dc951 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -3,6 +3,7 @@ class Character < ApplicationRecord
belongs_to :activity, optional: true
has_one :hearth
has_many :character_items
+ has_many :learned_activities
has_many :items, through: :character_items
has_many :character_skills
has_many :chat_messages
@@ -66,6 +67,7 @@ class Character < ApplicationRecord
end
def can_do_activity?(activity)
+ return false unless activity.innate? || self.learned_activities.exists?(activity: activity)
activity.whatnot[:cost]&.each do |cost|
case cost[:type]
when "item"
diff --git a/app/models/learned_activity.rb b/app/models/learned_activity.rb
new file mode 100644
index 0000000..58a6e93
--- /dev/null
+++ b/app/models/learned_activity.rb
@@ -0,0 +1,6 @@
+class LearnedActivity < ApplicationRecord
+ belongs_to :character
+ belongs_to :activity
+
+ validates :character_id, uniqueness: { scope: :activity_id }
+end