예제 #1
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)
        }));
    }
예제 #2
0
 public void RefreshCanExecute()
 {
     if (this.ArmyAction != null)
     {
         this.failure.Clear();
         bool flag = this.ArmyAction.CanExecute(this.Army, ref this.failure, new object[]
         {
             this.Target,
             this.UnitsSelection
         }) && !this.failure.Contains(ArmyAction.NoCanDoWhileMoving) && !this.failure.Contains(ArmyAction.NoCanDoWhileTutorial);
         if (flag)
         {
             ArmyAction_Bribe armyAction_Bribe = this.ArmyAction as ArmyAction_Bribe;
             if (armyAction_Bribe != null)
             {
                 Village village = this.Target as Village;
                 if (village != null)
                 {
                     DepartmentOfTheTreasury agency     = this.Army.Empire.GetAgency <DepartmentOfTheTreasury>();
                     ConstructionCost[]      bribeCosts = armyAction_Bribe.GetBribeCosts(this.Army, village);
                     flag = agency.CanAfford(bribeCosts);
                 }
             }
         }
         this.AgeTransform.Enable = flag;
         if (this.failure.Count > 0)
         {
             this.AgeTransform.AgeTooltip.Content = "%" + this.failure[0] + "Description";
             if (this.ArmyAction is ArmyActionWithCooldown)
             {
                 string text = AgeLocalizer.Instance.LocalizeString(this.AgeTransform.AgeTooltip.Content);
                 if (!string.IsNullOrEmpty(text))
                 {
                     float num = (this.ArmyAction as ArmyActionWithCooldown).ComputeRemainingCooldownDuration(this.Army);
                     this.AgeTransform.AgeTooltip.Content = text.Replace("$RemainingCooldownDuration", num.ToString());
                 }
             }
         }
         else
         {
             this.AgeTransform.AgeTooltip.Content = string.Empty;
         }
     }
 }
예제 #3
0
 private bool CanConvertVillage(Army army, Village village, DepartmentOfTheTreasury departmentOfTheTreasury, List <StaticString> failureFlags)
 {
     if (village == null)
     {
         failureFlags.Add(ArmyAction.NoCanDoWhileSystemError);
         return(false);
     }
     if (village.HasBeenConverted)
     {
         failureFlags.Add(ArmyAction_Convert.NoCanDoWhileVillageIsAlreadyConverted);
         return(false);
     }
     if (!village.HasBeenPacified)
     {
         failureFlags.Add(ArmyAction_BaseVillage.NoCanDoWhileVillageIsNotPacified);
         return(false);
     }
     if (village.PointOfInterest.SimulationObject.Tags.Contains(DepartmentOfDefense.PillageStatusDescriptor))
     {
         failureFlags.Add(ArmyAction_Convert.NoCanDoWhileVillageIsPillaged);
         return(false);
     }
     if (village.PointOfInterest.SimulationObject.Tags.Contains(DepartmentOfCreepingNodes.InfectedPointOfInterest))
     {
         failureFlags.Add(ArmyAction_Convert.NoCanDoWhileVillageIsInfected);
         return(false);
     }
     ConstructionCost[] convertionCost = this.GetConvertionCost(army, village);
     if (!departmentOfTheTreasury.CanAfford(convertionCost))
     {
         failureFlags.Add(ArmyAction_Convert.NoCanDoWhileCannotAfford);
         this.lastConvertCostDescription = GuiFormater.FormatCost(army.Empire, convertionCost, false, 1, null);
         return(false);
     }
     return(true);
 }
    public void RefreshActionAvailability(DepartmentOfTheTreasury departmentOfTheTreasury, int infiltrationLevel, InterpreterContext interpreterContext, Amplitude.Unity.Gui.IGuiService guiService)
    {
        this.CurrentAction = this.InfiltrationActions.FirstOrDefault((InfiltrationAction infiltrationAction) => infiltrationAction.Level == infiltrationLevel);
        if (this.CurrentAction == null)
        {
            this.CurrentAction = (from infiltrationAction in this.InfiltrationActions
                                  where infiltrationAction.Level < infiltrationLevel
                                  select infiltrationAction).LastOrDefault <InfiltrationAction>();
            if (this.CurrentAction == null)
            {
                this.CurrentAction = (from infiltrationAction in this.InfiltrationActions
                                      where infiltrationAction.Level > infiltrationLevel
                                      select infiltrationAction).FirstOrDefault <InfiltrationAction>();
            }
        }
        this.FailuresFlags.Clear();
        if (interpreterContext != null)
        {
            this.IsValid = this.CurrentAction.CanExecute(interpreterContext, ref this.failuresFlags, new object[0]);
            if (!this.IsValid)
            {
                this.IsValid = !this.failuresFlags.Contains(ConstructionFlags.Discard);
            }
            this.IsValid &= (this.CurrentAction.Level <= infiltrationLevel);
        }
        else
        {
            this.failuresFlags.Add(InfiltrationAction.NoCanDoWithoutInfiltratedSpy);
            this.IsValid = false;
        }
        GuiInfiltrationActionGroup.ComputeInfiltrationActionGuiElement(guiService, this.CurrentAction, out this.actionGuiElement);
        GuiInfiltrationActionGroup.ComputeInfiltrationActionSubCategoryTexture(guiService, this.CurrentAction, out this.subCategoryTexture);
        this.InfiltrationActionCostString.Clear();
        List <string> list = new List <string>();
        int           i    = 0;

        while (i < this.InfiltrationActions.Count)
        {
            list.Clear();
            if (interpreterContext == null || departmentOfTheTreasury == null)
            {
                goto IL_228;
            }
            this.InfiltrationActions[i].ComputeConstructionCost(interpreterContext);
            if (InfiltrationAction.Context.ConstructionCosts == null)
            {
                goto IL_228;
            }
            for (int j = 0; j < InfiltrationAction.Context.ConstructionCosts.Length; j++)
            {
                ConstructionCost constructionCost = InfiltrationAction.Context.ConstructionCosts[j];
                string           item             = ((!departmentOfTheTreasury.CanAfford(constructionCost.Value, constructionCost.ResourceName)) ? "#DF1010#" : string.Empty) + string.Format("{0}{1}", GuiFormater.FormatGui(constructionCost.Value, false, true, false, 1), guiService.FormatSymbol(constructionCost.ResourceName));
                list.Add(item);
            }
            this.InfiltrationActionCostString.Add(string.Join(" ", list.ToArray()));
IL_238:
            i++;
            continue;
IL_228:
            this.InfiltrationActionCostString.Add("-");
            goto IL_238;
        }
    }