protected virtual void ConfirmTrade_OnButtonClick(DaggerfallMessageBox sender, DaggerfallMessageBox.MessageBoxButtons messageBoxButton)
        {
            bool receivedLetterOfCredit = false;

            if (messageBoxButton == DaggerfallMessageBox.MessageBoxButtons.Yes)
            {
                // Proceed with trade.
                int tradePrice = GetTradePrice();
                switch (WindowMode)
                {
                case WindowModes.Sell:
                case WindowModes.SellMagic:
                    float goldWeight = tradePrice * DaggerfallBankManager.goldUnitWeightInKg;
                    if (PlayerEntity.CarriedWeight + goldWeight <= PlayerEntity.MaxEncumbrance)
                    {
                        PlayerEntity.GoldPieces += tradePrice;
                    }
                    else
                    {
                        DaggerfallUnityItem loc = ItemBuilder.CreateItem(ItemGroups.MiscItems, (int)MiscItems.Letter_of_credit);
                        loc.value = tradePrice;
                        GameManager.Instance.PlayerEntity.Items.AddItem(loc, Items.ItemCollection.AddPosition.Front);
                        receivedLetterOfCredit = true;
                    }
                    RaiseOnTradeHandler(remoteItems.GetNumItems(), tradePrice);
                    remoteItems.Clear();
                    break;

                case WindowModes.Buy:
                    PlayerEntity.DeductGoldAmount(tradePrice);
                    RaiseOnTradeHandler(basketItems.GetNumItems(), tradePrice);
                    PlayerEntity.Items.TransferAll(basketItems);
                    break;

                case WindowModes.Repair:
                    PlayerEntity.DeductGoldAmount(tradePrice);
                    if (DaggerfallUnity.Settings.InstantRepairs)
                    {
                        foreach (DaggerfallUnityItem item in remoteItemsFiltered)
                        {
                            item.currentCondition = item.maxCondition;
                        }
                    }
                    else
                    {
                        UpdateRepairTimes(true);
                    }
                    RaiseOnTradeHandler(remoteItems.GetNumItems(), tradePrice);
                    break;

                case WindowModes.Identify:
                    PlayerEntity.DeductGoldAmount(tradePrice);
                    for (int i = 0; i < remoteItems.Count; i++)
                    {
                        DaggerfallUnityItem item = remoteItems.GetItem(i);
                        item.IdentifyItem();
                    }
                    RaiseOnTradeHandler(remoteItems.GetNumItems(), tradePrice);
                    break;
                }
                if (receivedLetterOfCredit)
                {
                    DaggerfallUI.Instance.PlayOneShot(SoundClips.ParchmentScratching);
                }
                else
                {
                    DaggerfallUI.Instance.PlayOneShot(SoundClips.GoldPieces);
                }
                PlayerEntity.TallySkill(DFCareer.Skills.Mercantile, 1);
                Refresh();
            }
            CloseWindow();
            if (receivedLetterOfCredit)
            {
                DaggerfallUI.MessageBox(TextManager.Instance.GetText(textDatabase, "letterOfCredit"));
            }
        }
Esempio n. 2
0
        private void ConfirmTrade_OnButtonClick(DaggerfallMessageBox sender, DaggerfallMessageBox.MessageBoxButtons messageBoxButton)
        {
            if (messageBoxButton == DaggerfallMessageBox.MessageBoxButtons.Yes)
            {
                // Proceed with trade.
                int tradePrice = GetTradePrice();
                switch (windowMode)
                {
                case WindowModes.Sell:
                case WindowModes.SellMagic:
                    float goldWeight = tradePrice * DaggerfallBankManager.goldUnitWeightInKg;
                    if (PlayerEntity.CarriedWeight + goldWeight <= PlayerEntity.MaxEncumbrance)
                    {
                        PlayerEntity.GoldPieces += tradePrice;
                    }
                    else
                    {
                        DaggerfallUnityItem loc = ItemBuilder.CreateItem(ItemGroups.MiscItems, (int)MiscItems.Letter_of_credit);
                        loc.value = tradePrice;
                        GameManager.Instance.PlayerEntity.Items.AddItem(loc, Items.ItemCollection.AddPosition.Front);
                    }
                    RaiseOnTradeHandler(remoteItems.GetNumItems(), tradePrice);
                    remoteItems.Clear();
                    break;

                case WindowModes.Buy:
                    PlayerEntity.DeductGoldAmount(tradePrice);
                    RaiseOnTradeHandler(basketItems.GetNumItems(), tradePrice);
                    PlayerEntity.Items.TransferAll(basketItems);
                    break;

                case WindowModes.Repair:
                    PlayerEntity.DeductGoldAmount(tradePrice);
                    if (DaggerfallUnity.Settings.InstantRepairs)
                    {
                        foreach (DaggerfallUnityItem item in remoteItemsFiltered)
                        {
                            item.currentCondition = item.maxCondition;
                        }
                    }
                    else
                    {
                        int totalRepairTime = 0, longestRepairTime = 0;
                        DaggerfallUnityItem itemLongestTime = null;
                        foreach (DaggerfallUnityItem item in remoteItemsFiltered)
                        {
                            int repairTime = FormulaHelper.CalculateItemRepairTime(item.currentCondition, item.maxCondition);
                            if (!item.RepairData.IsBeingRepaired())
                            {
                                item.RepairData.LeaveForRepair(repairTime);
                                string note = string.Format(TextManager.Instance.GetText(textDatabase, "repairNote"), item.LongName, buildingDiscoveryData.displayName);
                                GameManager.Instance.PlayerEntity.Notebook.AddNote(note);
                            }
                            totalRepairTime += repairTime;
                            if (repairTime > longestRepairTime)
                            {
                                longestRepairTime = repairTime;
                                itemLongestTime   = item;
                            }
                            item.RepairData.RepairTime = repairTime;
                        }
                        if (itemLongestTime != null)
                        {
                            itemLongestTime.RepairData.RepairTime = longestRepairTime + ((totalRepairTime - longestRepairTime) / 2);
                        }
                    }
                    RaiseOnTradeHandler(remoteItems.GetNumItems(), tradePrice);
                    break;

                case WindowModes.Identify:
                    PlayerEntity.DeductGoldAmount(GetTradePrice());
                    for (int i = 0; i < remoteItems.Count; i++)
                    {
                        DaggerfallUnityItem item = remoteItems.GetItem(i);
                        item.IdentifyItem();
                    }
                    RaiseOnTradeHandler(remoteItems.GetNumItems(), tradePrice);
                    break;
                }
                DaggerfallUI.Instance.PlayOneShot(SoundClips.GoldPieces);
                PlayerEntity.TallySkill(DFCareer.Skills.Mercantile, 1);
                Refresh();
            }
            CloseWindow();
        }