Esempio n. 1
0
    public int GetCurrentUnitLevel()
    {
        int   maxEraNumber  = DepartmentOfScience.GetMaxEraNumber();
        float propertyValue = base.Empire.GetPropertyValue("MinorEmpireDifficultyFactor");

        return(Mathf.FloorToInt((float)maxEraNumber * this.eraFactorForUnitLevel * propertyValue + (float)this.EndTurnService.Turn * this.turnFactorForUnitLevel * propertyValue));
    }
Esempio n. 2
0
    public StaticString GetUpToDateDesignName()
    {
        int          maxEraNumber = DepartmentOfScience.GetMaxEraNumber();
        StaticString tag          = "Era" + maxEraNumber;

        foreach (UnitDesign unitDesign in this.departmentOfDefense.UnitDesignDatabase.GetAvailableUnitDesignsAsEnumerable())
        {
            if (!unitDesign.CheckAgainstTag(DownloadableContent16.SeafaringUnit) && !unitDesign.CheckAgainstTag("ConvertedVillageUnit") && !unitDesign.CheckAgainstTag("WildLiceArmy") && unitDesign.CheckAgainstTag(tag) && !unitDesign.Name.Contains("Mercenary"))
            {
                return(unitDesign.Name);
            }
        }
        return(StaticString.Empty);
    }
Esempio n. 3
0
    public static void UpdateTameCosts()
    {
        IDatabase <ArmyAction> database = Databases.GetDatabase <ArmyAction>(false);

        Diagnostics.Assert(database != null);
        int maxEraNumber = DepartmentOfScience.GetMaxEraNumber();

        for (int i = 0; i < database.Count <ArmyAction>(); i++)
        {
            ArmyAction armyAction = database.ElementAt(i);
            if (armyAction is IArmyActionWithKaijuTameCost)
            {
                KaijuTameCost tameCost = (armyAction as IArmyActionWithKaijuTameCost).TameCost;
                tameCost.UpdateActiveCost(maxEraNumber);
            }
        }
    }
Esempio n. 4
0
    private void Client_TurnBegin_SpawnLiceUnit()
    {
        int turn         = (this.GameService.Game as global::Game).Turn;
        int maxEraNumber = DepartmentOfScience.GetMaxEraNumber();

        if (this.CanSpawnMilitiaUnit() && this.NextTurnToSpawnUnit > 0 && this.NextTurnToSpawnUnit == turn)
        {
            GameEntityGUID guid = this.KaijuGarrison.GUID;
            StaticString   name = this.KaijuEmpire.FindLiceDesign(true).Name;
            if (this.OnArmyMode() && this.KaijuArmy != null)
            {
                guid = this.KaijuArmy.GUID;
            }
            global::PlayerController server = this.Empire.PlayerControllers.Server;
            if (server != null)
            {
                OrderSpawnUnit order = new OrderSpawnUnit(this.Empire.Index, maxEraNumber, false, name, guid, false);
                server.PostOrder(order);
            }
            this.ComputeNextTurnToSpawnUnits(true);
        }
    }
 protected void SpawnArmies(QuestBehaviour questBehaviour)
 {
     if (!string.IsNullOrEmpty(this.ArmyDroplist))
     {
         IGameService service = Services.GetService <IGameService>();
         if (service == null || service.Game == null)
         {
             Diagnostics.LogError("Failed to retrieve the game service.");
             return;
         }
         global::Game game = service.Game as global::Game;
         if (game == null)
         {
             Diagnostics.LogError("Failed to cast gameService.Game to Game.");
             return;
         }
         IDatabase <Droplist> database = Databases.GetDatabase <Droplist>(false);
         if (database == null)
         {
             return;
         }
         string   armyDroplist = this.ArmyDroplist;
         Droplist droplist;
         if (!database.TryGetValue(armyDroplist, out droplist))
         {
             Diagnostics.LogError("Cannot retrieve drop list '{0}' in quest definition '{1}'", new object[]
             {
                 armyDroplist,
                 questBehaviour.Quest.QuestDefinition.Name
             });
             return;
         }
         global::Empire empire = this.EmpireArmyOwner;
         if (empire == null || empire is LesserEmpire || this.UseBehaviorInitiatorEmpire)
         {
             empire = questBehaviour.Initiator;
         }
         if (this.UseBehaviorInitiatorEmpire)
         {
             this.EmpireArmyOwner = questBehaviour.Initiator;
         }
         if (this.EmpireArmyOwner is MajorEmpire && (this.EmpireArmyOwner as MajorEmpire).ELCPIsEliminated)
         {
             return;
         }
         Droplist droplist2;
         DroppableArmyDefinition droppableArmyDefinition = droplist.Pick(empire, out droplist2, new object[0]) as DroppableArmyDefinition;
         if (droppableArmyDefinition != null)
         {
             int num = 0;
             IDatabase <AnimationCurve> database2 = Databases.GetDatabase <AnimationCurve>(false);
             AnimationCurve             animationCurve;
             if (database2 != null && database2.TryGetValue(QuestBehaviourTreeNode_Action_SpawnArmies.questUnitLevelEvolution, out animationCurve))
             {
                 float propertyValue = questBehaviour.Initiator.GetPropertyValue(SimulationProperties.GameSpeedMultiplier);
                 num = (int)animationCurve.EvaluateWithScaledAxis((float)game.Turn, propertyValue, 1f);
                 num = Math.Max(0, Math.Min(100, num));
             }
             StaticString[] unitDesignsNames = Array.ConvertAll <string, StaticString>(droppableArmyDefinition.UnitDesigns, (string input) => input);
             StaticString[] armyTags         = new StaticString[]
             {
                 this.ArmyTag
             };
             StaticString[] unitsTags = new StaticString[]
             {
                 this.ArmyUnitTag
             };
             int val = 1;
             if (this.ScaleWithMaxEra)
             {
                 val = DepartmentOfScience.GetMaxEraNumber() - 1;
             }
             num = Math.Max(num, val);
             OrderSpawnArmies orderSpawnArmies = new OrderSpawnArmies(this.EmpireArmyOwner.Index, this.SpawnLocations.ToList <WorldPosition>().ToArray(), unitDesignsNames, 1, armyTags, unitsTags, num, QuestArmyObjective.QuestBehaviourType.Roaming);
             Diagnostics.Log("Posting order: {0}.", new object[]
             {
                 orderSpawnArmies.ToString()
             });
             this.EmpireArmyOwner.PlayerControllers.Server.PostOrder(orderSpawnArmies);
         }
     }
 }
Esempio n. 6
0
 protected void SpawnArmy(QuestBehaviour questBehaviour)
 {
     if (!string.IsNullOrEmpty(this.ArmyDroplist))
     {
         IGameService service = Services.GetService <IGameService>();
         if (service == null || service.Game == null)
         {
             Diagnostics.LogError("Failed to retrieve the game service.");
             return;
         }
         global::Game game = service.Game as global::Game;
         if (game == null)
         {
             Diagnostics.LogError("Failed to cast gameService.Game to Game.");
             return;
         }
         IDatabase <Droplist> database = Databases.GetDatabase <Droplist>(false);
         if (database == null)
         {
             return;
         }
         string text = this.ArmyDroplist;
         if (this.ArmyDroplistSuffix != string.Empty)
         {
             text = text + "_" + this.ArmyDroplistSuffix;
         }
         Droplist droplist;
         if (!database.TryGetValue(text, out droplist))
         {
             Diagnostics.LogError("Cannot retrieve drop list '{0}' in quest definition '{1}'", new object[]
             {
                 text,
                 questBehaviour.Quest.QuestDefinition.Name
             });
             return;
         }
         if (!string.IsNullOrEmpty(this.EmpireArmyOwnerVarName))
         {
             global::Empire empire = null;
             object         obj;
             if (questBehaviour.TryGetQuestVariableValueByName <object>(this.EmpireArmyOwnerVarName, out obj))
             {
                 if (obj is global::Empire)
                 {
                     empire = (obj as global::Empire);
                 }
                 else if (obj is int)
                 {
                     empire = game.Empires[(int)obj];
                 }
                 if (empire != null)
                 {
                     this.EmpireArmyOwner = empire;
                 }
             }
         }
         global::Empire empire2 = this.EmpireArmyOwner;
         if (empire2 == null || empire2 is LesserEmpire || this.UseBehaviorInitiatorEmpire)
         {
             empire2 = questBehaviour.Initiator;
         }
         if (this.UseBehaviorInitiatorEmpire)
         {
             this.EmpireArmyOwner = questBehaviour.Initiator;
         }
         if (this.EmpireArmyOwner is MajorEmpire && (this.EmpireArmyOwner as MajorEmpire).ELCPIsEliminated)
         {
             return;
         }
         Droplist droplist2;
         DroppableArmyDefinition droppableArmyDefinition = droplist.Pick(empire2, out droplist2, new object[0]) as DroppableArmyDefinition;
         if (droppableArmyDefinition != null)
         {
             int num = 0;
             if (this.ScaleWithMaxEra)
             {
                 num = DepartmentOfScience.GetMaxEraNumber() - 1;
             }
             int val = 0;
             IDatabase <AnimationCurve> database2 = Databases.GetDatabase <AnimationCurve>(false);
             AnimationCurve             animationCurve;
             if (database2 != null && database2.TryGetValue(QuestBehaviourTreeNode_Action_SpawnArmy.questUnitLevelEvolution, out animationCurve))
             {
                 float propertyValue = questBehaviour.Initiator.GetPropertyValue(SimulationProperties.GameSpeedMultiplier);
                 val = (int)animationCurve.EvaluateWithScaledAxis((float)game.Turn, propertyValue, 1f);
                 val = Math.Max(0, Math.Min(100, val));
             }
             num = Math.Max(num, val);
             StaticString[]         array     = Array.ConvertAll <string, StaticString>(droppableArmyDefinition.UnitDesigns, (string input) => input);
             bool                   flag      = false;
             IDatabase <UnitDesign> database3 = Databases.GetDatabase <UnitDesign>(false);
             for (int i = 0; i < array.Length; i++)
             {
                 UnitDesign unitDesign;
                 if (database3.TryGetValue(array[i], out unitDesign) && unitDesign != null && unitDesign.Tags.Contains(DownloadableContent16.TagSeafaring))
                 {
                     flag = true;
                     break;
                 }
             }
             IEnumerable <WorldPosition> enumerable = null;
             questBehaviour.TryGetQuestVariableValueByName <WorldPosition>(this.ForbiddenSpawnLocationVarName, out enumerable);
             List <WorldPosition>      list     = this.SpawnLocations.ToList <WorldPosition>().Randomize(null);
             IWorldPositionningService service2 = game.Services.GetService <IWorldPositionningService>();
             IPathfindingService       service3 = game.Services.GetService <IPathfindingService>();
             Diagnostics.Assert(service2 != null);
             WorldPosition worldPosition = WorldPosition.Invalid;
             if (!questBehaviour.Quest.QuestDefinition.IsGlobal)
             {
                 PathfindingMovementCapacity pathfindingMovementCapacity = PathfindingMovementCapacity.Water;
                 if (!flag)
                 {
                     pathfindingMovementCapacity |= PathfindingMovementCapacity.Ground;
                 }
                 for (int j = 0; j < list.Count; j++)
                 {
                     WorldPosition worldPosition2 = list[j];
                     if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(worldPosition2, pathfindingMovementCapacity))
                     {
                         if (enumerable != null)
                         {
                             if (enumerable.Contains(worldPosition2))
                             {
                                 goto IL_330;
                             }
                             this.AddPositionToForbiddenSpawnPosition(questBehaviour, worldPosition2);
                         }
                         worldPosition = worldPosition2;
                         break;
                     }
                     IL_330 :;
                 }
                 if (!service3.IsTileStopable(worldPosition, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water, PathfindingFlags.IgnoreFogOfWar))
                 {
                     worldPosition = WorldPosition.Invalid;
                 }
                 if (!worldPosition.IsValid && list.Count > 0)
                 {
                     List <WorldPosition>  list2 = new List <WorldPosition>();
                     Queue <WorldPosition> queue = new Queue <WorldPosition>();
                     worldPosition = list[0];
                     bool flag2 = false;
                     if (worldPosition.IsValid)
                     {
                         flag2 = service2.IsWaterTile(worldPosition);
                     }
                     do
                     {
                         if (queue.Count > 0)
                         {
                             worldPosition = queue.Dequeue();
                         }
                         for (int k = 0; k < 6; k++)
                         {
                             WorldPosition neighbourTileFullCyclic = service2.GetNeighbourTileFullCyclic(worldPosition, (WorldOrientation)k, 1);
                             if (!list2.Contains(neighbourTileFullCyclic) && list2.Count < 19)
                             {
                                 queue.Enqueue(neighbourTileFullCyclic);
                                 list2.Add(neighbourTileFullCyclic);
                             }
                         }
                         if (!DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(worldPosition, pathfindingMovementCapacity) || !service3.IsTileStopable(worldPosition, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water, PathfindingFlags.IgnoreFogOfWar) || flag2 != service2.IsWaterTile(worldPosition))
                         {
                             worldPosition = WorldPosition.Invalid;
                         }
                     }while (worldPosition == WorldPosition.Invalid && queue.Count > 0);
                 }
                 if (!worldPosition.IsValid)
                 {
                     string   format = "Cannot find a valid position to spawn on: {0}";
                     object[] array2 = new object[1];
                     array2[0] = string.Join(",", list.Select(delegate(WorldPosition position)
                     {
                         WorldPosition worldPosition3 = position;
                         return(worldPosition3.ToString());
                     }).ToArray <string>());
                     Diagnostics.LogError(format, array2);
                     return;
                 }
             }
             OrderSpawnArmy orderSpawnArmy;
             if (worldPosition.IsValid)
             {
                 list.Clear();
                 list.Add(worldPosition);
                 WorldOrientation worldOrientation = WorldOrientation.East;
                 for (int l = 0; l < 6; l++)
                 {
                     WorldPosition neighbourTile = service2.GetNeighbourTile(worldPosition, worldOrientation, 1);
                     bool          flag3         = flag == service2.IsWaterTile(neighbourTile);
                     if (neighbourTile.IsValid && flag3 && service3.IsTileStopable(worldPosition, PathfindingMovementCapacity.Ground | PathfindingMovementCapacity.Water, PathfindingFlags.IgnoreFogOfWar))
                     {
                         list.Add(neighbourTile);
                     }
                     worldOrientation = worldOrientation.Rotate(1);
                 }
                 orderSpawnArmy = new OrderSpawnArmy(this.EmpireArmyOwner.Index, list.ToArray(), num, true, this.CanMoveOnSpawn, true, questBehaviour.Quest.QuestDefinition.IsGlobal || this.ForceGlobalArmySymbol, array);
             }
             else
             {
                 orderSpawnArmy = new OrderSpawnArmy(this.EmpireArmyOwner.Index, list.ToArray(), num, true, this.CanMoveOnSpawn, true, questBehaviour.Quest.QuestDefinition.IsGlobal || this.ForceGlobalArmySymbol, array);
             }
             orderSpawnArmy.GameEntityGUID = this.ArmyGUID;
             Diagnostics.Log("Posting order: {0} at {1}", new object[]
             {
                 orderSpawnArmy.ToString(),
                 worldPosition
             });
             if (!string.IsNullOrEmpty(this.TransferResourceName) && this.TransferResourceAmount > 0)
             {
                 Ticket ticket;
                 this.EmpireArmyOwner.PlayerControllers.Server.PostOrder(orderSpawnArmy, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderSpawnArmy_TicketRaised));
                 return;
             }
             this.EmpireArmyOwner.PlayerControllers.Server.PostOrder(orderSpawnArmy);
         }
     }
 }
Esempio n. 7
0
    private void Server_TurnBegin_CheckLiceArmySpawn()
    {
        global::Game game = this.gameService.Game as global::Game;

        Diagnostics.Assert(game != null);
        ISessionService service = Services.GetService <ISessionService>();

        Diagnostics.Assert(service != null);
        global::Session session = service.Session as global::Session;

        Diagnostics.Assert(session != null);
        KaijuCouncil.WildLiceArmyPreferences.LoadRegistryValues(session);
        if (this.LiceArmies.Length >= KaijuCouncil.WildLiceArmyPreferences.MaxArmiesAlive)
        {
            return;
        }
        int turn = game.Turn;
        int num  = (int)Math.Ceiling((double)((float)KaijuCouncil.WildLiceArmyPreferences.SpawningCooldown * base.Empire.GetPropertyValue(SimulationProperties.GameSpeedMultiplier)));

        if (turn < this.lastLiceArmySpawnTurn + num)
        {
            return;
        }
        int num2 = this.Kaiju.OnGarrisonMode() ? KaijuCouncil.WildLiceArmyPreferences.ArmiesToSpawnCount : 0;

        if (num2 <= 0)
        {
            return;
        }
        List <WorldPosition> list = new List <WorldPosition>();

        for (int i = 0; i < this.Kaiju.Region.WorldPositions.Length; i++)
        {
            WorldPosition worldPosition = this.Kaiju.Region.WorldPositions[i];
            if (DepartmentOfDefense.CheckWhetherTargetPositionIsValidForUseAsArmySpawnLocation(worldPosition, PathfindingMovementCapacity.Ground) && worldPosition != this.Kaiju.WorldPosition)
            {
                list.Add(worldPosition);
            }
        }
        if (list.Count == 0)
        {
            return;
        }
        System.Random randomizer = new System.Random(World.Seed + turn);
        list = (from position in list
                orderby this.worldPositionningService.GetDistance(this.Kaiju.WorldPosition, position), randomizer.NextDouble()
                select position).ToList <WorldPosition>();
        WorldPosition[] worldPositions;
        if (list.Count > num2)
        {
            worldPositions = list.Take(Math.Min(list.Count, num2)).ToArray <WorldPosition>();
        }
        else
        {
            worldPositions = list.ToArray();
        }
        List <StaticString> list2 = new List <StaticString>();
        StaticString        name  = this.KaijuEmpire.FindLiceDesign(true).Name;
        int unitsPerArmy          = KaijuCouncil.WildLiceArmyPreferences.UnitsPerArmy;

        for (int j = 0; j < unitsPerArmy; j++)
        {
            list2.Add(name);
        }
        List <StaticString> list3 = new List <StaticString>();

        list3.Add(KaijuCouncil.WildLiceArmyPreferences.ArmyTag);
        List <StaticString> list4 = new List <StaticString>();

        list4.Add(KaijuCouncil.WildLiceArmyPreferences.UnitTag);
        List <MajorEmpire> list5 = new List <MajorEmpire>();
        int k = 0;

        while (k < game.Empires.Length)
        {
            if (game.Empires[k] is MajorEmpire && !(game.Empires[k] as MajorEmpire).ELCPIsEliminated)
            {
                if (game.Empires[k].GetAgency <DepartmentOfTheInterior>().NonInfectedCities.Count > 0)
                {
                    list5.Add(game.Empires[k] as MajorEmpire);
                    break;
                }
                break;
            }
            else
            {
                k++;
            }
        }
        DepartmentOfTheInterior agency      = list5[game.Turn % list5.Count].GetAgency <DepartmentOfTheInterior>();
        MinorEmpire             minorEmpire = agency.Cities[game.Turn % agency.Cities.Count].Region.MinorEmpire;
        OrderSpawnArmies        order       = new OrderSpawnArmies(minorEmpire.Index, worldPositions, list2.ToArray(), KaijuCouncil.WildLiceArmyPreferences.ArmiesToSpawnCount, list3.ToArray(), list4.ToArray(), Math.Max(0, DepartmentOfScience.GetMaxEraNumber()), QuestArmyObjective.QuestBehaviourType.Undefined);
        Ticket ticket = null;

        minorEmpire.PlayerControllers.Server.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OrderSpawnLiceArmies_TicketRaised));
    }
Esempio n. 8
0
    private void Client_TurnBegin_RecalculateELCPTameResource()
    {
        if (this.ELCPTameCostCooldown < 1)
        {
            return;
        }
        int num  = (this.gameService.Game as global::Game).Turn + 1;
        int num2 = num % this.ELCPTameCostCooldown;

        if (num2 != 0 && this.eLCPResourceName != StaticString.Empty)
        {
            return;
        }
        num -= num2;
        System.Random random        = new System.Random(World.Seed + base.Empire.Index * base.Empire.Index * base.Empire.Index * base.Empire.Index * base.Empire.Index + num * num);
        int           maxEraNumber  = DepartmentOfScience.GetMaxEraNumber();
        KaijuTameCost kaijuTameCost = KaijuCouncil.GetKaijuTameCost();
        Dictionary <string, List <PointOfInterestTemplate> > dictionary = KaijuTechsManager.ComputeLuxuryAbundance(this.gameService.Game as global::Game);
        List <PointOfInterestTemplate> list = new List <PointOfInterestTemplate>();
        List <string> list2 = new List <string>();

        for (int i = 0; i < kaijuTameCost.CostDefinitions.Length; i++)
        {
            KaijuTameCost.CostDefinition costDefinition = kaijuTameCost.CostDefinitions[i];
            if (!list2.Contains(costDefinition.LuxuryTier))
            {
                string[] array = costDefinition.EraNumber.Split(new char[]
                {
                    ','
                });
                bool flag = false;
                for (int j = 0; j < array.Length; j++)
                {
                    int num3 = 0;
                    if (int.TryParse(array[j], out num3) && num3 <= maxEraNumber)
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    list.AddRange(dictionary[costDefinition.LuxuryTier]);
                    list2.Add(costDefinition.LuxuryTier);
                }
            }
        }
        PointOfInterestTemplate pointOfInterestTemplate = list[random.Next(list.Count)];
        string empty = string.Empty;

        if (pointOfInterestTemplate.Properties.TryGetValue("ResourceName", out empty))
        {
            Diagnostics.Log("ELCP {0} Client_TurnBegin_RecalculateELCPTameResource rolled Resource {1} instead of {2}", new object[]
            {
                base.Empire.Index.ToString() + "/" + this.KaijuEmpire.KaijuFaction.LocalizedName,
                empty,
                kaijuTameCost.ResourceName
            });
            this.eLCPResourceName = new StaticString(empty);
        }
    }