Ejemplo n.º 1
0
 public void ExecuteTransferResource(BoosterEffect effect)
 {
     if (effect.Transfer == null)
     {
         return;
     }
     for (int i = 0; i < effect.Transfer.Length; i++)
     {
         BoosterEffect.TransferResource transferResource = effect.Transfer[i];
         if (string.IsNullOrEmpty(transferResource.ResourceName))
         {
             Diagnostics.LogWarning("Booster '{0}': Transfer number {1} resource name is null or empty.", new object[]
             {
                 this.BoosterDefinition.Name,
                 i
             });
         }
         else
         {
             DepartmentOfTheTreasury agency = this.empire.GetAgency <DepartmentOfTheTreasury>();
             if (agency != null)
             {
                 agency.TryTransferResources(this.Context, transferResource.ResourceName, (float)transferResource.Amount);
             }
         }
     }
 }
    void IDiplomaticTermManagement.ApplyEffects()
    {
        Diagnostics.Assert(base.Definition is DiplomaticTermResourceExchangeDefinition);
        Diagnostics.Assert(base.EmpireWhichProvides != null && base.EmpireWhichReceives != null);
        Diagnostics.Assert(base.EmpireWhichProvides.Index != base.EmpireWhichReceives.Index);
        DepartmentOfTheTreasury agency  = base.EmpireWhichProvides.GetAgency <DepartmentOfTheTreasury>();
        DepartmentOfTheTreasury agency2 = base.EmpireWhichReceives.GetAgency <DepartmentOfTheTreasury>();

        Diagnostics.Assert(agency != null && agency2 != null);
        if (this.BufferedAmount > 0f && this.BufferedAmount >= this.Amount)
        {
            this.BufferedAmount = 0f;
        }
        else if (!agency.TryTransferResources(base.EmpireWhichProvides, this.ResourceName, -this.Amount))
        {
            Diagnostics.LogError("DiplomaticTermResourceExchange.ApplyEffect failed, can't debit the empire which provides the term (resource: {0} amount: {1})", new object[]
            {
                this.ResourceName,
                -this.Amount
            });
            return;
        }
        if (!agency2.TryTransferResources(base.EmpireWhichReceives, this.ResourceName, this.Amount))
        {
            Diagnostics.LogError("DiplomaticTermResourceExchange.ApplyEffect failed, can't credt the empire which receive the term (resource: {0} amount: {1})", new object[]
            {
                this.ResourceName,
                this.Amount
            });
            return;
        }
    }
Ejemplo n.º 3
0
    private void SelectUnitToShift(AIData_Army army, float maxCost, out float cost, out GameEntityGUID[] shiftingUnitGuids)
    {
        cost = 0f;
        List <GameEntityGUID>   list   = new List <GameEntityGUID>();
        DepartmentOfTheTreasury agency = army.Army.Empire.GetAgency <DepartmentOfTheTreasury>();

        foreach (Unit unit in army.Army.Units)
        {
            if (this.aiDataRepositoryHelper.IsGUIDValid(unit.GUID))
            {
                if (unit.CanShift())
                {
                    ConstructionCost unitForceShiftingCost = agency.GetUnitForceShiftingCost(unit);
                    float            value = unitForceShiftingCost.Value;
                    if (cost + value > maxCost)
                    {
                        break;
                    }
                    cost += value;
                    list.Add(unit.GUID);
                }
            }
        }
        shiftingUnitGuids = list.ToArray();
    }
Ejemplo n.º 4
0
    private float GetWonderProgress(MajorEmpire empire)
    {
        DepartmentOfTheInterior agency  = empire.GetAgency <DepartmentOfTheInterior>();
        DepartmentOfIndustry    agency2 = empire.GetAgency <DepartmentOfIndustry>();
        float num = 0f;

        for (int i = 0; i < agency.Cities.Count; i++)
        {
            Construction construction = agency2.GetConstructionQueue(agency.Cities[i]).Get((Construction x) => x.ConstructibleElement.SubCategory == "SubCategoryVictory");
            if (construction != null)
            {
                for (int j = 0; j < construction.CurrentConstructionStock.Length; j++)
                {
                    if (construction.CurrentConstructionStock[j].PropertyName == "Production")
                    {
                        float stock = construction.CurrentConstructionStock[j].Stock;
                        if (stock > 0f)
                        {
                            float num2 = stock / DepartmentOfTheTreasury.GetProductionCostWithBonus(agency.Cities[i], construction.ConstructibleElement, "Production");
                            if (num2 > num)
                            {
                                num = num2;
                            }
                        }
                    }
                }
            }
        }
        return(num);
    }
Ejemplo n.º 5
0
    private void UpdatePointOfInterestStatus(global::Empire empire, Region region, AIRegionData regionData)
    {
        regionData.NewStrategicRessourcesCount      = 0;
        regionData.OwnedStrategicRessourcesCount    = 0;
        regionData.ProducedStrategicRessourcesCount = 0;
        regionData.NewLuxuryRessourcesCount         = 0;
        regionData.OwnedLuxuryRessourcesCount       = 0;
        regionData.ProducedLuxuryRessourcesCount    = 0;
        regionData.ResourcePointOfInterestCount     = 0;
        regionData.WatchTowerPointOfInterestCount   = 0;
        regionData.BuiltExtractor  = 0;
        regionData.BuiltWatchTower = 0;
        DepartmentOfTheTreasury agency = empire.GetAgency <DepartmentOfTheTreasury>();

        for (int i = 0; i < region.PointOfInterests.Length; i++)
        {
            PointOfInterest pointOfInterest = region.PointOfInterests[i];
            if (pointOfInterest.Type == "ResourceDeposit")
            {
                this.UpdateResourceStatus(pointOfInterest, empire, region, regionData, agency);
            }
            else if (pointOfInterest.Type == "WatchTower")
            {
                if (pointOfInterest.PointOfInterestImprovement != null)
                {
                    regionData.BuiltWatchTower++;
                }
                regionData.WatchTowerPointOfInterestCount++;
            }
        }
    }
Ejemplo n.º 6
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));
    }
Ejemplo n.º 7
0
    private bool IsSpellAlreadyCasted(SpellDefinitionTooltipData spellDefinitionTooltipData, ref bool isThisSpellActive)
    {
        Contender firstAlliedContenderFromEmpireWithUnits = spellDefinitionTooltipData.Encounter.GetFirstAlliedContenderFromEmpireWithUnits(spellDefinitionTooltipData.Empire);

        foreach (SpellDefinition spellDefinition in this.spellDefinitionDatabase)
        {
            if (DepartmentOfTheTreasury.CheckConstructiblePrerequisites(spellDefinitionTooltipData.Empire, spellDefinition, new string[]
            {
                ConstructionFlags.Prerequisite
            }))
            {
                for (int i = 0; i < spellDefinition.SpellBattleActions.Length; i++)
                {
                    StaticString       name = spellDefinition.SpellBattleActions[i].BattleActionUserDefinitionReference.Name;
                    BattleAction.State state;
                    if (firstAlliedContenderFromEmpireWithUnits.TryGetBattleActionUserState(name, out state) && state != BattleAction.State.Available)
                    {
                        isThisSpellActive = (spellDefinition.Name == spellDefinitionTooltipData.SpellDefinition.Name);
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Ejemplo n.º 8
0
    public void SetContent(SpellDefinition spellDefinition, Empire empire, GameObject client, bool isInTargetingPhase, bool thereAlreadyIsASpellCasted, Encounter encounter)
    {
        if (empire == null)
        {
            return;
        }
        this.SpellDefinition = spellDefinition;
        this.Empire          = empire;
        this.client          = client;
        this.ShowIcon();
        this.AgeTransform.AgeTooltip.Content    = this.SpellDefinition.Name;
        this.AgeTransform.AgeTooltip.Class      = "Spell";
        this.AgeTransform.AgeTooltip.ClientData = new SpellDefinitionTooltipData(this.Empire, this.Empire, this.SpellDefinition, encounter);
        bool enable;

        if (!isInTargetingPhase)
        {
            enable = false;
        }
        else if (thereAlreadyIsASpellCasted)
        {
            enable = false;
        }
        else
        {
            DepartmentOfTheTreasury     agency = this.Empire.GetAgency <DepartmentOfTheTreasury>();
            ConstructionResourceStock[] array;
            enable = (!ELCPUtilities.SpellUsage_HasSpellBeenUsed(encounter.GUID, empire.Index, spellDefinition.Name) && agency.GetInstantConstructionResourceCostForBuyout(empire, spellDefinition, out array));
        }
        this.AgeTransform.Enable = enable;
    }
Ejemplo n.º 9
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));
    }
Ejemplo n.º 10
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());
    }
Ejemplo n.º 11
0
    internal virtual void OnEmpireEliminated(global::Empire empire, bool authorized)
    {
        DepartmentOfDefense agency = base.GetAgency <DepartmentOfDefense>();

        if (agency != null)
        {
            agency.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfEducation agency2 = base.GetAgency <DepartmentOfEducation>();

        if (agency2 != null)
        {
            agency2.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfTheInterior agency3 = base.GetAgency <DepartmentOfTheInterior>();

        if (agency3 != null)
        {
            agency3.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfCreepingNodes agency4 = base.GetAgency <DepartmentOfCreepingNodes>();

        if (agency4 != null)
        {
            agency4.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfTheTreasury agency5 = base.GetAgency <DepartmentOfTheTreasury>();

        if (agency5 != null)
        {
            agency5.OnEmpireEliminated(empire, authorized);
        }
    }
Ejemplo n.º 12
0
    private void RefreshCostGroup(DepartmentOfScience.ConstructibleElement.State state)
    {
        bool flag = state != DepartmentOfScience.ConstructibleElement.State.Researched && state != DepartmentOfScience.ConstructibleElement.State.ResearchedButUnavailable;

        if (this.ShowCaptionCost && flag)
        {
            Amplitude.Unity.Gui.IGuiService service = Services.GetService <global::IGuiService>();
            Diagnostics.Assert(service != null);
            DepartmentOfTheTreasury agency = this.empire.GetAgency <DepartmentOfTheTreasury>();
            Diagnostics.Assert(agency != null);
            string empty = string.Empty;
            int    num   = 0;
            PanelFeatureCost.ComputeCostAndTurn(service, this.TechnologyDefinition, agency, this.empire, out empty, out num);
            if (string.IsNullOrEmpty(empty))
            {
                this.CaptionCostGroup.Visible = false;
            }
            else
            {
                this.CostLabel.Text           = empty;
                this.CaptionCostGroup.Visible = true;
            }
        }
        else if (this.CaptionCostGroup != null)
        {
            this.CaptionCostGroup.Visible = false;
        }
    }
Ejemplo n.º 13
0
    protected List <AILayer_CreepingNode.EvaluableCreepingNode> GetAvailableNodes()
    {
        List <AILayer_CreepingNode.EvaluableCreepingNode> list = new List <AILayer_CreepingNode.EvaluableCreepingNode>();
        List <StaticString> list2 = new List <StaticString>();

        CreepingNodeImprovementDefinition[] values = this.creepingNodeDefinitionDatabase.GetValues();
        for (int i = 0; i < this.worldPositionningService.World.Regions.Length; i++)
        {
            Region region = this.worldPositionningService.World.Regions[i];
            int    num    = region.IsRegionColonized() ? 1 : 0;
            bool   flag   = region.Kaiju != null;
            bool   flag2  = region.BelongToEmpire(base.AIEntity.Empire);
            bool   flag3  = false;
            if (ELCPUtilities.UseELCPPeacefulCreepingNodes && !flag2 && region.Owner != null && region.Owner is MajorEmpire)
            {
                flag3 = (this.departmentOfForeignAffairs.IsFriend(region.Owner) && this.departmentOfForeignAffairs.CanMoveOn(region.Index, false));
            }
            bool flag4 = false;
            if (flag)
            {
                flag4 = (region.Kaiju.IsWild() || region.Kaiju.OwnerEmpireIndex == base.AIEntity.Empire.Index);
            }
            if (num == 0 || flag2 || flag3 || (flag && flag4))
            {
                foreach (PointOfInterest pointOfInterest in region.PointOfInterests)
                {
                    bool flag5 = this.departmentOfCreepingNodes.POIIsOnCooldown(pointOfInterest.GUID);
                    if ((!flag3 || pointOfInterest.Type == "QuestLocation") && !flag5)
                    {
                        bool flag6 = this.IsPoiUnlocked(pointOfInterest);
                        if (pointOfInterest.CreepingNodeImprovement == null && (!(pointOfInterest.Type != "Village") || pointOfInterest.PointOfInterestImprovement == null) && ((this.worldPositionningService.GetExplorationBits(pointOfInterest.WorldPosition) & base.AIEntity.Empire.Bits) > 0 && flag6))
                        {
                            foreach (CreepingNodeImprovementDefinition creepingNodeImprovementDefinition in values)
                            {
                                if (creepingNodeImprovementDefinition.PointOfInterestTemplateName == pointOfInterest.PointOfInterestDefinition.PointOfInterestTemplateName && (!(pointOfInterest.Type == "Village") || (pointOfInterest.SimulationObject.Tags.Contains(Village.PacifiedVillage) && !pointOfInterest.SimulationObject.Tags.Contains(Village.ConvertedVillage))))
                                {
                                    list2.Clear();
                                    DepartmentOfTheTreasury.CheckConstructiblePrerequisites(this.aiEntityCity.City, creepingNodeImprovementDefinition, ref list2, new string[]
                                    {
                                        ConstructionFlags.Prerequisite
                                    });
                                    if (!list2.Contains(ConstructionFlags.Discard) && this.departmentOfTheTreasury.CheckConstructibleInstantCosts(this.aiEntityCity.City, creepingNodeImprovementDefinition))
                                    {
                                        CreepingNodeImprovementDefinition          bestCreepingNodeDefinition = this.departmentOfCreepingNodes.GetBestCreepingNodeDefinition(this.aiEntityCity.City, pointOfInterest, creepingNodeImprovementDefinition, list2);
                                        AILayer_CreepingNode.EvaluableCreepingNode item = new AILayer_CreepingNode.EvaluableCreepingNode(pointOfInterest, bestCreepingNodeDefinition);
                                        if (!list.Contains(item))
                                        {
                                            list.Add(item);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return(list);
    }
Ejemplo n.º 14
0
    public static bool CanELCPTameKaiju(Kaiju kaiju, KaijuTameCost tameCost, global::Empire empire)
    {
        KaijuCouncil            agency  = kaiju.KaijuEmpire.GetAgency <KaijuCouncil>();
        float                   num     = -tameCost.GetValue(empire.SimulationObject);
        DepartmentOfTheTreasury agency2 = empire.GetAgency <DepartmentOfTheTreasury>();

        return(agency2 != null && agency2.IsTransferOfResourcePossible(empire, agency.ELCPResourceName, ref num));
    }
Ejemplo n.º 15
0
    private float ScoreTransferFunctionDelegate(ConstructibleElement constructibleElement, float score)
    {
        EmpirePlanDefinition empirePlanDefinition = constructibleElement as EmpirePlanDefinition;

        Diagnostics.Assert(empirePlanDefinition != null);
        float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.AIEntity.Empire.SimulationObject, empirePlanDefinition, DepartmentOfTheTreasury.Resources.EmpirePoint);

        return((productionCostWithBonus <= float.Epsilon) ? score : (score / productionCostWithBonus));
    }
Ejemplo n.º 16
0
    private bool CanAfford(Tradable tradable, int quantity)
    {
        DepartmentOfTheTreasury agency = base.Empire.GetAgency <DepartmentOfTheTreasury>();
        float priceWithSalesTaxes      = tradable.GetPriceWithSalesTaxes(TradableTransactionType.Buyout, base.Empire, (float)quantity);

        return(agency.CanAfford(new ConstructionCost[]
        {
            new ConstructionCost(DepartmentOfTheTreasury.Resources.EmpireMoney, priceWithSalesTaxes, true, false)
        }));
    }
Ejemplo n.º 17
0
 public void Bind(City city)
 {
     this.City                    = city;
     this.IsOtherEmpire           = (this.playerControllerRepository.ActivePlayerController.Empire != this.City.Empire);
     this.keyMappingService       = Services.GetService <IKeyMappingService>();
     this.FilterTable.Visible     = !this.IsOtherEmpire;
     this.DepartmentOfTheTreasury = this.City.Empire.GetAgency <DepartmentOfTheTreasury>();
     this.departmentOfPlanificationAndDevelopment = this.city.Empire.GetAgency <DepartmentOfPlanificationAndDevelopment>();
     this.departmentOfForeignAffairs = this.city.Empire.GetAgency <DepartmentOfForeignAffairs>();
 }
Ejemplo n.º 18
0
 public static void ComputeCostAndTurn(Amplitude.Unity.Gui.IGuiService guiService, ReadOnlyCollection <Construction> constructibles, DepartmentOfTheTreasury departmentOfTheTreasury, SimulationObjectWrapper context, out string costString, out int turn)
 {
     PanelFeatureCost.costByResource.Clear();
     for (int i = 0; i < constructibles.Count; i++)
     {
         ConstructibleElement constructibleElement = constructibles[i].ConstructibleElement;
         if (constructibleElement.Costs != null)
         {
             if (constructibleElement is TechnologyDefinition && context.SimulationObject.Tags.Contains(FactionTrait.FactionTraitReplicants1) && (constructibleElement as TechnologyDefinition).TechnologyFlags != DepartmentOfScience.ConstructibleElement.TechnologyFlag.OrbUnlock && (constructibleElement as TechnologyDefinition).TechnologyFlags != DepartmentOfScience.ConstructibleElement.TechnologyFlag.KaijuUnlock)
             {
                 costString = string.Empty;
                 turn       = -1;
                 global::Empire empire = context as global::Empire;
                 if (empire == null)
                 {
                     Diagnostics.LogError("Empire is null.");
                     return;
                 }
                 DepartmentOfScience agency = empire.GetAgency <DepartmentOfScience>();
                 if (agency == null)
                 {
                     Diagnostics.LogError("Department of science is null");
                     return;
                 }
                 float buyOutTechnologyCost = agency.GetBuyOutTechnologyCost(constructibleElement);
                 if (buyOutTechnologyCost != 3.40282347E+38f)
                 {
                     costString = GuiFormater.FormatInstantCost(empire, buyOutTechnologyCost, DepartmentOfTheTreasury.Resources.EmpireMoney, true, 0);
                     return;
                 }
                 costString = "-";
                 return;
             }
             else
             {
                 for (int j = 0; j < constructibleElement.Costs.Length; j++)
                 {
                     if (constructibleElement.Costs[j] is PopulationConstructionCost)
                     {
                         PopulationConstructionCost populationConstructionCost = constructibleElement.Costs[j] as PopulationConstructionCost;
                         PanelFeatureCost.AppendCost(SimulationProperties.Population, populationConstructionCost.PopulationValue, true);
                     }
                     else
                     {
                         float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(context, constructibleElement, constructibleElement.Costs[j], true);
                         PanelFeatureCost.AppendCost(constructibleElement.Costs[j].ResourceName, productionCostWithBonus, constructibleElement.Costs[j].Instant || constructibleElement.Costs[j].InstantOnCompletion);
                     }
                 }
             }
         }
     }
     PanelFeatureCost.GetCostAndTurn(guiService, departmentOfTheTreasury, context, out costString, out turn);
 }
Ejemplo n.º 19
0
 public override void Bind(global::Empire empire)
 {
     if (empire == null)
     {
         throw new ArgumentNullException("empire");
     }
     base.Bind(empire);
     this.Kaijus = new List <Kaiju>();
     this.DepartmentOfTheTreasury = base.Empire.GetAgency <DepartmentOfTheTreasury>();
     this.KaijuUnlocksFrame.SetupFrame(base.Empire, base.gameObject);
     base.NeedRefresh = true;
 }
Ejemplo n.º 20
0
    private SynchronousJobState SynchronousJob_ChangeEmpirePlan()
    {
        if (this.empirePlanClasses == null)
        {
            this.empirePlanMessages.Clear();
            return(SynchronousJobState.Failure);
        }
        float num = 0f;
        AILayer_AccountManager layer = base.AIEntity.GetLayer <AILayer_AccountManager>();

        Diagnostics.Assert(layer != null);
        Account account = layer.TryGetAccount(AILayer_AccountManager.EmpirePlanAccountName);

        if (account == null)
        {
            this.empirePlanMessages.Clear();
            return(SynchronousJobState.Failure);
        }
        if (this.empirePlanMessages.Count != this.empirePlanClasses.Length)
        {
            Diagnostics.LogError("There must be one empire plan evaluable message by empire plan class.");
            this.empirePlanMessages.Clear();
            return(SynchronousJobState.Failure);
        }
        for (int i = 0; i < this.empirePlanMessages.Count; i++)
        {
            EvaluableMessage_EmpirePlan evaluableMessage_EmpirePlan = this.empirePlanMessages[i];
            if (this.departmentOfPlanification.IsEmpirePlanChoiced)
            {
                evaluableMessage_EmpirePlan.SetObtained();
            }
            else
            {
                EmpirePlanDefinition empirePlanDefinition = this.departmentOfPlanification.GetEmpirePlanDefinition(evaluableMessage_EmpirePlan.EmpirePlanClass, evaluableMessage_EmpirePlan.EmpirePlanLevel);
                if (empirePlanDefinition != null)
                {
                    float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.AIEntity.Empire.SimulationObject, empirePlanDefinition, DepartmentOfTheTreasury.Resources.EmpirePoint);
                    if (num + productionCostWithBonus <= account.PromisedAmount)
                    {
                        num += productionCostWithBonus;
                        OrderChangeEmpirePlan order = new OrderChangeEmpirePlan(base.AIEntity.Empire.Index, empirePlanDefinition.EmpirePlanClass, empirePlanDefinition.EmpirePlanLevel);
                        Ticket ticket;
                        base.AIEntity.Empire.PlayerControllers.Client.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderChangeEmpirePlan_TicketRaised));
                    }
                }
            }
        }
        this.empirePlanMessages.Clear();
        return(SynchronousJobState.Success);
    }
Ejemplo n.º 21
0
    public void FilterHighestItemTier()
    {
        this.HighestItemTiers.Clear();
        string       itemType = string.Empty;
        string       text     = string.Empty;
        StaticString x        = StaticString.Empty;

        foreach (ItemDefinition itemDefinition in this.allItems)
        {
            if (!itemDefinition.Hidden && DepartmentOfTheTreasury.CheckConstructiblePrerequisites(this.editableUnitDesign.GetSimulationObject(), itemDefinition, new string[]
            {
                "Discard"
            }))
            {
                itemType = itemDefinition.SubCategory;
                for (int i = 0; i < itemDefinition.Descriptors.Length; i++)
                {
                    if (itemDefinition.Descriptors[i].Type == "ItemTier")
                    {
                        x = itemDefinition.Descriptors[i].Name;
                    }
                    if (itemDefinition.Descriptors[i].Type == "ItemMaterial")
                    {
                        text = itemDefinition.Descriptors[i].Name;
                    }
                }
                bool flag = false;
                if (x != ForgePanel.ItemTier4)
                {
                    for (int j = 0; j < this.HighestItemTiers.Count; j++)
                    {
                        if (this.HighestItemTiers[j].MatchesTypeAndRessource(itemType, text))
                        {
                            if (string.Compare(x, this.HighestItemTiers[j].Tier) > 0)
                            {
                                this.HighestItemTiers[j].Tier = x;
                            }
                            flag = true;
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    this.HighestItemTiers.Add(new ForgePanel.ObsolescenceGroup(itemType, text, x));
                }
            }
        }
    }
    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);
    }
Ejemplo n.º 23
0
    private void BuildAvailableSpellsDefinitions()
    {
        this.availableSpellDefinitions.Clear();
        IDatabase <SpellDefinition> database = Databases.GetDatabase <SpellDefinition>(false);

        if (database != null)
        {
            this.availableSpellDefinitions.AddRange(from spellDefinition in database.GetValues()
                                                    where DepartmentOfTheTreasury.CheckConstructiblePrerequisites(base.Empire, spellDefinition, new string[]
            {
                ConstructionFlags.Prerequisite
            })
                                                    select spellDefinition);
        }
    }
Ejemplo n.º 24
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);
    }
Ejemplo n.º 25
0
 public void Unbind()
 {
     this.DepartmentOfScience     = null;
     this.DepartmentOfTheTreasury = null;
     if (this.City != null)
     {
         this.CityWorkersPanel.Unbind();
         base.GuiService.GetGuiPanel <CityManagementPanel>().Unbind();
         for (int i = 0; i < this.valuesFIDS.Count; i++)
         {
             SimulationPropertyTooltipData simulationPropertyTooltipData = this.valuesFIDS[i].AgeTransform.AgeTooltip.ClientData as SimulationPropertyTooltipData;
             if (simulationPropertyTooltipData != null)
             {
                 simulationPropertyTooltipData.Context = null;
             }
         }
         if (this.ApprovalGaugeTooltip.AgeTooltip != null)
         {
             SimulationPropertyTooltipData simulationPropertyTooltipData = this.ApprovalGaugeTooltip.AgeTooltip.ClientData as SimulationPropertyTooltipData;
             if (simulationPropertyTooltipData != null)
             {
                 simulationPropertyTooltipData.Context = null;
             }
         }
         if (this.ApprovalState.AgeTransform.AgeTooltip != null)
         {
             this.ApprovalState.AgeTransform.AgeTooltip.ClientData = null;
         }
         if (this.GaugePopulationTooltip.AgeTooltip != null)
         {
             SimulationPropertyTooltipData simulationPropertyTooltipData = this.GaugePopulationTooltip.AgeTooltip.ClientData as SimulationPropertyTooltipData;
             if (simulationPropertyTooltipData != null)
             {
                 simulationPropertyTooltipData.Context = null;
             }
         }
         if (this.PopulationCountGroup != null && this.PopulationCountGroup.AgeTooltip != null)
         {
             SimulationPropertyTooltipData simulationPropertyTooltipData = this.PopulationCountGroup.AgeTooltip.ClientData as SimulationPropertyTooltipData;
             if (simulationPropertyTooltipData != null)
             {
                 simulationPropertyTooltipData.Context = null;
             }
         }
         this.City = null;
     }
 }
Ejemplo n.º 26
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());
    }
Ejemplo n.º 27
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)));
    }
Ejemplo n.º 28
0
    public DepartmentOfScience.ConstructibleElement.State GetTechnologyState(ConstructibleElement technology, Empire empire)
    {
        if (technology == null)
        {
            throw new ArgumentNullException("technology");
        }
        ConstructionQueue constructionQueue = null;

        if (!this.researchQueues.TryGetValue(empire.Index, out constructionQueue))
        {
            Diagnostics.LogError("The provided empire does not have a construction queue. Make sure one is created.");
            return(DepartmentOfScience.ConstructibleElement.State.NotAvailable);
        }
        if (this.researchedTechNames.Contains(technology.Name))
        {
            if (empire is MajorEmpire && !DepartmentOfTheTreasury.CheckConstructiblePrerequisites(empire, technology, new string[]
            {
                ConstructionFlags.Prerequisite
            }))
            {
                return(DepartmentOfScience.ConstructibleElement.State.ResearchedButUnavailable);
            }
            return(DepartmentOfScience.ConstructibleElement.State.Researched);
        }
        else
        {
            Diagnostics.Assert(constructionQueue != null);
            Construction construction = constructionQueue.Get(technology);
            if (construction != null && construction.ConstructibleElement.Name == technology.Name)
            {
                return(DepartmentOfScience.ConstructibleElement.State.InProgress);
            }
            if (constructionQueue.Contains(technology))
            {
                return(DepartmentOfScience.ConstructibleElement.State.Queued);
            }
            if (!DepartmentOfTheTreasury.CheckConstructiblePrerequisites(empire, technology, new string[]
            {
                ConstructionFlags.Prerequisite
            }))
            {
                return(DepartmentOfScience.ConstructibleElement.State.NotAvailable);
            }
            return(DepartmentOfScience.ConstructibleElement.State.Available);
        }
    }
Ejemplo n.º 29
0
    public static void RefreshPopulationBuyoutButton(Amplitude.Unity.Game.Empire observer, City city, AgeControlButton populationBuyoutButton)
    {
        if (observer != city.Empire)
        {
            populationBuyoutButton.AgeTransform.Enable = false;
            return;
        }
        float propertyValue            = city.GetPropertyValue(SimulationProperties.CityGrowthStock);
        float propertyValue2           = city.GetPropertyValue(SimulationProperties.NetCityGrowth);
        float propertyValue3           = city.GetPropertyValue(SimulationProperties.Population);
        DepartmentOfTheInterior agency = city.Empire.GetAgency <DepartmentOfTheInterior>();
        float num;
        float num2;

        agency.GetGrowthLimits(propertyValue3, out num, out num2);
        if (propertyValue + propertyValue2 >= num2)
        {
            populationBuyoutButton.AgeTransform.Enable             = false;
            populationBuyoutButton.AgeTransform.AgeTooltip.Content = AgeLocalizer.Instance.LocalizeString("%CityBuyoutPopulationNotNeededDescription");
            return;
        }
        float propertyValue4 = city.Empire.GetPropertyValue(SimulationProperties.PopulationBuyoutCooldown);

        if (propertyValue4 > 0f)
        {
            populationBuyoutButton.AgeTransform.Enable             = false;
            populationBuyoutButton.AgeTransform.AgeTooltip.Content = AgeLocalizer.Instance.LocalizeString("%CityBuyoutPopulationCooldownDescription").Replace("$Cooldown", propertyValue4.ToString());
            return;
        }
        float num3 = -DepartmentOfTheTreasury.GetPopulationBuyOutCost(city);
        ResourceDefinition      resourceDefinition = ResourceDefinition.GetResourceDefinition(DepartmentOfTheTreasury.Resources.PopulationBuyout);
        string                  newValue           = GuiFormater.FormatInstantCost(city.Empire, -num3, resourceDefinition.GetName(city.Empire), true, 0);
        DepartmentOfTheTreasury agency2            = city.Empire.GetAgency <DepartmentOfTheTreasury>();

        if (agency2.IsTransferOfResourcePossible(city.Empire, DepartmentOfTheTreasury.Resources.PopulationBuyout, ref num3))
        {
            populationBuyoutButton.AgeTransform.Enable             = CityInfoPanel.interactionsAllowed;
            populationBuyoutButton.AgeTransform.AgeTooltip.Content = AgeLocalizer.Instance.LocalizeString("%CityBuyoutPopulationDescription").Replace("$Cost", newValue);
        }
        else
        {
            populationBuyoutButton.AgeTransform.Enable             = false;
            populationBuyoutButton.AgeTransform.AgeTooltip.Content = AgeLocalizer.Instance.LocalizeString("%CityCannotBuyoutPopulationDescription").Replace("$Cost", newValue);
        }
    }
Ejemplo n.º 30
0
 protected override void EvaluateNeeds(StaticString context, StaticString pass)
 {
     base.EvaluateNeeds(context, pass);
     Diagnostics.Assert(this.empirePlanMessages != null && this.empirePlanMessages.Count == 0);
     if (!this.departmentOfPlanification.IsEmpirePlanChoiceTurn)
     {
         return;
     }
     this.empirePlanMessages.AddRange(base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage_EmpirePlan>(BlackboardLayerID.Empire, (EvaluableMessage_EmpirePlan match) => match.EvaluationState == EvaluableMessage.EvaluableMessageState.Pending));
     this.empirePlanMessages.Sort((EvaluableMessage_EmpirePlan left, EvaluableMessage_EmpirePlan right) => - 1 * left.Interest.CompareTo(right.Interest));
     for (int i = 0; i < this.empirePlanMessages.Count; i++)
     {
         EvaluableMessage_EmpirePlan evaluableMessage_EmpirePlan = this.empirePlanMessages[i];
         EmpirePlanDefinition        empirePlanDefinition        = this.departmentOfPlanification.GetEmpirePlanDefinition(evaluableMessage_EmpirePlan.EmpirePlanClass, evaluableMessage_EmpirePlan.EmpirePlanLevel);
         float productionCostWithBonus = DepartmentOfTheTreasury.GetProductionCostWithBonus(base.AIEntity.Empire.SimulationObject, empirePlanDefinition, DepartmentOfTheTreasury.Resources.EmpirePoint);
         evaluableMessage_EmpirePlan.UpdateBuyEvaluation("EmpirePlan", 0UL, productionCostWithBonus, 2, 0f, 0UL);
     }
 }