Esempio n. 1
0
 public static bool OnConsoleCommand_spawn_Prefix(NotificationCenter.Notification n)
 {
     if (n != null && n.data != null && n.data.Count > 0)
     {
         string text = (string)n.data[0];
         if (UWE.Utils.TryParseEnum <TechType>(text, out TechType techType) && techType != TechType.None)
         {
             if (CraftData.IsAllowed(techType))
             {
                 foreach (IDecorationItem item in DecorationsMod.DecorationItems)
                 {
                     // If item being spawned is one of our decoration items.
                     if (techType == item.TechType)
                     {
                         // If item being spawned is one of our new flora.
                         if (!string.IsNullOrEmpty(item.ClassID) && CustomFlora.AllPlants.Contains(item.ClassID))
                         {
                             GameObject prefabForTechType = CraftData.GetPrefabForTechType(techType, true);
                             if (prefabForTechType != null)
                             {
                                 int num = 1;
                                 int num2;
                                 if (n.data.Count > 1 && int.TryParse((string)n.data[1], out num2))
                                 {
                                     num = num2;
                                 }
                                 float maxDist = 12f;
                                 if (n.data.Count > 2)
                                 {
                                     maxDist = float.Parse((string)n.data[2]);
                                 }
                                 Debug.LogFormat("Spawning {0} {1}", new object[] { num, techType });
                                 for (int i = 0; i < num; i++)
                                 {
                                     GameObject gameObject = global::Utils.CreatePrefab(prefabForTechType, maxDist, i > 0);
                                     LargeWorldEntity.Register(gameObject);
                                     CrafterLogic.NotifyCraftEnd(gameObject, techType);
                                     gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
                                     // Hide plant, show seed and enable pickupable
                                     PrefabsHelper.HidePlantAndShowSeed(gameObject.transform, item.ClassID);
                                 }
                             }
                             else
                             {
                                 ErrorMessage.AddDebug("Could not find prefab for TechType = " + techType);
                             }
                             // Dont call original function if item being spawned is one of our new flora.
                             return(false);
                         }
                         break;
                     }
                 }
             }
         }
     }
     // Give back execution to original function.
     return(true);
 }
Esempio n. 2
0
 public static bool OnConsoleCommand_item_Prefix(NotificationCenter.Notification n)
 {
     if (n != null && n.data != null && n.data.Count > 0)
     {
         string text = (string)n.data[0];
         if (UWE.Utils.TryParseEnum <TechType>(text, out TechType techType) && techType != TechType.None)
         {
             if (CraftData.IsAllowed(techType))
             {
                 foreach (IDecorationItem item in DecorationsMod.DecorationItems)
                 {
                     // If item being spawned is one of our decoration items.
                     if (techType == item.TechType)
                     {
                         // If item being spawned is one of our new flora.
                         if (!string.IsNullOrEmpty(item.ClassID) && CustomFlora.AllPlants.Contains(item.ClassID))
                         {
                             int num = 1;
                             if (n.data.Count > 1 && int.TryParse((string)n.data[1], out int num2))
                             {
                                 num = num2;
                             }
                             for (int i = 0; i < num; i++)
                             {
                                 GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false);
                                 if (gameObject != null)
                                 {
                                     gameObject.transform.position = MainCamera.camera.transform.position + MainCamera.camera.transform.forward * 3f;
                                     CrafterLogic.NotifyCraftEnd(gameObject, techType);
                                     Pickupable component = gameObject.GetComponent <Pickupable>();
                                     if (component != null && !Inventory.main.Pickup(component, false))
                                     {
                                         ErrorMessage.AddError(Language.main.Get("InventoryFull"));
                                         // Hide plant, show seed and enable pickupable
                                         PrefabsHelper.HidePlantAndShowSeed(gameObject.transform, item.ClassID);
                                     }
                                 }
                             }
                             // Dont call original function if item being spawned is one of our new flora.
                             return(false);
                         }
                         break;
                     }
                 }
             }
         }
     }
     // Give back execution to original function.
     return(true);
 }
        public static void Drop_Postfix(Pickupable __instance)
        {
            if (__instance.gameObject != null)
            {
                // Get current item PID
                var pid = __instance.gameObject.GetComponent <PrefabIdentifier>();

                // If current item is one of our new flora
                if (pid != null && !string.IsNullOrEmpty(pid.ClassId) && CustomFlora.AllPlants.Contains(pid.ClassId))
                {
                    PrefabsHelper.HidePlantAndShowSeed(__instance.gameObject.transform, pid.ClassId); // Hide plant, show seed and enable pickupable
                }
            }
        }
        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);
        }