class Monster < ApplicationRecord include HasWhatnot def max_hp self.whatnot[:max_hp][:base] end def speed self.whatnot[:speed][:base] end def accuracy(with_combat_style: false) self.whatnot[:accuracy][:base] end def power(with_combat_style: false) self.whatnot[:power][:base] end def evasion(with_combat_style: false) self.whatnot[:evasion][:base] end def damage_ranges self.whatnot[:hit_effects].filter_map { |e| { gid: e[:gid], min: e[:min], max: e[:max] } if e[:type] == "damage" && conditions_met?(e) } end def resistance(damage_type) unless %w[slash pierce bash arcane fire frost lightning acid thunder radiant necrotic poison bleed physical energy].include?(damage_type) raise "Invalid damage type" end res = 0 whatnot[:resistances]&.each do |data| if data[:gid] == damage_type res += data[:base] end end if %w[slash pierce bash].include?(damage_type) res += resistance("physical") elsif %w[arcane fire frost lightning acid thunder radiant necrotic].include?(damage_type) res += resistance("energy") end res end end