diff options
author | David Gay <david@davidgay.org> | 2021-05-28 10:21:12 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-28 10:21:12 -0400 |
commit | 04a81a4517c33d86cdebed9116bbd0a7656bd68d (patch) | |
tree | 3b817d0a4af5fc948c5d336dd7d9ecf825a7d889 /app/models | |
parent | 87d006ed6b34d00274c72dba055ba4fbc2980212 (diff) |
Refactor HA effects and equipment equip effects to use the same format, then include them both in Character#effects
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 10 | ||||
-rw-r--r-- | app/models/equipment.rb | 4 |
2 files changed, 10 insertions, 4 deletions
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 |