/// <summary> /// Collect from the selected mine deposit container /// </summary> /// <param name="nextDesiredState"></param> protected override void Collect(WorkerStates nextDesiredState) { // Set Collection from the current Mine's deposit container Container currentMineContainer = mineManager.Mines[selectedMine].DepositContainer; CollectionMethod = currentMineContainer.CollectFromContainer; if (currentMineContainer.HasValue) { // If CarryAmount has reached capacity it will progress to the next state base.Collect(nextDesiredState); } else { int newIndex = CycleMineIndex(selectedMine + 1); if (newIndex != 0) { // Collect more selectedMine = newIndex; ChangeState(WorkerStates.MoveToCollect); } else { // or else move on to the next state ( EG. Moving to deposit) ChangeState(nextDesiredState); } } }
/// <summary> /// Check's if there is value for purchasing to the next state, starting from the top of the mine /// </summary> /// <param name="nextDesiredState"></param> protected override void ReceiveOrders(WorkerStates nextDesiredState) { animator.Play("move"); // Check if MineList has any value before moving to the next state bool foundValue = false; for (int i = 0; i < mineManager.MineCount; i++) { if (mineManager.Mines[i].DepositContainer.HasValue) { foundValue = true; i = mineManager.MineCount; } } // Start at the top mine selectedMine = 0; // If found value, procede into the base state if (foundValue) { base.ReceiveOrders(nextDesiredState); } }
private void Error() { if (Faulted != null) { State = WorkerStates.Errored; Faulted(this, null); } }
void CheckForNeeds() { if (hunger <= hungerThreshold) { Status = WorkerStates.Needy; GameManager.instance.Tasks.RemoveWorker(this); GameManager.instance.SfxPlayer.PlaySfx((int)SoundClips.WorkerHungry); } else if (energy <= energyThreshold) { Status = WorkerStates.Needy; GameManager.instance.Tasks.RemoveWorker(this); GameManager.instance.SfxPlayer.PlaySfx((int)SoundClips.WorkerSleepy); } else if (fun <= funThreshold) { Status = WorkerStates.Needy; GameManager.instance.Tasks.RemoveWorker(this); GameManager.instance.SfxPlayer.PlaySfx(UnityEngine.Random.Range((int)SoundClips.WorkerMoody1, (int)SoundClips.WorkerNewTask)); } if (hunger == 0 || energy == 0) { //worker dead KillMe(); } }
/// <summary> /// If collection container has value, procede to the base class state /// </summary> /// <param name="nextDesiredState"></param> protected override void ReceiveOrders(WorkerStates nextDesiredState) { animator.Play("collect"); if (collectionContainer.HasValue) { base.ReceiveOrders(nextDesiredState); } }
public virtual void Stop() { try { OnStop(); State = WorkerStates.Stopped; } catch (Exception ex) { Error(); } }
/// <summary> /// Move to a location, when the worker has reach this It will progress states /// </summary> /// <param name="position"></param> /// <param name="nextDesiredState"></param> protected void MoveToLocation(Vector2 position, WorkerStates nextDesiredState) { if ((Vector2)transform.position != position) { transform.position = Vector2.MoveTowards(transform.position, position, (float)MovementSpeed * Time.deltaTime); } else { ChangeState(nextDesiredState); } }
// Start is called before the first frame update void Start() { Status = WorkerStates.Idle; isReadyToWork = true; energy = UnityEngine.Random.Range(energyThreshold + 2, energyMax); fun = UnityEngine.Random.Range(funThreshold + 2, funMax);; hunger = UnityEngine.Random.Range(hungerThreshold + 2, hungerMax);; GameManager.instance.DayCycle.OnPeriodComplete += GettingTired; }
protected virtual void ReceiveOrders(WorkerStates nextDesiredState) { if (MyArea.ManangerPresent) { ChangeState(nextDesiredState); } else { // TODO: Implement touch feature to progress worker on the next state. } }
public void AssignTask(int taskId) { currentTaskID = taskId; if (taskId != -1) { //Debug.Log(gameObject.name + " got a new job with id: " + taskId.ToString()); workTask = GameManager.instance.Tasks.TaskList[taskId]; Status = WorkerStates.Working; isReadyToWork = false; GameManager.instance.SfxPlayer.PlaySfx(13); StartOrUpdatePathFinding(); } }
/// <summary> /// Collect from the elevators deposit container /// </summary> /// <param name="nextDesiredState"></param> protected override void Collect(WorkerStates nextDesiredState) { animator.Play("collect"); if (collectionContainer.HasValue) { base.Collect(nextDesiredState); } else { ChangeState(nextDesiredState); } }
/// <summary> /// Deposits the current load as the same rate as collection, unless instantDeposit is defined; /// </summary> /// <param name="nextDesiredState"></param> protected virtual void Deposit(WorkerStates nextDesiredState) { decimal desiredDepositAmount = (decimal)Time.deltaTime * CollectionSpeed; if (CurrentCarryAmount > desiredDepositAmount && !InstantDeposit) { DepositAction(desiredDepositAmount); RemoveCarryAmount(desiredDepositAmount); } else { DepositAction(CurrentCarryAmount); CurrentCarryAmount = 0; UpdateCarryAmountText(CurrentCarryAmount); ChangeState(nextDesiredState); } }
void FindWorkerCompleted(object sender, FindWorkerCompletedEventArgs e) { if (e.Error == null) { Worker = e.Result; if (SelectedAttendance != null) { SelectedWorkerState = WorkerStates.FirstOrDefault(c => c.ID == selectedAttendance.WorkerStateID); SelectedWorkerTour = WorkerTours.FirstOrDefault(c => c.ID == selectedAttendance.WorkerTourID); Description = selectedAttendance.Description; (UpdateCommand as Command).OnCanExecuteChanged(); } } else { ErrorProvider.ShowError(e.Error, Navigator); } dataClient.FindWorkerCompleted -= FindWorkerCompleted; Busy = false; }
IEnumerator MoveForNeeds(List <Vector3> path, BuildingAgent building) { foreach (Vector3 pos in path) { while (Vector3.Distance(transform.position, pos) > 0.1f) { transform.position = Vector3.MoveTowards(transform.position, pos, moveSpeed * Time.deltaTime); yield return(null); } } if (building.Users.Count < building.Value) { building.Use(this); } else { Status = WorkerStates.Needy; } }
void SatisfyNeeds() { if (hunger <= hungerThreshold) { Debug.Log("hungru to go diner"); BuildingAgent building = GameManager.instance.GetNearestDiner(this.transform.position); if (building != null) { isReadyToWork = false; Status = WorkerStates.Working; GoSatisfy(building); } } else if (energy <= energyThreshold) { Debug.Log("energy low go to bed"); BuildingAgent building = GameManager.instance.GetNearestBed(this.transform.position); if (building != null) { isReadyToWork = false; Status = WorkerStates.Working; GoSatisfy(building); } } else if (fun <= funThreshold) { Debug.Log("bored go to pub"); BuildingAgent building = GameManager.instance.GetNearestPub(this.transform.position); if (building != null) { isReadyToWork = false; Status = WorkerStates.Working; GoSatisfy(building); } } else { Status = WorkerStates.Working; isReadyToWork = true; } }
private float CalculateSalary(WorkerStates workerStates, bool ParkingCar) { if (workerStates != WorkerStates.Absent) { switch (ParkingCar) { case true: Salary = Trip.Money * 0.25f; break; case false: Salary = Trip.Money * 0.5f; break; } } else { Salary = 0; } return(Salary); }
void DoAI(float dt) { if (Status == WorkerStates.Needy) { SatisfyNeeds(); } else if (Status == WorkerStates.Idle) { //if (needCheckCounter == 0) CheckForNeeds(); if (Status == WorkerStates.Idle) //if worker's still idle, check job { GameManager.instance.Tasks.AddWorker(this); } } else if (Status == WorkerStates.Working) { if (isReadyToWork) { Status = WorkerStates.Idle; } } }
/// <summary> /// Collect Resouces as defined in the Collection Method /// </summary> /// <param name="nextDesiredState"></param> protected virtual void Collect(WorkerStates nextDesiredState) { // Desired amount to collect each frame decimal desiredCollectionAmount = (decimal)Time.deltaTime * CollectionSpeed; if ((CurrentCarryAmount + desiredCollectionAmount <= CarryCapacity)) { decimal amountCollected = CollectionMethod(desiredCollectionAmount); AddCarryAmount(amountCollected); } else { decimal remainderLeft = (CarryCapacity - CurrentCarryAmount); decimal amountCollected = CollectionMethod(remainderLeft); AddCarryAmount(amountCollected); // Change to the next state once carry amount has reached capacity ChangeState(nextDesiredState); } }
/// <summary> /// Animate and execute base state /// </summary> protected override void ReceiveOrders(WorkerStates nextDesiredState) { workerAnimator.Play("wait"); base.ReceiveOrders(nextDesiredState); }
/// <summary> /// Move to the selected Mine shaft position /// </summary> /// <param name="nextDesiredState"></param> protected override void MoveToCollect(WorkerStates nextDesiredState) { Vector2 shaftPos = new Vector2(MyArea.transform.position.x, mineManager.Mines[selectedMine].transform.position.y); MoveToLocation(shaftPos, nextDesiredState); }
/// <summary> /// Flip the sprite, animate and execute the base state /// </summary> protected override void MoveToDeposit(WorkerStates nextDesiredState) { workerAnimator.Play("roll"); WorkerSprite.flipX = false; base.MoveToDeposit(nextDesiredState); }
/// <summary> /// Flip the sprite, animate and execute the base state /// </summary> /// <param name="nextDesiredState"></param> protected override void MoveToCollect(WorkerStates nextDesiredState) { animator.Play("move"); WorkerSprite.flipX = false; base.MoveToCollect(nextDesiredState); }
/// <summary> /// Flip the sprite, animate and execute the base state /// </summary> protected override void MoveToDeposit(WorkerStates nextDesiredState) { animator.Play("move"); WorkerSprite.flipX = true; base.MoveToDeposit(nextDesiredState); }
/// <summary> /// Animate and exucute the base state /// </summary> /// <param name="nextDesiredState"></param> protected override void Deposit(WorkerStates nextDesiredState) { animator.Play("collect"); base.Deposit(nextDesiredState); }
/// <summary> /// Animate and execute base state /// </summary> /// <param name="nextDesiredState"></param> protected override void Collect(WorkerStates nextDesiredState) { workerAnimator.Play("collect"); base.Collect(nextDesiredState); }
/// <summary> /// Move to the Collection Postion /// </summary> /// <param name="nextDesiredState"></param> protected virtual void MoveToCollect(WorkerStates nextDesiredState) { MoveToLocation(MyArea.CollectPosition, nextDesiredState); }
/// <summary> /// Change State /// </summary> /// <param name="newState"></param> protected void ChangeState(WorkerStates newState) { CurrentState = newState; }
/// <summary> /// Move to Deposit Position /// </summary> /// <param name="nextDesiredState"></param> protected virtual void MoveToDeposit(WorkerStates nextDesiredState) { MoveToLocation(MyArea.DepositPosition, WorkerStates.Deposit); }