コード例 #1
0
    public override bool CheckValidity()
    {
        Region region = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>().GetRegion(this.FortressPosition);

        if (region.NavalEmpire == null)
        {
            return(false);
        }
        PirateCouncil agency = region.NavalEmpire.GetAgency <PirateCouncil>();

        if (agency == null)
        {
            return(false);
        }
        Fortress fortressAt = agency.GetFortressAt(this.FortressPosition);

        if (fortressAt == null)
        {
            return(false);
        }
        if (fortressAt.Occupant != null && !base.NavyLayer.MightAttackOwner(region, fortressAt.Occupant))
        {
            return(false);
        }
        if (base.Owner is MajorEmpire && fortressAt.Occupant != null && base.NavyLayer.diplomacyLayer.GetPeaceWish(fortressAt.Occupant.Index))
        {
            return(false);
        }
        if (base.AssignedArmy != null && base.AssignedArmy.Garrison == null)
        {
            base.AssignedArmy = null;
            base.CurrentAssignationFitness.Reset();
        }
        if (base.AssignedArmy != null)
        {
            float enemyPower = this.GetEnemyPower();
            if (base.AssignedArmy.Garrison.GetPropertyValue(SimulationProperties.MilitaryPower) < enemyPower * 0.8f)
            {
                return(false);
            }
        }
        return(true);
    }
コード例 #2
0
    private float GetEnemyPower()
    {
        Region region = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>().GetRegion(this.FortressPosition);

        if (region.NavalEmpire == null)
        {
            return(0f);
        }
        PirateCouncil agency = region.NavalEmpire.GetAgency <PirateCouncil>();

        if (agency == null)
        {
            return(0f);
        }
        Fortress fortressAt = agency.GetFortressAt(this.FortressPosition);

        if (fortressAt == null)
        {
            return(0f);
        }
        return(fortressAt.GetPropertyValue(SimulationProperties.MilitaryPower));
    }
コード例 #3
0
    protected virtual void GenerateFortressTasks()
    {
        if (this.CommanderState == NavyCommander.NavyCommanderState.Inactive)
        {
            return;
        }
        PirateCouncil agency = this.NavyRegionData.WaterRegion.NavalEmpire.GetAgency <PirateCouncil>();

        if (agency != null)
        {
            foreach (Fortress fortress in agency.GetRegionFortresses(base.RegionData.WaterRegionIndex))
            {
                if (fortress.Occupant != null && fortress.Occupant.Index == base.Owner.Index)
                {
                    this.GenerateFillFortress(fortress);
                }
                else
                {
                    this.GenerateTakeOver(fortress);
                }
            }
        }
    }
コード例 #4
0
    public override IEnumerator LoadGame(Game game)
    {
        yield return(base.LoadGame(game));

        ISessionService service = Services.GetService <ISessionService>();

        this.InterpreterContext = new InterpreterContext(null);
        this.InterpreterContext.SimulationObject = new SimulationObject("VictoryController");
        this.InterpreterContext.SimulationObject.ModifierForward = ModifierForwardType.ParentOnly;
        float num = 1f;
        IDatabase <SimulationDescriptor> database = Databases.GetDatabase <SimulationDescriptor>(false);

        if (database != null)
        {
            SimulationDescriptor simulationDescriptor;
            if (database.TryGetValue("ClassVictoryController", out simulationDescriptor))
            {
                this.InterpreterContext.SimulationObject.AddDescriptor(simulationDescriptor);
            }
            string value = Amplitude.Unity.Runtime.Runtime.Registry.GetValue(VictoryManager.Registers.LobbyDataFilter);
            if (!string.IsNullOrEmpty(value))
            {
                string[] array = value.Split(Amplitude.String.Separators, StringSplitOptions.RemoveEmptyEntries);
                if (array.Length != 0 && service != null && service.Session != null)
                {
                    foreach (string text in array)
                    {
                        string lobbyData = service.Session.GetLobbyData <string>(text, null);
                        if (!string.IsNullOrEmpty(lobbyData))
                        {
                            string x = string.Format("VictoryModifier{0}{1}", text, lobbyData);
                            if (database.TryGetValue(x, out simulationDescriptor))
                            {
                                this.InterpreterContext.SimulationObject.AddDescriptor(simulationDescriptor);
                                SimulationModifierDescriptor simulationModifierDescriptor = Array.Find <SimulationModifierDescriptor>(simulationDescriptor.SimulationModifierDescriptors, (SimulationModifierDescriptor y) => y is SingleSimulationModifierDescriptor && y.TargetPropertyName == "PeacePointThreshold");
                                if (simulationModifierDescriptor != null)
                                {
                                    num *= float.Parse((simulationModifierDescriptor as SingleSimulationModifierDescriptor).Value);
                                }
                            }
                        }
                    }
                }
            }
            this.InterpreterContext.SimulationObject.Refresh();
        }
        foreach (Empire empire in base.Game.Empires)
        {
            if (empire is MajorEmpire)
            {
                (empire as MajorEmpire).SetPropertyBaseValue("TreatyPeacePointPerTurnMult", num);
            }
        }
        int  num2 = 0;
        int  num3 = 0;
        bool flag = Services.GetService <IDownloadableContentService>().IsShared(DownloadableContent16.ReadOnlyName);

        if (base.Game.World.Regions != null)
        {
            for (int j = 0; j < base.Game.World.Regions.Length; j++)
            {
                if (!base.Game.World.Regions[j].IsOcean && !base.Game.World.Regions[j].IsWasteland)
                {
                    num2++;
                }
                else if (flag && base.Game.World.Regions[j].IsOcean && base.Game.World.Regions[j].NavalEmpire != null)
                {
                    PirateCouncil agency = base.Game.World.Regions[j].NavalEmpire.GetAgency <PirateCouncil>();
                    if (agency != null && agency.GetRegionFortresses(base.Game.World.Regions[j]).Count > 0)
                    {
                        num3++;
                    }
                }
            }
        }
        if (num2 + num3 <= 0)
        {
            Diagnostics.LogError("Invalid number of regions (value: {0}), rounding up to '1'.", new object[]
            {
                num2
            });
            num2 = 1;
        }
        Diagnostics.Log("Registering new data (name: {0}, land: {1}, ocean: {2})", new object[]
        {
            "TotalNumberOfRegions",
            num2,
            num3
        });
        this.InterpreterContext.Register("NumberOfLandRegions", num2);
        this.InterpreterContext.Register("TotalNumberOfRegions", num2 + num3);
        if (game.Turn == 0 && service != null && service.Session != null)
        {
            using (IEnumerator <VictoryCondition> enumerator = this.VictoryConditions.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    VictoryCondition victoryCondition = enumerator.Current;
                    if (service.Session.GetLobbyData(victoryCondition.Name) != null && !service.Session.GetLobbyData <bool>(victoryCondition.Name, false))
                    {
                        if (!this.VictoryConditionsDiscabledThisGame.Contains(victoryCondition.Name))
                        {
                            this.VictoryConditionsDiscabledThisGame.Add(victoryCondition.Name);
                            Diagnostics.Log("Disabling victory condition '{0}'.", new object[]
                            {
                                victoryCondition.Name
                            });
                        }
                        if (!this.VictoryConditionsDiscardedThisGame.Contains(victoryCondition.Name))
                        {
                            this.VictoryConditionsDiscardedThisGame.Add(victoryCondition.Name);
                            Diagnostics.Log("Discarding victory condition '{0}'.", new object[]
                            {
                                victoryCondition.Name
                            });
                        }
                    }
                }
                yield break;
            }
        }
        yield break;
    }
コード例 #5
0
    public bool TryGetListOfTargetInRange(Army inputArmy, int targetEmpireIndex, bool addPointsOfInterest, int regionRestriction, ref List <IWorldPositionable> targetList)
    {
        if (targetList == null)
        {
            targetList = new List <IWorldPositionable>();
        }
        if (inputArmy == null || inputArmy.Empire == null)
        {
            return(false);
        }
        DepartmentOfForeignAffairs departmentOfForeignAffairs = null;
        bool flag  = inputArmy.Empire is MinorEmpire;
        bool flag2 = inputArmy.Empire is NavalEmpire;

        if (!flag && !flag2)
        {
            departmentOfForeignAffairs = inputArmy.Empire.GetAgency <DepartmentOfForeignAffairs>();
        }
        if (addPointsOfInterest)
        {
            for (int i = 0; i < this.World.Regions.Length; i++)
            {
                for (int j = 0; j < this.World.Regions[i].PointOfInterests.Length; j++)
                {
                    PointOfInterest pointOfInterest = this.World.Regions[i].PointOfInterests[j];
                    if (this.GetDistance(pointOfInterest.WorldPosition, inputArmy.WorldPosition) <= inputArmy.LineOfSightVisionRange && (regionRestriction == -1 || regionRestriction == pointOfInterest.Region.Index))
                    {
                        targetList.Add(pointOfInterest);
                    }
                }
            }
        }
        IGameService service = Services.GetService <IGameService>();

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

        for (int k = 0; k < game.Empires.Length; k++)
        {
            global::Empire empire = game.Empires[k];
            if (((!flag && !flag2) || empire is MajorEmpire) && (targetEmpireIndex == -1 || targetEmpireIndex == k))
            {
                DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>();
                if (agency != null)
                {
                    int l = 0;
                    while (l < agency.Armies.Count)
                    {
                        Army army = agency.Armies[l];
                        if (flag || flag2)
                        {
                            if (!army.IsPrivateers)
                            {
                                bool flag3 = false;
                                for (int m = 0; m < army.StandardUnits.Count; m++)
                                {
                                    if (army.StandardUnits[m].SimulationObject.Tags.Contains(WorldPositionning.FriendlyBannerDescriptor))
                                    {
                                        flag3 = true;
                                    }
                                }
                                if ((army.Hero == null || !army.Hero.IsSkillUnlocked(WorldPositionning.FriendlyBannerSkill)) && !flag3)
                                {
                                    int   distance      = this.GetDistance(army.WorldPosition, inputArmy.WorldPosition);
                                    float propertyValue = inputArmy.GetPropertyValue(SimulationProperties.DetectionRange);
                                    if (!army.IsCamouflaged)
                                    {
                                        goto IL_240;
                                    }
                                    if ((float)distance <= propertyValue)
                                    {
                                        goto IL_240;
                                    }
                                }
                            }
                        }
                        else if (army.Empire == inputArmy.Empire || !army.IsCamouflaged || this.VisibilityService.IsWorldPositionDetectedFor(army.WorldPosition, inputArmy.Empire))
                        {
                            goto IL_240;
                        }
IL_238:
                        l++;
                        continue;
IL_240:
                        if (this.GetDistance(army.WorldPosition, inputArmy.WorldPosition) <= inputArmy.LineOfSightVisionRange && (regionRestriction == -1 || regionRestriction == (int)this.GetRegionIndex(army.WorldPosition)))
                        {
                            targetList.Add(army);
                            goto IL_238;
                        }
                        goto IL_238;
                    }
                }
                if (empire is MajorEmpire)
                {
                    DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>();
                    if (agency2 != null)
                    {
                        for (int n = 0; n < agency2.Cities.Count; n++)
                        {
                            City city = agency2.Cities[n];
                            if ((city.Empire == inputArmy.Empire || flag || flag2 || departmentOfForeignAffairs == null || departmentOfForeignAffairs.CanAttack(city)) && this.GetDistance(city.WorldPosition, inputArmy.WorldPosition) <= inputArmy.LineOfSightVisionRange && (regionRestriction == -1 || regionRestriction == city.Region.Index))
                            {
                                targetList.Add(city);
                            }
                        }
                        for (int num = 0; num < agency2.Camps.Count; num++)
                        {
                            Camp camp = agency2.Camps[num];
                            if ((camp.Empire == inputArmy.Empire || flag || flag2 || departmentOfForeignAffairs == null || departmentOfForeignAffairs.CanAttack(camp)) && this.GetDistance(camp.WorldPosition, inputArmy.WorldPosition) <= inputArmy.LineOfSightVisionRange && (regionRestriction == -1 || regionRestriction == camp.City.Region.Index))
                            {
                                targetList.Add(camp);
                            }
                        }
                    }
                    MajorEmpire majorEmpire = empire as MajorEmpire;
                    for (int num2 = 0; num2 < majorEmpire.ConvertedVillages.Count; num2++)
                    {
                        Village village = majorEmpire.ConvertedVillages[num2];
                        if ((flag || flag2 || departmentOfForeignAffairs == null || departmentOfForeignAffairs.CanAttack(village)) && this.GetDistance(village.WorldPosition, inputArmy.WorldPosition) <= inputArmy.LineOfSightVisionRange && (regionRestriction == -1 || regionRestriction == village.Region.Index))
                        {
                            targetList.Add(village);
                        }
                    }
                }
                else if (empire is MinorEmpire)
                {
                    BarbarianCouncil agency3 = empire.GetAgency <BarbarianCouncil>();
                    if (agency3 != null)
                    {
                        for (int num3 = 0; num3 < agency3.Villages.Count; num3++)
                        {
                            Village village2 = agency3.Villages[num3];
                            if ((flag || flag2 || departmentOfForeignAffairs == null || departmentOfForeignAffairs.CanAttack(village2)) && this.GetDistance(village2.WorldPosition, inputArmy.WorldPosition) <= inputArmy.LineOfSightVisionRange && (regionRestriction == -1 || regionRestriction == village2.Region.Index))
                            {
                                targetList.Add(village2);
                            }
                        }
                    }
                }
                else if (empire is NavalEmpire)
                {
                    PirateCouncil agency4 = empire.GetAgency <PirateCouncil>();
                    if (agency4 != null)
                    {
                        for (int num4 = 0; num4 < agency4.Fortresses.Count; num4++)
                        {
                            Fortress fortress = agency4.Fortresses[num4];
                            if ((flag || flag2 || departmentOfForeignAffairs == null || departmentOfForeignAffairs.CanAttack(fortress)) && this.GetDistance(fortress.WorldPosition, inputArmy.WorldPosition) <= inputArmy.LineOfSightVisionRange && (regionRestriction == -1 || regionRestriction == fortress.Region.Index))
                            {
                                targetList.Add(fortress);
                            }
                        }
                    }
                }
            }
        }
        return(targetList.Count != 0);
    }