From 82eec1f68172857b3b39e6ab3e3b837de16c1198 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sun, 23 May 2021 20:15:03 -0400 Subject: Item usage --- app/models/character.rb | 2 +- app/models/item.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/character.rb b/app/models/character.rb index a6e8ff6..ef8768e 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -145,7 +145,7 @@ class Character < ApplicationRecord def equipment_stats stats = {} self.equipment.each do |eq| - eq.item.whatnot[:effects]&.each do |effect| + eq.item.whatnot[:equip_effects]&.each do |effect| if effect[:type] == "stat" stats[effect[:gid]] ||= 0 stats[effect[:gid]] += effect[:modifier] diff --git a/app/models/item.rb b/app/models/item.rb index 5e60f04..1ef5d7d 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -4,12 +4,15 @@ class Item < ApplicationRecord enum equip_slot: [:mainhand, :offhand, :head, :neck, :back, :torso, :grip, :left_ring, :right_ring, :waist, :legs, :feet, :curio] validates :gid, :name, :description, presence: true - validates :usable, inclusion: { in: [true, false] } def equipment? self.whatnot && self.whatnot[:equip_slots]&.any? end + def usable? + self.whatnot && self.whatnot[:use_effects]&.any? + end + def equip_slots return [] unless self.equipment? self.whatnot[:equip_slots].map { |data| data.to_sym } -- cgit v1.2.3