Example #1
0
        internal static void Postfix(uGUI_InventoryTab __instance)
        {
            // This event happens whenever the player opens their PDA.
            // We will make a series of checks to see if what they have opened is the Cyclops Bioreactor item container.

            if (__instance == null)
            {
                return; // Safety check
            }
            if (!Player.main.IsInSub() || !Player.main.currentSub.isCyclops)
            {
                return; // If not in Cyclops then all is irrelevant
            }
            uGUI_ItemsContainer storageUI = __instance.storage;

            if (storageUI == null)
            {
                return; // Not an equipment container
            }
            var container = (ItemsContainer)containerField.GetValue(storageUI);

            if (container == null)
            {
                return; // Safety check
            }
            string label = (container as IItemsContainer).label;

            if (label != CyNukReactorBuildable.StorageLabel())
            {
                return; // Not a CyNukReactor
            }
            List <CyNukeReactorMono> reactors = MCUServices.Find.AuxCyclopsManager <CyNukeManager>(Player.main.currentSub)?.CyNukeReactors;

            if (reactors == null || reactors.Count == 0)
            {
                return; // Cyclops has no reactors
            }
            // Look for the reactor that matches the container we just opened.
            CyNukeReactorMono reactor = reactors.Find(r => r.RodsContainer == container);

            if (reactor == null)
            {
                return; // Didn't find the reactor we were looking for. Could it be on another cyclops?
            }
            var lookup = (Dictionary <InventoryItem, uGUI_ItemIcon>)itemsField.GetValue(storageUI);

            reactor.ConnectToContainer(lookup); // Found!
        }
        private void InitializeRodsContainer()
        {
            if (_rodsRoot == null)
            {
                QuickLogger.Debug("Initializing StorageRoot");
                var storageRoot = new GameObject("StorageRoot");
                storageRoot.transform.SetParent(this.transform, false);
                _rodsRoot = storageRoot.AddComponent <ChildObjectIdentifier>();
            }

            if (RodsContainer == null)
            {
                QuickLogger.Debug("Initializing RodsContainer");
                RodsContainer = new ItemsContainer(ContainerWidth, ContainerHeight, _rodsRoot.transform, CyNukReactorBuildable.StorageLabel(), null);
                RodsContainer.SetAllowedTechTypes(new[] { TechType.ReactorRod, TechType.DepletedReactorRod });

                RodsContainer.isAllowedToAdd    += IsAllowedToAdd;
                RodsContainer.isAllowedToRemove += IsAllowedToRemove;

                RodsContainer.onAddItem    += OnAddItem;
                RodsContainer.onRemoveItem += OnRemoveItem;

                RodsContainer.onChangeItemPosition += RodsContainer_onChangeItemPosition;
            }
        }