Пример #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 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);
    }
    public override bool CanExecute(Army army, ref List <StaticString> failureFlags, params object[] parameters)
    {
        if (!base.CanExecute(army, ref failureFlags, parameters))
        {
            return(false);
        }
        if (army.HasCatspaw)
        {
            failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
            return(false);
        }
        int   num  = 0;
        int   num2 = 0;
        float num3 = float.MaxValue;
        bool  flag = false;

        for (int i = 0; i < parameters.Length; i++)
        {
            if (parameters[i] is Unit)
            {
                Unit unit = parameters[i] as Unit;
                if (unit.UnitDesign != null && unit.UnitDesign.Tags.Contains(DownloadableContent9.TagSolitary))
                {
                    failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
                    return(false);
                }
                if ((unit.UnitDesign != null && unit.UnitDesign.Tags.Contains(Kaiju.LiceUnitTag)) || unit.UnitDesign.Tags.Contains(Kaiju.MonsterUnitTag))
                {
                    flag = true;
                }
                num2 += (int)unit.GetPropertyValue(SimulationProperties.UnitSlotCount);
                num++;
            }
            else
            {
                if (!(parameters[i] is IEnumerable <Unit>))
                {
                    failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
                    return(false);
                }
                foreach (Unit unit2 in (parameters[i] as IEnumerable <Unit>))
                {
                    if (unit2.UnitDesign != null && unit2.UnitDesign.Tags.Contains(DownloadableContent9.TagSolitary))
                    {
                        failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
                        return(false);
                    }
                    if ((unit2.UnitDesign != null && unit2.UnitDesign.Tags.Contains(Kaiju.LiceUnitTag)) || unit2.UnitDesign.Tags.Contains(Kaiju.MonsterUnitTag))
                    {
                        flag = true;
                    }
                    num2 += (int)unit2.GetPropertyValue(SimulationProperties.UnitSlotCount);
                    num++;
                    float propertyValue = unit2.GetPropertyValue(SimulationProperties.Movement);
                    if (propertyValue < num3)
                    {
                        num3 = propertyValue;
                    }
                }
            }
        }
        if (num == 0)
        {
            failureFlags.Add(ArmyAction_TransferUnits.NoUnitSelectedForTransfer);
            return(false);
        }
        if (num3 == 0f)
        {
            failureFlags.Add(ArmyAction_TransferUnits.NotEnoughMovementToTransfer);
            return(false);
        }
        if (flag)
        {
            failureFlags.Add(ArmyAction_TransferUnits.UntransferableUnitSelectedForTransfer);
            return(false);
        }
        IGameService service = Services.GetService <IGameService>();
        IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();
        IPathfindingService       service3 = service.Game.Services.GetService <IPathfindingService>();
        bool flag2 = false;
        bool flag3 = false;
        PathfindingMovementCapacity pathfindingMovementCapacity = army.GenerateContext().MovementCapacities;

        for (int j = 0; j < parameters.Length; j++)
        {
            if (parameters[j] is Unit)
            {
                pathfindingMovementCapacity = (parameters[j] as Unit).GenerateContext().MovementCapacities;
            }
            else if (parameters[j] is IEnumerable <Unit> )
            {
                pathfindingMovementCapacity = PathfindingMovementCapacity.All;
                foreach (Unit unit3 in (parameters[j] as IEnumerable <Unit>))
                {
                    if (unit3.Garrison != null)
                    {
                        pathfindingMovementCapacity &= unit3.GenerateContext().MovementCapacities;
                    }
                }
            }
        }
        for (int k = 0; k < 6; k++)
        {
            bool          flag4         = false;
            WorldPosition neighbourTile = service2.GetNeighbourTile(army.WorldPosition, (WorldOrientation)k, 1);
            if (service3.IsTilePassable(neighbourTile, pathfindingMovementCapacity, (PathfindingFlags)0) && service3.IsTransitionPassable(army.WorldPosition, neighbourTile, army, PathfindingFlags.IgnoreArmies, null) && service3.IsTileStopable(neighbourTile, pathfindingMovementCapacity, PathfindingFlags.IgnoreArmies))
            {
                Region region = service2.GetRegion(neighbourTile);
                if (region.City != null && this.AllowedTransferTarget != ArmyAction_TransferUnits.AllowedTransferTargetType.Army)
                {
                    for (int l = 0; l < region.City.Districts.Count; l++)
                    {
                        if (region.City.Districts[l].Type != DistrictType.Exploitation && neighbourTile == region.City.Districts[l].WorldPosition)
                        {
                            if (this.AllowedTransferTarget != ArmyAction_TransferUnits.AllowedTransferTargetType.Army)
                            {
                                if (num2 + region.City.CurrentUnitSlot <= region.City.MaximumUnitSlot)
                                {
                                    return(true);
                                }
                                flag2 = true;
                            }
                            flag4 = true;
                            break;
                        }
                    }
                }
                if (this.AllowedTransferTarget != ArmyAction_TransferUnits.AllowedTransferTargetType.Army && flag2)
                {
                    failureFlags.Add(ArmyAction_TransferUnits.NotEnoughSlotsInNeighbouringGarrisonForTransfer);
                }
                Army armyAtPosition = service2.GetArmyAtPosition(neighbourTile);
                if (armyAtPosition != null && this.AllowedTransferTarget != ArmyAction_TransferUnits.AllowedTransferTargetType.City && armyAtPosition.Empire == army.Empire && !armyAtPosition.HasCatspaw)
                {
                    if (armyAtPosition.SimulationObject.Tags.Contains(KaijuArmy.ClassKaijuArmy) && !DepartmentOfScience.IsTechnologyResearched(army.Empire, "TechnologyDefinitionMimics1"))
                    {
                        failureFlags.Add(ArmyAction.NoCanDoWhileHidden);
                        return(false);
                    }
                    if (num2 + armyAtPosition.CurrentUnitSlot <= armyAtPosition.MaximumUnitSlot)
                    {
                        return(true);
                    }
                    flag3 = true;
                }
                else if (!flag4 && this.AllowedTransferTarget != ArmyAction_TransferUnits.AllowedTransferTargetType.City && armyAtPosition == null && num != army.StandardUnits.Count && service3.IsTileStopable(neighbourTile, army, (PathfindingFlags)0, null))
                {
                    return(true);
                }
            }
        }
        if (this.AllowedTransferTarget > ArmyAction_TransferUnits.AllowedTransferTargetType.City && flag3)
        {
            failureFlags.Add(ArmyAction_TransferUnits.NotEnoughSlotsInNeighbouringArmyForTransfer);
        }
        if (this.AllowedTransferTarget != ArmyAction_TransferUnits.AllowedTransferTargetType.Army)
        {
            failureFlags.Add(ArmyAction_TransferUnits.NoNeighbouringCityAvailable);
        }
        if (this.AllowedTransferTarget != ArmyAction_TransferUnits.AllowedTransferTargetType.City)
        {
            failureFlags.Add(ArmyAction_TransferUnits.NoNeighbouringArmyAvailable);
        }
        ArmyAction_TransferUnits.AllowedTransferTargetType allowedTransferTarget = this.AllowedTransferTarget;
        return(false);
    }