Exemple #1
0
 //called each time a player owned resource generator is either full or collected
 private void OnResourceGeneratorUpdated(ResourceGenerator resourceGenerator, int generatorID)
 {
     if (SelectionManager.IsSelected(resourceGenerator.building.GetSelection(), true, true)) //if the resource generator's building is the only selected entity
     {
         gameMgr.UIMgr.HideTooltip();                                                        //hide the tooltip in case resource have been collected and the task is gone
         Update();
     }
 }
Exemple #2
0
        public void UpdateResourceGeneratorTasks(FactionEntity sourceEntity, ResourceGenerator generatorComp)
        {
            if (sourceEntity == null || generatorComp == null)
            {
                return;
            }

            for (int generatorID = 0; generatorID < generatorComp.GetGeneratorsLength(); generatorID++)
            {
                ResourceGenerator.Generator generator = generatorComp.GetGenerator(generatorID);
                if (generator.IsMaxAmountReached() == true) //only display the resource collection task if the maximum amount is reached
                {
                    Add(new TaskUIAttributes
                    {
                        ID     = generatorID,
                        icon   = generator.GetTaskIcon(),
                        source = sourceEntity,
                        type   = TaskTypes.generateResource
                    }, generatorComp.GetTaskPanelCategory());
                }
            }
        }
Exemple #3
0
 public static void OnResourceGeneratorCollected(ResourceGenerator resourceGenerator, int generatorID)  //called when a generator is collected
 {
     ResourceGeneratorCollected(resourceGenerator, generatorID);
 }
Exemple #4
0
        public void LaunchTask(Building Building, int TaskID, int NPCUnitSpawnerID, TaskTypes TaskType)
        {
            if (TaskType == TaskTypes.ResourceGen)
            {
                GameMgr.UIMgr.TaskInfoText.gameObject.SetActive(false);
                GameMgr.UIMgr.TaskInfoMenu.gameObject.SetActive(false);
                //if the task is a resource gen one:
                ResourceGenerator Gen = Building.gameObject.GetComponent <ResourceGenerator> ();                                         //look for the generator
                int ResourceID        = Gen.ReadyToCollect [TaskID];                                                                     //get the resource id
                GameMgr.ResourceMgr.AddResource(Building.FactionID, Gen.Resources [ResourceID].Name, Gen.Resources [ResourceID].Amount); //add the resource to the faction
                Gen.Resources[ResourceID].Amount            = 0;
                Gen.Resources [ResourceID].MaxAmountReached = false;                                                                     //launch the timer again
                Gen.ReadyToCollect.Remove(TaskID);

                if (GameManager.PlayerFactionID == Building.FactionID)                //if this is the local player:
                {
                    if (GameMgr.UIMgr.SelectionMgr.SelectedBuilding == Building)      //if the building is selected.
                    {
                        GameMgr.UIMgr.UpdateInProgressTasksUI(Building);              //update the UI:
                        GameMgr.UIMgr.UpdateBuildingTasks(Building);
                    }
                    AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, Gen.Resources[ResourceID].CollectionAudioClip, false);                      //Launched task audio.
                }
            }
            else
            {
                if (TaskType == TaskTypes.CreateUnit)
                {
                    GameMgr.Factions [Building.FactionID].CurrentPopulation++;                     //add population
                    if (GameManager.PlayerFactionID == Building.FactionID)
                    {
                        GameMgr.UIMgr.UpdatePopulationUI();                          //if it's the local player then change the population UI:
                    }
                }
                else
                {
                    GameMgr.UIMgr.TaskInfoText.gameObject.SetActive(false);
                    GameMgr.UIMgr.TaskInfoMenu.gameObject.SetActive(false);
                }

                //Add the new task to the building's task queue
                Building.PendingTasksInfo Item = new Building.PendingTasksInfo();
                Item.ID            = TaskID;
                Item.UnitSpawnerID = NPCUnitSpawnerID;
                Item.Upgrade       = (TaskType == TaskTypes.TaskUpgrade);
                Building.TasksQueue.Add(Item);

                if (Item.Upgrade == false)                   //if the task is to upgrade

                //Launch the timer if there was no other tasks, else, the timer will launch automatically.
                {
                    if (Building.TasksQueue.Count == 1)
                    {
                        Building.TaskQueueTimer = Building.BuildingTasksList [TaskID].ReloadTime;
                    }
                    //Take the required resources:
                    GameMgr.ResourceMgr.TakeResources(Building.BuildingTasksList [TaskID].RequiredResources, Building.FactionID);
                }
                else
                {
                    //Launch the timer if there was no other tasks, else, the timer will launch automatically.
                    if (Building.TasksQueue.Count == 1)
                    {
                        Building.TaskQueueTimer = Building.BuildingTasksList [TaskID].Upgrades [Building.BuildingTasksList [TaskID].CurrentUpgradeLevel].UpgradeReload;
                    }
                    //take the upgrade's resource and launch it.
                    GameMgr.ResourceMgr.TakeResources(Building.BuildingTasksList [TaskID].Upgrades [Building.BuildingTasksList [TaskID].CurrentUpgradeLevel].UpgradeResources, Building.FactionID);
                }

                //custom events:
                GameMgr.Events.OnTaskLaunched(Building, Building.BuildingTasksList [TaskID]);

                if (GameManager.PlayerFactionID == Building.FactionID)                //if this is the local player:
                {
                    if (GameMgr.UIMgr.SelectionMgr.SelectedBuilding == Building)      //if the building is selected.
                    {
                        GameMgr.UIMgr.UpdateInProgressTasksUI(Building);              //update the UI:
                        GameMgr.UIMgr.UpdateBuildingTasks(Building);
                    }
                    AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, Building.LaunchTaskAudio, false);                      //Launched task audio.

                    if (Item.Upgrade == true || Building.BuildingTasksList [TaskID].TaskType == Building.BuildingTasks.Research)
                    {
                        Building.BuildingTasksList [TaskID].Active = true;
                        Building.CheckTaskUpgrades(TaskID, true, false);

                        //if this building is selected.
                        if (GameMgr.SelectionMgr.SelectedBuilding == Building)
                        {
                            //update the selection panel UI to show that this task is no longer in progress.
                            GameMgr.UIMgr.UpdateInProgressTasksUI(Building);
                            GameMgr.UIMgr.UpdateBuildingTasks(Building);
                        }
                    }
                }
            }
        }
Exemple #5
0
 //Resource Generator component related events:
 public static void OnResourceGeneratorFull(ResourceGenerator resourceGenerator, int generatorID)  //called when a generator is full
 {
     ResourceGeneratorFull(resourceGenerator, generatorID);
 }