diff options
author | David Gay <david@davidgay.org> | 2021-06-16 18:16:57 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-06-16 18:17:04 -0400 |
commit | b5234514e2c8d8a1e798726991892bf80eec90ae (patch) | |
tree | 3024f35983df5d2aaf371045dc3ccb6d19a18b04 /app/models | |
parent | 0f6b68f115d2d16c7ef73d80570b1b85a1368a43 (diff) |
Activity equipment item tag requirements, and apply to / adjust all relevant activities
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 10 | ||||
-rw-r--r-- | app/models/concerns/has_costs_and_requirements.rb | 6 |
2 files changed, 14 insertions, 2 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index 9db3f8c..a26fb93 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -162,6 +162,10 @@ class Character < ApplicationRecord self.equipment.find_by(item: item) end + def equipment_with_tag(tag) + self.equipment.all.find { |e| e.item.has_tag?(tag) } + end + def open_slots_for(item) full_slots = self.equipment.map { |e| e.slot } item.equip_slots.reject { |slot| full_slots.include?(slot) } @@ -297,7 +301,11 @@ class Character < ApplicationRecord activity.whatnot[:requirements]&.each do |requirement| case requirement[:type] when "equipment" - return false unless self.equipment_with_gid(requirement[:gid]) + if requirement[:tag] + return false unless self.equipment_with_tag(requirement[:tag]) + else + return false unless self.equipment_with_gid(requirement[:gid]) + end when "stat" # TODO: HACK: This won't work with built-in stats! Need to change this to work with power and whatnot. return false unless self.total_stat_change(requirement[:gid]) >= requirement[:value] diff --git a/app/models/concerns/has_costs_and_requirements.rb b/app/models/concerns/has_costs_and_requirements.rb index 9f859f5..9c4abf8 100644 --- a/app/models/concerns/has_costs_and_requirements.rb +++ b/app/models/concerns/has_costs_and_requirements.rb @@ -22,7 +22,11 @@ module HasCostsAndRequirements when "stat" requirements.push "#{req[:value]} #{req[:gid]}" when "equipment" - requirements.push "equipped #{Item.find_by_gid(req[:gid]).name}" + if req[:tag] + requirements.push "equipped #{req[:tag]}" + else + requirements.push "equipped #{Item.find_by_gid(req[:gid]).name}" + end when "hearth_amenity" requirements.push "level #{req[:level]} #{HearthAmenity.find_by_gid(req[:gid]).name}" else |