public void DestroyTask() { if (GetTargetObject() != null) { TaskLibrary.Get().UpdateOrderMarker(GetTargetObject(), null); } }
void CreateTask(Building building) { UnitTask tempTask = TaskLibrary.Get().CreateTask(UnitTask.TaskType.Build, building.transform.position, building.gameObject); building._BuildTask = tempTask; TaskList.AddTaskToGlobalTaskList(tempTask); }
/// <summary> /// When selecting to pick up a resource, create pick up task depending on resource type and add to task list /// </summary> public void PickUpResource() { if (_ore != null) { TaskList.AddTaskToGlobalTaskList(TaskLibrary.Get().CreateTask(UnitTask.TaskType.Pickup, _ore.transform.position, _ore.gameObject)); //UnitTask tempTask = new UnitTask //{ // _location = _ore.transform.position, // _taskType = UnitTask.TaskType.Pickup, // _taskDescription = "Transporting an Ore", // _itemToPickUp = _ore.transform.gameObject, // _itemType = UnitTask.ItemType.Ore, // _requiredTool = Unit.UnitTool.none //}; //AddTaskToGlobalTaskList(tempTask); } else if (_energyCrystal != null) { TaskList.AddTaskToGlobalTaskList(TaskLibrary.Get().CreateTask(UnitTask.TaskType.Pickup, _energyCrystal.transform.position, _energyCrystal.gameObject)); //UnitTask tempTask = new UnitTask //{ // _location = _energyCrystal.transform.position, // _taskType = UnitTask.TaskType.Pickup, // _taskDescription = "Transporting an Ore", // _itemToPickUp = _energyCrystal.transform.gameObject, // _itemType = UnitTask.ItemType.EnergyCrystal, // _requiredTool = Unit.UnitTool.none //}; //AddTaskToGlobalTaskList(tempTask); } }
/// <summary> /// "Used to Instantiate an extra worker" /// </summary> public void AddUnit(bool requireOre = true) { if (_Energy > 0) { if (_worldController._oreCount >= workerCost || requireOre == false) { StartCoroutine(PlayEffect()); if (_worldController._workers.Count >= _worldController._workerLimit) { _worldController.UIScript.ShowNotification("Max amount of Workers!"); return; } Unit worker = Instantiate(_worker, spawnPoint.position, _worker.transform.rotation); _worldController._workers.Add(worker); _worldController._levelStatsController.UnitSpawned(); //Physics.IgnoreCollision(worker.GetComponent<Collider>(), transform.GetComponent<Collider>(), true); worker._worldController = _worldController; worker._currentTool = Unit.UnitTool.MiningTool; worker.SetTool(); UnitTask newTask = TaskLibrary.Get().CreateTask(UnitTask.TaskType.Walk, worker.transform.position + transform.forward * 4f, null); worker.GetComponent <Worker>().AddTask(newTask); if (requireOre) { ReduceEnergy(5); _worldController._oreCount -= workerCost; _worldController._levelStatsController.OreUsed(workerCost); } } else { _worldController.UIScript.ShowNotification("Not enough Ore!"); } } }
/// <summary> /// When selecting to refill oxygen, find the nearest oxygen generator and create refill task /// </summary> public void RefillO2() { for (int i = 0; i < _workers.Count; i++) { _workers[i].SetTask(TaskLibrary.Get().CreateTask(UnitTask.TaskType.RefillOxygen, Vector3.zero, _workers[i].gameObject), (i < 4)); } }
public void UpdateTask() { if (GetTargetObject()) { TaskLibrary.Get().UpdateOrderMarker(GetTargetObject(), this); Tile t = GetTargetObject().GetComponent <Tile>(); if (t != null)//tell tiles about task that target them for easy canceling! { t.NotifyAboutTask(this); } } }
/// <summary> /// When selecting to attack, create attack task and add to task list /// </summary> public void AttackEnemy() { TaskList.AddTaskToGlobalTaskList(TaskLibrary.Get().CreateTask(UnitTask.TaskType.Attack, _monster.transform.position, _monster.gameObject)); // UnitTask tempTask = new UnitTask // { // _location = _monster.transform.position, // _taskType = UnitTask.TaskType.Attack, // _requiredTool = Unit.UnitTool.Weapon, // _taskDescription = "Attacking" // }; // AddTaskToGlobalTaskList(tempTask); }
/// <summary> /// When selecting to enter a vehicle, create and set get in vehicle task /// </summary> public void EnterVehicle() { UnitTask tempTask = TaskLibrary.Get().CreateTask(UnitTask.TaskType.GetInVehicle, _vehicle.transform.position, _vehicle.gameObject); if (_worker != null) { _worker.SetTask(tempTask); } else { TaskList.AddTaskToGlobalTaskList(tempTask); } }
/// <summary> /// When selecting to power, power building /// </summary> public void PowerBuilding() { TaskList.InsertTaskToBeginning(TaskLibrary.Get().CreateTask(UnitTask.TaskType.RefillEnergy, _building.transform.position, _building.gameObject)); //UnitTask tempTask = new UnitTask //{ // _location = _building.transform.position, // _taskType = UnitTask.TaskType.RefillEnergy, // _targetBuilding = _building, // _taskDescription = "Refill building energy" //}; //AddTaskToGlobalTaskList(tempTask); }
/// <summary> /// When selecting to dig rubble, create digging task and add to task list /// </summary> public void DigRubble() { TaskList.AddTaskToGlobalTaskList(TaskLibrary.Get().CreateTask(UnitTask.TaskType.ClearRubble, _rubble.transform.position, _rubble.gameObject)); //UnitTask tempTask = new UnitTask //{ // _location = _rubble.transform.position, // _taskType = UnitTask.TaskType.ClearRubble, // _targetRubble = _rubble, // _requiredTool = Unit.UnitTool.Shovel, // _taskDescription = "Clearing rubble" //}; //AddTaskToGlobalTaskList(tempTask); }
/// <summary> /// When selecting to reinforce a wall, create a reinforce task and add to task list /// </summary> public void ReinforceRock() { TaskList.AddTaskToGlobalTaskList(TaskLibrary.Get().CreateTask(UnitTask.TaskType.Reinforce, _rock.transform.position, _rock.gameObject)); //UnitTask tempTask = new UnitTask //{ // _location = _rock.transform.position, // _taskType = UnitTask.TaskType.Reinforce, // _targetRock = _rock, // _requiredTool = Unit.UnitTool.Hammer, // _taskDescription = "Reinforcing a wall" //}; //TaskList.AddTaskToGlobalTaskList(tempTask); }
// Start is called before the first frame update void Start() { _unitType = UnitType.vehicle; _barsUpdater = GetComponentInChildren <BuildingBarsUpdaterScript>(); _barsUpdater._maxHealth = Health; _navAgent = GetComponent <NavMeshAgent>(); _worldController = WorldController.GetWorldController; _worldController._workers.Add(this); _localTaskList = new List <UnitTask>(); _navAgent.speed = _speed; Energy = 100; _taskLibary = TaskLibrary.Get(); //SetTool(); }
bool TryAddOrder(Tile tile, UnitTask.TaskType type) { if (type == UnitTask.TaskType.none) { tile.CancelTilesTasks(); return(true); } UnitTask task = TaskLibrary.Get().CreateTask(type, tile.transform.position, tile.gameObject); if (task == null || !task.IsValid()) { return(false); } TaskList.AddTaskToGlobalTaskList(task); return(true); }
public void ReduceEnergy(float amt) { _Energy -= amt; _barsUpdater.UpdateEnergyFill(_Energy); if (_Energy < 30 && !_EnergyRequest && _worldController._energyCrystalsCount > 0) { _EnergyRequest = true; TaskList.InsertTaskToBeginning(TaskLibrary.Get().CreateTask(UnitTask.TaskType.RefillEnergy, transform.position, gameObject)); //TaskList.AddTaskToGlobalTaskList(tempTask); } if (_Energy < 0) { _Energy = 0; } if (_Energy > 100) { _Energy = 100; } }
bool AddTaskToVehicle(UnitTask.TaskType t, Vehicle V, Vector3 Pos, GameObject OBJ, bool set = false) { UnitTask newTask = TaskLibrary.Get().CreateTask(t, Pos, OBJ); if (newTask == null) { return(false); } if (!TaskLibrary.CanVehicleExecuteTask(t, V)) { return(false); } if (set) { V.SetTask(newTask); } else { V.AddTask(newTask); } return(true); }
/// <summary> /// When a new tool is selected, if it is not the workers current tool, create a get tool task /// </summary> /// <param name="newToolID">Id of the new tool type</param> public void SelectTool(int newToolID) { Unit.UnitTool newTool = (Unit.UnitTool)newToolID; for (int i = 0; i < _workers.Count; i++) { if (newTool != _workers[i]._currentTool) { RadialMenuScript.instance.NewTool = newTool; _workers[i].SetTask(TaskLibrary.Get().CreateTask(UnitTask.TaskType.GetTool, _hqPos, _workers[i].gameObject), (i < 4)); //UnitTask tempTask = new UnitTask //{ // _location = _hqPos, // _taskType = UnitTask.TaskType.GetTool, // _taskDescription = "Getting tool", // _requiredTool = newTool //}; //_worker.SetTask(tempTask); } } }
bool AddTaskToWorker(UnitTask.TaskType t, Worker W, Vector3 Pos, GameObject OBJ, bool set = false) { UnitTask newTask = TaskLibrary.Get().CreateTask(t, Pos, OBJ); if (newTask == null) { return(false); } if (!TaskLibrary.CanWorkerExecuteTask(t, W)) { return(false); } if (set) { W.SetTask(newTask, ShouldPlaySound()); } else { W.AddTask(newTask); } return(true); }
/// <summary> /// When selecting to power, power garage /// </summary> public void PowerBuilding() { TaskList.AddTaskToGlobalTaskList(TaskLibrary.Get().CreateTask(UnitTask.TaskType.RefillEnergy, _garage.transform.position, _garage.gameObject)); }
/// <summary> /// When selecting to recharge a vehicle, create and set recharge vehicle task /// </summary> public void RechargeVehicle() { _vehicle.SetTask(TaskLibrary.Get().CreateTask(UnitTask.TaskType.RechargeVehicle, _vehicle.transform.position, _vehicle.gameObject)); }
/// <summary> /// When selecting to dig rubble, create digging task and add to task list /// </summary> public void BurnCluster() { TaskList.AddTaskToGlobalTaskList(TaskLibrary.Get().CreateTask(UnitTask.TaskType.flameTarget, _mushroomCluster.transform.position, _mushroomCluster.gameObject)); }