summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/activities_controller.rb1
-rw-r--r--app/controllers/game_controller.rb3
-rw-r--r--app/models/activity.rb9
-rw-r--r--app/models/character.rb16
4 files changed, 18 insertions, 11 deletions
diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb
index a32ffab..f72bc3a 100644
--- a/app/controllers/activities_controller.rb
+++ b/app/controllers/activities_controller.rb
@@ -6,6 +6,7 @@ class ActivitiesController < ApplicationController
def start
@activity = Activity.find(params[:id])
if current_char.can_do_activity?(@activity)
+ current_char.start_activity(@activity)
redirect_to action: :show
else
flash[:alert] = "You can't do that. Make sure you have the items and meet the requirements."
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb
index 1b88cb8..d3d3ce2 100644
--- a/app/controllers/game_controller.rb
+++ b/app/controllers/game_controller.rb
@@ -44,7 +44,8 @@ class GameController < ApplicationController
end
end
when "hearth_amenity"
- bhi = BuiltHearthAmenity.find_or_initialize_by(hearth_amenity: HearthAmenity.find_by_gid(result[:gid]))
+ bhi = current_char.hearth.built_hearth_amenities
+ .find_or_initialize_by(hearth_amenity: HearthAmenity.find_by_gid(result[:gid]))
bhi.update(level: result[:level])
@results.push({ type: type, hearth_amenity: bhi.hearth_amenity })
else
diff --git a/app/models/activity.rb b/app/models/activity.rb
index e70121e..b8eeed7 100644
--- a/app/models/activity.rb
+++ b/app/models/activity.rb
@@ -6,10 +6,11 @@ class Activity < ApplicationRecord
def cost_string
requirements = []
- data = self.whatnot[:cost]
- return nil unless data
- data[:items].each do |item_gid, quantity|
- requirements.push "#{quantity} #{Item.find_by_gid(item_gid).name}"
+ self.whatnot[:cost].each do |cost|
+ case cost[:type]
+ when "item"
+ requirements.push "#{cost[:quantity]} #{Item.find_by_gid(cost[:gid]).name}"
+ end
end
requirements.join(", ")
end
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)