diff options
author | David Gay <david@davidgay.org> | 2021-06-13 21:29:52 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-06-13 21:29:52 -0400 |
commit | e78a3513632954cb53fc8c806158c1fc98357173 (patch) | |
tree | a8d7ac13bb4db9ef244bec57416fc08ef4345d6d /app/models | |
parent | 18c2378d06d5f9323e50eead92b3cf7dc61917b5 (diff) |
ItemInfixes
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 6 | ||||
-rw-r--r-- | app/models/item_infix.rb | 13 |
2 files changed, 19 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index d386002..03bd510 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -9,6 +9,7 @@ class Character < ApplicationRecord has_many :character_items has_many :learned_activities has_many :items, through: :character_items + has_many :item_infixes has_many :character_skills has_many :conditions, through: :states has_many :states @@ -182,6 +183,11 @@ class Character < ApplicationRecord end end + def max_infixes(skill) + skill = Skill.find_by_gid(skill) if skill.is_a? String + 1 + (skill_level(skill) / 20).floor + end + def add_skill_xp(skill, amount) skill = Skill.find_by_gid(skill) if skill.is_a? String Character.transaction do diff --git a/app/models/item_infix.rb b/app/models/item_infix.rb new file mode 100644 index 0000000..cc99ee7 --- /dev/null +++ b/app/models/item_infix.rb @@ -0,0 +1,13 @@ +class ItemInfix < ApplicationRecord + belongs_to :character + belongs_to :item + belongs_to :skill + + before_create :check_max_infixes + + private + def check_max_infixes + current_infixes = character.item_infixes.where(skill: skill) + raise :abort if current_infixes.count >= character.max_infixes(skill) + end +end |