Beispiel #1
0
    public void UpdateInfoBar()
    {
        // Change the label to match the current date
        infoBar.DateLabel.GetComponent <TMPro.TMP_Text>().SetText(DateFuncs.DateToString(curDate));
        // Change the season and weather label
        string weatherSeasonLabel = string.Format("{0} - {1}", curSeason, ClimateFuncs.WeatherToString(curWeather));

        infoBar.WeatherSeasonLabel.GetComponent <TMPro.TMP_Text>().SetText(weatherSeasonLabel);
    }
Beispiel #2
0
    public override void DoJob()
    {
        base.DoJob();

        // Look for relevant items in inventory
        foreach (Item item in me.inventory)
        {
            if (item.type.Contains("Farm Animal"))
            {
                animals.Add((FarmAnimal)item);
            }
            else if (item.type.Contains("Produce"))
            {
                produce.Add(item);
            }
        }

        // Buy animals if possible
        for (int i = animals.Count; i < maxAnimals; i++)
        {
            FarmAnimal toBuy = new FarmAnimal(possibleAnimals[Random.Range(0, possibleAnimals.Count)]);
            if (me.money >= toBuy.value + me.alwaysDoJobThreshold)             // Make sure the farmer has enough money saved to buy the animal
            {
                gc.LogMessage(me.name + " has bought a " + toBuy.name + " for " + toBuy.value + " Gold.", "LGray");
                me.GetPaid(-toBuy.value, true);
                me.inventory.Add(toBuy);
                animals.Add(toBuy);
            }
        }

        // Get produce from animals
        foreach (FarmAnimal animal in animals)
        {
            int animalHarvestRoll = Random.Range(0, 100);
            if (animalHarvestRoll < me.GetEffectiveJobSkill() + 40)             // Anyone with a jobSkill of at least 60 should always succeed at harvesting
            {
                Item newProduce = animal.MakeProduce();
                me.inventory.Add(newProduce);
                produce.Add(newProduce);
                gc.LogMessage(me.name + " got a " + newProduce.name + " from a " + animal.name + ".", "LGray");
            }
        }

        // Plant crops if nothing is growing already, and if it's either Spring or Summer, and NOT Droughtlike or Dry.
        if (currentlyGrowing.Count < 1 && (gc.curSeason == Season.Spring || gc.curSeason == Season.Summer) && gc.curWeather != Weather.Droughtlike && gc.curWeather != Weather.Dry)
        {
            Item cropToGrow  = possibleCrops[Random.Range(0, possibleCrops.Count)];
            int  cropsToGrow = Random.Range(1, Mathf.CeilToInt(me.GetEffectiveJobSkill() / 10f));
            for (int i = 0; i < cropsToGrow; i++)
            {
                currentlyGrowing.Add(new Item(cropToGrow));
            }
            me.Speak("Let's plant some " + cropToGrow.pluralName + " today.");

            // Time to grow is affected by jobSkill.
            int daysTillHarvest = Random.Range(minHarvestDays, maxHarvestDays + 1);
            //Debug.Log("daysTillHarvest: " + daysTillHarvest);
            daysTillHarvest = Mathf.RoundToInt(daysTillHarvest * ((float)minJobSkillToReduceGrowTime / me.GetEffectiveJobSkill()));
            //Debug.Log("timeModifier: " + (float)minJobSkillToReduceGrowTime / me.GetEffectiveJobSkill());
            harvestDate = DateFuncs.GetFutureDate(gc.curDate, daysTillHarvest);
            //Debug.Log("Crops will be ready to harvest on " + DateFuncs.DateToString(harvestDate) + ", which is in " + daysTillHarvest + " days.");
        }

        // Crops get wiped if there's an ongoing drought.
        if (gc.curWeather == Weather.Droughtlike)
        {
            gc.LogMessage("The ongoing drought has withered away " + me.commonName + "'s crops.", "DRed");
            currentlyGrowing.Clear();
        }

        // Harvest if crops are ready
        if (DateFuncs.Equals(gc.curDate, harvestDate))
        {
            me.Speak("Ah, the harvest is in!");
            foreach (Item crop in currentlyGrowing)
            {
                Item toAdd = new Item(crop);
                me.inventory.Add(toAdd);
                produce.Add(toAdd);
            }
            gc.LogMessage(me.name + " has harvested " + currentlyGrowing.Count + " " + currentlyGrowing[0].pluralName + ".", "LGray");
            currentlyGrowing.Clear();
        }

        // Check how much food the farmer has
        int foodAmt = me.CountItemsByType("Food");
        //Debug.Log(me.myName + " has " + foodAmt + " units of food left.");

        // Sell up to 3 crops to market
        int cropsToSell = produce.Count;

        if (cropsToSell > 3)
        {
            cropsToSell = 3;
        }
        if (cropsToSell > 0)
        {
            int sellValue = 0;
            for (int i = 0; i < cropsToSell; i++)
            {
                if (produce[0].type.Contains("Food") && foodAmt <= me.prefMinFood && me.money >= me.alwaysDoJobThreshold)
                {
                    break;
                }

                sellValue += produce[0].value;
                gc.LogMessage(me.name + " has sold a " + produce[0].name + ".", "LGray");
                if (produce[0].type.Contains("Food"))
                {
                    foodAmt--;
                }
                gc.GetComponent <ShopScript>().SellToShop(produce[0]);
                me.inventory.Remove(produce[0]);
                produce.RemoveAt(0);
            }
            if (sellValue > 0)
            {
                me.Speak("Nice, I sold " + sellValue + " Gold worth of produce today.");
                me.GetPaid(sellValue, true);
            }
            else
            {
                me.Speak("I ain't got no produce to sell today.");
            }
            //Debug.Log(me.myName + " has " + foodAmt + " units of food left.");
        }
        else
        {
            me.Speak("I ain't got no produce to sell today.");
        }
        animals.Clear();
        produce.Clear();
    }
Beispiel #3
0
    // Finds the number of days it would take to reach the current day one month from now, and simulates that many days.
    public void SimMonth()
    {
        Date futureDate = DateFuncs.GetFutureDate(curDate, 0, 0, 1);

        SimDays(DateFuncs.DaysUntil(curDate, futureDate));
    }
Beispiel #4
0
    // Runs at the end of each day
    public IEnumerator EndDay(float waitTime = 0f)
    {
        yield return(new WaitForSeconds(waitTime));

        yield return(new WaitForEndOfFrame());        // All of these WaitForEndOfFrames are so that the LogSpaces show up properly.

        curDate    = DateFuncs.NextDay(curDate);
        curWeather = ClimateFuncs.GetNextWeather(curWeather, curDate);
        curSeason  = ClimateFuncs.GetSeason(curDate);

        LogSpace();

        // Get rid of dead citizens
        bool buriedSomeone = false;

        for (int i = 0; i < citizens.Count; i++)
        {
            if (citizens[i].isDead)
            {
                citizens[i].Bury();
                buriedSomeone = true;
                i--;
            }
        }
        if (buriedSomeone)
        {
            LogSpace();
        }

        // A new citizen moves in each day if there's space.
        if (citizens.Count < maxCitizens)
        {
            citizens.Add(SpawnCitizen());
            yield return(new WaitForEndOfFrame());

            LogSpace();
        }

        yield return(new WaitForEndOfFrame());

        UpdateInfoBar();
        LogMessage("A new day has begun.\n ", "Peach");

        // Do upkeep for living citizens
        foreach (CitizenScript citizen in citizens)
        {
            if (!citizen.isDead)
            {
                citizen.Upkeep();
                LogSpace();
            }
        }
        LogMessage("The day has ended.", "Blue");

        // Clear excess items from shop, oldest items go first.
        GetComponent <ShopScript>().ClearExcess();

        // The responsible thing to do would be clearing old event messages after a certain point,
        // otherwise it will quickly eat up all of the computer's memory.
        int excessMessages = eventLog.transform.childCount - maxEvtLogMessages;

        for (int i = 0; i < excessMessages; i++)
        {
            if (eventLog.transform.childCount > maxEvtLogMessages)
            {
                Destroy(eventLog.transform.GetChild(i).gameObject);
            }
        }

        GameObject newDay = Instantiate(evtLogTxtTemplate, eventLog.transform);

        curDayTextObject = newDay;
        curDayTextObject.GetComponent <TMPro.TMP_Text>().SetText("");

        Canvas.ForceUpdateCanvases();
        if (scrollToBottomOnNewDay)
        {
            eventLog.GetComponentInParent <ScrollRect>().verticalNormalizedPosition = 0;
        }
    }