summaryrefslogtreecommitdiff
path: root/app/models/character.rb
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-28 11:26:44 -0400
committerDavid Gay <david@davidgay.org>2021-05-28 11:26:54 -0400
commit5ae89950fb330fd623634b98a77de259ab174b53 (patch)
tree3ec11fae10758379761f5b824586b1c22bc57c12 /app/models/character.rb
parentc522bc8efa0378e0fcbcfdd137d6cd2ae4010d5b (diff)
Lockbox unlocking, and with it items that start activities when used
Diffstat (limited to 'app/models/character.rb')
-rw-r--r--app/models/character.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/models/character.rb b/app/models/character.rb
index 42f5f10..fda6868 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -60,7 +60,7 @@ class Character < ApplicationRecord
activity.whatnot[:cost]&.each do |cost|
case cost[:type]
when "item"
- self.shift_item(cost[:gid], -cost[:quantity])
+ self.shift_item(cost[:gid], -(cost[:quantity] || 1))
end
end
end
@@ -72,6 +72,11 @@ class Character < ApplicationRecord
ci && ci.quantity >= quantity
end
+ def equipment_with_gid(item)
+ item = Item.find_by_gid(item) if item.is_a? String
+ self.equipment.find_by(item: item)
+ end
+
def open_slots_for(item)
full_slots = self.equipment.map { |e| e.slot }
item.equip_slots.reject { |slot| full_slots.include?(slot) }
@@ -134,17 +139,23 @@ class Character < ApplicationRecord
activity.whatnot[:cost]&.each do |cost|
case cost[:type]
when "item"
- return false unless self.has_item?(cost[:gid], cost[:quantity])
+ return false unless self.has_item?(cost[:gid], cost[:quantity] || 1)
+ else
+ raise "Invalid cost type string (#{cost[:type]})"
end
end
end
unless ignore_requirements
activity.whatnot[:requirements]&.each do |requirement|
case requirement[:type]
+ when "equipment"
+ return false unless self.equipment_with_gid(requirement[:gid])
when "skill"
return false unless self.skill_level(requirement[:gid]) >= requirement[:level]
when "hearth_amenity"
return false unless self.hearth.has_amenity?(requirement[:gid], requirement[:level])
+ else
+ raise "Invalid requirement type string (#{requirement[:type]})"
end
end
end