예제 #1
0
    public static string FormatInstantCost(Empire empire, float cost, StaticString resourceName, bool monochromatic = false, int decimals = 1)
    {
        DepartmentOfTheTreasury agency = empire.GetAgency <DepartmentOfTheTreasury>();
        float num;

        if (!agency.TryGetResourceStockValue(empire.SimulationObject, resourceName, out num, false))
        {
            Diagnostics.Log("Can't get resource stock value {0} on simulation object {1}.", new object[]
            {
                resourceName,
                empire.SimulationObject.Name
            });
        }
        StringBuilder stringBuilder = new StringBuilder();
        bool          flag          = false;

        if (!monochromatic && num < cost)
        {
            AgeUtils.ColorToHexaKey(Color.red, ref stringBuilder, false);
            flag = true;
        }
        stringBuilder.Append(GuiFormater.FormatGui(cost, false, decimals == 0, false, decimals));
        if (!monochromatic && flag)
        {
            stringBuilder.Append("#REVERT#");
        }
        stringBuilder.Append(" ");
        stringBuilder.Append(Services.GetService <IGuiService>().FormatSymbol(resourceName));
        return(stringBuilder.ToString());
    }
예제 #2
0
    private static void GetResourceUnitMarketPrice(global::Empire empire, out float averageStrategicUnitPrice, out float averageLuxuryUnitPrice)
    {
        DepartmentOfTheTreasury agency = empire.GetAgency <DepartmentOfTheTreasury>();
        float num  = 0f;
        int   num2 = 0;
        float num3 = 0f;
        int   num4 = 0;
        IDatabase <ResourceDefinition> database = Databases.GetDatabase <ResourceDefinition>(false);

        foreach (ResourceDefinition resourceDefinition in database)
        {
            if (resourceDefinition.ResourceType == ResourceDefinition.Type.Strategic || resourceDefinition.ResourceType == ResourceDefinition.Type.Luxury)
            {
                float num5;
                agency.TryGetResourceStockValue(empire.SimulationObject, resourceDefinition.Name, out num5, true);
                float priceWithSalesTaxes = TradableResource.GetPriceWithSalesTaxes(resourceDefinition.Name, TradableTransactionType.Sellout, empire, 1f);
                if (resourceDefinition.ResourceType == ResourceDefinition.Type.Strategic)
                {
                    num += priceWithSalesTaxes;
                    num2++;
                }
                else if (resourceDefinition.ResourceType == ResourceDefinition.Type.Luxury)
                {
                    num3 += priceWithSalesTaxes;
                    num4++;
                }
            }
        }
        averageStrategicUnitPrice = ((num2 <= 0) ? 0f : (num / (float)num2));
        averageLuxuryUnitPrice    = ((num4 <= 0) ? 0f : (num3 / (float)num4));
    }
예제 #3
0
    private string FormatEmpirePoints(global::Empire empire, bool withNet = false)
    {
        DepartmentOfTheTreasury agency = empire.GetAgency <DepartmentOfTheTreasury>();
        float stockValue;

        if (!agency.TryGetResourceStockValue(empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out stockValue, false))
        {
            Diagnostics.LogError("Can't get resource stock value {0} on simulation object {1}.", new object[]
            {
                DepartmentOfTheTreasury.Resources.EmpirePoint,
                empire.SimulationObject
            });
        }
        if (!withNet)
        {
            return(GuiFormater.FormatStock(stockValue, SimulationProperties.EmpirePoint, 1, false));
        }
        float netValue;

        if (!agency.TryGetNetResourceValue(empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out netValue, false))
        {
            Diagnostics.LogError("Can't get resource net value {0} on simulation object {1}.", new object[]
            {
                DepartmentOfTheTreasury.Resources.EmpirePoint,
                empire.SimulationObject
            });
        }
        return(GuiFormater.FormatStockAndNet(stockValue, netValue, SimulationProperties.EmpirePoint, false));
    }
예제 #4
0
    private void UpdateResourceStatus(PointOfInterest pointOfInterest, global::Empire empire, Region region, AIRegionData regionData, DepartmentOfTheTreasury departmentOfTheTreasury)
    {
        regionData.ResourcePointOfInterestCount++;
        if (pointOfInterest.PointOfInterestImprovement != null)
        {
            regionData.BuiltExtractor++;
        }
        if (!DepartmentOfTheInterior.IsPointOfInterestVisible(empire, pointOfInterest))
        {
            return;
        }
        string empty     = string.Empty;
        bool   condition = pointOfInterest.PointOfInterestDefinition.TryGetValue("ResourceName", out empty);

        Diagnostics.Assert(condition);
        ResourceDefinition.Type resourceType = departmentOfTheTreasury.GetResourceType(empty);
        float num        = 0f;
        bool  condition2 = departmentOfTheTreasury.TryGetNetResourceValue(empire, empty, out num, true);

        Diagnostics.Assert(condition2);
        if (num > 0f)
        {
            if (resourceType == ResourceDefinition.Type.Luxury)
            {
                regionData.ProducedLuxuryRessourcesCount++;
            }
            else if (resourceType == ResourceDefinition.Type.Strategic)
            {
                regionData.ProducedStrategicRessourcesCount++;
            }
            return;
        }
        float num2       = 0f;
        bool  condition3 = departmentOfTheTreasury.TryGetResourceStockValue(empire, empty, out num2, true);

        Diagnostics.Assert(condition3);
        if (num2 > 0f)
        {
            if (resourceType == ResourceDefinition.Type.Luxury)
            {
                regionData.OwnedLuxuryRessourcesCount++;
            }
            else if (resourceType == ResourceDefinition.Type.Strategic)
            {
                regionData.OwnedStrategicRessourcesCount++;
            }
            return;
        }
        if (resourceType == ResourceDefinition.Type.Luxury)
        {
            regionData.NewLuxuryRessourcesCount++;
        }
        else if (resourceType == ResourceDefinition.Type.Strategic)
        {
            regionData.NewStrategicRessourcesCount++;
        }
    }
    public static string GenerateInfiltrationElementDescription(Empire spyEmpire, InfiltrationAction infiltrationAction, GuiElement guiElement)
    {
        string text = AgeLocalizer.Instance.LocalizeString(guiElement.Description);
        IInfiltrationActionWithBooster infiltrationActionWithBooster = infiltrationAction as IInfiltrationActionWithBooster;

        if (infiltrationActionWithBooster != null && spyEmpire.GetAgency <DepartmentOfPlanificationAndDevelopment>() != null)
        {
            int duration = infiltrationActionWithBooster.Duration;
            int num      = 0;
            BoosterDefinition boosterDefinition;
            if (duration <= 0 && infiltrationActionWithBooster.BoosterReferences != null && infiltrationActionWithBooster.BoosterReferences.Length != 0 && Databases.GetDatabase <BoosterDefinition>(false).TryGetValue(infiltrationActionWithBooster.BoosterReferences[0], out boosterDefinition))
            {
                num = DepartmentOfPlanificationAndDevelopment.GetBoosterDurationWithBonus(spyEmpire, spyEmpire, boosterDefinition);
            }
            if (num <= 0)
            {
                num = DepartmentOfPlanificationAndDevelopment.GetBoosterDurationWithBonus(spyEmpire, duration);
            }
            text = text.Replace("$Duration", num.ToString());
        }
        if (infiltrationAction is InfiltrationActionOnEmpire_StealResource)
        {
            string newValue = string.Empty;
            EspionageActionPanel guiPanel = Services.GetService <global::IGuiService>().GetGuiPanel <EspionageActionPanel>();
            if (guiPanel != null && guiPanel.TargetedCity != null)
            {
                InfiltrationActionOnEmpire_StealResource infiltrationActionOnEmpire_StealResource = infiltrationAction as InfiltrationActionOnEmpire_StealResource;
                DepartmentOfTheTreasury agency = guiPanel.TargetedCity.Empire.GetAgency <DepartmentOfTheTreasury>();
                float num2 = 0f;
                if (agency.TryGetResourceStockValue(guiPanel.TargetedCity.Empire, infiltrationActionOnEmpire_StealResource.ResourceName, out num2, false))
                {
                    float num3 = num2 * infiltrationActionOnEmpire_StealResource.AmountParameters.TargetStockPercentage + infiltrationActionOnEmpire_StealResource.AmountParameters.BaseAmount;
                    float num4 = num3 * infiltrationActionOnEmpire_StealResource.AmountParameters.RandomThreshold;
                    float num5 = Mathf.Floor(Mathf.Min(num3 - num4, num2));
                    float num6 = Mathf.Floor(Mathf.Min(num3 + num4, num2));
                    newValue = AgeLocalizer.Instance.LocalizeString(string.Concat(new string[]
                    {
                        " (#FFD768#\\7703\\#REVERT# ",
                        num5.ToString(),
                        " - #FFD768#\\7703\\#REVERT# ",
                        num6.ToString(),
                        ")"
                    }));
                }
            }
            text = text.Replace("$Amount", newValue);
        }
        return(text);
    }
예제 #6
0
    private float ComputeAmountToSteal(Empire targetEmpire)
    {
        DepartmentOfTheTreasury agency = targetEmpire.GetAgency <DepartmentOfTheTreasury>();
        float num = 0f;

        if (agency.TryGetResourceStockValue(targetEmpire.SimulationObject, this.ResourceName, out num, false))
        {
            float num2 = num * this.AmountParameters.TargetStockPercentage;
            num2 += this.AmountParameters.BaseAmount;
            float num3 = num2 * this.AmountParameters.RandomThreshold;
            num2 = UnityEngine.Random.Range(num2 - num3, num2 + num3);
            return(Mathf.Floor(Mathf.Min(num2, num)));
        }
        return(0f);
    }
예제 #7
0
    public static string FormatCost(Empire empire, IConstructionCost[] costs, bool monochromatic = false, int decimals = 1, SimulationObject context = null)
    {
        DepartmentOfTheTreasury agency = empire.GetAgency <DepartmentOfTheTreasury>();

        if (context == null)
        {
            context = empire.SimulationObject;
        }
        StringBuilder stringBuilder = new StringBuilder();

        if (costs != null)
        {
            bool flag = false;
            for (int i = 0; i < costs.Length; i++)
            {
                float value = costs[i].GetValue(empire);
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(" ");
                }
                float num;
                if (!agency.TryGetResourceStockValue(context, costs[i].ResourceName, out num, false))
                {
                    Diagnostics.Log("Can't get resource stock value {0} on simulation object {1}.", new object[]
                    {
                        costs[i].ResourceName,
                        empire.SimulationObject.Name
                    });
                }
                if (!monochromatic && (costs[i].Instant || costs[i].InstantOnCompletion) && num < value)
                {
                    AgeUtils.ColorToHexaKey(Color.red, ref stringBuilder, false);
                    flag = true;
                }
                stringBuilder.Append(GuiFormater.FormatGui(value, false, decimals == 0, false, decimals));
                if (!monochromatic && flag)
                {
                    stringBuilder.Append("#REVERT#");
                    flag = false;
                }
                stringBuilder.Append(" ");
                stringBuilder.Append(Services.GetService <IGuiService>().FormatSymbol(costs[i].ResourceName));
            }
        }
        return(stringBuilder.ToString());
    }
예제 #8
0
    private int ComputeWantedNumberOfOrbs(int neededVoteCount)
    {
        float num = this.seasonService.Target.ComputePrayerOrbCost(base.AIEntity.Empire);

        if (num <= 1.401298E-45f)
        {
            return(neededVoteCount);
        }
        float num2 = 0f;
        DepartmentOfTheTreasury agency = base.AIEntity.Empire.GetAgency <DepartmentOfTheTreasury>();

        if (!agency.TryGetResourceStockValue(base.AIEntity.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.Orb, out num2, true))
        {
            return(1);
        }
        return(Mathf.Max(neededVoteCount, Mathf.FloorToInt(0.1f * num2 / num)));
    }
예제 #9
0
    public static string FormatStockCost(Empire empire, ConstructionResourceStock[] stockCosts, bool monochromatic = false, int decimals = 1)
    {
        DepartmentOfTheTreasury agency        = empire.GetAgency <DepartmentOfTheTreasury>();
        StringBuilder           stringBuilder = new StringBuilder();

        if (stockCosts != null)
        {
            bool flag = false;
            for (int i = 0; i < stockCosts.Length; i++)
            {
                float stock = stockCosts[i].Stock;
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(" ");
                }
                float num;
                if (!agency.TryGetResourceStockValue(empire.SimulationObject, stockCosts[i].PropertyName, out num, false))
                {
                    Diagnostics.Log("Can't get resource stock value {0} on simulation object {1}.", new object[]
                    {
                        stockCosts[i].PropertyName,
                        empire.SimulationObject.Name
                    });
                }
                if (!monochromatic)
                {
                    AgeUtils.ColorToHexaKey(Color.red, ref stringBuilder, false);
                    flag = true;
                }
                stringBuilder.Append(GuiFormater.FormatGui(stock, false, decimals == 0, false, decimals));
                if (!monochromatic && flag)
                {
                    stringBuilder.Append("#REVERT#");
                    flag = false;
                }
                stringBuilder.Append(" ");
                stringBuilder.Append(Services.GetService <IGuiService>().FormatSymbol(stockCosts[i].PropertyName));
            }
        }
        return(stringBuilder.ToString());
    }
예제 #10
0
    public override bool CanExecute(InterpreterContext context, ref List <StaticString> failureFlags, params object[] parameters)
    {
        if (!base.CanExecute(context, ref failureFlags, parameters))
        {
            return(false);
        }
        if (context == null)
        {
            failureFlags.Add(InfiltrationAction.NoCanDoWhileSystemError);
            return(false);
        }
        if (!context.Contains("InfiltratedCity"))
        {
            failureFlags.Add(InfiltrationAction.NoCanDoWhileHidden);
            return(false);
        }
        City city = context.Get("InfiltratedCity") as City;

        if (city == null)
        {
            failureFlags.Add(InfiltrationAction.NoCanDoWhileSystemError);
            return(false);
        }
        DepartmentOfTheTreasury agency = city.Empire.GetAgency <DepartmentOfTheTreasury>();
        float num = 0f;

        if (!agency.TryGetResourceStockValue(city.Empire.SimulationObject, this.ResourceName, out num, false))
        {
            failureFlags.Add(InfiltrationAction.NoCanDoWhileSystemError);
            return(false);
        }
        if (num <= 0f)
        {
            string x = InfiltrationActionOnEmpire_StealResource.NoCanDoWhileNoResourceToSteal + this.ResourceName;
            failureFlags.Add(x);
            return(false);
        }
        return(true);
    }
    private bool CanSearchQuest(Army army, IWorldPositionable item, IQuestManagementService questManagementService, IQuestRepositoryService questRepositoryService)
    {
        PointOfInterest pointOfInterest = item as PointOfInterest;

        if (pointOfInterest == null)
        {
            return(false);
        }
        if (pointOfInterest.Type != ELCPUtilities.QuestLocation && pointOfInterest.Type != "NavalQuestLocation")
        {
            return(false);
        }
        if (ELCPUtilities.UseELCPPeacefulCreepingNodes)
        {
            if (pointOfInterest.CreepingNodeGUID != GameEntityGUID.Zero && pointOfInterest.Empire != army.Empire)
            {
                if (pointOfInterest.Empire == null)
                {
                    return(false);
                }
                if (!(pointOfInterest.Empire is MajorEmpire))
                {
                    return(false);
                }
                DepartmentOfForeignAffairs agency = army.Empire.GetAgency <DepartmentOfForeignAffairs>();
                if (agency == null)
                {
                    return(false);
                }
                if (!agency.IsFriend(pointOfInterest.Empire))
                {
                    return(false);
                }
            }
        }
        else if (pointOfInterest.CreepingNodeImprovement != null && pointOfInterest.Empire.Index != army.Empire.Index)
        {
            return(false);
        }
        if (!pointOfInterest.Interaction.IsLocked(army.Empire.Index, "ArmyActionSearch"))
        {
            foreach (QuestMarker questMarker in questManagementService.GetMarkersByBoundTargetGUID(pointOfInterest.GUID))
            {
                Quest quest;
                if (questRepositoryService.TryGetValue(questMarker.QuestGUID, out quest))
                {
                    QuestBehaviour questBehaviour = questRepositoryService.GetQuestBehaviour(quest.Name, army.Empire.Index);
                    if (questBehaviour != null && quest.EmpireBits == army.Empire.Bits && questMarker.IsVisibleFor(army.Empire))
                    {
                        string a = quest.QuestDefinition.Name;
                        if (quest.QuestDefinition.Name == AILayer_QuestSolver.ImportantQuestNames.GlobalQuestACursedBountyName && questMarker.IsVisibleInFogOfWar)
                        {
                            if (this.QuestLayer == null)
                            {
                                GameServer           gameServer = (Services.GetService <ISessionService>().Session as global::Session).GameServer as GameServer;
                                AIPlayer_MajorEmpire aiplayer_MajorEmpire;
                                if (gameServer.AIScheduler != null && gameServer.AIScheduler.TryGetMajorEmpireAIPlayer(army.Empire as MajorEmpire, out aiplayer_MajorEmpire))
                                {
                                    AIEntity entity = aiplayer_MajorEmpire.GetEntity <AIEntity_Empire>();
                                    if (entity != null)
                                    {
                                        this.QuestLayer = entity.GetLayer <AILayer_QuestSolver>();
                                    }
                                }
                            }
                            if (this.QuestLayer.SearchACursedBountyRuin)
                            {
                                return(true);
                            }
                            this.CursedBountyPosition = questMarker.WorldPosition;
                            return(false);
                        }
                        else
                        {
                            if (a == "VictoryQuest-Chapter3" && questMarker.IsVisibleInFogOfWar)
                            {
                                return(true);
                            }
                            if (a == "VictoryQuest-Chapter1Alt" || a == "VictoryQuest-Chapter1")
                            {
                                QuestBehaviourTreeNode_ConditionCheck_Prerequisite questBehaviourTreeNode_ConditionCheck_Prerequisite;
                                if (!ELCPUtilities.TryGetFirstNodeOfType <QuestBehaviourTreeNode_ConditionCheck_Prerequisite>(questBehaviour.Root as BehaviourTreeNodeController, out questBehaviourTreeNode_ConditionCheck_Prerequisite))
                                {
                                    return(false);
                                }
                                foreach (QuestBehaviourPrerequisites questBehaviourPrerequisites in questBehaviourTreeNode_ConditionCheck_Prerequisite.Prerequisites)
                                {
                                    for (int j = 0; j < questBehaviourPrerequisites.Prerequisites.Length; j++)
                                    {
                                        InterpreterPrerequisite interpreterPrerequisite = questBehaviourPrerequisites.Prerequisites[j] as InterpreterPrerequisite;
                                        if (interpreterPrerequisite != null && !interpreterPrerequisite.Check(army))
                                        {
                                            return(false);
                                        }
                                    }
                                }
                                return(true);
                            }
                            else if (a == "GlobalQuestCoop#0004")
                            {
                                if (quest.QuestDefinition.Variables.First((QuestVariableDefinition p) => p.VarName == "$NameOfStrategicResourceToGather1") != null)
                                {
                                    QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount questBehaviourTreeNode_ConditionCheck_HasResourceAmount;
                                    if (!ELCPUtilities.TryGetFirstNodeOfType <QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount>(questBehaviour.Root as BehaviourTreeNodeController, out questBehaviourTreeNode_ConditionCheck_HasResourceAmount))
                                    {
                                        return(false);
                                    }
                                    string resourceName             = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.ResourceName;
                                    int    wantedAmount             = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.WantedAmount;
                                    DepartmentOfTheTreasury agency2 = army.Empire.GetAgency <DepartmentOfTheTreasury>();
                                    float num;
                                    if (agency2 != null && agency2.TryGetResourceStockValue(army.Empire.SimulationObject, resourceName, out num, false) && num >= (float)(wantedAmount * 3))
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
        return(false);
    }
예제 #12
0
 public void RefreshCanExecute()
 {
     if (this.ArmyAction != null && !this.Army.IsEmpty)
     {
         this.failure.Clear();
         bool flag;
         if (this.ArmyAction is IArmyActionWithTargetSelection && this.ArmyAction is IArmyActionWithUnitSelection)
         {
             this.armyActionTargets.Clear();
             (this.ArmyAction as IArmyActionWithTargetSelection).FillTargets(this.Army, this.armyActionTargets, ref this.failure);
             flag = this.ArmyAction.CanExecute(this.Army, ref this.failure, new object[]
             {
                 this.unitListPanel.SelectUnits,
                 this.armyActionTargets
             });
         }
         else if (this.ArmyAction is IArmyActionWithTargetSelection)
         {
             this.armyActionTargets.Clear();
             (this.ArmyAction as IArmyActionWithTargetSelection).FillTargets(this.Army, this.armyActionTargets, ref this.failure);
             flag = this.ArmyAction.CanExecute(this.Army, ref this.failure, new object[]
             {
                 this.armyActionTargets
             });
         }
         else if (this.ArmyAction is IArmyActionWithUnitSelection)
         {
             flag = this.ArmyAction.CanExecute(this.Army, ref this.failure, new object[]
             {
                 this.unitListPanel.SelectUnits
             });
         }
         else
         {
             flag = this.ArmyAction.CanExecute(this.Army, ref this.failure, new object[0]);
         }
         flag &= (!this.failure.Contains(ArmyAction.NoCanDoWhileMoving) && !this.failure.Contains(ArmyAction.NoCanDoWhileTutorial));
         if (!this.failure.Contains(ArmyAction.NoCanDoWhileHidden))
         {
             this.AgeTransform.AgeTooltip.Content = string.Empty;
             GuiElement guiElement;
             if (Services.GetService <Amplitude.Unity.Gui.IGuiService>().GuiPanelHelper.TryGetGuiElement(this.ArmyAction.Name, out guiElement))
             {
                 if (this.failure.Count == 0)
                 {
                     this.AgeTransform.AgeTooltip.Content = "#50FF50#" + AgeLocalizer.Instance.LocalizeString(guiElement.Title).ToUpper() + "#REVERT#";
                 }
                 else
                 {
                     this.AgeTransform.AgeTooltip.Content = "#FF5050#" + AgeLocalizer.Instance.LocalizeString(guiElement.Title).ToUpper() + "#REVERT#";
                 }
             }
             if (this.ArmyAction is IArmyActionWithToggle)
             {
                 bool flag2 = this.failure.Contains(ArmyAction.NoCanDoWhileToggledOn);
                 if (flag2)
                 {
                     this.failure.RemoveAll((StaticString failureFlag) => failureFlag.Equals(ArmyAction.NoCanDoWhileToggledOn));
                 }
                 IArmyActionWithToggle armyActionWithToggle = this.ArmyAction as IArmyActionWithToggle;
                 this.ActionToggle.AgeTransform.Enable = flag;
                 this.ActionImage.AgeTransform.Alpha   = ((this.ActionToggle.AgeTransform.Enable && !flag2) ? 1f : 0.5f);
                 this.ActionToggle.State = ((flag || flag2) && armyActionWithToggle.IsToggled(this.Army));
                 if (this.ActionToggle.State && !this.ModifierSector.IsStarted())
                 {
                     this.ModifierSector.StartAnimation();
                 }
                 else if (!this.ActionToggle.State && this.ModifierSector.IsStarted())
                 {
                     this.ModifierSector.Reset();
                 }
                 if (this.failure.Count == 0)
                 {
                     if (this.ActionToggle.State)
                     {
                         StaticString toggledOnDescriptionOverride = armyActionWithToggle.ToggledOnDescriptionOverride;
                         if (!StaticString.IsNullOrEmpty(toggledOnDescriptionOverride))
                         {
                             AgeTooltip ageTooltip = this.AgeTransform.AgeTooltip;
                             ageTooltip.Content = ageTooltip.Content + " : " + AgeLocalizer.Instance.LocalizeString("%" + toggledOnDescriptionOverride);
                         }
                         else
                         {
                             AgeTooltip ageTooltip2 = this.AgeTransform.AgeTooltip;
                             ageTooltip2.Content = ageTooltip2.Content + " : " + AgeLocalizer.Instance.LocalizeString(this.ArmyAction.FormatDescription("%" + this.ArmyAction.Name + "OffDescription"));
                         }
                     }
                     else
                     {
                         StaticString toggledOffDescriptionOverride = armyActionWithToggle.ToggledOffDescriptionOverride;
                         if (!StaticString.IsNullOrEmpty(toggledOffDescriptionOverride))
                         {
                             AgeTooltip ageTooltip3 = this.AgeTransform.AgeTooltip;
                             ageTooltip3.Content = ageTooltip3.Content + " : " + AgeLocalizer.Instance.LocalizeString("%" + toggledOffDescriptionOverride);
                         }
                         else
                         {
                             AgeTooltip ageTooltip4 = this.AgeTransform.AgeTooltip;
                             ageTooltip4.Content = ageTooltip4.Content + " : " + AgeLocalizer.Instance.LocalizeString(this.ArmyAction.FormatDescription("%" + this.ArmyAction.Name + "OnDescription"));
                         }
                     }
                 }
             }
             else
             {
                 this.ActionButton.AgeTransform.Enable = flag;
                 this.ActionImage.AgeTransform.Alpha   = ((!this.ActionButton.AgeTransform.Enable) ? 0.5f : 1f);
                 if (this.failure.Count == 0)
                 {
                     AgeTooltip ageTooltip5 = this.AgeTransform.AgeTooltip;
                     ageTooltip5.Content = ageTooltip5.Content + " : " + AgeLocalizer.Instance.LocalizeString(this.ArmyAction.FormatDescription("%" + this.ArmyAction.Name + "Description"));
                     if (this.ArmyAction is ArmyActionWithCooldown)
                     {
                         float num = (this.ArmyAction as ArmyActionWithCooldown).ComputeCooldownDuration(this.Army);
                         this.AgeTransform.AgeTooltip.Content = this.AgeTransform.AgeTooltip.Content.Replace("$CooldownDuration", num.ToString());
                     }
                 }
             }
             if (this.failure.Count > 0)
             {
                 AgeTooltip ageTooltip6 = this.AgeTransform.AgeTooltip;
                 ageTooltip6.Content = ageTooltip6.Content + " : " + AgeLocalizer.Instance.LocalizeString(this.ArmyAction.FormatDescription("%" + this.failure[0] + "Description"));
                 if (this.ArmyAction is ArmyActionWithCooldown)
                 {
                     float num2 = (this.ArmyAction as ArmyActionWithCooldown).ComputeRemainingCooldownDuration(this.Army);
                     this.AgeTransform.AgeTooltip.Content = this.AgeTransform.AgeTooltip.Content.Replace("$RemainingCooldownDuration", num2.ToString());
                 }
             }
         }
         float costInActionPoints = this.ArmyAction.GetCostInActionPoints();
         if (costInActionPoints > 0f)
         {
             AgeTooltip ageTooltip7 = this.AgeTransform.AgeTooltip;
             ageTooltip7.Content = ageTooltip7.Content + "\n \n" + AgeLocalizer.Instance.LocalizeString("%ArmyActionPointRequirementFormat").Replace("$Value", costInActionPoints.ToString());
         }
         for (int i = 0; i < this.ArmyAction.Costs.Length; i++)
         {
             string text  = this.ArmyAction.Costs[i].ResourceName;
             bool   flag3 = false;
             if (ELCPUtilities.UseELCPSymbiosisBuffs && this.ArmyAction is ArmyAction_TameUnstunnedKaiju)
             {
                 foreach (IGameEntity gameEntity in this.armyActionTargets)
                 {
                     Kaiju kaiju = gameEntity as Kaiju;
                     if (kaiju != null)
                     {
                         KaijuCouncil agency = kaiju.KaijuEmpire.GetAgency <KaijuCouncil>();
                         if (agency != null)
                         {
                             text  = agency.ELCPResourceName;
                             flag3 = true;
                             break;
                         }
                     }
                 }
             }
             if (!string.IsNullOrEmpty(text) && !text.Equals(DepartmentOfTheTreasury.Resources.ActionPoint))
             {
                 float num3 = this.ArmyAction.GetCostForResource(text, this.Army.Empire);
                 if (flag3)
                 {
                     num3 = KaijuCouncil.GetKaijuTameCost().GetValue(this.Army.Empire);
                 }
                 if (num3 != 0f)
                 {
                     DepartmentOfTheTreasury agency2 = this.Army.Empire.GetAgency <DepartmentOfTheTreasury>();
                     float f = 0f;
                     if (agency2.TryGetResourceStockValue(this.Army.Empire.SimulationObject, text, out f, false))
                     {
                         GuiElement guiElement2;
                         if (Services.GetService <global::IGuiService>().GuiPanelHelper.TryGetGuiElement(text, out guiElement2) && guiElement2 is ExtendedGuiElement)
                         {
                             ExtendedGuiElement extendedGuiElement = guiElement2 as ExtendedGuiElement;
                             if (extendedGuiElement == null)
                             {
                                 Diagnostics.LogError("Resource extended gui is 'null'.");
                             }
                             string text2        = AgeLocalizer.Instance.LocalizeString(extendedGuiElement.Title);
                             string symbolString = extendedGuiElement.SymbolString;
                             string arg          = string.Format(AgeLocalizer.Instance.LocalizeString("%ArmyActionResourceRequirementFormat"), new object[]
                             {
                                 num3,
                                 text2,
                                 symbolString,
                                 Mathf.Ceil(f)
                             });
                             this.AgeTransform.AgeTooltip.Content = string.Format("{0}\n\n\n{1}", this.AgeTransform.AgeTooltip.Content, arg);
                         }
                         else
                         {
                             Diagnostics.LogError("Could not retrieve the resource gui element.");
                         }
                     }
                 }
             }
         }
     }
 }
예제 #13
0
    public static void GetCostAndTurn(Amplitude.Unity.Gui.IGuiService guiService, DepartmentOfTheTreasury departmentOfTheTreasury, SimulationObjectWrapper context, out string costString, out int turn)
    {
        turn = 0;
        StringBuilder stringBuilder = new StringBuilder();

        if (PanelFeatureCost.costByResource.Count > 0)
        {
            bool flag = false;
            IDatabase <ResourceDefinition> database = Databases.GetDatabase <ResourceDefinition>(false);
            foreach (KeyValuePair <StaticString, PanelFeatureCost.CostResume> keyValuePair in PanelFeatureCost.costByResource)
            {
                if (keyValuePair.Key == SimulationProperties.Population)
                {
                    stringBuilder.Append(GuiFormater.FormatGui(keyValuePair.Value.Cost, false, true, false, 1));
                    stringBuilder.Append(guiService.FormatSymbol(keyValuePair.Key));
                }
                else if (keyValuePair.Key == DepartmentOfTheTreasury.Resources.FreeBorough)
                {
                    stringBuilder.Append(GuiFormater.FormatGui(keyValuePair.Value.Cost, false, true, false, 1));
                    stringBuilder.Append(guiService.FormatSymbol(keyValuePair.Key));
                    float num;
                    if (!departmentOfTheTreasury.TryGetResourceStockValue(context.SimulationObject, DepartmentOfTheTreasury.Resources.QueuedFreeBorough, out num, true))
                    {
                        Diagnostics.Log("Can't get resource stock value {0} on simulation object {1}.", new object[]
                        {
                            DepartmentOfTheTreasury.Resources.QueuedFreeBorough,
                            context.SimulationObject.Name
                        });
                    }
                    else
                    {
                        stringBuilder.Append(string.Format(AgeLocalizer.Instance.LocalizeString("%CityFreeBoroughsLeft"), num));
                    }
                }
                else
                {
                    float              cost = keyValuePair.Value.Cost;
                    StaticString       key  = keyValuePair.Key;
                    ResourceDefinition resourceDefinition;
                    if (!database.TryGetValue(key, out resourceDefinition))
                    {
                        Diagnostics.LogError("Invalid resource name. The resource {0} does not exist in the resource database.", new object[]
                        {
                            key
                        });
                    }
                    else
                    {
                        string value = guiService.FormatSymbol(resourceDefinition.GetName(departmentOfTheTreasury.Empire));
                        if (!string.IsNullOrEmpty(value))
                        {
                            global::Empire empire = null;
                            if (context is City)
                            {
                                empire = (context as City).Empire;
                            }
                            else if (context is global::Empire)
                            {
                                empire = (context as global::Empire);
                            }
                            if (empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitMimics2) && key == DepartmentOfTheTreasury.Resources.Production)
                            {
                                ResourceDefinition resourceDefinition2;
                                if (!database.TryGetValue(SimulationProperties.CityGrowth, out resourceDefinition2))
                                {
                                    Diagnostics.LogError("Invalid resource name. The resource {0} does not exist in the resource database.", new object[]
                                    {
                                        key
                                    });
                                    continue;
                                }
                                value = guiService.FormatSymbol(resourceDefinition2.GetName(departmentOfTheTreasury.Empire));
                                if (string.IsNullOrEmpty(value))
                                {
                                    continue;
                                }
                            }
                            float num2;
                            if (!departmentOfTheTreasury.TryGetResourceStockValue(context.SimulationObject, key, out num2, true))
                            {
                                num2 = 0f;
                            }
                            if (keyValuePair.Value.Instant && num2 < cost)
                            {
                                AgeUtils.ColorToHexaKey(Color.red, ref stringBuilder, false);
                                flag = true;
                            }
                            stringBuilder.Append(GuiFormater.FormatGui(cost, false, true, false, 1));
                            stringBuilder.Append(value);
                            if (flag)
                            {
                                stringBuilder.Append("#REVERT#");
                                flag = false;
                            }
                            if (!keyValuePair.Value.Instant)
                            {
                                float num3;
                                if (!departmentOfTheTreasury.TryGetNetResourceValue(context.SimulationObject, key, out num3, true))
                                {
                                    num3 = 0f;
                                }
                                if (cost > num2)
                                {
                                    if (num3 <= 0f)
                                    {
                                        turn = int.MaxValue;
                                    }
                                    else
                                    {
                                        int num4 = Mathf.CeilToInt((cost - num2) / num3);
                                        if (num4 > turn)
                                        {
                                            turn = num4;
                                        }
                                    }
                                }
                            }
                            stringBuilder.Append(" ");
                        }
                    }
                }
            }
        }
        costString = stringBuilder.ToString();
        if (string.IsNullOrEmpty(costString))
        {
            costString = "-";
        }
    }
예제 #14
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        Army army2;

        base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army2);
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();
        State result;

        if (this.orderTicket != null)
        {
            if (!this.orderTicket.Raised)
            {
                result = State.Running;
            }
            else
            {
                OrderInteractWith orderInteractWith = this.orderTicket.Order as OrderInteractWith;
                IGameEntity       gameEntity        = null;
                if (this.orderTicket.PostOrderResponse != PostOrderResponse.Processed)
                {
                    if (service2.TryGetValue(orderInteractWith.TargetGUID, out gameEntity))
                    {
                        PointOfInterest pointOfInterest;
                        if (gameEntity is Village)
                        {
                            pointOfInterest = (gameEntity as Village).PointOfInterest;
                        }
                        else
                        {
                            pointOfInterest = (gameEntity as PointOfInterest);
                        }
                        if (pointOfInterest != null)
                        {
                            IQuestRepositoryService service3 = service.Game.Services.GetService <IQuestRepositoryService>();
                            foreach (QuestMarker questMarker in service.Game.Services.GetService <IQuestManagementService>().GetMarkersByBoundTargetGUID(pointOfInterest.GUID))
                            {
                                Quest quest;
                                if (service3.TryGetValue(questMarker.QuestGUID, out quest) && quest.QuestDefinition.Name == "GlobalQuestCoop#0004" && quest.EmpireBits == army2.Empire.Bits && questMarker.IsVisibleFor(army2.Empire))
                                {
                                    this.orderTicket = null;
                                    QuestBehaviour questBehaviour = service3.GetQuestBehaviour(quest.Name, army2.Empire.Index);
                                    if (questBehaviour != null)
                                    {
                                        if (quest.QuestDefinition.Variables.First((QuestVariableDefinition p) => p.VarName == "$NameOfStrategicResourceToGather1") != null)
                                        {
                                            QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount questBehaviourTreeNode_ConditionCheck_HasResourceAmount;
                                            if (!ELCPUtilities.TryGetFirstNodeOfType <QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount>(questBehaviour.Root as BehaviourTreeNodeController, out questBehaviourTreeNode_ConditionCheck_HasResourceAmount))
                                            {
                                                break;
                                            }
                                            string resourceName            = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.ResourceName;
                                            int    wantedAmount            = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.WantedAmount;
                                            DepartmentOfTheTreasury agency = army2.Empire.GetAgency <DepartmentOfTheTreasury>();
                                            if (agency == null)
                                            {
                                                break;
                                            }
                                            float num;
                                            if (agency != null && agency.TryGetResourceStockValue(army2.Empire.SimulationObject, resourceName, out num, false) && num >= (float)wantedAmount)
                                            {
                                                return(State.Running);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            if ((pointOfInterest.Interaction.Bits & aiBehaviorTree.AICommander.Empire.Bits) != aiBehaviorTree.AICommander.Empire.Bits)
                            {
                                pointOfInterest.Interaction.Bits |= 1 << orderInteractWith.EmpireIndex;
                            }
                        }
                    }
                    aiBehaviorTree.ErrorCode = 30;
                    this.orderTicket         = null;
                    result = State.Failure;
                }
                else
                {
                    if (this.orderTicket.PostOrderResponse == PostOrderResponse.Processed && service2.TryGetValue(orderInteractWith.TargetGUID, out gameEntity) && gameEntity is PointOfInterest && orderInteractWith.Tags.Contains("Talk") && orderInteractWith.QuestRewards == null)
                    {
                        PointOfInterest pointOfInterest2 = gameEntity as PointOfInterest;
                        Diagnostics.Log("ELCP: Empire {0} AIBehaviorTreeNode_Action_SearchInRuin parley order without quest reward: {1} ", new object[]
                        {
                            aiBehaviorTree.AICommander.Empire.ToString(),
                            pointOfInterest2.WorldPosition
                        });
                        if (pointOfInterest2 != null)
                        {
                            pointOfInterest2.Interaction.Bits |= 1 << orderInteractWith.EmpireIndex;
                        }
                    }
                    this.orderTicket = null;
                    result           = State.Success;
                }
            }
        }
        else
        {
            Army army;
            if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
            {
                result = State.Failure;
            }
            else
            {
                if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
                {
                    aiBehaviorTree.LogError("${0} not set", new object[]
                    {
                        this.TargetVarName
                    });
                    return(State.Failure);
                }
                IGameEntity gameEntity2 = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
                if (!(gameEntity2 is IWorldPositionable) || (!(gameEntity2 is PointOfInterest) && !(gameEntity2 is Village)))
                {
                    aiBehaviorTree.ErrorCode = 10;
                    return(State.Failure);
                }
                if (gameEntity2 is Village)
                {
                    Village village = gameEntity2 as Village;
                    Diagnostics.Log("ELCP {0} {1} AIBehaviorTreeNode_Action_SearchInRuin village {2} {3}", new object[]
                    {
                        aiBehaviorTree.AICommander.Empire,
                        army.LocalizedName,
                        village.WorldPosition,
                        this.QuestVillage
                    });
                    PointOfInterest pointOfInterest3 = village.PointOfInterest;
                    if (pointOfInterest3 == null)
                    {
                        return(State.Failure);
                    }
                    if (!this.QuestVillage)
                    {
                        if (village.HasBeenConverted || village.HasBeenPacified || village.IsInEncounter || village.PointOfInterest.PointOfInterestImprovement == null)
                        {
                            return(State.Failure);
                        }
                        if (!aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfScience>().CanParley())
                        {
                            return(State.Failure);
                        }
                        if (pointOfInterest3.SimulationObject.Tags.Contains(Village.DissentedVillage))
                        {
                            return(State.Failure);
                        }
                        if ((pointOfInterest3.Interaction.Bits & army.Empire.Bits) != 0)
                        {
                            Diagnostics.Log("fail");
                            return(State.Failure);
                        }
                        QuestMarker questMarker2;
                        if (service.Game.Services.GetService <IQuestManagementService>().TryGetMarkerByGUID(pointOfInterest3.GUID, out questMarker2))
                        {
                            Diagnostics.Log("ELCP: Empire {0} AIBehaviorTreeNode_Action_SearchInRuin Questmarker active", new object[]
                            {
                                aiBehaviorTree.AICommander.Empire.ToString()
                            });
                            return(State.Failure);
                        }
                    }
                }
                Diagnostics.Assert(AIScheduler.Services != null);
                if (service.Game.Services.GetService <IWorldPositionningService>().GetDistance(army.WorldPosition, (gameEntity2 as IWorldPositionable).WorldPosition) != 1)
                {
                    aiBehaviorTree.ErrorCode = 12;
                    result = State.Failure;
                }
                else
                {
                    IEncounterRepositoryService service4 = service.Game.Services.GetService <IEncounterRepositoryService>();
                    if (service4 != null)
                    {
                        IEnumerable <Encounter> enumerable = service4;
                        if (enumerable != null && enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false)))
                        {
                            return(State.Running);
                        }
                    }
                    if (gameEntity2 is Village)
                    {
                        Diagnostics.Log("ELCP {0} {1} AIBehaviorTreeNode_Action_SearchInRuin2 village", new object[]
                        {
                            aiBehaviorTree.AICommander.Empire,
                            army.LocalizedName
                        });
                        PointOfInterest   pointOfInterest4   = (gameEntity2 as Village).PointOfInterest;
                        OrderInteractWith orderInteractWith2 = new OrderInteractWith(army.Empire.Index, army.GUID, "ArmyActionParley");
                        orderInteractWith2.WorldPosition = army.WorldPosition;
                        orderInteractWith2.Tags.AddTag("Talk");
                        orderInteractWith2.TargetGUID     = pointOfInterest4.GUID;
                        orderInteractWith2.ArmyActionName = "ArmyActionParley";
                        orderInteractWith2.NumberOfActionPointsToSpend = 0f;
                        aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderInteractWith2, out this.orderTicket, null);
                    }
                    else
                    {
                        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
                        {
                            Diagnostics.Log("~~~~~ ELCP: {0}/{1} ArmyActionSearch at {2}, {3} {4} ~~~~~", new object[]
                            {
                                army.LocalizedName,
                                army.Empire,
                                (gameEntity2 as PointOfInterest).WorldPosition,
                                ((gameEntity2 as PointOfInterest).Interaction.Bits & army.Empire.Bits) == army.Empire.Bits,
                                (gameEntity2 as PointOfInterest).UntappedDustDeposits
                            });
                        }
                        OrderInteractWith orderInteractWith3 = new OrderInteractWith(army.Empire.Index, army.GUID, "ArmyActionSearch");
                        orderInteractWith3.WorldPosition = army.WorldPosition;
                        orderInteractWith3.Tags.AddTag("Interact");
                        orderInteractWith3.TargetGUID = gameEntity2.GUID;
                        aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderInteractWith3, out this.orderTicket, null);
                    }
                    result = State.Running;
                }
            }
        }
        return(result);
    }
예제 #15
0
    void IDiplomaticContractManagement.SetDiplomaticState(DiplomaticContractState destinationState)
    {
        DiplomaticContractState state   = this.State;
        IGameService            service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        global::Game game = service.Game as global::Game;

        Diagnostics.Assert(game != null);
        this.TurnAtTheBeginningOfTheState = game.Turn;
        if (destinationState == DiplomaticContractState.Proposed && this.EmpireWhichProposes.IsControlledByAI && !this.EmpireWhichReceives.IsControlledByAI)
        {
            for (int i = this.terms.Count - 1; i >= 0; i--)
            {
                DiplomaticTermResourceExchange diplomaticTermResourceExchange = this.terms[i] as DiplomaticTermResourceExchange;
                if (diplomaticTermResourceExchange != null && diplomaticTermResourceExchange.EmpireWhichProvides.Index == this.EmpireWhichProposes.Index)
                {
                    DepartmentOfTheTreasury agency = diplomaticTermResourceExchange.EmpireWhichProvides.GetAgency <DepartmentOfTheTreasury>();
                    if (agency.TryTransferResources(diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.ResourceName, -diplomaticTermResourceExchange.Amount))
                    {
                        float num;
                        agency.TryGetResourceStockValue(diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.ResourceName, out num, false);
                        Diagnostics.Log("ELCP {0} with {1} Buffering Resource {2} {3}, providerstock2: {4}", new object[]
                        {
                            diplomaticTermResourceExchange.EmpireWhichProvides,
                            diplomaticTermResourceExchange.EmpireWhichReceives,
                            diplomaticTermResourceExchange.ResourceName,
                            diplomaticTermResourceExchange.Amount,
                            num
                        });
                        diplomaticTermResourceExchange.BufferedAmount = diplomaticTermResourceExchange.Amount;
                    }
                }
            }
        }
        if (destinationState == DiplomaticContractState.Negotiation || destinationState == DiplomaticContractState.Refused || destinationState == DiplomaticContractState.Ignored)
        {
            for (int j = this.terms.Count - 1; j >= 0; j--)
            {
                DiplomaticTermResourceExchange diplomaticTermResourceExchange2 = this.terms[j] as DiplomaticTermResourceExchange;
                if (diplomaticTermResourceExchange2 != null && diplomaticTermResourceExchange2.BufferedAmount > 0f)
                {
                    DepartmentOfTheTreasury agency2 = diplomaticTermResourceExchange2.EmpireWhichProvides.GetAgency <DepartmentOfTheTreasury>();
                    agency2.TryTransferResources(diplomaticTermResourceExchange2.EmpireWhichProvides, diplomaticTermResourceExchange2.ResourceName, diplomaticTermResourceExchange2.BufferedAmount);
                    float num2;
                    agency2.TryGetResourceStockValue(diplomaticTermResourceExchange2.EmpireWhichProvides, diplomaticTermResourceExchange2.ResourceName, out num2, false);
                    Diagnostics.Log("ELCP {0} with {1} UnBuffering Resource {2} {3} {4}, providerstock2: {5}", new object[]
                    {
                        diplomaticTermResourceExchange2.EmpireWhichProvides,
                        diplomaticTermResourceExchange2.EmpireWhichReceives,
                        diplomaticTermResourceExchange2.ResourceName,
                        diplomaticTermResourceExchange2.BufferedAmount,
                        diplomaticTermResourceExchange2.Amount,
                        num2
                    });
                    diplomaticTermResourceExchange2.BufferedAmount = 0f;
                }
            }
        }
        if (state == DiplomaticContractState.Proposed && destinationState == DiplomaticContractState.Negotiation)
        {
            global::Empire empireWhichProposes = this.EmpireWhichProposes;
            this.EmpireWhichProposes = this.EmpireWhichReceives;
            this.EmpireWhichReceives = empireWhichProposes;
            float empireWhichProposesEmpirePointInvestment = this.EmpireWhichProposesEmpirePointInvestment;
            this.EmpireWhichProposesEmpirePointInvestment = this.EmpireWhichReceivesEmpirePointInvestment;
            this.EmpireWhichReceivesEmpirePointInvestment = empireWhichProposesEmpirePointInvestment;
            for (int k = this.terms.Count - 1; k >= 0; k--)
            {
                DiplomaticTerm diplomaticTerm = this.terms[k];
                Diagnostics.Assert(diplomaticTerm != null);
                if (!diplomaticTerm.CanApply(this, new string[0]))
                {
                    this.terms.RemoveAt(k);
                }
            }
            int contractRevisionNumber = this.ContractRevisionNumber;
            this.ContractRevisionNumber = contractRevisionNumber + 1;
        }
        if (destinationState == DiplomaticContractState.Signed)
        {
            this.ApplyTerms();
        }
        Diagnostics.Log("Contract {0} pass from state {1} to state {2}.", new object[]
        {
            this.GUID,
            this.State,
            destinationState
        });
        this.State = destinationState;
        this.OnDiplomaticContractChange();
    }
예제 #16
0
    private void UpdateAccountBalance(StaticString resourceName, int[] accountIndexForResource)
    {
        DepartmentOfTheTreasury agency = base.AIEntity.Empire.GetAgency <DepartmentOfTheTreasury>();
        float num = 0f;
        float estimatedNetOutcome = 0f;

        agency.TryGetNetResourceValue(base.AIEntity.Empire, resourceName, out estimatedNetOutcome, false);
        float num2 = 0f;

        for (int i = 0; i < accountIndexForResource.Length; i++)
        {
            Account account = this.accounts[accountIndexForResource[i]];
            account.EstimatedNetOutcome = estimatedNetOutcome;
            if (account.MaxAccount >= 0f && account.MaxAccount <= account.EstimatedBalance)
            {
                account.EstimatedBalance = account.MaxAccount;
                num += account.MaxAccount;
            }
            else
            {
                num  += account.EstimatedBalance;
                num2 += account.CurrentProfitPercent;
            }
        }
        float num3 = 0f;

        if (num2 == 0f || !agency.TryGetResourceStockValue(base.AIEntity.Empire, resourceName, out num3, false) || num3 == 0f)
        {
            num3 = 0f;
            for (int j = 0; j < accountIndexForResource.Length; j++)
            {
                this.accounts[accountIndexForResource[j]].EstimatedBalance = 0f;
            }
            return;
        }
        float num4 = num3;

        num4 -= num;
        if (Mathf.Abs(num4) <= (float)accountIndexForResource.Length)
        {
            return;
        }
        if (num4 < 0f)
        {
            for (int k = 0; k < accountIndexForResource.Length; k++)
            {
                Account account2 = this.accounts[accountIndexForResource[k]];
                if (account2.CurrentProfitPercent < 0.01f)
                {
                    num4 += account2.EstimatedBalance;
                    account2.EstimatedBalance = 0f;
                    if (num4 >= 0f)
                    {
                        account2.EstimatedBalance = num4;
                        break;
                    }
                }
            }
        }
        int num5 = 0;

        while (Mathf.Abs(num4) > 0.1f && num5 < 100)
        {
            num5++;
            float num6 = 0f;
            for (int l = 0; l < accountIndexForResource.Length; l++)
            {
                Account account3 = this.accounts[accountIndexForResource[l]];
                if (num4 <= 0f || account3.MaxAccount < 0f || account3.MaxAccount > account3.EstimatedBalance)
                {
                    int   index = accountIndexForResource[l];
                    float num7  = num4 * (account3.CurrentProfitPercent / num2);
                    account3.EstimatedBalance += num7;
                    num6 += num7;
                    if (account3.EstimatedBalance < 0f)
                    {
                        num6 -= this.accounts[index].EstimatedBalance;
                        account3.EstimatedBalance = 0f;
                    }
                    if (account3.MaxAccount >= 0f && account3.MaxAccount < account3.EstimatedBalance)
                    {
                        num6 += account3.EstimatedBalance - account3.MaxAccount;
                        account3.EstimatedBalance = account3.MaxAccount;
                    }
                    if (num6 == num4)
                    {
                        break;
                    }
                }
            }
            num4 -= num6;
            num2  = 0f;
            for (int m = 0; m < accountIndexForResource.Length; m++)
            {
                Account account4 = this.accounts[accountIndexForResource[m]];
                if (account4.MaxAccount < 0f || account4.MaxAccount > account4.EstimatedBalance)
                {
                    num2 += this.accounts[accountIndexForResource[m]].CurrentProfitPercent;
                }
            }
        }
        if (num5 >= 100)
        {
            num2 = 0f;
            for (int n = 0; n < accountIndexForResource.Length; n++)
            {
                num2 += this.accounts[accountIndexForResource[n]].CurrentProfitPercent;
            }
            for (int num8 = 0; num8 < accountIndexForResource.Length; num8++)
            {
                Account account5 = this.accounts[accountIndexForResource[num8]];
                account5.EstimatedBalance = num3 * (this.accounts[accountIndexForResource[num8]].CurrentProfitPercent / num2);
            }
            Diagnostics.LogWarning("Account manager took too much time. Empire = {0}, resource = {1}", new object[]
            {
                base.AIEntity.Empire.Index,
                resourceName
            });
        }
    }