Ejemplo n.º 1
0
    public int OffsetValue(int amount)
    {
        if (Amount + amount < 0)
        {
            return(-1);
        }

        var amountAdded = amount;

        if (Amount + amount > Capacity)
        {
            amountAdded = Capacity - Amount;
            Amount      = Capacity;
        }
        else
        {
            Amount += amount;
        }

        if (amountAdded < 0)
        {
            FloatingText.Instantiate(display.transform, amountAdded, type.ToString(), false, false, 0.7f);
        }
        display.text = Amount + "/" + Capacity;
        OnChangeEvent.Invoke(type, amountAdded);
        return(amountAdded);
    }
Ejemplo n.º 2
0
    public bool EatMeal()
    {
        var food = ResourceManager.GetInstance()[ResourceType.Food];

        if (food.Amount - starvingPeople < 0)
        {
            Debug.Log("Game Over!");
            return(false);
        }
        var previousFoodAmount           = food.Amount;
        var previousStarvingPeopleAmount = starvingPeople;

        food.OffsetValue(-starvingPeople);
        starvingPeople = 0;
        if (food.Amount - workers.Count >= 0)
        {
            food.OffsetValue(-workers.Count);
        }
        else
        {
            starvingPeople += (workers.Count - food.Amount);
            food.OffsetValue(-food.Amount);
        }

        var deltaFood     = food.Amount - previousFoodAmount;
        var deltaStarving = starvingPeople - previousStarvingPeopleAmount;

        if (deltaStarving != 0)
        {
            FloatingText.Instantiate(starvingPeopleText.transform, deltaStarving, "Starving", false, deltaStarving < 0, 0.7f);
        }

        return(true);
    }
Ejemplo n.º 3
0
    private void Update()
    {
        var dayCycleManager = DayCycleManager.GetInstance();

        if (dayCycleManager.Day > 2 && dayCycleManager.GetCurrentHour() == spawnHour && prevHour != spawnHour)
        {
            var randomPoint = Random.insideUnitSphere;
            FloatingText.Instantiate(populationText.transform, 1, "Worker", false, true, 1);
            Worker.Instantiate(
                PopulationManager.GetInstance().GetAvailableHome(),
                spawnpoint.position + new Vector3(randomPoint.x, 0, randomPoint.z),
                spawnpoint.rotation);
        }
        prevHour = dayCycleManager.GetCurrentHour();
    }
Ejemplo n.º 4
0
    private void Update()
    {
        var assignable = GetComponent <Assignable>();

        if (IsFunctioning())
        {
            progress += Time.deltaTime * assignable.GetWorkersInRange() * DayCycleManager.GetInstance().ClockMinuteRate;
        }

        if (assignable.GetWorkersInRange() == 0 || DayCycleManager.GetInstance().IsRestTime())
        {
            progress = 0;
        }

        if (PercentComplete > 1)
        {
            ResourceManager.GetInstance()[type].OffsetValue(TakeFromPile(1));
            FloatingText.Instantiate(statusUI.transform, "+1 " + type.ToString());
            progress = progress - gatherPeriod;
        }
    }