public TaskSystem.Task FulfilNeed(NeedDefinition need) { TaskSystem.Task fulfil = null; if (GetNearestNeed(need) != null) { fulfil = new TaskSystem.Task { moveToPosition = new TaskSystem.Task.MoveTo(GetNearestNeed(need).transform.position, 1f, () => { GetNearestNeed(need).FulFillneed(worker); currentThought = DialogueSys.GetCelebration(); state = State.WaitingForNewTask; }), }; currentTask = "Taking a break."; } return(fulfil); }
private void RequestNextTask() { HandleNeeds(); TaskSystem.Task task = null; if (taskManager.tasks.Count > 0) { task = taskManager.tasks.Dequeue(); } if (task == null) { if (TimeScale.isDayTime()) { if (worker.Desk != null) { worker.Desk.SetWorker(this); } else { currentTask = "Waiting for a task."; state = State.WaitingForNewTask; if (GetNearestDesk != null) { taskManager.tasks.Enqueue(GetNearestDesk); } } } else { taskManager.tasks.Enqueue(GoHome); } } else { if (task == ComeBack && TimeScale.isDayTime() == false && AtHome) { taskManager.tasks.Clear(); return; } state = State.ExecutingTask; if (task.moveToPosition != null) { currentTask = "Moving to location."; worker.MoveTo(task.moveToPosition.targetPosition, task.moveToPosition.stoppingDistance, () => { if (task.moveToPosition.executeAction != null) { task.moveToPosition.executeAction.Invoke(); } state = State.WaitingForNewTask; }); } if (task.executeAction != null) { currentTask = "Executing task."; worker.ExecuteAction(task.executeAction); state = State.WaitingForNewTask; } if (task.executeActionRecurring != null) { worker.workerData.experience += Random.Range(0f, 1 - ((worker.workerData.skill * 0.005f) + (worker.unhappiness * 0.01f))) * Time.deltaTime; currentTask = "Executing a recurring task."; worker.ExecuteAction(task.executeActionRecurring); TaskSystem.Task recurringTask = new TaskSystem.Task { executeActionRecurring = task.executeActionRecurring }; state = State.WaitingForNewTask; } } }
private void HandleNeeds() { float valX = Mathf.Abs(worker.workerData.skill - worker.unhappiness) + (worker.workerData.skill / 2); if (valX <= worker.workerData.skill) { //Alieve this unhappiness taskManager.tasks.Clear(); currentThought = "Need a break. "; float skill = 200 - worker.workerData.skill; if (worker.GetNeed(NeedDefinition.Thirst).value <= skill) { currentThought += "Thirsty. "; TaskSystem.Task thirst = FulfilNeed(NeedDefinition.Thirst); if (thirst != null) { taskManager.tasks.Enqueue(thirst); } else { taskManager.tasks.Clear(); taskManager.tasks.Enqueue(GoHome); taskManager.tasks.Enqueue(ComeBack); return; } } if (worker.GetNeed(NeedDefinition.Hunger).value <= skill) { currentThought += "Hungry. "; TaskSystem.Task hunger = FulfilNeed(NeedDefinition.Hunger); if (hunger != null) { taskManager.tasks.Enqueue(hunger); } else { taskManager.tasks.Clear(); taskManager.tasks.Enqueue(GoHome); taskManager.tasks.Enqueue(ComeBack); return; } } taskManager.tasks.Enqueue(ComeBack); } }