public static float GetUnitPrice(TradableCategoryDefinition tradableCategoryDefinition, float value = 0f) { float num = 0f; float num2 = 0f; float num3 = 0f; IGameService service = Services.GetService <IGameService>(); if (service != null) { global::Game game = service.Game as global::Game; num3 = (float)game.Turn * Tradable.InflationMultiplier; ITradeManagementService service2 = game.Services.GetService <ITradeManagementService>(); TradableCategoryTendency tendency; TradableCategoryStockFactor stockFactor; if (service2 != null && service2.TryGetTradableCategoryState(tradableCategoryDefinition.Name, out tendency, out stockFactor)) { num = tendency; num2 = stockFactor; } } num3 *= tradableCategoryDefinition.SensitivityToInflation; num *= tradableCategoryDefinition.SensitivityToTendency; num2 *= tradableCategoryDefinition.SensitivityToStockFactor; value *= tradableCategoryDefinition.ValueModifier; float num4 = tradableCategoryDefinition.ReferencePrice * (1f + num3) + value * (1f + num3); float val = num4 * (1f + num + num2); float val2 = num4 * Tradable.MinimumPriceMultiplier; float val3 = num4 * Tradable.MaximumPriceMultiplier; return(Math.Max(val2, Math.Min(val3, val))); }
protected override IEnumerator OnHide(bool instant) { base.NeedRefresh = false; this.BuyablePanel.Hide(true); this.SalablePanel.Hide(true); this.ExchangeInfoPanel.Hide(true); base.GuiService.GetGuiPanel <ControlBanner>().OnHideScreen(GameScreenType.Marketplace); ITradeManagementService tradeManagementService = Services.GetService <ITradeManagementService>(); if (tradeManagementService != null) { tradeManagementService.TransactionComplete -= this.TradeManagerService_TransactionComplete; } yield return(base.OnHide(instant)); yield break; }
protected override IEnumerator OnShow(params object[] parameters) { yield return(base.OnShow(parameters)); ITradeManagementService tradeManagementService = base.GameService.Game.Services.GetService <ITradeManagementService>(); if (tradeManagementService != null) { tradeManagementService.TransactionComplete += this.TradeManagerService_TransactionComplete; } base.AgeTransform.Enable = true; base.GuiService.Show(typeof(EmpireBannerPanel), new object[] { EmpireBannerPanel.Full }); base.GuiService.GetGuiPanel <ControlBanner>().OnShowScreen(GameScreenType.Marketplace); this.BuyablePanel.Show(parameters); this.ExchangeInfoPanel.Show(new object[0]); this.UpdateSalablePanelVisibility(); base.NeedRefresh = true; yield break; }
private void RefreshButtons() { if (this.SelectedTradableLine != null && this.SelectedTradableLine.Tradable != null && this.SelectedTradableLine.Tradable.Quantity > 0f) { this.QuantityTextField.AgeTransform.Enable = true; this.QuantityMinusButton.AgeTransform.Enable = (this.CurrentQuantity > 1); if (this.CurrentQuantity >= Mathf.FloorToInt(this.SelectedTradableLine.Tradable.Quantity)) { this.QuantityPlusButton.AgeTransform.Enable = false; this.QuantityPlusButton.AgeTransform.AgeTooltip.Content = "%MarketplaceBuyQuantityPlusTradableQuantityReachedDescription"; } else if (this.CurrentQuantity >= 10) { this.QuantityPlusButton.AgeTransform.Enable = false; this.QuantityPlusButton.AgeTransform.AgeTooltip.Content = string.Format(AgeLocalizer.Instance.LocalizeString("%MarketplaceBuyQuantityPlusHardLimitReachedDescription"), 10); } else { this.QuantityPlusButton.AgeTransform.Enable = true; this.QuantityPlusButton.AgeTransform.AgeTooltip.Content = "%MarketplaceBuyQuantityPlusDescription"; } string formattedPrice = this.GetFormattedPrice(this.SelectedTradableLine.Tradable, this.CurrentQuantity); this.BuyButtonPriceLabel.Text = formattedPrice; if (this.SelectedTradableLine.Tradable.Quantity >= (float)this.CurrentQuantity && this.CanAfford(this.SelectedTradableLine.Tradable, this.CurrentQuantity)) { this.BuyButton.AgeTransform.Enable = this.interactionsAllowed; AgeTooltip ageTooltip = this.BuyButton.AgeTransform.AgeTooltip; if (ageTooltip != null) { string formattedLine = AgeLocalizer.Instance.LocalizeString("%MarketplaceBuyDescription").Replace("$Quantity", this.CurrentQuantity.ToString()).Replace("$TradableName", this.SelectedTradableLine.LocalizedName).Replace("$Price", formattedPrice); StringBuilder stringBuilder = new StringBuilder(); AgeUtils.CleanLine(formattedLine, ref stringBuilder); ageTooltip.Content = stringBuilder.ToString(); if (this.SelectedTradableLine.Tradable is TradableUnit) { ITradeManagementService service = base.Game.Services.GetService <ITradeManagementService>(); UnitDesign unitDesign; if (service != null && service.TryRetrieveUnitDesign((this.SelectedTradableLine.Tradable as TradableUnit).Barcode, out unitDesign) && unitDesign.Tags.Contains(DownloadableContent9.TagColossus)) { float propertyValue = base.Empire.GetPropertyValue(SimulationProperties.MaximumNumberOfColossi); float propertyValue2 = base.Empire.GetPropertyValue(SimulationProperties.NumberOfColossi); if (propertyValue - propertyValue2 < 1f) { formattedLine = AgeLocalizer.Instance.LocalizeString("%MarketplaceCannotBuyColossusDescription").Replace("$ColossiCap", propertyValue.ToString()); stringBuilder = new StringBuilder(); AgeUtils.CleanLine(formattedLine, ref stringBuilder); this.BuyButton.AgeTransform.Enable = false; ageTooltip.Content = stringBuilder.ToString(); } } } } } else { this.BuyButton.AgeTransform.Enable = false; AgeTooltip ageTooltip2 = this.BuyButton.AgeTransform.AgeTooltip; if (ageTooltip2 != null) { string formattedLine2 = AgeLocalizer.Instance.LocalizeString("%MarketplaceCannotBuyDescription").Replace("$Quantity", this.CurrentQuantity.ToString()).Replace("$TradableName", this.SelectedTradableLine.LocalizedName); StringBuilder stringBuilder2 = new StringBuilder(); AgeUtils.CleanLine(formattedLine2, ref stringBuilder2); ageTooltip2.Content = stringBuilder2.ToString(); } } } else { this.QuantityTextField.AgeTransform.Enable = false; this.QuantityMinusButton.AgeTransform.Enable = false; this.QuantityPlusButton.AgeTransform.Enable = false; this.BuyButton.AgeTransform.Enable = false; this.BuyButtonPriceLabel.Text = string.Empty; AgeTooltip ageTooltip3 = this.BuyButton.AgeTransform.AgeTooltip; if (ageTooltip3 != null) { ageTooltip3.Content = null; } } }