summaryrefslogtreecommitdiff
path: root/app/models/character.rb
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-03 20:08:28 -0400
committerDavid Gay <david@davidgay.org>2021-05-03 20:08:28 -0400
commitdddbf75428477f5e073584939d098e55d6324be3 (patch)
treec35291b32f1ba19bda66839d778b9758549a140f /app/models/character.rb
parentaa25545eb204d0ca842ab948af4c27cb217352d6 (diff)
Add CharacterSkills
Diffstat (limited to 'app/models/character.rb')
-rw-r--r--app/models/character.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb
index ebda598..1e75b63 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -3,11 +3,14 @@ class Character < ApplicationRecord
belongs_to :activity, optional: true
has_many :character_items
has_many :items, through: :character_items
+ has_many :character_skills
validates :name, presence: true
validates_length_of :name, maximum: 15, message: "can't be longer than 15 characters"
validates_uniqueness_of :name, message: "is already being used"
validates_format_of :name, with: /\A[a-z]+\z/i, message: "must consist of letters only"
+ after_create :create_skills
+
def shift_item(gid, amount)
CharacterItem.transaction do
item = self.character_items.find_or_initialize_by(item: Item.find_by_gid(gid))
@@ -15,4 +18,9 @@ class Character < ApplicationRecord
item.save
end
end
+
+ private
+ def create_skills
+ Skill.all.each { |skill| self.character_skills.create(skill: skill, xp: 0) }
+ end
end