From e63703a412ff146b028e68baa100837b58f0c200 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 7 Jul 2021 18:54:35 -0400 Subject: Consolidate identical bazaar postings --- CHANGELOG.md | 4 ++++ app/controllers/bazaar_controller.rb | 18 ++++++++++++++---- 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 -- cgit v1.2.3