public static bool OnHandClick_Prefix(GrownPlant __instance, GUIHand hand) { if (__instance.seed != null && __instance.seed.gameObject != null) { PrefabIdentifier prefabID = __instance.seed.gameObject.GetComponent <PrefabIdentifier>(); if (prefabID == null) { return(true); } if (prefabID.ClassId == "MarbleMelonTiny") { PlantGenericController controllerA = __instance.gameObject.GetComponent <PlantGenericController>(); if (controllerA == null) { controllerA = __instance.seed.gameObject.GetComponent <PlantGenericController>(); } if (controllerA != null && controllerA._progress >= 1.0f) { if (__instance.seed.currentPlanter != null && Inventory.Get().HasRoomFor(1, 1)) { __instance.seed.currentPlanter.RemoveItem(__instance.seed); if (global::Utils.GetSubRoot() != null) { __instance.seed.pickupable.destroyOnDeath = false; } SkyEnvironmentChanged.Send(__instance.seed.pickupable.gameObject, Player.main.GetSkyEnvironment()); UnityEngine.Object.Destroy(__instance.seed.pickupable.gameObject); CraftData.AddToInventorySync(CrafterLogicFixer.MarbleMelonTinyFruit, 1, false, false); hand.player.PlayGrab(); } } return(false); } else if (prefabID.ClassId == "MarbleMelonTinyFruit") { if (__instance.seed.currentPlanter != null && __instance.seed.pickupable != null && Inventory.Get().HasRoomFor(__instance.seed.pickupable)) { PlantGenericController controllerA = __instance.gameObject.GetComponent <PlantGenericController>(); if (controllerA == null) { controllerA = __instance.seed.gameObject.GetComponent <PlantGenericController>(); } if (controllerA != null && controllerA._progress >= 1.0f) { __instance.seed.currentPlanter.RemoveItem(__instance.seed); Inventory.Get().Pickup(__instance.seed.pickupable, false); hand.player.PlayGrab(); } } return(false); } } return(true); }
public static void OnHandHover_Postfix(GrownPlant __instance, GUIHand hand) { // If current plant is valid if (__instance.seed != null && __instance.seed.pickupable != null && __instance.seed.currentPlanter != null) { bool showMelonTooltip = false; // Get prefab ID PrefabIdentifier prefabID = __instance.seed.gameObject.GetComponent <PrefabIdentifier>(); if (prefabID == null) { return; } // If current plant is one of our custom plants bool isSmallMelon = prefabID.ClassId == "MarbleMelonTiny" || prefabID.ClassId == "MarbleMelonTinyFruit"; if (CustomFlora.AllPlants.Contains(prefabID.ClassId)) { LiveMixin liveMixin = null; bool componentEnabled = false; float progress = -1.0f; PlantGenericController controllerA = __instance.gameObject.GetComponent <PlantGenericController>(); if (controllerA == null) { controllerA = __instance.seed.gameObject.GetComponent <PlantGenericController>(); if (controllerA != null) { liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } if (controllerA == null) { PlantMonoTransformController controllerB = __instance.gameObject.GetComponent <PlantMonoTransformController>(); if (controllerB == null) { controllerB = __instance.seed.gameObject.GetComponent <PlantMonoTransformController>(); if (controllerB != null) { liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } if (controllerB == null) { LandTree1Controller controllerC = __instance.gameObject.GetComponent <LandTree1Controller>(); if (controllerC == null) { controllerC = __instance.seed.gameObject.GetComponent <LandTree1Controller>(); if (controllerC != null) { liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } if (controllerC != null) { progress = controllerC._progress; componentEnabled = controllerC.enabled; } } else { progress = controllerB._progress; componentEnabled = controllerB.enabled; } } else { progress = controllerA._progress; componentEnabled = controllerA.enabled; } if (componentEnabled) { if (progress >= 0.0f && progress < 1.0f) { // Display growing tooltip HandReticle.main.SetIcon(HandReticle.IconType.Progress, 1f); HandReticle.main.SetProgress(progress); // Fix knifeable if (liveMixin != null && liveMixin.data != null && liveMixin.knifeable) { liveMixin.data.knifeable = false; } } else if (isSmallMelon && progress >= 1.0f) { showMelonTooltip = true; } } else if (isSmallMelon && progress >= 1.0f) { showMelonTooltip = true; } } else if (isSmallMelon) { showMelonTooltip = true; } if (showMelonTooltip) { HandReticle.main.SetIcon(HandReticle.IconType.Hand, 1f); if (!Player.main.HasInventoryRoom(1, 1)) { #if BELOWZERO HandReticle.main.SetText(HandReticle.TextType.Hand, LanguageHelper.GetFriendlyWord("PickupMarbleMelonTinyFruit"), false, GameInput.Button.None); HandReticle.main.SetText(HandReticle.TextType.HandSubscript, "InventoryFull", true, GameInput.Button.None); #else HandReticle.main.SetInteractText(LanguageHelper.GetFriendlyWord("PickupMarbleMelonTinyFruit"), "InventoryFull", false, true, HandReticle.Hand.None); #endif } else { #if BELOWZERO HandReticle.main.SetText(HandReticle.TextType.Hand, LanguageHelper.GetFriendlyWord("PickupMarbleMelonTinyFruit"), false, GameInput.Button.None); #else HandReticle.main.SetInteractText(LanguageHelper.GetFriendlyWord("PickupMarbleMelonTinyFruit"), string.Empty, false, false, HandReticle.Hand.None); #endif } } } }
public override GameObject GetGameObject() { GameObject prefab = GameObject.Instantiate(this.GameObject); prefab.name = this.ClassID; GameObject.DestroyImmediate(prefab.GetComponent <PickPrefab>()); GameObject.DestroyImmediate(prefab.GetComponent <LiveMixin>()); PrefabsHelper.AddNewGenericSeed(ref prefab); var model = prefab.FindChild("farming_plant_01_02"); // Scale float scaleRatio = 0.75f; model.transform.localScale *= scaleRatio; // Update rigid body var rb = prefab.GetComponent <Rigidbody>(); // Add EntityTag var entityTag = prefab.AddComponent <EntityTag>(); entityTag.slotType = EntitySlot.Type.Small; // Add TechTag var techTag = prefab.AddComponent <TechTag>(); techTag.type = this.TechType; // Update prefab identifier var prefabId = prefab.GetComponent <PrefabIdentifier>(); prefabId.ClassId = this.ClassID; // Update large world entity var lwe = prefab.GetComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Near; // Add world forces var worldForces = prefab.AddComponent <WorldForces>(); worldForces.handleGravity = true; worldForces.aboveWaterGravity = 9.81f; worldForces.underwaterGravity = 1.0f; worldForces.handleDrag = true; worldForces.aboveWaterDrag = 0.0f; worldForces.underwaterDrag = 10.0f; worldForces.useRigidbody = rb; // Add pickupable var pickupable = prefab.AddComponent <Pickupable>(); pickupable.isPickupable = true; pickupable.destroyOnDeath = true; #if BELOWZERO pickupable.isLootCube = false; #else pickupable.cubeOnPickup = false; #endif pickupable.randomizeRotationWhenDropped = true; pickupable.usePackUpIcon = false; // Add eatable Eatable eatable = null; if (ConfigSwitcher.config_MarbleMelonTiny.Eatable) { eatable = prefab.AddComponent <Eatable>(); eatable.foodValue = ConfigSwitcher.config_MarbleMelonTiny.FoodValue; eatable.waterValue = ConfigSwitcher.config_MarbleMelonTiny.WaterValue; #if SUBNAUTICA eatable.stomachVolume = 10.0f; eatable.allowOverfill = false; #endif eatable.decomposes = ConfigSwitcher.config_MarbleMelonTiny.Decomposes; eatable.kDecayRate = ConfigSwitcher.config_MarbleMelonTiny.KDecayRate; eatable.despawns = ConfigSwitcher.config_MarbleMelonTiny.Despawns; eatable.despawnDelay = ConfigSwitcher.config_MarbleMelonTiny.DespawnDelay; } // Add plantable var plantable = prefab.AddComponent <Plantable>(); plantable.aboveWater = true; plantable.underwater = false; plantable.isSeedling = true; plantable.plantTechType = this.TechType; plantable.size = Plantable.PlantSize.Small; plantable.pickupable = pickupable; plantable.eatable = eatable; plantable.model = prefab; // prefab.FindChild("farming_plant_01_02"); plantable.linkedGrownPlant = new GrownPlant(); plantable.linkedGrownPlant.seed = plantable; plantable.linkedGrownPlant.seedUID = "MarbleMelonTinyFruit"; // Add live mixin var liveMixin = prefab.AddComponent <LiveMixin>(); liveMixin.health = ConfigSwitcher.config_MarbleMelonTiny.Health; liveMixin.data = ScriptableObject.CreateInstance <LiveMixinData>(); liveMixin.data.broadcastKillOnDeath = false; liveMixin.data.canResurrect = false; liveMixin.data.destroyOnDeath = true; #if SUBNAUTICA liveMixin.data.explodeOnDestroy = false; #endif liveMixin.data.invincibleInCreative = false; liveMixin.data.minDamageForSound = 10.0f; liveMixin.data.passDamageDataOnDeath = true; liveMixin.data.weldable = false; liveMixin.data.knifeable = false; liveMixin.data.maxHealth = ConfigSwitcher.config_MarbleMelonTiny.Health; //liveMixin.startHealthPercent = 1.0f; // Adjust sky applier SkyApplier sa = prefab.GetComponent <SkyApplier>(); sa.renderers = prefab.GetComponentsInChildren <MeshRenderer>(); sa.anchorSky = Skies.Auto; sa.dynamic = true; // Adjust colliders CapsuleCollider cc = prefab.GetComponentInChildren <CapsuleCollider>(); cc.radius *= scaleRatio; cc.height *= scaleRatio; SphereCollider sc = prefab.GetComponentInChildren <SphereCollider>(); sc.radius *= scaleRatio; // Add generic plant controller PlantGenericController plantController = prefab.AddComponent <PlantGenericController>(); plantController.GrowthDuration = ConfigSwitcher.config_MarbleMelonTiny.GrowthDuration; plantController.Health = ConfigSwitcher.config_MarbleMelonTiny.Health; plantController.Knifeable = ConfigSwitcher.config_MarbleMelonTiny.Knifeable; CustomFloraSerializer customSerializer = prefab.AddComponent <CustomFloraSerializer>(); // Hide plant and show seed PrefabsHelper.HidePlantAndShowSeed(prefab.transform, this.ClassID); return(prefab); }
//public void OnHandHover(GUIHand hand) public static void OnHandHover_Postfix(GrownPlant __instance, GUIHand hand) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A"); #endif // If current plant is valid if (__instance.seed != null && __instance.seed.pickupable != null && __instance.seed.currentPlanter != null) { // Get prefab ID PrefabIdentifier prefabID = __instance.seed.gameObject.GetComponent <PrefabIdentifier>(); // If current plant is one of our custom plants if (prefabID != null && InventoryFixer._plants.Contains(prefabID.ClassId)) { LiveMixin liveMixin = null; bool componentEnabled = false; float progress = -1.0f; PlantGenericController controllerA = __instance.gameObject.GetComponent <PlantGenericController>(); if (controllerA == null) { controllerA = __instance.seed.gameObject.GetComponent <PlantGenericController>(); if (controllerA != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN SEED A"); #endif liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN A"); #endif liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } PlantMonoTransformController controllerB = __instance.gameObject.GetComponent <PlantMonoTransformController>(); if (controllerB == null) { controllerB = __instance.seed.gameObject.GetComponent <PlantMonoTransformController>(); if (controllerB != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN SEED B"); #endif liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN B"); #endif liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } LandTree1Controller controllerC = __instance.gameObject.GetComponent <LandTree1Controller>(); if (controllerC == null) { controllerC = __instance.seed.gameObject.GetComponent <LandTree1Controller>(); if (controllerC != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN SEED C"); #endif liveMixin = __instance.seed.gameObject.GetComponent <LiveMixin>(); } } else { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: CONTROLLER IN C"); #endif liveMixin = __instance.gameObject.GetComponent <LiveMixin>(); } if (controllerA != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A1 enabled=[" + controllerA.enabled + "] progress=[" + controllerA._progress + "] passedProgress=[" + controllerA._passedProgress + "]"); #endif progress = controllerA._progress;// + controllerA._passedProgress; componentEnabled = controllerA.enabled; } else if (controllerB != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A2 enabled=[" + controllerB.enabled + "] progress=[" + controllerB._progress + "] passedProgress=[" + controllerB._passedProgress + "]"); #endif progress = controllerB._progress;// + controllerB._passedProgress; componentEnabled = controllerB.enabled; } else if (controllerC != null) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A3 enabled=[" + controllerC.enabled + "] progress=[" + controllerC._progress + "] passedProgress=[" + controllerC._passedProgress + "]"); #endif progress = controllerC._progress;// + controllerC._passedProgress; componentEnabled = controllerC.enabled; } #if DEBUG_GROWNPLANT_FIXER else { Logger.Log("DEBUG: TEST A4"); } #endif if (componentEnabled && progress >= 0.0f && progress < 1.0f) { #if DEBUG_GROWNPLANT_FIXER Logger.Log("DEBUG: TEST A5 progress=[" + progress + "]"); #endif // Display growing tooltip HandReticle.main.SetIcon(HandReticle.IconType.Progress, 1f); HandReticle.main.SetProgress(progress); // Fix knifeable if (liveMixin != null && liveMixin.data != null && liveMixin.knifeable) { liveMixin.data.knifeable = false; } } } #if DEBUG_GROWNPLANT_FIXER else { Logger.Log("DEBUG: TEST B4"); } } else { Logger.Log("DEBUG: TEST C"); } #else }