예제 #1
0
    private bool CanTransferTo(Army army, WorldPosition worldPosition, ref bool atLeastOneNeighbourgCityWithNotEnoughSlotsLeft, ref bool atLeastOneNeighbourgVillageWithNotEnoughSlotsLeft, IWorldPositionningService worldPositionningService, int transferringUnitSlot)
    {
        Region region = worldPositionningService.GetRegion(worldPosition);

        if (region.City != null && region.City.Empire == army.Empire)
        {
            int i = 0;
            while (i < region.City.Districts.Count)
            {
                if (region.City.Districts[i].Type != DistrictType.Exploitation && region.City.Districts[i].Type != DistrictType.Improvement && worldPosition == region.City.Districts[i].WorldPosition)
                {
                    if (transferringUnitSlot + region.City.CurrentUnitSlot > region.City.MaximumUnitSlot)
                    {
                        atLeastOneNeighbourgCityWithNotEnoughSlotsLeft = true;
                        break;
                    }
                    if (army.WorldPosition == worldPosition)
                    {
                        return(true);
                    }
                    if (region.City.BesiegingEmpireIndex < 0 || (army.Hero != null && army.Hero.CheckUnitAbility(UnitAbility.UnitAbilityAllowAssignationUnderSiege, -1)))
                    {
                        return(true);
                    }
                    break;
                }
                else
                {
                    i++;
                }
            }
        }
        if (region != null && region.MinorEmpire != null)
        {
            BarbarianCouncil agency = region.MinorEmpire.GetAgency <BarbarianCouncil>();
            if (agency != null)
            {
                Village villageAt = agency.GetVillageAt(worldPosition);
                if (villageAt != null && villageAt.HasBeenConverted && villageAt.Converter == army.Empire)
                {
                    if (transferringUnitSlot + villageAt.CurrentUnitSlot <= villageAt.MaximumUnitSlot)
                    {
                        return(true);
                    }
                    atLeastOneNeighbourgVillageWithNotEnoughSlotsLeft = true;
                }
            }
        }
        return((region != null && region.City != null && region.City.Camp != null && worldPosition == region.City.Camp.WorldPosition && region.City.Camp.Empire == army.Empire && transferringUnitSlot + region.City.Camp.CurrentUnitSlot <= region.City.Camp.MaximumUnitSlot) || (region != null && region.Kaiju != null && region.Kaiju.KaijuGarrison != null && worldPosition == region.Kaiju.KaijuGarrison.WorldPosition && region.Kaiju.Empire.Index == army.Empire.Index && DepartmentOfScience.IsTechnologyResearched(army.Empire, "TechnologyDefinitionMimics1") && transferringUnitSlot + region.Kaiju.KaijuGarrison.CurrentUnitSlot <= region.Kaiju.KaijuGarrison.MaximumUnitSlot));
    }
예제 #2
0
    private Village GetVillageFromPointOfInterest(PointOfInterest pointOfInterest, IWorldPositionningService worldPositionningService = null)
    {
        if (worldPositionningService == null)
        {
            IGameService service = Services.GetService <IGameService>();
            Diagnostics.Assert(service != null);
            Diagnostics.Assert(service.Game != null);
            worldPositionningService = service.Game.Services.GetService <IWorldPositionningService>();
            Diagnostics.Assert(worldPositionningService != null);
        }
        Region region = worldPositionningService.GetRegion(pointOfInterest.WorldPosition);

        if (region != null && region.MinorEmpire != null)
        {
            BarbarianCouncil agency = region.MinorEmpire.GetAgency <BarbarianCouncil>();
            return(agency.GetVillageAt(pointOfInterest.WorldPosition));
        }
        return(null);
    }
    private List <IWorldPositionable> Execute_GetVillages(AIBehaviorTree aiBehaviorTree, Army army, IGameService gameService, List <IWorldPositionable> unfilteredTargetList)
    {
        List <IWorldPositionable> list = new List <IWorldPositionable>();

        for (int i = 0; i < unfilteredTargetList.Count; i++)
        {
            PointOfInterest pointOfInterest = unfilteredTargetList[i] as PointOfInterest;
            if (pointOfInterest != null && !(pointOfInterest.Type != "Village") && pointOfInterest.Region != null && pointOfInterest.Region.MinorEmpire != null)
            {
                BarbarianCouncil agency = pointOfInterest.Region.MinorEmpire.GetAgency <BarbarianCouncil>();
                if (agency != null)
                {
                    Village villageAt = agency.GetVillageAt(pointOfInterest.WorldPosition);
                    if (villageAt != null && !villageAt.HasBeenPacified && this.TypeOfDiplomaticRelation != "VillageConvert" && pointOfInterest.PointOfInterestImprovement != null && !villageAt.HasBeenInfected)
                    {
                        list.Add(villageAt);
                    }
                    else if (this.TypeOfDiplomaticRelation == "VillageConvert" && army.Empire is MajorEmpire && army.Empire.SimulationObject.Tags.Contains(AILayer_Village.TagConversionTrait) && villageAt.HasBeenPacified && DepartmentOfTheInterior.IsArmyAbleToConvert(army, true) && !villageAt.HasBeenConverted && !villageAt.HasBeenInfected)
                    {
                        DepartmentOfForeignAffairs agency2 = aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfForeignAffairs>();
                        City city = villageAt.Region.City;
                        if (city != null && city.Empire != aiBehaviorTree.AICommander.Empire)
                        {
                            DiplomaticRelation diplomaticRelation = agency2.GetDiplomaticRelation(city.Empire);
                            if (diplomaticRelation == null || diplomaticRelation.State.Name != DiplomaticRelationState.Names.War || (diplomaticRelation.State.Name == DiplomaticRelationState.Names.War && pointOfInterest.PointOfInterestImprovement == null))
                            {
                                goto IL_1FB;
                            }
                        }
                        float num;
                        army.Empire.GetAgency <DepartmentOfTheTreasury>().TryGetResourceStockValue(army.Empire.SimulationObject, DepartmentOfTheTreasury.Resources.EmpirePoint, out num, false);
                        if (AILayer_Village.GetVillageConversionCost(army.Empire as MajorEmpire, villageAt) * 2f < num)
                        {
                            list.Add(villageAt);
                        }
                    }
                }
            }
            IL_1FB :;
        }
        return(list);
    }
예제 #4
0
    private bool TransferTo(Army army, WorldPosition worldPosition, List <GameEntityGUID> units, IWorldPositionningService worldPositionningService, global::PlayerController playerController, out Ticket ticket, EventHandler <TicketRaisedEventArgs> ticketRaisedEventHandler)
    {
        Region         region         = worldPositionningService.GetRegion(worldPosition);
        GameEntityGUID gameEntityGUID = GameEntityGUID.Zero;

        ticket = null;
        if (region.MinorEmpire != null)
        {
            BarbarianCouncil agency = region.MinorEmpire.GetAgency <BarbarianCouncil>();
            if (agency != null)
            {
                Village villageAt = agency.GetVillageAt(worldPosition);
                if (villageAt != null)
                {
                    gameEntityGUID = villageAt.GUID;
                }
            }
        }
        if (region.City != null && region.City.Camp != null && gameEntityGUID == GameEntityGUID.Zero && region.City.Camp.WorldPosition == worldPosition)
        {
            gameEntityGUID = region.City.Camp.GUID;
        }
        if (region.City != null && gameEntityGUID == GameEntityGUID.Zero)
        {
            gameEntityGUID = region.City.GUID;
        }
        if (region.Kaiju != null && region.Kaiju.KaijuGarrison != null && gameEntityGUID == GameEntityGUID.Zero && DepartmentOfScience.IsTechnologyResearched(army.Empire, "TechnologyDefinitionMimics1") && region.Kaiju.KaijuGarrison.WorldPosition == worldPosition)
        {
            gameEntityGUID = region.Kaiju.KaijuGarrison.GUID;
        }
        if (gameEntityGUID != GameEntityGUID.Zero)
        {
            OrderTransferUnits order = new OrderTransferUnits(army.Empire.Index, army.GUID, gameEntityGUID, units.ToArray(), false);
            playerController.PostOrder(order, out ticket, ticketRaisedEventHandler);
            return(true);
        }
        return(false);
    }
예제 #5
0
    public override bool CanExecute(Army army, ref List <StaticString> failureFlags, params object[] parameters)
    {
        this.lastConvertCostDescription = string.Empty;
        if (!base.CanExecute(army, ref failureFlags, parameters))
        {
            return(false);
        }
        if (army.IsNaval)
        {
            failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
            return(false);
        }
        IGameService service = Services.GetService <IGameService>();

        if (service == null)
        {
            failureFlags.Add(ArmyAction.NoCanDoWhileSystemError);
            return(false);
        }
        global::Game x = service.Game as global::Game;

        if (x == null)
        {
            failureFlags.Add(ArmyAction.NoCanDoWhileSystemError);
            return(false);
        }
        IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();

        if (service2 == null)
        {
            failureFlags.Add(ArmyAction.NoCanDoWhileSystemError);
            return(false);
        }
        if (parameters == null)
        {
            failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
            return(false);
        }
        if (parameters.Length == 0)
        {
            failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
            return(false);
        }
        List <Village> list = new List <Village>();

        for (int i = 0; i < parameters.Length; i++)
        {
            if (parameters[i] is Village)
            {
                list.Add(parameters[i] as Village);
            }
            else if (parameters[i] is List <IGameEntity> )
            {
                List <IGameEntity> list2 = parameters[i] as List <IGameEntity>;
                for (int j = 0; j < list2.Count; j++)
                {
                    if (list2[j] is Village)
                    {
                        list.Add(parameters[i] as Village);
                    }
                    else if (list2[j] is PointOfInterest)
                    {
                        PointOfInterest pointOfInterest = list2[j] as PointOfInterest;
                        Region          region          = service2.GetRegion(pointOfInterest.WorldPosition);
                        if (region != null && region.MinorEmpire != null)
                        {
                            BarbarianCouncil agency    = region.MinorEmpire.GetAgency <BarbarianCouncil>();
                            Village          villageAt = agency.GetVillageAt(pointOfInterest.WorldPosition);
                            if (villageAt != null)
                            {
                                list.Add(villageAt);
                            }
                        }
                    }
                }
            }
        }
        if (list.Count == 0)
        {
            failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
            return(false);
        }
        if (!this.ArmyCanConvert(army, failureFlags))
        {
            return(false);
        }
        DepartmentOfTheTreasury agency2 = army.Empire.GetAgency <DepartmentOfTheTreasury>();

        for (int k = list.Count - 1; k >= 0; k--)
        {
            if (!this.CanConvertVillage(army, list[k], agency2, failureFlags))
            {
                list.RemoveAt(k);
            }
        }
        if (list.Count == 0)
        {
            return(false);
        }
        ArmyAction.FailureFlags.Clear();
        return(true);
    }
예제 #6
0
    protected override IEnumerator OnShow(params object[] parameters)
    {
        this.Description.AgeTransform.Height = 0f;
        this.Description.Text = string.Empty;
        if (this.content.StartsWith("%"))
        {
            this.Description.Text = this.content;
        }
        else if (this.technologyOnly && this.context is MultipleConstructibleTooltipData)
        {
            GuiElement guiElement;
            if (base.GuiService.GuiPanelHelper.TryGetGuiElement((this.context as MultipleConstructibleTooltipData).TechnologyDefinition.Name, out guiElement))
            {
                this.Description.Text = guiElement.Description;
            }
        }
        else if (this.context is IDescriptionFeatureProvider)
        {
            this.Description.Text = (this.context as IDescriptionFeatureProvider).Description;
        }
        else
        {
            IGuiEntity guiEntity = this.context as IGuiEntity;
            GuiElement guiElement2;
            if (this.context != null && guiEntity != null && guiEntity.Gui != null)
            {
                this.Description.Text = guiEntity.Gui.Description;
            }
            else if (base.GuiService.GuiPanelHelper.TryGetGuiElement(this.content, out guiElement2))
            {
                this.Description.Text = guiElement2.Description;
            }
            else
            {
                this.Description.Text = this.content;
            }
        }
        if (this.context is CreepingNode || this.context is PointOfInterest || this.context is Village)
        {
            WorldPosition worldPosition;
            if (this.context is PointOfInterest)
            {
                worldPosition = (this.context as PointOfInterest).WorldPosition;
            }
            else if (this.context is CreepingNode)
            {
                worldPosition = (this.context as CreepingNode).WorldPosition;
            }
            else
            {
                worldPosition = (this.context as Village).WorldPosition;
            }
            Region region = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>().GetRegion(worldPosition);
            if (region.IsLand && !region.IsWasteland && region.MinorEmpire != null)
            {
                BarbarianCouncil agency = region.MinorEmpire.GetAgency <BarbarianCouncil>();
                if (agency != null && agency.GetVillageAt(worldPosition) != null)
                {
                    global::IGuiService      service      = Services.GetService <global::IGuiService>();
                    List <EffectDescription> list         = new List <EffectDescription>();
                    MinorFaction             minorFaction = region.MinorEmpire.MinorFaction;
                    if (minorFaction != null)
                    {
                        service.GuiSimulationParser.ParseSimulationDescriptor(minorFaction, list, null, false, false);
                        this.Description.Text = AgeLocalizer.Instance.LocalizeString(this.Description.Text);
                        foreach (EffectDescription effectDescription in list)
                        {
                            if (effectDescription == list[0])
                            {
                                AgePrimitiveLabel description = this.Description;
                                description.Text = description.Text + "\n \n#FFB43F#" + AgeLocalizer.Instance.LocalizeString("%EffectsOnEmpireTitle") + "#REVERT#";
                            }
                            AgePrimitiveLabel description2 = this.Description;
                            description2.Text = description2.Text + "\n" + effectDescription.ToString();
                        }
                    }
                }
            }
        }
        if (!string.IsNullOrEmpty(this.Description.Text))
        {
            this.Description.AgeTransform.Width = this.DefaultWidth - this.Description.AgeTransform.PixelMarginLeft - this.Description.AgeTransform.PixelMarginRight;
            this.Description.ComputeText();
            base.AgeTransform.Height = this.Description.Font.LineHeight * (float)this.Description.TextLines.Count + this.Description.AgeTransform.PixelMarginTop + this.Description.AgeTransform.PixelMarginBottom;
            if (this.Description.TextLines.Count == 1)
            {
                base.AgeTransform.Width = this.Description.AgeTransform.PixelMarginLeft + this.Description.Font.ComputeTextWidth(this.Description.TextLines[0], false, true) + this.Description.AgeTransform.PixelMarginRight;
            }
            else
            {
                base.AgeTransform.Width = this.DefaultWidth;
            }
        }
        yield return(base.OnShow(parameters));

        yield break;
    }