コード例 #1
0
        internal static float PriceFor(this Tradeable _this, TradeAction action)
        {
            float num  = TradeSession.trader.TraderKind.PriceTypeFor(_this.ThingDef, action).PriceMultiplier();
            float num2 = TradeUtility.RandomPriceFactorFor(TradeSession.trader, _this);
            float num3;

            if (action == TradeAction.PlayerBuys)
            {
                num3 = _this.BaseMarketValue * (1f - TradeSession.playerNegotiator.GetStatValue(StatDefOf.TradePriceImprovement, true)) * num * num2;
                num3 = Mathf.Max(num3, 0.5f);
            }
            else
            {
                num3  = _this.BaseMarketValue * Find.Storyteller.difficulty.baseSellPriceFactor * _this.AnyThing.GetStatValue(StatDefOf.SellPriceFactor, true) * (1f + TradeSession.playerNegotiator.GetStatValue(StatDefOf.TradePriceImprovement, true)) * num * num2;
                num3 *= Detours_Tradeable.LaunchPricePostFactorCurve.Evaluate(num3);
                num3  = Mathf.Max(num3, 0.01f);
                if (num3 >= _this.PriceFor(TradeAction.PlayerBuys))
                {
                    Log.ErrorOnce("Skill of negotitator trying to put sell price above buy price.", 65387);
                    num3 = _this.PriceFor(TradeAction.PlayerBuys);
                }
            }
            if (num3 > 99.5f)
            {
                num3 = Mathf.Round(num3);
            }
            return(num3);
        }
コード例 #2
0
        private static void DrawPrice(Rect rect, Tradeable trad, TradeAction action)
        {
            if (trad.IsCurrency || !trad.TraderWillTrade)
            {
                return;
            }
            rect = rect.Rounded();
            if (Mouse.IsOver(rect))
            {
                Widgets.DrawHighlight(rect);
            }
            float     num   = trad.PriceFor(action);
            PriceType pType = PriceTypeUtlity.ClosestPriceType(num / trad.BaseMarketValue);

            switch (pType)
            {
            case PriceType.VeryCheap:
                GUI.color = new Color(0f, 1f, 0f);
                break;

            case PriceType.Cheap:
                GUI.color = new Color(0.5f, 1f, 0.5f);
                break;

            case PriceType.Normal:
                GUI.color = Color.white;
                break;

            case PriceType.Expensive:
                GUI.color = new Color(1f, 0.5f, 0.5f);
                break;

            case PriceType.Exorbitant:
                GUI.color = new Color(1f, 0f, 0f);
                break;
            }
            float factor = TradeUtility.RandomPriceFactorFor(TradeSession.trader, trad);

            factor = (factor - 1) * 100;
            string        label      = "$" + num.ToString("F2") + " (" + factor.ToString("F1") + "%)";
            Func <string> textGetter = delegate
            {
                if (!trad.HasAnyThing)
                {
                    return(string.Empty);
                }
                return(((action != TradeAction.PlayerBuys) ? "SellPriceDesc".Translate() : "BuyPriceDesc".Translate()) + "\n\n" + "PriceTypeDesc".Translate(("PriceType" + pType).Translate()));
            };

            TooltipHandler.TipRegion(rect, new TipSignal(textGetter, trad.GetHashCode() * 297));
            Rect rect2 = new Rect(rect);

            rect2.xMax -= 5f;
            rect2.xMin += 5f;
            if (Text.Anchor == TextAnchor.MiddleLeft)
            {
                rect2.xMax += 300f;
            }
            if (Text.Anchor == TextAnchor.MiddleRight)
            {
                rect2.xMin -= 300f;
            }
            Widgets.Label(rect2, label);
            GUI.color = Color.white;
        }