Ejemplo n.º 1
0
    /// <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);
            }
        }
    }
Ejemplo n.º 2
0
    /// <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);
        }
    }
Ejemplo n.º 3
0
 private void Error()
 {
     if (Faulted != null) {
         State = WorkerStates.Errored;
         Faulted(this, null);
     }
 }
Ejemplo n.º 4
0
    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();
        }
    }
Ejemplo n.º 5
0
    /// <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);
        }
    }
Ejemplo n.º 6
0
 public virtual void Stop()
 {
     try {
         OnStop();
         State = WorkerStates.Stopped;
     }
     catch (Exception ex) {
         Error();
     }
 }
Ejemplo n.º 7
0
 /// <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);
     }
 }
Ejemplo n.º 8
0
    // 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;
    }
Ejemplo n.º 9
0
 protected virtual void ReceiveOrders(WorkerStates nextDesiredState)
 {
     if (MyArea.ManangerPresent)
     {
         ChangeState(nextDesiredState);
     }
     else
     {
         //  TODO: Implement touch feature to progress worker on the next state.
     }
 }
Ejemplo n.º 10
0
 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();
     }
 }
Ejemplo n.º 11
0
    /// <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);
        }
    }
Ejemplo n.º 12
0
    /// <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);
        }
    }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 14
0
    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;
        }
    }
Ejemplo n.º 15
0
 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;
     }
 }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
 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;
         }
     }
 }
Ejemplo n.º 18
0
    /// <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);
        }
    }
Ejemplo n.º 19
0
 /// <summary>
 /// Animate and execute base state
 /// </summary>
 protected override void ReceiveOrders(WorkerStates nextDesiredState)
 {
     workerAnimator.Play("wait");
     base.ReceiveOrders(nextDesiredState);
 }
Ejemplo n.º 20
0
    /// <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);
    }
Ejemplo n.º 21
0
 /// <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);
 }
Ejemplo n.º 22
0
 /// <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);
 }
Ejemplo n.º 23
0
 /// <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);
 }
Ejemplo n.º 24
0
    /// <summary>
    /// Animate and exucute the base state
    /// </summary>
    /// <param name="nextDesiredState"></param>
    protected override void Deposit(WorkerStates nextDesiredState)
    {
        animator.Play("collect");

        base.Deposit(nextDesiredState);
    }
Ejemplo n.º 25
0
 /// <summary>
 /// Animate and execute base state
 /// </summary>
 /// <param name="nextDesiredState"></param>
 protected override void Collect(WorkerStates nextDesiredState)
 {
     workerAnimator.Play("collect");
     base.Collect(nextDesiredState);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Move to the Collection Postion
 /// </summary>
 /// <param name="nextDesiredState"></param>
 protected virtual void MoveToCollect(WorkerStates nextDesiredState)
 {
     MoveToLocation(MyArea.CollectPosition, nextDesiredState);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Change State
 /// </summary>
 /// <param name="newState"></param>
 protected void ChangeState(WorkerStates newState)
 {
     CurrentState = newState;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Move to Deposit Position
 /// </summary>
 /// <param name="nextDesiredState"></param>
 protected virtual void MoveToDeposit(WorkerStates nextDesiredState)
 {
     MoveToLocation(MyArea.DepositPosition, WorkerStates.Deposit);
 }