コード例 #1
0
        internal static async Task <string> Accept(Player player, string data)
        {
            NPC npc = player.Encounter.npc;
            PendingTransaction transaction;

            if (data.EndsWith(";"))//Selling
            {
                string[] selection = data.TrimEnd(';').Split(';');
                transaction = new PendingTransaction(player, selection, Transaction.Sell, true);

                int count = transaction.Count;
                for (int i = 0; i < count; i++)
                {
                    StackedItems si = transaction.Get(i, true);

                    long price = ShopCommands.GetPrice(si.item.GetValue(),
                                                       npc.stats.PriceMod(), player.stats.PriceMod(),
                                                       (int)transaction.transation) * si.count;

                    transaction.TotalPrice += price;

                    npc.inventory.Add(si, -1);
                }

                player.KCoins += transaction.TotalPrice;
                npc.KCoins    -= transaction.TotalPrice;
            }
            else //Buying
            {
                transaction = Database.LoadRecord(null,
                                                  MongoDatabase.FilterEqual <PendingTransaction, Guid>("_id", Guid.Parse(data)));

                if (transaction == null)
                {
                    return("Transaction no longer available");
                }

                player.KCoins -= transaction.TotalPrice;
                npc.KCoins    += transaction.TotalPrice;

                int invSize = player.InventorySize();
                foreach (var si in transaction.items)
                {
                    if (!player.inventory.Add(si, invSize))
                    {
                        transaction.Delete();
                        throw NeitsilliaError.ReplyError("Inventory can not contain all items in this order. Transaction canceled.");
                    }
                }
            }

            await player.ui.TryDeleteMessage();

            player.ui = null;
            player.SaveFileMongo();

            return($"```{Dialog.GetDialog(npc, Dialog.tradingBusiness)}```");
        }
コード例 #2
0
        internal static string Cancel(Player player, string data)
        {
            if (data == null)
            {
                return(null);
            }

            if (data != null && data.EndsWith(";"))
            {
                _         = player.ui?.TryDeleteMessage();
                player.ui = null;
                return(player.Encounter?.npc != null ?
                       $"```{Dialog.GetDialog(player.Encounter.npc, Dialog.offerCancelled)}```" :
                       "Transaction canceled");
            }

            if (!Guid.TryParse(data, out Guid id))
            {
                return(null);
            }

            PendingTransaction transaction = Database.LoadRecord(null,
                                                                 MongoDatabase.FilterEqual <PendingTransaction, Guid>("_id", id));

            if (transaction == null)
            {
                _         = player.ui?.TryDeleteMessage();
                player.ui = null;
                return("Transaction not found");
            }

            foreach (var si in transaction.items)
            {
                player.Encounter.npc.inventory.Add(si, -1);
            }

            player.Encounter.Save();

            transaction?.Delete();
            _ = player.ui?.TryDeleteMessage();

            return(player.Encounter?.npc != null ?
                   $"```{Dialog.GetDialog(player.Encounter.npc, Dialog.offerCancelled)}```" :
                   "Transaction canceled");
        }