示例#1
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);
        }
    }
示例#2
0
    private void AddWinnerToQuestVariable(QuestBehaviour questBehaviour, EventEncounterStateChange e)
    {
        Contender contender = e.EventArgs.Encounter.Contenders.FirstOrDefault((Contender match) => match.Empire == questBehaviour.Initiator && match.ContenderState == ContenderState.Survived);

        if (contender != null)
        {
            this.WinnerArmyGUID = contender.GUID;
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.Output_WinnerVarName);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.Output_WinnerVarName);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            DepartmentOfDefense agency = questBehaviour.Initiator.GetAgency <DepartmentOfDefense>();
            Diagnostics.Assert(agency != null);
            Army army = agency.Armies.FirstOrDefault((Army match) => match.GUID == this.WinnerArmyGUID);
            if (army == null)
            {
                Diagnostics.LogError("Decorator_KillArmy: the army (GUID:'{0}') cannot be found in the empire (index:'{1}') armies", new object[]
                {
                    this.WinnerArmyGUID,
                    questBehaviour.Initiator.Index
                });
            }
            questVariable.Object = army;
        }
    }
示例#3
0
    public override void GatherAuctionItems(Empire empire)
    {
        base.GatherAuctionItems(empire);
        DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>();

        for (int i = 0; i < agency.Armies.Count; i++)
        {
            for (int j = 0; j < agency.Armies[i].StandardUnits.Count; j++)
            {
                if (this.CanSellUnit(agency.Armies[i].StandardUnits[j]))
                {
                    float score = this.ComputeUnitScore(agency.Armies[i].StandardUnits[j]);
                    base.AuctionItems.Add(new AuctionItem_GameEntity(agency.Armies[i].StandardUnits[j], score));
                }
            }
        }
        DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>();

        for (int k = 0; k < agency2.Cities.Count; k++)
        {
            for (int l = 0; l < agency2.Cities[k].StandardUnits.Count; l++)
            {
                if (this.CanSellUnit(agency2.Cities[k].StandardUnits[l]))
                {
                    float score2 = this.ComputeUnitScore(agency2.Cities[k].StandardUnits[l]);
                    base.AuctionItems.Add(new AuctionItem_GameEntity(agency2.Cities[k].StandardUnits[l], score2));
                }
            }
        }
    }
示例#4
0
    private void TryRecruitingExplorers()
    {
        if (this.City == null)
        {
            return;
        }
        DepartmentOfDefense agency = base.Commander.Empire.GetAgency <DepartmentOfDefense>();
        List <AIData_Army>  list   = new List <AIData_Army>();

        for (int i = 0; i < agency.Armies.Count; i++)
        {
            Army army = agency.Armies[i];
            if (army.StandardUnits.Count > army.MaximumUnitSlot / 4)
            {
                AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(army.GUID);
                if (aidata != null && !aidata.IsSolitary && !aidata.Army.IsSeafaring && !aidata.Army.HasCatspaw && !(aidata.Army is KaijuArmy) && (aidata.CommanderMission == null || (aidata.CommanderMission.Commander != null && aidata.CommanderMission.Commander.Category == AICommanderMissionDefinition.AICommanderCategory.Exploration)))
                {
                    list.Add(aidata);
                }
            }
        }
        if (list.Count > 0)
        {
            list.Sort((AIData_Army left, AIData_Army right) => - 1 * left.Army.GetPropertyValue(SimulationProperties.MilitaryPower).CompareTo(right.Army.GetPropertyValue(SimulationProperties.MilitaryPower)));
            if (list[0].CommanderMission != null)
            {
                list[0].CommanderMission.Interrupt();
            }
            base.AIDataArmyGUID = list[0].Army.GUID;
            base.TryGetArmyData();
        }
    }
示例#5
0
    public virtual void UpdateLifeAfterEncounter(Encounter encounter)
    {
        Diagnostics.Assert(this.Empire != null);
        DepartmentOfDefense agency = this.Empire.GetAgency <DepartmentOfDefense>();

        agency.UpdateLifeAfterEncounter(this);
    }
示例#6
0
    public Amplitude.Unity.Game.Orders.Order CreateArmyFromMixedArmy(BaseNavyArmy army)
    {
        if (!this.IsMixed(army))
        {
            return(null);
        }
        if (!base.HasMovementLeft(army))
        {
            return(null);
        }
        WorldPosition armyPosition = WorldPosition.Invalid;
        PathfindingMovementCapacity movementCapacity = PathfindingMovementCapacity.Water;

        for (int i = 0; i < 6; i++)
        {
            WorldPosition neighbourTile = this.worldPositionService.GetNeighbourTile(army.Garrison.WorldPosition, (WorldOrientation)i, 1);
            if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(neighbourTile, movementCapacity))
            {
                armyPosition = neighbourTile;
                break;
            }
        }
        bool flag = false;
        List <GameEntityGUID> list = new List <GameEntityGUID>();

        for (int j = 0; j < army.Garrison.StandardUnits.Count; j++)
        {
            if (flag == army.Garrison.StandardUnits[j].IsSeafaring)
            {
                list.Add(army.Garrison.StandardUnits[j].GUID);
            }
        }
        return(new OrderTransferGarrisonToNewArmy(army.Garrison.Empire.Index, army.Garrison.GUID, list.ToArray(), armyPosition, null, false, true, true));
    }
示例#7
0
 private void SlapUnitsUnderLightningWeatherEffect()
 {
     for (int i = 0; i < this.game.Empires.Length; i++)
     {
         DepartmentOfDefense agency = this.game.Empires[i].GetAgency <DepartmentOfDefense>();
         if (agency != null)
         {
             for (int j = agency.Armies.Count - 1; j >= 0; j--)
             {
                 Army army = agency.Armies[j];
                 if (army.SimulationObject.Tags.Contains(WeatherManager.LightningTarget))
                 {
                     int  unitsCount = army.UnitsCount;
                     bool flag       = false;
                     for (int k = army.StandardUnits.Count - 1; k >= 0; k--)
                     {
                         flag |= this.DamageUnit(agency, army.StandardUnits[k]);
                     }
                     if (army.Hero != null)
                     {
                         flag |= this.DamageUnit(agency, army.Hero);
                     }
                     if (flag && this.game.Empires[i] is MajorEmpire)
                     {
                         ArmyHitInfo armyInfo = new ArmyHitInfo(army, unitsCount, army.WorldPosition, ArmyHitInfo.HitType.Weather);
                         this.eventService.Notify(new EventArmyHit(this.game.Empires[i], armyInfo, false));
                     }
                 }
             }
         }
     }
 }
示例#8
0
    private void Client_TurnEnded_RegenUnits()
    {
        if (this.OnArmyMode())
        {
            return;
        }
        Garrison activeTroops = this.GetActiveTroops();
        float    num          = activeTroops.GetPropertyValue(SimulationProperties.InGarrisonRegenModifier);

        if (this.majorEmpire != null)
        {
            Region region = this.gameService.Game.Services.GetService <IWorldPositionningService>().GetRegion(this.WorldPosition);
            if (region.Owner != null && region.Owner.Index == this.Empire.Index)
            {
                num += this.Empire.GetPropertyValue(SimulationProperties.InOwnedRegionUnitRegenModifier);
            }
        }
        else
        {
            num += this.Empire.GetPropertyValue(SimulationProperties.InOwnedRegionUnitRegenModifier);
        }
        foreach (Unit unit in activeTroops.Units)
        {
            DepartmentOfDefense.RegenUnit(unit, num, 0);
            unit.Refresh(false);
        }
        this.Empire.GetAgency <DepartmentOfDefense>().CleanGarrisonAfterEncounter(activeTroops);
        this.Refresh(false);
    }
示例#9
0
    public WorldPosition GetRandomValidArmyPosition(Village village)
    {
        WorldOrientation orientation = (WorldOrientation)this.random.Next(0, 6);
        WorldPosition    result      = WorldPosition.Invalid;

        for (int i = 0; i < 6; i++)
        {
            WorldOrientation direction  = orientation.Rotate(i);
            WorldPosition    neighbourg = this.worldPositionningService.GetNeighbourTile(village.WorldPosition, direction, 1);
            int regionIndex             = (int)this.worldPositionningService.GetRegionIndex(neighbourg);
            if (regionIndex == village.Region.Index)
            {
                if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(neighbourg, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water))
                {
                    global::Empire[] empires = (this.GameService.Game as global::Game).Empires;
                    int j = 0;
                    while (j < empires.Length)
                    {
                        global::Empire empire = empires[j];
                        if (!(empire is KaijuEmpire))
                        {
                            goto IL_106;
                        }
                        KaijuEmpire kaijuEmpire = empire as KaijuEmpire;
                        if (kaijuEmpire == null)
                        {
                            goto IL_106;
                        }
                        KaijuCouncil agency = kaijuEmpire.GetAgency <KaijuCouncil>();
                        if (agency == null || agency.Kaiju == null || !(agency.Kaiju.WorldPosition == neighbourg))
                        {
                            goto IL_106;
                        }
IL_145:
                        j++;
                        continue;
IL_106:
                        if (!(empire is MajorEmpire))
                        {
                            goto IL_145;
                        }
                        MajorEmpire majorEmpire = empire as MajorEmpire;
                        if (majorEmpire == null || majorEmpire.TamedKaijus.Any((Kaiju m) => m.WorldPosition == neighbourg))
                        {
                            goto IL_145;
                        }
                        goto IL_145;
                    }
                    District district = this.worldPositionningService.GetDistrict(neighbourg);
                    if (district == null || !District.IsACityTile(district))
                    {
                        result = neighbourg;
                        break;
                    }
                }
            }
        }
        return(result);
    }
示例#10
0
    public virtual void CleanAfterEncounter(Encounter encounter)
    {
        Diagnostics.Assert(this.Empire != null);
        DepartmentOfDefense agency = this.Empire.GetAgency <DepartmentOfDefense>();

        agency.CleanGarrisonAfterEncounter(this);
        this.LeaveEncounter();
    }
示例#11
0
 public override State CheckCondition(QuestBehaviour questBehaviour, GameEvent gameEvent, params object[] parameters)
 {
     if (this.RegionIndex != -1)
     {
         IGameService service = Services.GetService <IGameService>();
         Diagnostics.Assert(service != null);
         global::Game game = service.Game as global::Game;
         if (game == null)
         {
             return(State.Failure);
         }
         IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();
         global::Empire            empire;
         if (gameEvent != null)
         {
             empire = (gameEvent.Empire as global::Empire);
         }
         else
         {
             empire = questBehaviour.Initiator;
         }
         DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>();
         Diagnostics.Assert(agency != null);
         for (int i = 0; i < game.Empires.Length; i++)
         {
             if (i != empire.Index && (this.IgnoredEmpiresIndex == null || !this.IgnoredEmpiresIndex.Contains(i)))
             {
                 global::Empire empire2 = game.Empires[i];
                 bool           flag;
                 if (empire2 is MajorEmpire)
                 {
                     DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(empire2);
                     Diagnostics.Assert(diplomaticRelation != null);
                     Diagnostics.Assert(diplomaticRelation.State != null);
                     flag = (diplomaticRelation.State.Name == DiplomaticRelationState.Names.ColdWar || diplomaticRelation.State.Name == DiplomaticRelationState.Names.War || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Unknown);
                 }
                 else
                 {
                     flag = true;
                 }
                 if (flag)
                 {
                     DepartmentOfDefense agency2 = empire2.GetAgency <DepartmentOfDefense>();
                     for (int j = 0; j < agency2.Armies.Count; j++)
                     {
                         if ((this.IncludeNaval || !agency2.Armies[j].IsNaval) && (int)service2.GetRegionIndex(agency2.Armies[j].WorldPosition) == this.RegionIndex)
                         {
                             return(State.Success);
                         }
                     }
                 }
             }
         }
     }
     return(State.Failure);
 }
示例#12
0
    public void SetArmy(KaijuArmy kaijuArmy)
    {
        this.KaijuArmy       = kaijuArmy;
        this.KaijuArmy.Kaiju = this;
        this.kaijuArmyGUID   = kaijuArmy.GUID;
        DepartmentOfDefense agency = this.Empire.GetAgency <DepartmentOfDefense>();

        agency.AddArmy(this.KaijuArmy);
        this.KaijuArmy.StandardUnitCollectionChange += this.KaijuArmy_StandardUnitCollectionChange;
    }
示例#13
0
 private bool GenerateHeroUnitFromHeroDescriptor(GameEntityGUID gameEntityGUID, HeroPool.HeroDescriptor?heroDescriptor, out Unit unit)
 {
     unit = DepartmentOfDefense.CreateUnitByDesign(gameEntityGUID, heroDescriptor.Value.UnitProfile);
     if (unit != null)
     {
         this.AssignNewUserDefinedName(unit);
         return(true);
     }
     return(false);
 }
示例#14
0
    private void ManageGeomancy()
    {
        if (ELCPUtilities.GeomancyDuration < 1 || ELCPUtilities.GeomancyRadius < 0)
        {
            return;
        }
        Stopwatch stopwatch = new Stopwatch();

        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
        {
            stopwatch.Start();
        }
        foreach (global::Empire empire in base.Game.Empires)
        {
            List <IGarrison>        list   = new List <IGarrison>();
            DepartmentOfTheInterior agency = empire.GetAgency <DepartmentOfTheInterior>();
            if (agency != null)
            {
                list.AddRange(agency.Cities.Cast <IGarrison>());
                list.AddRange(agency.Camps.Cast <IGarrison>());
            }
            DepartmentOfDefense agency2 = empire.GetAgency <DepartmentOfDefense>();
            if (agency2 != null)
            {
                list.AddRange(agency2.Armies.Cast <IGarrison>());
            }
            foreach (IGarrison garrison in list)
            {
                using (IEnumerator <Unit> enumerator2 = garrison.Units.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        if (enumerator2.Current.CheckUnitAbility(UnitAbility.UnitAbilityGeomancy, -1))
                        {
                            WorldCircle     worldCircle = new WorldCircle((garrison as IWorldPositionable).WorldPosition, ELCPUtilities.GeomancyRadius);
                            WorldPosition[] array       = base.Game.World.PerformReversibleTerraformation(worldCircle.GetWorldPositions(base.Game.World.WorldParameters), false, ELCPUtilities.GeomancyDuration + 1);
                            if (array.Length != 0)
                            {
                                base.Game.World.UpdateTerraformStateMap(true);
                                this.eventService.Notify(new EventEmpireWorldTerraformed(empire, array, true));
                            }
                        }
                    }
                }
            }
        }
        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
        {
            stopwatch.Stop();
            Diagnostics.Log("ELCP ManageGeomancy time elapsed: {0}", new object[]
            {
                stopwatch.Elapsed
            });
        }
    }
示例#15
0
    public static bool AreaIsSave(WorldPosition pos, int size, DepartmentOfForeignAffairs departmentOfForeignAffairs, out float rangescore, out float incomingMP, bool NavalOnly = false)
    {
        incomingMP = 0f;
        rangescore = 0f;
        if (size < 1)
        {
            return(true);
        }
        List <global::Empire> list = new List <global::Empire>(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && departmentOfForeignAffairs.IsAtWarWith(match)));

        if (list.Count < 1)
        {
            return(true);
        }
        bool result = true;
        IWorldPositionningService service = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>();

        foreach (global::Empire empire in list)
        {
            List <IGarrison>        list2   = new List <IGarrison>();
            DepartmentOfDefense     agency  = empire.GetAgency <DepartmentOfDefense>();
            DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>();
            if (!NavalOnly)
            {
                list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler).Cast <IGarrison>());
                list2.AddRange(agency2.Cities.Cast <IGarrison>());
                list2.AddRange(agency2.Camps.Cast <IGarrison>());
                list2.AddRange(agency2.ConvertedVillages.Cast <IGarrison>());
            }
            if (NavalOnly)
            {
                list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => match.IsNaval && !match.IsSettler).Cast <IGarrison>());
                list2.AddRange(agency2.OccupiedFortresses.Cast <IGarrison>());
            }
            foreach (IGarrison garrison in list2)
            {
                if (garrison.UnitsCount > 0 && garrison is IWorldPositionable)
                {
                    float num = (float)service.GetDistance((garrison as IWorldPositionable).WorldPosition, pos);
                    if (num <= (float)size)
                    {
                        incomingMP += garrison.GetPropertyValue(SimulationProperties.MilitaryPower);
                        result      = false;
                        float num2 = 1f - num / (float)size;
                        if (num2 > rangescore)
                        {
                            rangescore = num2;
                        }
                    }
                }
            }
        }
        return(result);
    }
示例#16
0
 private void UpdateWeatherOnArmies(bool apply)
 {
     for (int i = 0; i < this.game.Empires.Length; i++)
     {
         DepartmentOfDefense agency = this.game.Empires[i].GetAgency <DepartmentOfDefense>();
         for (int j = 0; j < agency.Armies.Count; j++)
         {
             this.UpdateWeatherEffectAtPosition(agency.Armies[j].WorldPosition, agency.Armies[j], apply);
         }
     }
 }
示例#17
0
    private void ComputeMilitaryBodyRatio()
    {
        this.overralBodyRatio = 1f;
        this.overralUnitCount = 1f;
        this.bodyCount.Clear();
        this.availableMilitaryDesign.Clear();
        this.wantedBodyRatio.Clear();
        this.availableMilitaryBody.Clear();
        this.averageMilitaryPower = 0f;
        IAIUnitDesignDataRepository service = AIScheduler.Services.GetService <IAIUnitDesignDataRepository>();
        DepartmentOfDefense         agency  = this.AIEntity.Empire.GetAgency <DepartmentOfDefense>();

        for (int i = 0; i < agency.UnitDesignDatabase.UserDefinedUnitDesigns.Count; i++)
        {
            UnitDesign unitDesign = agency.UnitDesignDatabase.UserDefinedUnitDesigns[i];
            if (this.UnitDesignFilter(unitDesign))
            {
                AIUnitDesignData aiunitDesignData;
                if (service.TryGetUnitDesignData(this.AIEntity.Empire.Index, unitDesign.Model, out aiunitDesignData))
                {
                    this.availableMilitaryDesign.Add(unitDesign);
                    if (unitDesign.Context != null)
                    {
                        this.averageMilitaryPower += unitDesign.Context.GetPropertyValue(SimulationProperties.MilitaryPower);
                    }
                    int num = this.availableMilitaryBody.IndexOf(aiunitDesignData.BodyName);
                    if (num < 0)
                    {
                        num = this.availableMilitaryBody.Count;
                        this.availableMilitaryBody.Add(aiunitDesignData.BodyName);
                        this.bodyCount.Add(aiunitDesignData.EmpireBodyCount);
                        this.overralUnitCount += aiunitDesignData.EmpireBodyCount;
                        float bodyWeight = this.GetBodyWeight(unitDesign);
                        this.wantedBodyRatio.Add(bodyWeight);
                        this.overralBodyRatio += bodyWeight;
                    }
                }
            }
        }
        if (this.availableMilitaryDesign.Count > 0)
        {
            this.averageMilitaryPower /= (float)this.availableMilitaryDesign.Count;
        }
        for (int j = 0; j < this.wantedBodyRatio.Count; j++)
        {
            List <float> list2;
            List <float> list = list2 = this.wantedBodyRatio;
            int          index2;
            int          index = index2 = j;
            float        num2  = list2[index2];
            list[index] = num2 / this.overralBodyRatio;
        }
    }
示例#18
0
    public override void CleanAfterEncounter(Encounter encounter)
    {
        global::Empire occupant  = this.Occupant;
        bool           flag      = false;
        global::Empire empire    = null;
        Contender      contender = null;

        foreach (Contender contender2 in base.Encounter.Contenders)
        {
            if (!contender2.IsAttacking && contender2.Garrison.GUID == this.GUID)
            {
                DepartmentOfDefense agency = this.Empire.GetAgency <DepartmentOfDefense>();
                agency.UpdateLifeAfterEncounter(this);
                agency.CleanGarrisonAfterEncounter(this);
                if (base.Units.Count <Unit>() <= 0 && contender2.IsMainContender)
                {
                    flag = true;
                    foreach (Contender contender3 in base.Encounter.GetAlliedContendersFromContender(contender2))
                    {
                        if (contender3.IsTakingPartInBattle && contender3.ContenderState != ContenderState.Defeated)
                        {
                            flag = false;
                        }
                    }
                }
            }
            if (contender2.IsMainContender && contender2.IsAttacking)
            {
                empire    = contender2.Empire;
                contender = contender2;
            }
        }
        if (flag && empire != null)
        {
            DepartmentOfTheInterior departmentOfTheInterior = null;
            if (empire is MajorEmpire)
            {
                departmentOfTheInterior = (empire as MajorEmpire).GetAgency <DepartmentOfTheInterior>();
            }
            else if (occupant is MajorEmpire)
            {
                departmentOfTheInterior = (occupant as MajorEmpire).GetAgency <DepartmentOfTheInterior>();
            }
            if (departmentOfTheInterior != null)
            {
                departmentOfTheInterior.SwapFortressOccupant(this, empire, new object[]
                {
                    contender.Garrison as Army
                });
            }
        }
        base.LeaveEncounter();
    }
    private float ComputeInfluence(Army army, PointOfInterest pointOfInterest)
    {
        int   remainingTurnToPillage = DepartmentOfDefense.GetRemainingTurnToPillage(army, pointOfInterest);
        float num  = this.ComputeInfluence(remainingTurnToPillage, pointOfInterest.WorldPosition, pointOfInterest.Region.City.Empire);
        float num2 = this.ComputeInfluence(remainingTurnToPillage, pointOfInterest.WorldPosition, army.Empire);

        if (num > num2)
        {
            return(-num2 / num);
        }
        return(num / num2);
    }
示例#20
0
 public override State CheckCondition(QuestBehaviour questBehaviour, GameEvent gameEvent, params object[] parameters)
 {
     this.Initialize(questBehaviour);
     if (this.RegionIndex != -1)
     {
         IGameService service = Services.GetService <IGameService>();
         Diagnostics.Assert(service != null);
         if (service.Game as global::Game == null)
         {
             return(State.Failure);
         }
         IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();
         global::Empire            empire;
         if (gameEvent != null)
         {
             empire = (gameEvent.Empire as global::Empire);
         }
         else
         {
             empire = questBehaviour.Initiator;
         }
         DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>();
         if (this.CheckAllArmies)
         {
             for (int i = 0; i < agency.Armies.Count; i++)
             {
                 if ((int)service2.GetRegionIndex(agency.Armies[i].WorldPosition) == this.RegionIndex)
                 {
                     return(State.Success);
                 }
             }
         }
         else
         {
             Army army = agency.GetArmy(this.ArmyGuid);
             if (army == null)
             {
                 return(State.Failure);
             }
             Region region = service2.GetRegion(army.WorldPosition);
             if (region == null)
             {
                 return(State.Failure);
             }
             if (this.RegionIndex == region.Index)
             {
                 return(State.Success);
             }
         }
     }
     return(State.Failure);
 }
示例#21
0
    private void UpdatePillageProgress(Army army, PointOfInterest pointOfInterest)
    {
        if (!DepartmentOfDefense.CanStartPillage(army, pointOfInterest, true))
        {
            DepartmentOfDefense.StopPillage(army, pointOfInterest);
            return;
        }
        float propertyValue = army.GetPropertyValue(SimulationProperties.PillagePower);
        float num           = pointOfInterest.GetPropertyValue(SimulationProperties.PillageDefense);

        num -= propertyValue;
        pointOfInterest.SetPropertyBaseValue(SimulationProperties.PillageDefense, Mathf.Max(0f, num));
    }
    private UnitDesign FindSettlerDesign()
    {
        DepartmentOfDefense agency = base.AIEntity.Empire.GetAgency <DepartmentOfDefense>();

        for (int i = 0; i < agency.UnitDesignDatabase.UserDefinedUnitDesigns.Count; i++)
        {
            if (agency.UnitDesignDatabase.UserDefinedUnitDesigns[i].CheckUnitAbility(UnitAbility.ReadonlyColonize, -1))
            {
                return(agency.UnitDesignDatabase.UserDefinedUnitDesigns[i]);
            }
        }
        return(null);
    }
示例#23
0
 public void CheckArmiesOverMapBoostAfterDistribution()
 {
     for (int i = 0; i < base.Game.Empires.Length; i++)
     {
         if (base.Game.Empires[i] is MajorEmpire)
         {
             DepartmentOfDefense agency = base.Game.Empires[i].GetAgency <DepartmentOfDefense>();
             if (agency != null)
             {
                 agency.CheckArmiesOnMapBoost();
             }
         }
     }
 }
示例#24
0
    private void ReleaseKaijuArmyActions()
    {
        DepartmentOfDefense  agency = this.Empire.GetAgency <DepartmentOfDefense>();
        SimulationDescriptor value  = this.SimulationDescriptorDatabase.GetValue(DepartmentOfTheInterior.ArmyStatusBesiegerDescriptorName);

        this.KaijuArmy.RemoveDescriptor(value);
        if (this.KaijuArmy.IsEarthquaker)
        {
            this.KaijuArmy.SetEarthquakerStatus(false, false, null);
        }
        if (this.KaijuArmy.PillageTarget.IsValid)
        {
            DepartmentOfDefense.StopPillage(this.KaijuArmy);
        }
        if (this.KaijuArmy.IsAspirating)
        {
            agency.StopAspirating(this.KaijuArmy);
        }
        if (this.KaijuArmy.IsDismantlingDevice)
        {
            ITerraformDeviceRepositoryService service = this.gameService.Game.Services.GetService <ITerraformDeviceRepositoryService>();
            TerraformDevice device = service[this.KaijuArmy.DismantlingDeviceTarget] as TerraformDevice;
            agency.StopDismantelingDevice(this.KaijuArmy, device);
        }
        if (this.KaijuArmy.IsDismantlingCreepingNode)
        {
            CreepingNode creepingNode = null;
            if (this.gameEntityRepositoryService.TryGetValue <CreepingNode>(this.KaijuArmy.DismantlingCreepingNodeTarget, out creepingNode))
            {
                agency.StopDismantelingCreepingNode(this.KaijuArmy, creepingNode);
            }
        }
        IWorldPositionningService service2 = this.gameService.Game.Services.GetService <IWorldPositionningService>();
        Region region = service2.GetRegion(this.KaijuArmy.WorldPosition);

        if (region.City != null && region.City.Empire != this.Empire)
        {
            DepartmentOfTheInterior agency2 = region.City.Empire.GetAgency <DepartmentOfTheInterior>();
            if (agency2 != null)
            {
                if (region.City.BesiegingEmpire == this.Empire && agency2.NeedToStopSiege(region.City))
                {
                    agency2.StopSiege(region.City);
                }
                agency2.StopNavalSiege(region.City, this.KaijuArmy);
            }
            IVisibilityService service3 = this.gameService.Game.Services.GetService <IVisibilityService>();
            service3.NotifyVisibilityHasChanged(this.Empire);
        }
    }
示例#25
0
    public void SpawnKaiju(WorldPosition targetPosition, GameEntityGUID kaijuGUID, GameEntityGUID garrisonGUID, GameEntityGUID armyGUID, GameEntityGUID monsterGUID, GameEntityGUID[] licesGUIDs)
    {
        Kaiju kaiju = new Kaiju(base.Empire as KaijuEmpire, kaijuGUID);

        string[] kaijuDescriptors = this.KaijuEmpire.KaijuFaction.KaijuDescriptors;
        for (int i = 0; i < kaijuDescriptors.Length; i++)
        {
            SimulationDescriptor descriptor = null;
            if (this.descriptorsDatabase.TryGetValue(kaijuDescriptors[i], out descriptor))
            {
                kaiju.AddDescriptor(descriptor, false);
            }
        }
        KaijuGarrison        kaijuGarrison = new KaijuGarrison(garrisonGUID, targetPosition);
        SimulationDescriptor value         = this.descriptorsDatabase.GetValue(Kaiju.ClassKaijuGarrison);

        kaijuGarrison.AddDescriptor(value, false);
        kaijuGarrison.SetPropertyBaseValue(SimulationProperties.MaximumUnitSlotCount, (float)(licesGUIDs.Length + 1));
        kaiju.SetGarrison(kaijuGarrison);
        KaijuArmy            kaijuArmy = this.departmentOfDefense.CreateKaijuArmy(armyGUID, targetPosition, true);
        SimulationDescriptor value2    = this.descriptorsDatabase.GetValue(Kaiju.ClassKaijuArmy);

        kaijuArmy.AddDescriptor(value2, false);
        kaijuArmy.SetPropertyBaseValue(SimulationProperties.MaximumUnitSlotCount, (float)(licesGUIDs.Length + 1));
        kaiju.SetArmy(kaijuArmy);
        this.gameEntityRepositoryService.Register(kaijuArmy);
        this.gameEntityRepositoryService.Register(kaiju);
        kaiju.ChangeToWildState();
        kaiju.ChangeToGarrisonMode(false);
        Unit unit = DepartmentOfDefense.CreateUnitByDesign(monsterGUID, this.KaijuEmpire.FindMonsterDesign(true));

        kaiju.AddUnit(unit);
        for (int j = 0; j < licesGUIDs.Length; j++)
        {
            Unit unit2 = DepartmentOfDefense.CreateUnitByDesign(licesGUIDs[j], this.KaijuEmpire.FindLiceDesign(true));
            kaiju.AddUnit(unit2);
        }
        this.lastLiceArmySpawnTurn = (this.gameService.Game as global::Game).Turn;
        this.Kaiju = kaiju;
        this.KaijuEmpire.AddKaiju(kaiju);
        kaiju.Refresh(false);
        foreach (global::Empire empire in (this.gameService.Game as global::Game).Empires)
        {
            if (empire is MajorEmpire)
            {
                this.eventService.Notify(new EventKaijuSpawned(empire, this.Kaiju));
            }
        }
    }
示例#26
0
    public static bool AreaIsSave(WorldPosition pos, int size, DepartmentOfForeignAffairs departmentOfForeignAffairs, bool NavalOnly = false, bool ignoreColdwar = false)
    {
        if (size < 1)
        {
            return(true);
        }
        List <global::Empire> list = new List <global::Empire>();

        if (ignoreColdwar)
        {
            list.AddRange(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && departmentOfForeignAffairs.IsAtWarWith(match)));
        }
        else
        {
            list.AddRange(Array.FindAll <global::Empire>((Services.GetService <IGameService>().Game as global::Game).Empires, (global::Empire match) => match is MajorEmpire && !departmentOfForeignAffairs.IsFriend(match)));
        }
        if (list.Count == 0)
        {
            return(true);
        }
        IWorldPositionningService service = Services.GetService <IGameService>().Game.Services.GetService <IWorldPositionningService>();

        foreach (global::Empire empire in list)
        {
            List <IGarrison>        list2   = new List <IGarrison>();
            DepartmentOfDefense     agency  = empire.GetAgency <DepartmentOfDefense>();
            DepartmentOfTheInterior agency2 = empire.GetAgency <DepartmentOfTheInterior>();
            if (!NavalOnly)
            {
                list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => !match.IsSeafaring && !match.IsSettler).Cast <IGarrison>());
                list2.AddRange(agency2.Cities.Cast <IGarrison>());
                list2.AddRange(agency2.Camps.Cast <IGarrison>());
                list2.AddRange(agency2.ConvertedVillages.Cast <IGarrison>());
            }
            if (NavalOnly)
            {
                list2.AddRange(agency.Armies.ToList <Army>().FindAll((Army match) => match.IsNaval && !match.IsSettler).Cast <IGarrison>());
                list2.AddRange(agency2.OccupiedFortresses.Cast <IGarrison>());
            }
            foreach (IGarrison garrison in list2)
            {
                if (garrison.UnitsCount > 0 && garrison is IWorldPositionable && service.GetDistance((garrison as IWorldPositionable).WorldPosition, pos) <= size)
                {
                    return(false);
                }
            }
        }
        return(true);
    }
示例#27
0
    private IEnumerator GameClientState_Turn_End_UnitHealthPerTurnGain(string context, string name)
    {
        DepartmentOfDefense defense = base.Empire.GetAgency <DepartmentOfDefense>();

        for (int index = 0; index < this.villages.Count; index++)
        {
            float regenModifier = this.ComputeVillageRegenModifier(this.villages[index]);
            foreach (Unit unit in this.villages[index].Units)
            {
                DepartmentOfDefense.RegenUnit(unit, regenModifier, 0);
            }
            this.villages[index].Refresh(false);
            defense.CleanGarrisonAfterEncounter(this.villages[index]);
        }
        yield break;
    }
示例#28
0
    private bool DamageUnit(DepartmentOfDefense departmentOfDefense, Unit unit)
    {
        if (unit == null || unit.CheckUnitAbility(UnitAbility.ReadonlySubmersible, -1))
        {
            return(false);
        }
        float num = this.lightningDamageInPercent - unit.GetPropertyValue(SimulationProperties.LightningDamageReduction);

        num *= unit.GetPropertyValue(SimulationProperties.MaximumHealth);
        if (num > 0f)
        {
            departmentOfDefense.WoundUnit(unit, num);
            return(true);
        }
        return(false);
    }
示例#29
0
    public Amplitude.Unity.Game.Orders.Order CreateArmyFromFortress(BaseNavyArmy army)
    {
        if (!this.IsFortress(army))
        {
            return(null);
        }
        WorldPosition    armyPosition = WorldPosition.Invalid;
        WorldOrientation orientation  = WorldOrientation.East;

        if (army.MainAttackableTarget != null)
        {
            orientation = this.worldPositionService.GetOrientation(army.Garrison.WorldPosition, army.MainAttackableTarget.WorldPosition);
        }
        Fortress fortress = army.Garrison as Fortress;

        for (int i = 0; i < 6; i++)
        {
            WorldPosition neighbourTile = this.worldPositionService.GetNeighbourTile(fortress.WorldPosition, orientation.Rotate(i), 1);
            if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(neighbourTile, PathfindingMovementCapacity.Water))
            {
                armyPosition = neighbourTile;
                break;
            }
        }
        if (!armyPosition.IsValid)
        {
            for (int j = 0; j < fortress.Facilities.Count; j++)
            {
                for (int k = 0; k < 6; k++)
                {
                    WorldPosition neighbourTile2 = this.worldPositionService.GetNeighbourTile(fortress.Facilities[j].WorldPosition, (WorldOrientation)k, 1);
                    if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(neighbourTile2, PathfindingMovementCapacity.Water))
                    {
                        armyPosition = neighbourTile2;
                        break;
                    }
                }
            }
        }
        GameEntityGUID[] array = new GameEntityGUID[army.Garrison.StandardUnits.Count];
        for (int l = 0; l < army.Garrison.StandardUnits.Count; l++)
        {
            array[l] = army.Garrison.StandardUnits[l].GUID;
        }
        return(new OrderTransferGarrisonToNewArmy(army.Garrison.Empire.Index, army.Garrison.GUID, array, armyPosition, null, false, true, true));
    }
    private void ResetRecruitementLocks()
    {
        this.unitsGUIDS.Clear();
        foreach (AICommander aicommander in base.AICommanders)
        {
            foreach (AICommanderMission aicommanderMission in aicommander.Missions)
            {
                if (aicommanderMission.Completion == AICommanderMission.AICommanderMissionCompletion.Initializing)
                {
                    AICommanderMission_RegroupArmyAt aicommanderMission_RegroupArmyAt = aicommanderMission as AICommanderMission_RegroupArmyAt;
                    if (aicommanderMission_RegroupArmyAt != null)
                    {
                        this.unitsGUIDS.AddRange(aicommanderMission_RegroupArmyAt.UnitGuids);
                    }
                }
            }
        }
        DepartmentOfDefense agency = this.Empire.GetAgency <DepartmentOfDefense>();

        for (int i = 0; i < agency.Armies.Count; i++)
        {
            this._Internal_ResetRecruitementLocks(agency.Armies[i]);
        }
        if (this.Empire is MajorEmpire)
        {
            DepartmentOfTheInterior agency2 = this.Empire.GetAgency <DepartmentOfTheInterior>();
            if (agency2 != null)
            {
                for (int j = 0; j < agency2.Cities.Count; j++)
                {
                    this._Internal_ResetRecruitementLocks(agency2.Cities[j]);
                }
            }
            List <Village> convertedVillages = ((MajorEmpire)this.Empire).ConvertedVillages;
            for (int k = 0; k < convertedVillages.Count; k++)
            {
                Village village = convertedVillages[k];
                if (village != null)
                {
                    this._Internal_ResetRecruitementLocks(village);
                }
            }
        }
    }