Ejemplo n.º 1
0
    void Update()
    {
        List <int> removedindexes = new List <int>();
        int        index          = 0;

        foreach (WorkerItem workerItem in WorkerItems)
        {
            Worker w           = workerItem.Worker;
            float  timetolearn = TimeToLearnSkill * w.GetLevel(Type);
            float  time        = (float)DateTime.Now.Subtract(workerItem.WorkerTimeOfArrival).TotalSeconds;
            CircleBar.SetPercentage(time / timetolearn);

            if (time >= timetolearn)
            {
                w.SwitchState(Worker.States.WalkingToPlayer);
                w.AddLevel(Type);
                CircleBar.SetPercentage(0);
                removedindexes.Add(index);
            }

            index++;
        }

        foreach (int i in removedindexes)
        {
            WorkerItems.RemoveAt(i);
        }
    }
Ejemplo n.º 2
0
    override public void Update()
    {
        if (!Investigated)
        {
            Vector2 BossPos = new Vector2(Boss.Instance.transform.position.x, Boss.Instance.transform.position.y);
            Vector2 Pos     = new Vector2(transform.position.x, transform.position.y);
            if (Vector3.Distance(Boss.Instance.transform.position, transform.position) <= InvestigateDistance)
            {
                TextCloud.SetActive(true);
                InvestigatedFor += Time.deltaTime;
                InfoText.text    = OriginalInfoText.Substring(0, (int)Mathf.Floor((InvestigatedFor / TimeToInvestigate) * OriginalInfoText.Length));
                if (InvestigatedFor >= TimeToInvestigate)
                {
                    TextCloud.SetActive(false);
                    transform.FindChild("task-icon").gameObject.SetActive(true);
                    transform.FindChild("questionmark-icon").gameObject.SetActive(false);
                    Investigated = true;
                }
            }
        }

        base.Update();

        // If nobody is working, dont mind this
        if (WorkerItems.Count == 0)
        {
            return;
        }

        // Calculate how much time there is worked on the task
        int i = 0;

        foreach (WorkerItem workerItem in WorkerItems)
        {
            float increaserForHardWorkers   = workerItem.Worker.IsWorkingExtraHard ? 2.5f : 1f;
            float increaserSoItWontBeSoSlow = 1.5f;
            TotalTimeWorkedOnTask += Time.deltaTime * increaserSoItWontBeSoSlow * workerItem.Worker.GetLevel(this.Type) * increaserForHardWorkers;
            i++;
        }

        // Stop if there is not worked on the task
        if (TotalTimeWorkedOnTask == 0)
        {
            return;
        }

        // Make progressbar active if there is build for a bit
        if (!ProgressBar.gameObject.activeSelf)
        {
            ProgressBar.gameObject.SetActive(true);
        }

        // Update progressbar with new value
        ProgressBar.SetPercentage((float)TotalTimeWorkedOnTask / Airplane.CurrentAirplane.TimeToFinishPlane);

        // If the worked time is bigger than than the needed time to finish the task, dismiss the task and workers
        if (TotalTimeWorkedOnTask >= Airplane.CurrentAirplane.TimeToFinishPlane)
        {
            FinishTask();
        }
    }