summaryrefslogtreecommitdiff
path: root/app/models/character.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/character.rb')
-rw-r--r--app/models/character.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/app/models/character.rb b/app/models/character.rb
index 1d24f93..55ea7ba 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -24,15 +24,17 @@ class Character < ApplicationRecord
def pay_cost_for(activity)
CharacterItem.transaction do
- if activity.whatnot[:cost]
- activity.whatnot[:cost][:items]&.each do |item_gid, quantity|
- self.shift_item(item_gid, -quantity)
+ activity.whatnot[:cost]&.each do |cost|
+ case cost[:type]
+ when "item"
+ self.shift_item(cost[:gid], -cost[:quantity])
end
end
end
end
def has_item?(item, quantity = 1)
+ item = Item.find_by_gid(item) if item.is_a? String
ci = self.character_items.find_by(item: item)
ci && ci.quantity >= quantity
end
@@ -57,9 +59,10 @@ class Character < ApplicationRecord
end
def can_do_activity?(activity)
- if activity.whatnot[:cost]
- activity.whatnot[:cost][:items]&.each do |item_gid, quantity|
- return false unless self.has_item?(item_gid, quantity)
+ activity.whatnot[:cost]&.each do |cost|
+ case cost[:type]
+ when "item"
+ return false unless self.has_item?(cost[:gid], cost[:quantity])
end
end
activity.whatnot[:requirements]&.each do |requirement|
@@ -68,6 +71,7 @@ class Character < ApplicationRecord
return false unless self.hearth.has_amenity?(requirement[:gid], requirement[:level])
end
end
+ true
end
def start_activity(activity)