From 04a81a4517c33d86cdebed9116bbd0a7656bd68d Mon Sep 17 00:00:00 2001 From: David Gay Date: Fri, 28 May 2021 10:21:12 -0400 Subject: Refactor HA effects and equipment equip effects to use the same format, then include them both in Character#effects --- app/models/character.rb | 10 ++++++---- app/models/equipment.rb | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/character.rb b/app/models/character.rb index 1ff0a06..b06220b 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -174,7 +174,7 @@ class Character < ApplicationRecord stats = {} self.equipment.each do |eq| eq.item.whatnot[:equip_effects]&.each do |effect| - if effect[:type] == "stat" + if effect[:type] == "stat_change" stats[effect[:gid]] ||= 0 stats[effect[:gid]] += effect[:modifier] end @@ -185,11 +185,13 @@ class Character < ApplicationRecord def effects # TODO: Review this filter_map to see if it can be simplified - self.hearth.built_hearth_amenities.filter_map { |a| a.effects if a.effects }.flatten + hearth_amenity_effects = self.hearth.built_hearth_amenities.filter_map { |a| a.effects if a.effects } + equipment_effects = self.equipment.filter_map { |a| a.effects if a.effects } + (hearth_amenity_effects + equipment_effects).flatten end - def total_stat_change(stat) - effects.filter_map { |e| e[:modifier] if e[:type] == "stat_change" && e[:stat] == stat }.sum + def total_stat_change(gid) + effects.filter_map { |e| e[:modifier] if e[:type] == "stat_change" && e[:gid] == gid }.sum end def can_fight? diff --git a/app/models/equipment.rb b/app/models/equipment.rb index 11030fd..ce3822c 100644 --- a/app/models/equipment.rb +++ b/app/models/equipment.rb @@ -8,4 +8,8 @@ class Equipment < ApplicationRecord def slot self[:slot].to_sym end + + def effects + self.item.whatnot[:equip_effects] + end end -- cgit v1.2.3