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); } }
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); Chat.AddActionMsgToChat(interaction.Performer, $"You add reagents to the {gameObject.ExpensiveName()}.", $"{interaction.Performer.name} adds reagents to the {gameObject.ExpensiveName()}."); if (reagentContainer.Contains("mutagen", 5)) { reagentContainer.Contents["mutagen"] = reagentContainer.Contents["mutagen"] - 5; plantData.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 {gameObject.ExpensiveName()}."); 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) { if (HasPlant) { Chat.AddActionMsgToChat(interaction.Performer, $"You compost the {foodObject.name} in the {gameObject.ExpensiveName()}.", $"{interaction.Performer.name} composts {foodObject.name} in the {gameObject.ExpensiveName()}."); nutritionLevel = nutritionLevel + foodObject.plantData.Potency; Despawn.ServerSingle(interaction.HandObject); return; } else { plantData = PlantData.CreateNewPlant(foodObject.plantData); UpdatePlant(null, plantData.Name); UpdatePlantGrowthStage(0, 0); UpdatePlantStage(PlantSpriteStage.None, PlantSpriteStage.Growing); Inventory.ServerVanish(slot); Chat.AddActionMsgToChat(interaction.Performer, $"You plant the {foodObject.name} in the {gameObject.ExpensiveName()}.", $"{interaction.Performer.name} plants the {foodObject.name} in the {gameObject.ExpensiveName()}."); } } //If hand slot contains seeds, plant the seeds var Object = slot?.Item?.GetComponent <SeedPacket>(); if (Object != null) { plantData = PlantData.CreateNewPlant(slot.Item.GetComponent <SeedPacket>().plantData); UpdatePlant(null, plantData.Name); UpdatePlantGrowthStage(0, 0); UpdatePlantStage(PlantSpriteStage.None, PlantSpriteStage.Growing); Inventory.ServerVanish(slot); Chat.AddActionMsgToChat(interaction.Performer, $"You plant the {Object.name} in the {gameObject.ExpensiveName()}.", $"{interaction.Performer.name} plants the {Object.name} in the {gameObject.ExpensiveName()}."); 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)) { plantData.NextGrowthStageProgress = 0; UpdatePlantGrowthStage(growingPlantStage, 0); UpdatePlantStage(plantCurrentStage, PlantSpriteStage.Growing); UpdateHarvestFlag(harvestNotifier, false); } //Else remove plant from tray else { plantData = null; UpdatePlant(plantSyncString, null); UpdatePlantStage(plantCurrentStage, PlantSpriteStage.None); UpdateHarvestFlag(harvestNotifier, false); } } //Commenting unless this causes issues /*else * { * UpdatePlantStage(plantCurrentStage, PlantSpriteStage.None); * }*/ }