Beispiel #1
0
        public void HandleRequest(IRequest request)
        {
            var character = request.Session.Character;
            var orderId   = request.Data.GetOrDefault <int>(k.ID);
            var newPrice  = request.Data.GetOrDefault <double>(k.price);
            var testMode  = request.Session.AccessLevel.IsAdminOrGm();


            using (var scope = Db.CreateTransaction())
            {
                newPrice.ThrowIfLessOrEqual(0, ErrorCodes.IllegalMarketPrice);

                var order = _marketOrderRepository.Get(orderId).ThrowIfNull(ErrorCodes.ItemNotFound);
                order.submitterEID.ThrowIfNotEqual(character.Eid, ErrorCodes.AccessDenied);

                if (!request.Session.AccessLevel.IsAdminOrGm())
                {
                    if (!order.IsModifyTimeValid())
                    {
                        Message.Builder.FromRequest(request).WithData(order.GetValidModifyInfo()).WrapToResult().Send();
                        return;
                    }
                }


                var newTotalPrice = newPrice * order.quantity;
                var oldPrice      = order.FullPrice;

                order.price = newPrice; // set the new price

                if (!order.isSell)
                {
                    //BUY order
                    var priceDifference = newTotalPrice - oldPrice;

                    if (Math.Abs(priceDifference) < double.Epsilon)
                    {
                        //nothing to do
                        return;
                    }

                    // take the deposit from the character or corp
                    _marketHelper.CashIn(character, order.useCorporationWallet, priceDifference, order.itemDefinition, 1, TransactionType.ModifyMarketOrder);

                    //store the deposit in the central bank
                    var dockingBase = order.GetMarket().GetDockingBase();
                    dockingBase.AddCentralBank(TransactionType.ModifyMarketOrder, priceDifference);
                }

                //update the price in sql
                _marketOrderRepository.UpdatePrice(order);

                var result = _marketHelper.GetMarketOrdersInfo(character);
                Message.Builder.FromRequest(request).WithData(result).WrapToResult().Send();

                scope.Complete();
            }

            Task.Run(() => { BackgroundProcess(testMode); });
        }