private static IEnumerator SpawnCreature(WaterPark waterPark, WaterParkCreature parkCreature, ItemsContainer container)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(parkCreature.pickupable.GetTechType(), false);

            yield return(task);

            GameObject prefab = task.GetResult();

            prefab.SetActive(false);
            GameObject gameObject = GameObject.Instantiate(prefab);

            Pickupable pickupable = gameObject.EnsureComponent <Pickupable>();

#if SUBNAUTICA_EXP
            TaskResult <Pickupable> taskResult = new TaskResult <Pickupable>();
            yield return(pickupable.PickupAsync(taskResult, false));

            pickupable = taskResult.Get();
#else
            pickupable.Pickup(false);
#endif
            container.AddItem(pickupable);

            yield break;
        }
        public void Add(BioEnergy material, ItemsContainer container)
        {
            InventoryItem inventoryItem = container.AddItem(material.Pickupable);

            material.Size = inventoryItem.width * inventoryItem.height;
            base.Add(material);
            this.SpacesOccupied += material.Size;
        }
Пример #3
0
        private static IEnumerator SpawnCreature(WaterPark waterPark, TechType parkCreatureTechType, ItemsContainer container)
        {
            var task = CraftData.GetPrefabForTechTypeAsync(parkCreatureTechType, false);

            yield return(task);

            var prefab = task.GetResult();

            if (prefab == null)
            {
                yield break;
            }

            prefab.SetActive(false);
            var gameObject = Object.Instantiate(prefab);

            if (container is not null)
            {
                var pickupable = gameObject.EnsureComponent <Pickupable>();
#if SUBNAUTICA_EXP
                TaskResult <Pickupable> taskResult = new TaskResult <Pickupable>();
                yield return(pickupable.PickupAsync(taskResult, false));

                pickupable = taskResult.Get();
#else
                pickupable.Pickup(false);
#endif
                gameObject.SetActive(false);
                container.AddItem(pickupable);
                yield break;
            }

            var spawnPoint = waterPark.transform.position + (Random.insideUnitSphere * 50);
            var @base      =
#if SN1
                waterPark.GetComponentInParent <Base>();
#elif BZ
                waterPark.hostBase;
#endif

            while (Vector3.Distance(@base.GetClosestPoint(spawnPoint), spawnPoint) < 25 || spawnPoint.y >= 0)
            {
                yield return(null);

                spawnPoint = @base.GetClosestPoint(spawnPoint) + (Random.insideUnitSphere * 50);
            }

            gameObject.transform.SetPositionAndRotation(spawnPoint, Quaternion.identity);
            gameObject.SetActive(true);
        }
        public float GetPower(ref float powerDeficit)
        {
            if (powerDeficit <= MCUServices.MinimalPowerValue)
            {
                return(0f);
            }

            if (reactorRodData.Count == 0)
            {
                return(0f);
            }

            float totalPowerProduced = 0f;

            SlotData depletedRod = null;
            int      max         = Math.Min(this.MaxActiveSlots, this.TotalItemCount);

            for (int i = 0; i < max; i++)
            {
                if (powerDeficit <= MCUServices.MinimalPowerValue)
                {
                    break;
                }

                SlotData slotData = reactorRodData[i];

                if (!slotData.HasPower())
                {
                    continue;
                }

                float powerProduced = Mathf.Min(PowerMultiplier * DayNightCycle.main.deltaTime, slotData.Charge);
                powerProduced = Mathf.Min(powerDeficit, powerProduced);

                slotData.Charge    -= powerProduced;
                totalPowerProduced += powerProduced;
                powerDeficit       -= powerProduced;

                if (slotData.Charge <= MCUServices.MinimalPowerValue)
                {
                    depletedRod = slotData;
                }

                UpdateGraphicalRod(slotData);
            }

            if (depletedRod != null)
            {
                isDepletingRod = true;

                RodsContainer.RemoveItem(depletedRod.Item, true);
                GameObject.Destroy(depletedRod.Item.gameObject);
                RodsContainer.AddItem(SpawnItem(TechType.DepletedReactorRod).item);

                ErrorMessage.AddMessage(CyNukReactorBuildable.DepletedMessage());

                isDepletingRod = false;
            }

            if (pdaIsOpen)
            {
                UpdateDisplayText();
            }

            return(totalPowerProduced);
        }
        static void KillFish(LiveMixin liveMixin)
        {
            //AddDebug("KillFish " + liveMixin.gameObject.name);
            //Main.Log("Kill " + liveMixin.gameObject.name);

            liveMixin.health     = 0f;
            liveMixin.tempDamage = 0f;
            liveMixin.SyncUpdatingState();
            //if (liveMixin.deathClip)
            //    liveMixin.deathClip.Play();
            //if (liveMixin.deathSound)
            //    Utils.PlayFMODAsset(liveMixin.deathSound, liveMixin.transform);
            //if (liveMixin.passDamageDataOnDeath)
            //    liveMixin.gameObject.BroadcastMessage("OnKill", DamageType.Normal, SendMessageOptions.DontRequireReceiver);
            //else if (liveMixin.broadcastKillOnDeath)
            //    liveMixin.gameObject.BroadcastMessage("OnKill", SendMessageOptions.DontRequireReceiver);
            //if (liveMixin.sendKillOnDeath)
            //{
            //    if (liveMixin.passDamageDataOnDeath)
            //        liveMixin.gameObject.SendMessage("OnKill", DamageType.Normal, SendMessageOptions.DontRequireReceiver);
            //    else
            //        liveMixin.gameObject.SendMessage("OnKill", SendMessageOptions.DontRequireReceiver);
            //}

            AquariumFish af = liveMixin.GetComponent <AquariumFish>();

            if (af)
            {
                UnityEngine.Object.Destroy(af);
            }
            Locomotion locomotion = liveMixin.GetComponent <Locomotion>();

            locomotion.enabled = false;
            CreatureDeath creatureDeath = liveMixin.GetComponent <CreatureDeath>();
            Eatable       eatable       = liveMixin.GetComponent <Eatable>();

            eatable.SetDecomposes(true);
            Rigidbody rb = liveMixin.GetComponent <Rigidbody>();

            if (rb)
            {
                rb.isKinematic = false;
                rb.constraints = RigidbodyConstraints.None;
                WorldForces worldForces = liveMixin.GetComponent <WorldForces>();
                if (worldForces)
                {
                    worldForces.handleDrag = false;
                }
                rb.drag        = Mathf.Max(rb.drag, 1f);
                rb.angularDrag = Mathf.Max(rb.angularDrag, 1f);
            }
            liveMixin.gameObject.EnsureComponent <EcoTarget>().SetTargetType(EcoTargetType.DeadMeat);

            if (creatureDeath)
            {
                if (creatureDeath.respawn && !creatureDeath.respawnOnlyIfKilledByCreature)
                {
                    creatureDeath.SpawnRespawner();
                }
                if (creatureDeath.removeCorpseAfterSeconds >= 0.0)
                {
                    creatureDeath.Invoke("RemoveCorpse", creatureDeath.removeCorpseAfterSeconds);
                }
                creatureDeath.SyncFixedUpdatingState();
            }
            Pickupable     pickupable = liveMixin.GetComponent <Pickupable>();
            ItemsContainer container  = pickupable.inventoryItem.container as ItemsContainer;

            if (container != null)
            { // fix offset decay bar
                container.RemoveItem(pickupable, true);
                container.AddItem(pickupable);
            }
        }