//for local player only, not for NPC factions public bool CanAddTask(TaskLauncher TaskComp, int TaskID, TaskTypes TaskType) { //Always check that the health is above the minimal limit to launch tasks and that the building was built (to max health) at least once: if (TaskComp.GetTaskHolderHealth() < TaskComp.MinTaskHealth) { UIMgr.ShowPlayerMessage("Health is too low to launch task!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. return(false); } else if (TaskComp.MaxTasks <= TaskComp.TasksQueue.Count) { //Notify the player that the maximum amount of tasks for this building has been reached UIMgr.ShowPlayerMessage("Maximum building tasks has been reached", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. return(false); } //Do we have enough resources for this task? if (TaskType == TaskManager.TaskTypes.TaskUpgrade) { //upgrade task: //Make sure there are enough resources if (ResourceMgr.CheckResources(TaskComp.TasksList[TaskID].UnitCreationSettings.Upgrades[TaskComp.TasksList[TaskID].CurrentUpgradeLevel].UpgradeResources, GameManager.PlayerFactionID, 1.0f) == false) { UIMgr.ShowPlayerMessage("Not enough resources to launch upgrade task!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. return(false); } } else { if (ResourceMgr.CheckResources(TaskComp.TasksList[TaskID].RequiredResources, GameManager.PlayerFactionID, 1) == false) { UIMgr.ShowPlayerMessage("Not enough resources to launch task!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. return(false); } if (TaskType == TaskManager.TaskTypes.CreateUnit) { //create unit task if (GameMgr.Factions[GameManager.PlayerFactionID].CurrentPopulation >= GameMgr.Factions[GameManager.PlayerFactionID].MaxPopulation) { //Inform the player that there's no more room for new units. UIMgr.ShowPlayerMessage("Maximum population has been reached!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. return(false); } //if there's population slots but the local faction already hit the limit with this faction else if (GameMgr.Factions[GameManager.PlayerFactionID].FactionMgr.HasReachedLimit(TaskComp.TasksList[TaskID].UnitCreationSettings.Prefabs[0].Code)) { //inform the player that he can't create this unit UIMgr.ShowPlayerMessage("This unit has reached its creation limit", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. return(false); } } } return(true); }
//for local player only, not for NPC factions public AddTaskMsg CanAddTask(TaskLauncher TaskComp, int FactionID, int TaskID, TaskTypes TaskType) { if (TaskComp.TaskHolder == TaskLauncher.TaskHolders.Unit) //if the task holder is a unit { if (TaskComp.RefUnit.Dead == true) //if the unit is already dead { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { UIMgr.ShowPlayerMessage("Unit is dead, can not launch tasks!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.Destroyed); } } else //if not, make sure the building is built, not destroyed, not upgrading and has enough health. { if (TaskComp.RefBuilding.Destroyed == true) //if the unit is already dead { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { UIMgr.ShowPlayerMessage("Building is destroyed, can not launch tasks!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.Destroyed); } else if (TaskComp.RefBuilding.BuildingUpgrading == true) //if the building is currently upgrading: { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { UIMgr.ShowPlayerMessage("Building is upgrading, can not launch tasks at the moment!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.Upgrading); } } //Always check that the health is above the minimal limit to launch tasks and that the building was built (to max health) at least once: if (TaskComp.GetTaskHolderHealth() < TaskComp.MinTaskHealth) { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { UIMgr.ShowPlayerMessage("Health is too low to launch task!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.LowHealth); } if (TaskComp.MaxTasks <= TaskComp.TasksQueue.Count) { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { //Notify the player that the maximum amount of tasks for this building has been reached UIMgr.ShowPlayerMessage("Maximum building tasks has been reached", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.MaxTasksReached); } //Do we have enough resources for this task? if (TaskType == TaskManager.TaskTypes.TaskUpgrade) { //upgrade task: //Make sure there are enough resources if (ResourceMgr.CheckResources(TaskComp.TasksList[TaskID].UnitCreationSettings.Upgrades[TaskComp.TasksList[TaskID].CurrentUpgradeLevel].UpgradeResources, FactionID) == false) { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { UIMgr.ShowPlayerMessage("Not enough resources to launch upgrade task!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.LowResources); } } else { if (ResourceMgr.CheckResources(TaskComp.TasksList[TaskID].RequiredResources, FactionID) == false) { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { UIMgr.ShowPlayerMessage("Not enough resources to launch task!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.LowResources); } if (TaskType == TaskManager.TaskTypes.CreateUnit) { //create unit task if (GameMgr.Factions[FactionID].GetCurrentPopulation() >= GameMgr.Factions[FactionID].GetMaxPopulation()) { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { //Inform the player that there's no more room for new units. UIMgr.ShowPlayerMessage("Maximum population has been reached!", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.MaxPopulationReached); } //if there's population slots but the local faction already hit the limit with this faction else if (GameMgr.Factions[GameManager.PlayerFactionID].FactionMgr.HasReachedLimit(TaskComp.TasksList[TaskID].UnitCreationSettings.Prefabs[0].Code)) { if (FactionID == GameManager.PlayerFactionID) //message and sound effect if it is the player faciton { //inform the player that he can't create this unit UIMgr.ShowPlayerMessage("This unit has reached its creation limit", UIManager.MessageTypes.Error); AudioManager.PlayAudio(GameMgr.GeneralAudioSource.gameObject, TaskComp.DeclinedTaskAudio, false); //Declined task audio. } return(AddTaskMsg.MaxPopulationReached); } } } return(AddTaskMsg.Success); }