Esempio n. 1
0
 private void EnsureInit()
 {
     if (defaultPlantData != null)
     {
         plantData = new PlantData();
         plantData.SetValues(defaultPlantData);
     }
 }
Esempio n. 2
0
    /// <summary>
    /// Gets a new instance of PlantData based on param
    /// </summary>
    /// <param name="plantData">PlantData to copy</param>
    /// <returns></returns>
    public static PlantData CreateNewPlant(PlantData plantData)
    {
        PlantData newPlant = new PlantData();

        newPlant.SetValues(plantData);
        newPlant.Health = 100;
        newPlant.Age    = 0;
        return(newPlant);
    }
Esempio n. 3
0
 void Start()
 {
     if (defaultPlantData != null)
     {
         plantData = new PlantData();
         plantData.SetValues(defaultPlantData);
     }
     SyncPlant(plantData.Name);
 }
Esempio n. 4
0
    public static PlantData MutateNewPlant(PlantData plantData, PlantTrayModification modification)
    {
        PlantData newPlant = new PlantData();

        newPlant.SetValues(plantData);
        newPlant.Health = 100;
        newPlant.Age    = 0;
        newPlant.NaturalMutation(modification);
        return(newPlant);
    }
Esempio n. 5
0
 public override void OnStartServer()
 {
     UpdateManager.Instance.Add(ServerUpdate);
     if (isSoilPile)
     {
         hasPlant  = false;
         plantData = new PlantData();
         plantData.SetValues(DefaultPlantData.PlantDictionary.Values.PickRandom());
         SyncPlant(plantData.Name);
         //NaturalMutation();
         SyncStage(PlantSpriteStage.FullyGrown);
         readyToHarvest = true;
         ProduceCrop();
     }
 }
Esempio n. 6
0
    //private bool IsServer; //separate flag as NetworkBehaviour isServer is not accurate when destroying an object

    public void OnSpawnServer(SpawnInfo info)
    {
        EnsureInit();
        if (isSoilPile)
        {
            hasPlant  = false;
            plantData = new PlantData();
            plantData.SetValues(DefaultPlantData.PlantDictionary.Values.PickRandom());
            UpdatePlant(null, plantData.Name);
            //NaturalMutation();
            UpdatePlantStage(PlantSpriteStage.None, PlantSpriteStage.FullyGrown);
            readyToHarvest = true;
            ProduceCrop();
        }
    }
Esempio n. 7
0
    private void UpdatePlant(string oldPlantSyncString, string newPlantSyncString)
    {
        //if (plantSyncString == newPlantSyncString) return;

        plantSyncString = newPlantSyncString;
        if (newPlantSyncString == null)
        {
            plantData = null;
        }
        else if (DefaultPlantData.PlantDictionary.ContainsKey(plantSyncString))
        {
            plantData = new PlantData();
            plantData.SetValues(DefaultPlantData.PlantDictionary[plantSyncString].plantData);
        }
        UpdateSprite();
    }
Esempio n. 8
0
 public void SyncPlant(string _OldPlantSyncString, string _PlantSyncString)
 {
     PlantSyncString = _PlantSyncString;
     if (!isServer)
     {
         if (DefaultPlantData.PlantDictionary.ContainsKey(PlantSyncString))
         {
             plantData = new PlantData();
             plantData.SetValues(DefaultPlantData.PlantDictionary[PlantSyncString].plantData);
         }
     }
     SpriteHandler.spriteData = SpriteFunctions.SetupSingleSprite(plantData.ProduceSprite);
     SpriteHandler.PushTexture();
     if (ItemAttributesV2 == null)
     {
         ItemAttributesV2 = this.GetComponent <ItemAttributesV2>();
     }
     if (isServer && ItemAttributesV2 != null)
     {
         ItemAttributesV2.ServerSetArticleDescription(plantData.Description);
         ItemAttributesV2.ServerSetArticleName(plantData.Plantname);
     }
     this.name = plantData.Plantname;
 }
Esempio n. 9
0
    public void DoTick()
    {
        if (hasPlant)
        {
            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))
            {
                plantHealth = plantHealth + (((plantData.WeedResistance - 11f) / 10f) * (weedLevel / 10f) * 5);
                //Logger.Log("plantData.weed > " + plantData.PlantHealth);
            }

            if (reagentContainer.Contents.ContainsKey("water"))
            {
                if (reagentContainer.Contents["water"] > 0)
                {
                    reagentContainer.Contents["water"] = reagentContainer.Contents["water"] - 0.1f;
                }
                else if (reagentContainer.Contents["water"] <= 0 &&
                         !plantData.PlantTrays.Contains(PlantTrays.Fungal_Vitality))
                {
                    plantHealth = plantHealth + (((plantData.Endurance - 101f) / 100f) * 1);
                }
            }
            else if (!plantData.PlantTrays.Contains(PlantTrays.Fungal_Vitality))
            {
                plantHealth = plantHealth + (((plantData.Endurance - 101f) / 100f) * 1);
            }

            numberOfUpdatesAlive++;
            //Logger.Log(plantData.NumberOfUpdatesAlive.ToString());
            if (!readyToHarvest)
            {
                plantSubStage = plantSubStage + plantData.GrowthSpeed;

                if (plantSubStage > 100)
                {
                    //Logger.Log("NutritionLevel" + NutritionLevel);
                    plantSubStage = 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)
                        {
                            SyncGrowingPlantStage(growingPlantStage + 1);
                            SyncStage(PlantSpriteStage.Growing);
                        }
                        else
                        {
                            if (!readyToHarvest)
                            {
                                NaturalMutation();
                                SyncStage(PlantSpriteStage.FullyGrown);
                                readyToHarvest = true;
                                ProduceCrop();
                                SyncHarvest(true);
                            }
                        }
                    }
                    else
                    {
                        plantHealth = plantHealth + (((plantData.Endurance - 101f) / 100f) * 5);
                        //Logger.Log("plantData.Nutriment > " + plantData.PlantHealth);
                    }
                }
            }

            if (plantHealth < 0)
            {
                CropDeath();
            }
            else if (numberOfUpdatesAlive > plantData.Lifespan * 500)
            {
                CropDeath();
            }
        }
        else
        {
            if (weedLevel < 10)
            {
                weedLevel = weedLevel + ((0.1f) * (0.1f));
                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 = new PlantData();
                    plantData.SetValues(data.plantData);
                    SyncPlant(plantData.Name);
                    SyncGrowingPlantStage(0);
                    SyncStage(PlantSpriteStage.Growing);
                    weedLevel = 0;
                    hasPlant  = true;
                }
            }
        }

        if (nutritionLevel < 25)
        {
            SyncNutriment(true);
        }
        else
        {
            SyncNutriment(false);
        }

        if (reagentContainer.Contents.ContainsKey("water"))
        {
            if (reagentContainer.Contents["water"] < 25)
            {
                SyncWater(true);
            }
            else
            {
                SyncWater(false);
            }
        }
        else
        {
            SyncWater(true);
        }

        if (weedLevel > 5)
        {
            SyncWeed(true);
        }
        else
        {
            SyncWeed(false);
        }

        SendUpdateToNearbyPlayers();
    }
Esempio n. 10
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        var slot = interaction.HandSlot;

        var objectContainer = slot?.Item?.GetComponent <ReagentContainer>();

        if (hasPlant)
        {
            if (plantData.MutatesInTo.Count > 0)
            {
                if (objectContainer != null)
                {
                    if (!objectContainer.InSolidForm)
                    {
                        objectContainer.MoveReagentsTo(5, reagentContainer);
                        if (reagentContainer.Contains("mutagen", 5))
                        {
                            reagentContainer.Contents["mutagen"] = reagentContainer.Contents["mutagen"] - 5;
                            Mutation();
                            return;
                        }
                    }
                }
            }
        }

        var objectItemAttributes = slot?.Item?.GetComponent <ItemAttributesV2>();

        if (objectItemAttributes != null)
        {
            if (objectItemAttributes.HasTrait(CommonTraits.Instance.Cultivator))
            {
                if (weedLevel > 0)
                {
                    Chat.AddActionMsgToChat(interaction.Performer,
                                            $"You remove the weeds from the {gameObject.ExpensiveName()}.",
                                            $"{interaction.Performer.name} uproots the weeds.");
                }
                weedNotifier.PushClear();
                weedLevel = 0;
                return;
            }

            if (objectItemAttributes.HasTrait(CommonTraits.Instance.Bucket))
            {
                Chat.AddActionMsgToChat(interaction.Performer, $"You water the {gameObject.ExpensiveName()}.",
                                        $"{interaction.Performer.name} waters the tray.");
                reagentContainer.Contents["water"] = 100f;
                return;
            }

            if (objectItemAttributes.HasTrait(CommonTraits.Instance.Trowel))
            {
                if (hasPlant)
                {
                    Chat.AddActionMsgToChat(interaction.Performer,
                                            $"You dig out all of the {gameObject.ExpensiveName()}'s plants!",
                                            $"{interaction.Performer.name} digs out the plants in the {gameObject.ExpensiveName()}!");
                    CropDeath();
                }

                SyncStage(PlantSpriteStage.None);
                return;
            }
        }

        var foodObject = slot?.Item?.GetComponent <GrownFood>();

        if (foodObject != null)
        {
            nutritionLevel = nutritionLevel + foodObject.plantData.Potency;
            Despawn.ServerSingle(interaction.HandObject);
            return;
        }

        var Object = slot?.Item?.GetComponent <SeedPacket>();

        if (Object != null)
        {
            hasPlant  = true;
            plantData = new PlantData();
            plantData.SetValues(slot.Item.GetComponent <SeedPacket>().plantData);
            SyncPlant(plantData.Name);
            SyncGrowingPlantStage(0);
            SyncStage(PlantSpriteStage.Growing);
            Inventory.ServerVanish(slot);

            //Force a quick refresh:
            SendUpdateToNearbyPlayers();
            return;
        }

        if (plantData != null)
        {
            if (readyToHarvest)
            {
                for (int i = 0; i < readyProduce.Count; i++)
                {
                    CustomNetTransform netTransform = readyProduce[i].GetComponent <CustomNetTransform>();
                    netTransform.AppearAtPosition(registerTile.WorldPositionServer);
                    netTransform.AppearAtPositionServer(registerTile.WorldPositionServer);
                }

                readyProduce.Clear();
                if (plantData.PlantTrays.Contains(PlantTrays.Perennial_Growth))
                {
                    hasPlant       = true;
                    readyToHarvest = false;
                    plantSubStage  = 0;
                    SyncGrowingPlantStage(0);
                    SyncStage(PlantSpriteStage.Growing);
                    SyncHarvest(false);
                }
                else
                {
                    plantData      = null;
                    hasPlant       = false;
                    readyToHarvest = false;
                    SyncStage(PlantSpriteStage.None);
                    SyncHarvest(false);
                }
            }
        }
        else
        {
            SyncStage(PlantSpriteStage.None);
        }
    }
Esempio n. 11
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        var slot = interaction.HandSlot;

        //If hand slot contains mutagen, use 5 mutagen mutate plant
        if (hasPlant)
        {
            if (plantData.MutatesInTo.Count > 0)
            {
                var objectContainer = slot?.Item?.GetComponent <ReagentContainer>();
                if (objectContainer != null)
                {
                    if (!objectContainer.InSolidForm)
                    {
                        objectContainer.MoveReagentsTo(5, reagentContainer);
                        if (reagentContainer.Contains("mutagen", 5))
                        {
                            reagentContainer.Contents["mutagen"] = reagentContainer.Contents["mutagen"] - 5;
                            Mutation();
                            return;
                        }
                    }
                }
            }
        }


        var objectItemAttributes = slot?.Item?.GetComponent <ItemAttributesV2>();

        if (objectItemAttributes != null)
        {
            //If hand slot contains Cultivator remove weeds
            if (objectItemAttributes.HasTrait(CommonTraits.Instance.Cultivator))
            {
                if (weedLevel > 0)
                {
                    Chat.AddActionMsgToChat(interaction.Performer,
                                            $"You remove the weeds from the {gameObject.ExpensiveName()}.",
                                            $"{interaction.Performer.name} uproots the weeds.");
                }
                weedNotifier.PushClear();
                weedLevel = 0;
                return;
            }

            //If hand slot contains Bucket water plants
            if (objectItemAttributes.HasTrait(CommonTraits.Instance.Bucket))
            {
                Chat.AddActionMsgToChat(interaction.Performer, $"You water the {gameObject.ExpensiveName()}.",
                                        $"{interaction.Performer.name} waters the tray.");
                reagentContainer.Contents["water"] = 100f;
                return;
            }

            //If hand slot contains Trowel remove plants
            if (objectItemAttributes.HasTrait(CommonTraits.Instance.Trowel))
            {
                if (hasPlant)
                {
                    Chat.AddActionMsgToChat(interaction.Performer,
                                            $"You dig out all of the {gameObject.ExpensiveName()}'s plants!",
                                            $"{interaction.Performer.name} digs out the plants in the {gameObject.ExpensiveName()}!");
                    CropDeath();
                }

                UpdatePlantStage(plantCurrentStage, PlantSpriteStage.None);
                return;
            }
        }

        //If hand slot contains grown food, plant the food
        //This temporarily replaces the seed machine until it is implemented, see commented code for original compost behavior
        var foodObject = slot?.Item?.GetComponent <GrownFood>();

        if (foodObject != null)
        {
            hasPlant  = true;
            plantData = new PlantData();
            plantData.SetValues(foodObject.plantData);
            UpdatePlant(null, plantData.Name);
            UpdatePlantGrowthStage(0, 0);
            UpdatePlantStage(PlantSpriteStage.None, PlantSpriteStage.Growing);
            Inventory.ServerVanish(slot);

            /*nutritionLevel = nutritionLevel + foodObject.plantData.Potency;
             * Despawn.ServerSingle(interaction.HandObject);
             * return;*/
        }

        //If hand slot contains seeds, plant the seeds
        var Object = slot?.Item?.GetComponent <SeedPacket>();

        if (Object != null)
        {
            hasPlant  = true;
            plantData = new PlantData();
            plantData.SetValues(slot.Item.GetComponent <SeedPacket>().plantData);
            UpdatePlant(null, plantData.Name);
            UpdatePlantGrowthStage(0, 0);
            UpdatePlantStage(PlantSpriteStage.None, PlantSpriteStage.Growing);
            Inventory.ServerVanish(slot);

            return;
        }

        //If plant is ready to harvest then make produce visible and update plant state
        if (plantData != null && readyToHarvest)
        {
            for (int i = 0; i < readyProduce.Count; i++)
            {
                CustomNetTransform netTransform = readyProduce[i].GetComponent <CustomNetTransform>();
                netTransform.AppearAtPosition(registerTile.WorldPositionServer);
                netTransform.AppearAtPositionServer(registerTile.WorldPositionServer);
            }
            readyProduce.Clear();

            //If plant is Perennial then reset growth to the start of growing stage
            if (plantData.PlantTrays.Contains(PlantTrays.Perennial_Growth))
            {
                hasPlant       = true;
                readyToHarvest = false;
                plantSubStage  = 0;
                UpdatePlantGrowthStage(growingPlantStage, 0);
                UpdatePlantStage(plantCurrentStage, PlantSpriteStage.Growing);
                UpdateHarvestFlag(harvestNotifier, false);
            }
            //Else remove plant from tray
            else
            {
                plantData      = null;
                hasPlant       = false;
                readyToHarvest = false;
                UpdatePlant(plantSyncString, null);
                UpdatePlantStage(plantCurrentStage, PlantSpriteStage.None);
                UpdateHarvestFlag(harvestNotifier, false);
            }
        }
        //Commenting unless this causes issues

        /*else
         * {
         *      UpdatePlantStage(plantCurrentStage, PlantSpriteStage.None);
         * }*/
    }
Esempio n. 12
0
    /// <summary>
    /// Server updates plant status and updates clients as needed
    /// </summary>
    public override void UpdateMe()
    {
        //Only server checks plant status
        if (!isServer)
        {
            return;
        }

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


        if (hasPlant)
        {
            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))
            {
                plantHealth = plantHealth + (((plantData.WeedResistance - 110f) / 100f) * (weedLevel / 10f) * 5);
                //Logger.Log("plantData.weed > " + plantData.PlantHealth);
            }

            if (reagentContainer.Contents.ContainsKey("water"))
            {
                if (reagentContainer.Contents["water"] > 0)
                {
                    reagentContainer.Contents["water"] = reagentContainer.Contents["water"] - 0.1f;
                }
                else if (reagentContainer.Contents["water"] <= 0 &&
                         !plantData.PlantTrays.Contains(PlantTrays.Fungal_Vitality))
                {
                    plantHealth = plantHealth + (((plantData.Endurance - 101f) / 100f) * 1);
                }
            }
            else if (!plantData.PlantTrays.Contains(PlantTrays.Fungal_Vitality))
            {
                plantHealth = plantHealth + (((plantData.Endurance - 101f) / 100f) * 1);
            }

            numberOfUpdatesAlive++;
            //Logger.Log(plantData.NumberOfUpdatesAlive.ToString());
            if (!readyToHarvest)
            {
                plantSubStage = plantSubStage + (int)Math.Round(plantData.GrowthSpeed / 10f);

                if (plantSubStage > 100)
                {
                    //Logger.Log("NutritionLevel" + NutritionLevel);
                    plantSubStage = 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)
                            {
                                NaturalMutation();
                                UpdatePlantStage(plantCurrentStage, PlantSpriteStage.FullyGrown);
                                readyToHarvest = true;
                                ProduceCrop();
                            }
                            UpdateHarvestFlag(harvestNotifier, true);
                        }
                    }
                    else
                    {
                        plantHealth = plantHealth + (((plantData.Endurance - 101f) / 100f) * 5);
                        //Logger.Log("plantData.Nutriment > " + plantData.PlantHealth);
                    }
                }
            }

            if (plantHealth < 0)
            {
                CropDeath();
            }
            else if (numberOfUpdatesAlive > plantData.Lifespan * 500)
            {
                CropDeath();
            }
        }
        else
        {
            if (weedLevel < 10)
            {
                weedLevel = weedLevel + ((0.1f) * (0.1f));
                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 = new PlantData();
                    plantData.SetValues(data.plantData);
                    UpdatePlant(null, plantData.Name);
                    UpdatePlantGrowthStage(growingPlantStage, 0);
                    UpdatePlantStage(plantCurrentStage, PlantSpriteStage.Growing);
                    weedLevel = 0;
                    hasPlant  = true;
                }
            }
        }

        if (nutritionLevel < 25)
        {
            UpdateNutrimentFlag(showNutrimenetFlag, true);
        }
        else
        {
            UpdateNutrimentFlag(showNutrimenetFlag, false);
        }

        if (reagentContainer.Contents.ContainsKey("water"))
        {
            if (reagentContainer.Contents["water"] < 25)
            {
                UpdateWaterFlag(showWaterFlag, true);
            }
            else
            {
                UpdateWaterFlag(showWaterFlag, false);
            }
        }
        else
        {
            UpdateWaterFlag(showWaterFlag, true);
        }

        if (weedLevel > 5)
        {
            UpdateWeedsFlag(showWeedsFlag, true);
        }
        else
        {
            UpdateWeedsFlag(showWeedsFlag, false);
        }
    }