From b5234514e2c8d8a1e798726991892bf80eec90ae Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 16 Jun 2021 18:16:57 -0400 Subject: Activity equipment item tag requirements, and apply to / adjust all relevant activities --- app/models/character.rb | 10 +++++++++- app/models/concerns/has_costs_and_requirements.rb | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'app') 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 -- cgit v1.2.3