diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 13 | ||||
-rw-r--r-- | app/models/item.rb | 13 |
2 files changed, 26 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index 7e80d65..56be0c0 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -133,8 +133,21 @@ class Character < ApplicationRecord end end + def can_equip?(item) + item.whatnot[:equip_requirements]&.each do |requirement| + case requirement[:type] + when "skill" + return false unless self.skill_level(requirement[:gid]) >= requirement[:level] + else + raise "Invalid requirement type string (#{requirement[:type]})" + end + end + true + end + def equip(item) Character.transaction do + raise EquipmentError unless self.can_equip?(item) open_slots = self.open_slots_for(item) raise EquipmentError unless open_slots.any? self.shift_item(item, -1) diff --git a/app/models/item.rb b/app/models/item.rb index 1ef5d7d..8b80788 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -17,4 +17,17 @@ class Item < ApplicationRecord return [] unless self.equipment? self.whatnot[:equip_slots].map { |data| data.to_sym } end + + def equip_requirements + requirements = [] + self.whatnot[:equip_requirements]&.each do |req| + case req[:type] + when "skill" + requirements.push "level #{req[:level]} #{Skill.find_by_gid(req[:gid]).name}" + else + raise "Invalid equip requirement type string (#{req[:type]})" + end + end + requirements + end end |