コード例 #1
0
        /// <summary>
        /// Server updates plant status and updates clients as needed
        /// </summary>
        public override void UpdateMe()
        {
            //Only server checks plant status, wild plants do not grow
            if (!isServer || isWild)
            {
                return;
            }

            //Only update at set rate
            tickCount += Time.deltaTime;
            if (tickCount < tickRate)
            {
                return;
            }

            tickCount = 0f;


            if (HasPlant)
            {
                //Up plants age
                plantData.Age++;

                //Weeds checks
                if (weedLevel < 10)
                {
                    weedLevel = weedLevel + ((0.1f) * (plantData.WeedGrowthRate / 10f));
                    if (weedLevel > 10)
                    {
                        weedLevel = 10;
                    }
                }

                if (weedLevel > 9.5f && !plantData.PlantTrays.Contains(PlantTrays.Weed_Adaptation))
                {
                    plantData.Health += (((plantData.WeedResistance - 110f) / 100f) * (weedLevel / 10f) * 5);
                    //Logger.Log("plantData.weed > " + plantData.PlantHealth);
                }

                //Water Checks
                if (reagentContainer[water] > 0)
                {
                    reagentContainer.Subtract(new ReagentMix(water, .1f));
                }
                else if (!plantData.PlantTrays.Contains(PlantTrays.Fungal_Vitality))
                {
                    plantData.Health += (plantData.Endurance - 101f) / 100f;
                }


                //Growth and harvest checks
                if (!ReadyToHarvest)
                {
                    plantData.NextGrowthStageProgress += (int)Math.Ceiling(plantData.GrowthSpeed / 5f);

                    if (plantData.NextGrowthStageProgress > 100)
                    {
                        plantData.NextGrowthStageProgress = 0;
                        if (reagentContainer[nutriment] > 0 || plantData.PlantTrays.Contains(PlantTrays.Weed_Adaptation))
                        {
                            if (!plantData.PlantTrays.Contains(PlantTrays.Weed_Adaptation))
                            {
                                if (reagentContainer[nutriment] > 0)
                                {
                                    reagentContainer.Subtract(new ReagentMix(nutriment, 1));
                                }
                            }

                            if ((growingPlantStage + 1) < plantData.GrowthSpritesSOs.Count)
                            {
                                growingPlantStage = growingPlantStage + 1;
                                UpdateSprite();
                                plantCurrentStage = PlantSpriteStage.Growing;
                            }
                            else
                            {
                                if (!ReadyToHarvest)
                                {
                                    //plantData.NaturalMutation(modification);
                                    plantCurrentStage = PlantSpriteStage.FullyGrown;
                                    ProduceCrop();
                                }
                                UpdateHarvestFlag(showHarvestFlag, true);
                                UpdateSprite();
                            }
                        }
                        else
                        {
                            plantData.Health += (((plantData.Endurance - 101f) / 100f) * 5);
                            //Logger.Log("plantData.Nutriment > " + plantData.PlantHealth);
                        }
                    }
                }

                //Health checks
                if (plantData.Health < 0)
                {
                    CropDeath();
                }
                else if (plantData.Age > plantData.Lifespan * 2500)
                {
                    CropDeath();
                }
            }
            //Empty tray checks
            else
            {
                if (weedLevel < 10)
                {
                    weedLevel += 0.01f;
                    if (weedLevel > 10)
                    {
                        weedLevel = 10;
                    }
                }

                // If there is no living plant in the tray and weed level is at least 10, choose a seed from the "Potential Weeds" list to grow in the tray.
                if (plantData == null)
                {
                    if (weedLevel >= 10)
                    {
                        var data = potentialWeeds[random.Next(potentialWeeds.Count)];
                        plantData         = PlantData.CreateNewPlant(data.plantData);
                        growingPlantStage = 0;
                        plantCurrentStage = PlantSpriteStage.Growing;
                        weedLevel         = 0;
                        //hasPlant = true;
                        UpdateSprite();
                    }
                }
            }


            UpdateNutrimentFlag(showNutrimenetFlag, reagentContainer[nutriment] < 25);

            UpdateWaterFlag(showWaterFlag, reagentContainer[water] < 25);
            UpdateWeedsFlag(showWeedsFlag, weedLevel > 5);
        }
コード例 #2
0
    /// <summary>
    /// Server updates plant status and updates clients as needed
    /// </summary>
    public override void UpdateMe()
    {
        //Only server checks plant status, wild plants do not grow
        if (!isServer || isWild)
        {
            return;
        }

        //Only update at set rate
        tickCount += Time.deltaTime;
        if (tickCount < tickRate)
        {
            return;
        }

        tickCount = 0f;


        if (HasPlant)
        {
            //Up plants age
            plantData.Age++;

            //Weeds checks
            if (weedLevel < 10)
            {
                weedLevel = weedLevel + ((0.1f) * (plantData.WeedGrowthRate / 100f));
                if (weedLevel > 10)
                {
                    weedLevel = 10;
                }
            }

            if (weedLevel > 9.5f && !plantData.PlantTrays.Contains(PlantTrays.Weed_Adaptation))
            {
                plantData.Health += (((plantData.WeedResistance - 110f) / 100f) * (weedLevel / 10f) * 5);
                //Logger.Log("plantData.weed > " + plantData.PlantHealth);
            }

            //Water Checks
            if (reagentContainer[water] > 0)
            {
                reagentContainer.Subtract(new ReagentMix(water, .1f));
            }
            else if (!plantData.PlantTrays.Contains(PlantTrays.Fungal_Vitality))
            {
                plantData.Health += (plantData.Endurance - 101f) / 100f;
            }


            //Growth and harvest checks
            if (!ReadyToHarvest)
            {
                plantData.NextGrowthStageProgress += (int)Math.Round(plantData.GrowthSpeed / 10f);

                if (plantData.NextGrowthStageProgress > 100)
                {
                    plantData.NextGrowthStageProgress = 0;
                    if (nutritionLevel > 0 || plantData.PlantTrays.Contains(PlantTrays.Weed_Adaptation))
                    {
                        if (!plantData.PlantTrays.Contains(PlantTrays.Weed_Adaptation))
                        {
                            if (nutritionLevel != 0)
                            {
                                nutritionLevel = nutritionLevel - 1;
                            }

                            if (nutritionLevel < 0)
                            {
                                nutritionLevel = 0;
                            }
                        }

                        if ((growingPlantStage + 1) < plantData.GrowthSprites.Count)
                        {
                            UpdatePlantGrowthStage(growingPlantStage, growingPlantStage + 1);
                            UpdatePlantStage(plantCurrentStage, PlantSpriteStage.Growing);
                        }
                        else
                        {
                            if (!ReadyToHarvest)
                            {
                                //plantData.NaturalMutation(modification);
                                UpdatePlantStage(plantCurrentStage, PlantSpriteStage.FullyGrown);
                                ProduceCrop();
                            }

                            UpdateHarvestFlag(harvestNotifier, true);
                        }
                    }
                    else
                    {
                        plantData.Health += (((plantData.Endurance - 101f) / 100f) * 5);
                        //Logger.Log("plantData.Nutriment > " + plantData.PlantHealth);
                    }
                }
            }

            //Health checks
            if (plantData.Health < 0)
            {
                CropDeath();
            }
            else if (plantData.Age > plantData.Lifespan * 500)
            {
                CropDeath();
            }
        }
        //Empty tray checks
        else
        {
            if (weedLevel < 10)
            {
                weedLevel += 0.01f;
                if (weedLevel > 10)
                {
                    weedLevel = 10;
                }
            }

            if (plantData != null)
            {
                if (weedLevel >= 10 && !plantData.PlantTrays.Contains(PlantTrays.Weed_Adaptation))
                {
                    var data = potentialWeeds[random.Next(potentialWeeds.Count)];
                    plantData = PlantData.CreateNewPlant(data.plantData);
                    UpdatePlant(null, plantData.Name);
                    UpdatePlantGrowthStage(growingPlantStage, 0);
                    UpdatePlantStage(plantCurrentStage, PlantSpriteStage.Growing);
                    weedLevel = 0;
                    //hasPlant = true;
                }
            }
        }

        UpdateNutrimentFlag(showNutrimenetFlag, nutritionLevel < 25);

        UpdateWaterFlag(showWaterFlag, reagentContainer[water] == null || reagentContainer[water] < 25);

        UpdateWeedsFlag(showWeedsFlag, weedLevel > 5);
    }