private void BuildMerchantSellTransaction()
        {
            if (AManager<ResourceManager>.getInstance().buyList.Count == 0) {
                trader.setBubble("I have nothing to buy.");
                return;
            }
            Resource resource = ResourceManager.getInstance().buyList.RandomElement<Resource>();
            if (resourcesSold.Contains(resource) || resource.index == 55)
            {
                return;
            }
            if (UnityEngine.Random.value < 0.2f)
            {
                //this.unit.setBubble("I'm afraid I have no use for " + resource.name + " at this time.");
                resourcesBought.Add(resource);
                return;
            }
            if (resourcesBought.Contains(resource))
            {
                return;
            }

            int traderLevel = trader.getProfession().getLevel();
            if (trader.preferences["trait.charismatic"])
            {
                traderLevel = Mathf.Min(traderLevel + 5, 20);
            }
            float traderInfluence = 2f - (float) (traderLevel/40);
            int resourceCount = 1;
            if (resource.name.Contains("Arrows") || resource.name.Contains("Bolts") ||
                (!(resource is Armor) && !(resource is Weapon) && !(resource is Tool)))
            {
                float resourceCountMax =
                    Mathf.Min(0.75f*trader.faction.storage.getStorageAvailable(resource.storageIndex)/resource.mass,
                        (float) playerCoin/(resource.value*traderInfluence));
                resourceCount = (int) (resourceCountMax*UnityEngine.Random.Range(0.5f, 1f));
                if (resourceCount < 0)
                {
                    resourceCount *= -1;
                }
            }
            int resourceValue = Mathf.CeilToInt(resource.value * traderInfluence);

            Transaction transaction = new Transaction(false, resource, resourceCount == 1 ? 1 : resourceCount / 2, resourceCount, resourceValue);

            TradeWindowSellList.Add(transaction);
            resourcesSold.Add(resource);
        }
        private void BuildTransactionView(Transaction transaction, ref float buttonAboveHeight)
        {
            Rect buttonRect = new Rect(LeftRightMargin, buttonAboveHeight += (ButtonHeight + InbetweenMargin), 20, ButtonHeight);
            guiMgr.DrawCheckBox(buttonRect, "", ref transaction.completeTransaction);
            buttonRect.x += 30;
            transaction.amount = BuildTextField(buttonRect, 0, transaction.maxAmount, transaction.amount);
            buttonRect.x += 130;
            buttonRect.width = 100;
            buttonRect.y -= InbetweenMargin;
            GUI.Label(buttonRect, new GUIContent(string.Empty, "trade tooltip/" + transaction.resource.index), guiMgr.boxStyle);
            buttonRect.width = 560;
            GUI.Label(buttonRect, new GUIContent(string.Empty), guiMgr.boxStyle);
            buttonRect.x += 5;
            buttonRect.width = 30;
            GUI.DrawTexture(buttonRect, transaction.resource.icon);

            string temp = transaction.storageNeeded == 0 ? "" : " (" + Mathf.CeilToInt(transaction.storageNeeded) + " Storage needed)";

            buttonRect.x += 37;
            buttonRect.y += InbetweenMargin;
            buttonRect.width = 530;
            guiMgr.DrawTextLeftWhite(buttonRect, transaction.resource.name + " for " +
                transaction.totalValue + " coin. " + transaction.value + " coin per." + temp);
        }
        private void BuildMerchantBuyTransaction()
        {
            if (AManager<ResourceManager>.getInstance().sellList.Count == 0) {
                //trader.setBubble("I have nothing to sell.");
                return;
            }
            Resource resource = AManager<ResourceManager>.getInstance().sellList.RandomElement<Resource>();
            if (trader.faction.storage[resource] == 0 || resource.index == 55) {
                return;
            }
            if (resourcesBought.Contains(resource)) {
                return;
            }
            if (UnityEngine.Random.value < 0.3f) {
                //this.unit.setBubble("I'm afraid I have no use for " + resource.name + " at this time.");
                resourcesBought.Add(resource);
                return;
            }
            int resourceCountMin = Mathf.CeilToInt((float)trader.faction.storage[resource] * 0.5f);
            int resourceCountMax = Mathf.CeilToInt((float)trader.faction.storage[resource] * UnityEngine.Random.Range(0.5f, 0.9f));
            int resourceCount = UnityEngine.Random.Range(resourceCountMin, resourceCountMax + 1);
            int traderLevel = trader.getProfession().getLevel();
            if (trader.preferences["trait.charismatic"]) {
                traderLevel = Mathf.Min(traderLevel + 5, 20);
            }
            float traderInfluence = traderLevel * Mathf.Min(1f, (traderLevel / 20) + 0.2f);
            merchantCoin += Mathf.CeilToInt((resource.value*traderInfluence*resourceCount)/3);
            int resourceValue = Mathf.CeilToInt(resource.value * traderInfluence);

            Transaction transaction = new Transaction(true, resource, resourceCount == 1 ? 1 : resourceCount / 2, resourceCount, resourceValue);

            TradeWindowBuyList.Add(transaction);
            resourcesBought.Add(resource);
        }