コード例 #1
0
        private static double GetSellValueOfItems(Configuration.SellLocation sellLocation, Eleon.Modding.ItemExchangeInfo itemExchangeInfoInQuote)
        {
            double credits = 0;

            foreach (var stack in itemExchangeInfoInQuote.items)
            {
                double unitPrice;
                if (!sellLocation.ItemIdToUnitPrice.TryGetValue(stack.id, out unitPrice))
                {
                    unitPrice = sellLocation.DefaultPrice;
                }

                credits += unitPrice * stack.count;
            }

            return(System.Math.Round(credits, 2));
        }
コード例 #2
0
        private async void DoSellTransaction(Player player, Configuration.SellLocation sellLocation)
        {
            // await continues the operation later when the server returns the response.
            var itemExchangeInfoInQuote = await player.DoItemExchange(
                title : "Sell Items - Step 1",
                description : "Place Items to get a price",
                buttonText : "Process"); // BUG: button text can only be set once, otherwise I would put "Get Price"

            // If the player ever removes all items from the item exchange window, stop the transaction.
            while (itemExchangeInfoInQuote.items != null)
            {
                // calculate the worth of the items the player put in the item exchange window
                double credits = GetSellValueOfItems(sellLocation, itemExchangeInfoInQuote);

                // Show the price with the same items he put in, in case he wants to adjust his order.
                var itemExchangeInfoSold = await player.DoItemExchange(
                    "Sell Items - Step 2",
                    $"We will pay you {credits} credits.",
                    "Process", // BUG: button text can only be set once "Sell Items",
                    itemExchangeInfoInQuote.items);

                if ((itemExchangeInfoSold.items != null) && (itemExchangeInfoSold.items.AreTheSame(itemExchangeInfoInQuote.items)))
                {
                    // the player didn't change his items, complete the purchase
                    _gameServerConnection.DebugOutput("Player {0} sold items for {1} credits.", player, credits);
                    await player.AddCredits(credits);

                    await player.SendAlertMessage("Items sold for {0} credits.", credits);

                    break;
                }
                else
                {
                    // if the items changed, continue the while loop with the new items returned.
                    _gameServerConnection.DebugOutput("Player {0} changed things.", player);
                    itemExchangeInfoInQuote = itemExchangeInfoSold;
                }
            }
        }