Beispiel #1
0
        private void ConstructionAmountChanged(ConstructionAmountChangedEvent amountChanged)
        {
            GameObject          constructing        = NitroxEntity.RequireObjectFrom(amountChanged.Id);
            BaseDeconstructable baseDeconstructable = constructing.GetComponent <BaseDeconstructable>();

            // Bases don't  send a deconstruct being packet.  Instead, we just make sure
            // that if we are changing the amount that we set it into deconstruction mode
            // if it still has a BaseDeconstructable object on it.
            if (baseDeconstructable)
            {
                baseDeconstructable.Deconstruct();

                // After we have begun the deconstructing for a base piece, we need to transfer the id
                Optional <object> opGhost = Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GHOST);

                if (opGhost.HasValue && opGhost.Value is Component component)
                {
                    NitroxEntity.SetNewId(component.gameObject, amountChanged.Id);
                    Destroy(constructing);
                }
                else
                {
                    Log.Error($"Could not find newly created ghost to set deconstructed id {amountChanged.Id}");
                }
            }
            else
            {
                Constructable constructable = constructing.GetComponentInChildren <Constructable>();
                constructable.constructedAmount = amountChanged.Amount;
                constructable.UpdateMaterial();
            }
        }
Beispiel #2
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null)
            {
                var thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(false);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    TechType destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                    {
                        var storageContainer = ((Exosuit)thisVehicle).storageContainer;

                        if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                        {
                            storageContainer.container.DestroyItem(destroyTechType);
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                    else
                    {
                        var  seamoth      = (SeaMoth)thisVehicle;
                        bool storageCheck = false;
                        for (int i = 0; i < 12; i++)
                        {
                            try
                            {
                                var storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                if (storage != null && storage.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                                {
                                    storage.DestroyItem(destroyTechType);
                                    storageCheck = true;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    __instance.SetState(true, true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #3
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null)
            {
                var thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(true);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount -= Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID && GameModeUtils.RequiresIngredients())
                {
                    TechType   techType   = __instance.resourceMap[resourceID2];
                    GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false);
                    Pickupable component  = gameObject.GetComponent <Pickupable>();

                    if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                    {
                        var storageContainer = ((Exosuit)thisVehicle).storageContainer;

                        if (storageContainer.container.HasRoomFor(component) && GameModeUtils.RequiresIngredients())
                        {
                            var name = Language.main.Get(component.GetTechName());
                            ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                            uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                            component = component.Initialize();

                            var item = new InventoryItem(component);
                            storageContainer.container.UnsafeAdd(item);
                            component.PlayPickupSound();
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                    else
                    {
                        var  seamoth      = (SeaMoth)thisVehicle;
                        bool storageCheck = false;
                        for (int i = 0; i < 12; i++)
                        {
                            try
                            {
                                var storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                if (storage != null && storage.HasRoomFor(component) && GameModeUtils.RequiresIngredients())
                                {
                                    var name = Language.main.Get(component.GetTechName());
                                    ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                    uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                                    component = component.Initialize();

                                    var item = new InventoryItem(component);
                                    storage.UnsafeAdd(item);
                                    component.PlayPickupSound();
                                    storageCheck = true;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount <= 0f)
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #4
0
        public static bool Prefix(Constructable __instance)
        {
#endif
            if (Player.main.GetVehicle() != null && GameModeUtils.RequiresIngredients())
            {
                Vehicle thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(true);
                }
                int count = __instance.resourceMap.Count;

                int   resourceID = __instance.GetResourceID();
                float backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount -= Time.deltaTime / (count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    TechType techType = __instance.resourceMap[resourceID2];

                    Vector2int size =
#if SN1
                        CraftData.GetItemSize(techType);
#elif BZ
                        TechData.GetItemSize(techType);
#endif

                    if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                    {
                        StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer;

                        if (storageContainer.container.HasRoomFor(size.x, size.y))
                        {
                            CoroutineHost.StartCoroutine(AddToVehicle(techType, storageContainer.container));
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
#if SN1
                    else
                    {
                        SeaMoth seamoth      = (SeaMoth)thisVehicle;
                        bool    storageCheck = false;
                        for (int i = 0; i < 12; i++)
                        {
                            try
                            {
                                ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                if (storage != null && storage.HasRoomFor(size.x, size.y))
                                {
                                    CoroutineHost.StartCoroutine(AddToVehicle(techType, storage));
                                    storageCheck = true;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
#endif
                }
                __instance.UpdateMaterial();
#if SUBNAUTICA_EXP || BZ
                result.Set(__instance.constructedAmount <= 0f);
                return(false);
#elif SUBNAUTICA_STABLE
                return(__instance.constructedAmount <= 0f);
#endif
            }
            return(true);
        }
Beispiel #5
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null || Player.main.GetComponentInParent <SeaTruckSegment>() != null)
            {
                var thisVehicle  = Player.main.GetVehicle();
                var thisSeatruck = Player.main.GetComponentInParent <SeaTruckSegment>();

                if (__instance._constructed)
                {
                    return(false);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    bool     storageCheck    = false;
                    TechType destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    if (thisVehicle != null)
                    {
                        if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                        {
                            StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer;

                            if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                            {
                                storageContainer.container.DestroyItem(destroyTechType);
                                storageCheck = true;
                            }
                        }
                    }
                    else if (thisSeatruck != null)
                    {
                        SeaTruckSegment[]         seaTruckSegments = thisSeatruck.GetComponents <SeaTruckSegment>();
                        List <StorageContainer[]> containers       = new List <StorageContainer[]>();
                        foreach (SeaTruckSegment seaTruckSegment in seaTruckSegments)
                        {
                            containers.Add(seaTruckSegment.GetComponentsInChildren <StorageContainer>());
                        }
                        foreach (StorageContainer[] storageContainers in containers)
                        {
                            foreach (StorageContainer storageContainer in storageContainers)
                            {
                                if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                                {
                                    storageContainer.container.DestroyItem(destroyTechType);
                                    storageCheck = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!storageCheck)
                    {
                        __instance.constructedAmount = backupConstructedAmount;
                        return(true);
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    __instance.SetState(true, true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #6
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null || Player.main.GetComponentInParent <SeaTruckSegment>() != null)
            {
                var thisVehicle  = Player.main.GetVehicle();
                var thisSeatruck = Player.main.GetComponentInParent <SeaTruckSegment>();
                if (__instance._constructed)
                {
                    return(true);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount -= Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID && GameModeUtils.RequiresIngredients())
                {
                    bool       storageCheck = false;
                    TechType   techType     = __instance.resourceMap[resourceID2];
                    GameObject gameObject   = CraftData.InstantiateFromPrefab(techType, false);
                    Pickupable component    = gameObject.GetComponent <Pickupable>();

                    if (thisVehicle != null)
                    {
                        if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                        {
                            StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer;

                            if (storageContainer.container.HasRoomFor(component) && GameModeUtils.RequiresIngredients())
                            {
                                var name = Language.main.Get(component.GetTechName());
                                ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                                component.Initialize();

                                var item = new InventoryItem(component);
                                storageContainer.container.UnsafeAdd(item);
                                component.PlayPickupSound();
                                storageCheck = true;
                            }
                        }
                    }
                    else
                    {
                        SeaTruckSegment[]         seaTruckSegments = thisSeatruck.GetComponents <SeaTruckSegment>();
                        List <StorageContainer[]> containers       = new List <StorageContainer[]>();
                        foreach (SeaTruckSegment seaTruckSegment in seaTruckSegments)
                        {
                            containers.Add(seaTruckSegment.GetComponentsInChildren <StorageContainer>());
                        }
                        foreach (StorageContainer[] storageContainers in containers)
                        {
                            foreach (StorageContainer storageContainer in storageContainers)
                            {
                                if (storageContainer.container.HasRoomFor(component) && GameModeUtils.RequiresIngredients())
                                {
                                    var name = Language.main.Get(component.GetTechName());
                                    ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                    uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                                    component.Initialize();

                                    var item = new InventoryItem(component);
                                    storageContainer.container.UnsafeAdd(item);
                                    component.PlayPickupSound();
                                    storageCheck = true;
                                    break;
                                }
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount <= 0f)
                {
                    return(true);
                }

                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #7
0
        public static bool Prefix(Constructable __instance)
        {
#endif
            var player = Player.main;
            if (player.isPiloting && GameModeUtils.RequiresIngredients())
            {
                if (__instance._constructed)
                {
                    return(true);
                }
#if BZ
                if (player.GetComponentInParent <Hoverbike>() is not null)
                {
                    return(true);
                }
#endif
                var count = __instance.resourceMap.Count;

                var resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount -= Time.deltaTime / (count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                var resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    var techType = __instance.resourceMap[resourceID2];

                    var size =
#if SN1
                        CraftData.GetItemSize(techType);
#elif BZ
                        TechData.GetItemSize(techType);
#endif

                    var storageCheck = false;
                    var thisVehicle  = Player.main.GetVehicle();
                    if (thisVehicle != null)
                    {
                        switch (thisVehicle)
                        {
                        case Exosuit exosuit:
                        {
                            var storageContainer = exosuit.storageContainer;

                            if (storageContainer.container.HasRoomFor(size.x, size.y))
                            {
                                CoroutineHost.StartCoroutine(AddToVehicle(techType, storageContainer.container));
                                storageCheck = true;
                            }
                            break;
                        }

                        case SeaMoth seaMoth:
                        {
                            for (var i = 0; i < 12; i++)
                            {
                                try
                                {
                                    var storage = seaMoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                    if (storage == null || !storage.HasRoomFor(size.x, size.y))
                                    {
                                        continue;
                                    }
                                    CoroutineHost.StartCoroutine(AddToVehicle(techType, storage));
                                    storageCheck = true;
                                    break;
                                }
                                catch
                                {
                                    // ignored
                                }
                            }

                            break;
                        }
                        }
                    }
#if BZ
                    var seaTruck = player.GetComponentInParent <SeaTruckUpgrades>();
                    if (seaTruck != null)
                    {
                        foreach (var storageContainer in seaTruck.GetComponentsInChildren <StorageContainer>() ?? new StorageContainer[0])
                        {
                            try
                            {
                                var storage = storageContainer.container;
                                if (storage == null || !storage.HasRoomFor(size.x, size.y))
                                {
                                    continue;
                                }
                                CoroutineHost.StartCoroutine(AddToVehicle(techType, storage));
                                storageCheck = true;
                                break;
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                    }
#endif

                    if (!storageCheck)
                    {
                        __instance.constructedAmount = backupConstructedAmount;
                        return(true);
                    }
                }
                __instance.UpdateMaterial();
#if SUBNAUTICA_EXP || BZ
                result.Set(__instance.constructedAmount <= 0f);
                return(false);
#elif SUBNAUTICA_STABLE
                return(__instance.constructedAmount <= 0f);
#endif
            }
            return(true);
        }
Beispiel #8
0
        public static bool Prefix(Constructable __instance)
        {
            var player = Player.main;

            if (player.isPiloting && GameModeUtils.RequiresIngredients())
            {
                if (__instance._constructed)
                {
                    return(false);
                }
#if BZ
                if (player.GetComponentInParent <Hoverbike>() is not null)
                {
                    return(true);
                }
#endif

                var count      = __instance.resourceMap.Count;
                var resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / (count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                var resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    var destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    var thisVehicle     = player.GetVehicle();
                    var storageCheck    = false;
                    if (thisVehicle != null)
                    {
                        switch (thisVehicle)
                        {
                        case Exosuit exosuit:
                            if (exosuit.storageContainer.container.Contains(destroyTechType) &&
                                exosuit.storageContainer.container.DestroyItem(destroyTechType))
                            {
                                storageCheck = true;
                            }
                            break;

                        case SeaMoth seaMoth:
                            for (var i = 0; i < 12; i++)
                            {
                                try
                                {
                                    var storage = seaMoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                    if (storage == null || !storage.Contains(destroyTechType))
                                    {
                                        continue;
                                    }
                                    if (!storage.DestroyItem(destroyTechType))
                                    {
                                        continue;
                                    }
                                    storageCheck = true;
                                    break;
                                }
                                catch
                                {
                                    // ignored
                                }
                            }
                            break;
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
#if BZ
                    var seaTruck = player.GetComponentInParent <SeaTruckUpgrades>();
                    if (seaTruck != null)
                    {
                        foreach (var storageContainer in seaTruck.GetComponentsInChildren <StorageContainer>() ?? new StorageContainer[0])
                        {
                            try
                            {
                                if (!storageContainer.container.DestroyItem(destroyTechType))
                                {
                                    continue;
                                }
                                storageCheck = true;
                                break;
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                    }
                    if (!storageCheck)
                    {
                        __instance.constructedAmount = backupConstructedAmount;
                        return(true);
                    }
#endif
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    _ = __instance.SetState(true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }