summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--app/controllers/bazaar_controller.rb18
2 files changed, 18 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43995da..366035d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,10 @@ All notable changes to this project will be documented in this file.
- Pit leech, stalk beast, and grinpad damage reduced.
- XP awards reduced (except balgoloth).
+### Bazaar
+- When posting an order for an item and price which you already have an order for, the orders are combined instead
+ of creating a new order with the same item and price.
+
### Chat
- Chat area now shows most recent 200 messages, instead of 100.
- New "History" link shows a chat history of the last 2,000 messages.
diff --git a/app/controllers/bazaar_controller.rb b/app/controllers/bazaar_controller.rb
index d51a419..4ba858a 100644
--- a/app/controllers/bazaar_controller.rb
+++ b/app/controllers/bazaar_controller.rb
@@ -11,15 +11,25 @@ class BazaarController < ApplicationController
if params[:buy_order] == "1"
BazaarOrder.transaction do
current_char.shift_item("vestige", (-price_each * quantity))
- current_char.bazaar_orders.create!(item: item, quantity: quantity,
- price_each: price_each, buy_order: true)
+ order = current_char.bazaar_orders.find_or_initialize_by(item: item, price_each: price_each, buy_order: true)
+ if order.new_record?
+ order.quantity = quantity
+ else
+ order.quantity += quantity
+ end
+ order.save!
flash[:notice] = "Posted buy order for #{item.name} at #{price_each} vg each."
end
else
BazaarOrder.transaction do
current_char.shift_item(item, -quantity)
- current_char.bazaar_orders.create!(item: item, quantity: quantity,
- price_each: price_each, buy_order: false)
+ order = current_char.bazaar_orders.find_or_initialize_by(item: item, price_each: price_each, buy_order: false)
+ if order.new_record?
+ order.quantity = quantity
+ else
+ order.quantity += quantity
+ end
+ order.save!
flash[:notice] = "Posted sell order for #{item.name} at #{price_each} vg each."
end
end