Example #1
0
    private void OnSelloutOrder(object sender, TicketRaisedEventArgs ticketRaisedEventArgs)
    {
        if (ticketRaisedEventArgs.Result != PostOrderResponse.Processed)
        {
            return;
        }
        OrderSelloutTradableResource orderSelloutTradableResource = ticketRaisedEventArgs.Order as OrderSelloutTradableResource;

        Diagnostics.Assert(orderSelloutTradableResource != null);
        AILayer_ResourceManager.SellInfo sellInfo = this.sellInfos.Find((AILayer_ResourceManager.SellInfo match) => match.ResourceDefinition.Name == orderSelloutTradableResource.ResourceName);
        Diagnostics.Assert(sellInfo != null);
        sellInfo.AmountToSell        = 0f;
        sellInfo.NextTurnSoldAmount += orderSelloutTradableResource.Quantity;
        sellInfo.TotalSoldAmount    += orderSelloutTradableResource.Quantity;
    }
Example #2
0
 private void EvaluateResourceSellNeeds()
 {
     this.resourcesAIData.RegisterValue(SimulationProperties.NetEmpireMoney, base.AIEntity.Empire.GetPropertyValue(SimulationProperties.NetEmpireMoney));
     this.resourcesAIData.RegisterValue(SimulationProperties.BankAccount, base.AIEntity.Empire.GetPropertyValue(SimulationProperties.BankAccount));
     for (int i = 0; i < this.sellInfos.Count; i++)
     {
         AILayer_ResourceManager.SellInfo sellInfo = this.sellInfos[i];
         float value;
         if (this.departmentOfTheTreasury.TryGetResourceStockValue(base.AIEntity.Empire, sellInfo.ResourceDefinition.Name, out value, true))
         {
             this.resourcesAIData.RegisterValue(string.Format("{0}Stock", sellInfo.ResourceDefinition.Name), value);
         }
         if (this.departmentOfTheTreasury.TryGetNetResourceValue(base.AIEntity.Empire, sellInfo.ResourceDefinition.Name, out value, true))
         {
             this.resourcesAIData.RegisterValue(string.Format("{0}Income", sellInfo.ResourceDefinition.Name), value);
         }
         this.resourcesAIData.RegisterValue(string.Format("{0}Expenditure", sellInfo.ResourceDefinition.Name), sellInfo.NextTurnSoldAmount);
     }
 }
Example #3
0
    private float GetStrategicSellThreshold(AILayer_ResourceManager.SellInfo sellInfo, float stockValue)
    {
        float num;

        if (!this.departmentOfTheTreasury.TryGetResourceStockValue(base.AIEntity.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpireMoney, out num, false))
        {
            num = 0f;
        }
        bool flag = false;

        if (base.AIEntity.Empire.GetPropertyValue(SimulationProperties.NetEmpireMoney) >= 1f)
        {
            flag = true;
        }
        float averageValue        = this.resourcesAIData.GetAverageValue(string.Format("{0}Stock", sellInfo.ResourceDefinition.Name));
        float averageValue2       = this.resourcesAIData.GetAverageValue(string.Format("{0}Income", sellInfo.ResourceDefinition.Name));
        float averageValue3       = this.resourcesAIData.GetAverageValue(string.Format("{0}Expenditure", sellInfo.ResourceDefinition.Name));
        float num2                = averageValue + 8f * base.AIEntity.Empire.GetPropertyValue(SimulationProperties.GameSpeedMultiplier) * (averageValue2 - averageValue3);
        float b                   = base.AIEntity.Empire.GetPropertyValue(SimulationProperties.EmpireScaleFactor) * this.strategicResourceMinimumStockPerCity;
        float num3                = Mathf.Max(stockValue - num2, b);
        float averageValue4       = this.resourcesAIData.GetAverageValue(SimulationProperties.BankAccount);
        float averageValue5       = this.resourcesAIData.GetAverageValue(SimulationProperties.NetEmpireMoney);
        float b2                  = averageValue4 + 8f * base.AIEntity.Empire.GetPropertyValue(SimulationProperties.GameSpeedMultiplier) * averageValue5;
        float quantity            = stockValue - num3;
        float priceWithSalesTaxes = TradableResource.GetPriceWithSalesTaxes(sellInfo.ResourceDefinition.Name, TradableTransactionType.Sellout, base.AIEntity.Empire, quantity);

        if (priceWithSalesTaxes <= 1.401298E-45f)
        {
            return(float.PositiveInfinity);
        }
        float num4  = priceWithSalesTaxes / Mathf.Max(1f, b2);
        float value = 1f / num4;
        float num5  = Mathf.Clamp01(this.maxDeviationFromResourceMinimumStock);
        float num6  = num3 * Mathf.Clamp(value, 1f - num5, 1f + num5);

        if (flag)
        {
            float num7 = this.departmentOfForeignAffairs.IsInWarWithSomeone() ? 2f : 1f;
            float b3   = (20f + ((float)this.departmentOfScience.CurrentTechnologyEraNumber - 1f) * 10f) * num7;
            num6 = Mathf.Max(num6, b3);
        }
        return(num6);
    }
Example #4
0
    private SynchronousJobState SynchronousJob_SellResources()
    {
        IGameService service = Services.GetService <IGameService>();
        int          turn    = (service.Game as global::Game).Turn;
        ReadOnlyCollection <TradableTransaction> pastTransactions = this.tradeManagementService.GetPastTransactions();

        for (int i = 0; i < this.sellInfos.Count; i++)
        {
            AILayer_ResourceManager.SellInfo sellInfo = this.sellInfos[i];
            if (sellInfo.AmountToSell >= 1f && !pastTransactions.Any((TradableTransaction T) => T.ReferenceName == sellInfo.ResourceDefinition.Name && T.Type == TradableTransactionType.Buyout && T.Turn >= (uint)(turn - 5) && T.EmpireIndex == (uint)this.AIEntity.Empire.Index))
            {
                float amountToSell = sellInfo.AmountToSell;
                if (this.departmentOfTheTreasury.IsTransferOfResourcePossible(base.AIEntity.Empire, sellInfo.ResourceDefinition.Name, ref amountToSell) && amountToSell >= 1f)
                {
                    OrderSelloutTradableResource order = new OrderSelloutTradableResource(base.AIEntity.Empire.Index, sellInfo.ResourceDefinition.Name, amountToSell, false);
                    Ticket ticket;
                    base.AIEntity.Empire.PlayerControllers.AI.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OnSelloutOrder));
                }
            }
        }
        return(SynchronousJobState.Success);
    }
Example #5
0
    private void ExecuteResourceSellNeeds()
    {
        if (!base.AIEntity.Empire.GetAgency <DepartmentOfScience>().CanTradeResourcesAndBoosters(false))
        {
            return;
        }
        bool flag = false;

        for (int i = 0; i < this.sellInfos.Count; i++)
        {
            AILayer_ResourceManager.SellInfo sellInfo = this.sellInfos[i];
            sellInfo.AmountToSell       = 0f;
            sellInfo.NextTurnSoldAmount = 0f;
            float num;
            if (this.departmentOfTheTreasury.TryGetResourceStockValue(base.AIEntity.Empire, sellInfo.ResourceDefinition.Name, out num, true))
            {
                float num2 = float.PositiveInfinity;
                if (sellInfo.ResourceDefinition.ResourceType == ResourceDefinition.Type.Strategic)
                {
                    num2 = this.GetStrategicSellThreshold(sellInfo, num);
                }
                else if (sellInfo.ResourceDefinition.ResourceType == ResourceDefinition.Type.Luxury)
                {
                    num2 = this.GetLuxurySellThreshold(sellInfo, num);
                }
                float num3 = Mathf.Max(0f, num - num2);
                if (num3 >= 1f)
                {
                    sellInfo.AmountToSell = num3;
                    flag = true;
                }
            }
        }
        if (flag)
        {
            AIScheduler.Services.GetService <ISynchronousJobRepositoryAIHelper>().RegisterSynchronousJob(new SynchronousJob(this.SynchronousJob_SellResources));
        }
    }
Example #6
0
    private float GetLuxurySellThreshold(AILayer_ResourceManager.SellInfo sellInfo, float stockValue)
    {
        float propertyValue = base.AIEntity.Empire.GetPropertyValue(SimulationProperties.EmpireScaleFactor);
        float num           = 5f * (propertyValue + 1f);
        float num2          = 0f;

        if (this.aILayer_Research.ResourcesNeededForKaijus.TryGetValue(sellInfo.ResourceDefinition.Name, out num2))
        {
            return(1.5f * num + num2);
        }
        if (this.aILayer_QuestBTController.ResourcesNeededForQuest.TryGetValue(sellInfo.ResourceDefinition.Name, out num2))
        {
            return(1.5f * num + num2);
        }
        float num3;

        this.departmentOfTheTreasury.TryGetNetResourceValue(base.AIEntity.Empire, sellInfo.ResourceDefinition.Name, out num3, true);
        if (num3 < 0.5f && stockValue < num)
        {
            if (this.departmentOfScience.CanTradeResourcesAndBoosters(false))
            {
                List <string> list = new List <string>
                {
                    "Luxury5",
                    "Luxury11",
                    "Luxury12",
                    "Luxury7",
                    "Luxury3",
                    "Luxury13",
                    "Luxury6",
                    "Luxury2",
                    "Luxury10",
                    "Luxury4",
                    "Luxury8",
                    "Luxury1",
                    "Luxury9",
                    "Luxury15",
                    "Luxury14"
                };
                float num4 = 0f;
                foreach (City city in this.departmentOfTheInterior.Cities)
                {
                    num4 += city.GetPropertyValue(SimulationProperties.OverrallTradeRoutesCityDustIncome);
                }
                if (num4 < 50f)
                {
                    list.Remove("Luxury7");
                }
                if (this.departmentOfEducation.Heroes.Count < 5)
                {
                    list.Remove("Luxury13");
                }
                if (base.AIEntity.Empire.GetPropertyValue(SimulationProperties.NetEmpireApproval) > 90f)
                {
                    list.Remove("Luxury14");
                    list.Remove("Luxury5");
                }
                if (!this.departmentOfForeignAffairs.IsInWarWithSomeone())
                {
                    list.Remove("Luxury6");
                    list.Remove("Luxury2");
                }
                if (base.AIEntity.Empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitReplicants1))
                {
                    list.Remove("Luxury8");
                }
                if (base.AIEntity.Empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitBrokenLords2))
                {
                    list.Remove("Luxury4");
                }
                float num5;
                if (!this.departmentOfTheTreasury.TryGetResourceStockValue(base.AIEntity.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpireMoney, out num5, false))
                {
                    num5 = 0f;
                }
                if (num5 < 600f || (float)this.departmentOfEducation.Heroes.Count < (float)this.departmentOfTheInterior.Cities.Count * 1.5f || base.AIEntity.Empire.GetPropertyValue(SimulationProperties.NetEmpireMoney) < 10f)
                {
                    list.Remove("Luxury14");
                    list.Remove("Luxury15");
                    list.Remove("Luxury9");
                }
                if (list.Contains(sellInfo.ResourceDefinition.Name))
                {
                    float            num6             = Mathf.Ceil(num - stockValue);
                    TradableResource tradableResource = this.TryGetTradableRessource(sellInfo.ResourceDefinition.Name);
                    if (tradableResource != null && tradableResource.Quantity >= num6)
                    {
                        float priceWithSalesTaxes = TradableResource.GetPriceWithSalesTaxes(sellInfo.ResourceDefinition.Name, TradableTransactionType.Buyout, base.AIEntity.Empire, num6);
                        float num7 = (num6 <= 10f) ? 2.5f : (2.5f + (num6 - 10f) / 20f);
                        if (num5 >= priceWithSalesTaxes * num7)
                        {
                            return(1.5f * num);
                        }
                    }
                }
            }
            return(0f);
        }
        return(1.5f * num);
    }