Esempio n. 1
0
    private void SpawnArmy()
    {
        IGameService service = Services.GetService <IGameService>();

        if (service.Game == null)
        {
            return;
        }
        if (WorldCursor.HighlightedWorldPosition.IsValid)
        {
            IPlayerControllerRepositoryService service2 = service.Game.Services.GetService <IPlayerControllerRepositoryService>();
            string value = Amplitude.Unity.Runtime.Runtime.Registry.GetValue <string>("Debug/GodCursor/SpawnArmy", string.Empty);
            int    index = service2.ActivePlayerController.Empire.Index;
            if (string.IsNullOrEmpty(value))
            {
                return;
            }
            string[] array = value.Split(new char[]
            {
                ','
            });
            if (array.Length == 0)
            {
                return;
            }
            StaticString[] unitDesignsByName = Array.ConvertAll <string, StaticString>(array, (string input) => input);
            OrderSpawnArmy orderSpawnArmy    = new OrderSpawnArmy(index, WorldCursor.HighlightedWorldPosition, unitDesignsByName);
            service2.ActivePlayerController.PostOrder(orderSpawnArmy);
            Diagnostics.Log("Posting order: {0}.", new object[]
            {
                orderSpawnArmy.ToString()
            });
        }
    }
Esempio n. 2
0
    private void SpawnMinorArmy()
    {
        IGameService service = Services.GetService <IGameService>();

        if (service.Game == null)
        {
            return;
        }
        if (WorldCursor.HighlightedWorldPosition.IsValid && WorldCursor.HighlightedRegion.MinorEmpire != null)
        {
            IPlayerControllerRepositoryService service2 = service.Game.Services.GetService <IPlayerControllerRepositoryService>();
            UnitDesign          unitDesign = WorldCursor.HighlightedRegion.MinorEmpire.GetAgency <DepartmentOfDefense>().UnitDesignDatabase.UserDefinedUnitDesigns[0];
            List <StaticString> list       = new List <StaticString>();
            for (int i = 0; i < 3; i++)
            {
                list.Add(unitDesign.Name);
            }
            OrderSpawnArmy orderSpawnArmy = new OrderSpawnArmy(WorldCursor.HighlightedRegion.MinorEmpire.Index, WorldCursor.HighlightedWorldPosition, list.ToArray());
            service2.ActivePlayerController.PostOrder(orderSpawnArmy);
            Diagnostics.Log("Posting order: {0}.", new object[]
            {
                orderSpawnArmy.ToString()
            });
        }
    }
Esempio n. 3
0
 private void OrderSpawnArmy_TicketRaised(object sender, TicketRaisedEventArgs e)
 {
     if (e.Result == PostOrderResponse.Processed)
     {
         OrderSpawnArmy orderSpawnArmy = e.Order as OrderSpawnArmy;
         IGameEntity    gameEntity;
         if (this.gameEntityRepositoryService != null && this.gameEntityRepositoryService.TryGetValue(orderSpawnArmy.GameEntityGUID, out gameEntity) && gameEntity != null)
         {
             Army army = gameEntity as Army;
             if (army != null && army.StandardUnits.Count > 0)
             {
                 OrderTransferResources order = new OrderTransferResources(this.EmpireArmyOwner.Index, this.TransferResourceName, (float)this.TransferResourceAmount, army.StandardUnits[0].GUID);
                 this.EmpireArmyOwner.PlayerControllers.Server.PostOrder(order);
             }
         }
     }
 }
Esempio n. 4
0
 private void UnitSpawnWorldCursor_Click(object sender, CursorTargetMouseEventArgs e)
 {
     if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.LeftControl))
     {
         this.SpawnEnnemyArmy();
         return;
     }
     if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftShift))
     {
         IGameService service = Services.GetService <IGameService>();
         if (service.Game == null || GodWorldCursor.EditorSelectedEmpire == null || GodWorldCursor.EditorSelectedUnitDesigns == null || GodWorldCursor.EditorSelectedUnitDesigns.Length == 0)
         {
             return;
         }
         if (WorldCursor.HighlightedWorldPosition.IsValid)
         {
             OrderSpawnArmy orderSpawnArmy = new OrderSpawnArmy(GodWorldCursor.EditorSelectedEmpire.Index, WorldCursor.HighlightedWorldPosition, GodWorldCursor.EditorSelectedUnitDesigns);
             service.Game.Services.GetService <IPlayerControllerRepositoryService>().ActivePlayerController.PostOrder(orderSpawnArmy);
             Diagnostics.Log("Posting order: {0}.", new object[]
             {
                 orderSpawnArmy.ToString()
             });
             return;
         }
     }
     else
     {
         if (Input.GetKey(KeyCode.RightControl))
         {
             this.SpawnWildlingArmy();
             return;
         }
         if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.LeftAlt))
         {
             this.SpawnMinorArmy();
             return;
         }
         if (Input.GetKey(KeyCode.LeftShift))
         {
             this.SpawnArmy();
             return;
         }
         if (Input.GetKey(KeyCode.LeftAlt))
         {
             this.SpawnCity();
             return;
         }
         if (Input.GetKey(KeyCode.RightShift))
         {
             this.SpawnCamp();
             return;
         }
         if (Input.GetKey(KeyCode.C))
         {
             Amplitude.Unity.View.IViewService service2 = Services.GetService <Amplitude.Unity.View.IViewService>();
             if (service2.CurrentView != null && service2.CurrentView.CameraController is IWorldViewCameraController)
             {
                 (service2.CurrentView.CameraController as IWorldViewCameraController).FocusCameraAt(WorldCursor.HighlightedWorldPosition, false, true);
             }
         }
     }
 }
Esempio n. 5
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);
         }
     }
 }