Ejemplo n.º 1
0
        public static void Patch()
        {
            MCUServices.Logger.Info("Started patching. Version: " + QuickLogger.GetAssemblyVersion());

            CyNukReactorBuildable.PatchSMLHelper();
            CyNukeEnhancerMk1.PatchSMLHelper();
            CyNukeEnhancerMk2.PatchSMLHelper();

            MCUServices.Logger.Debug("Registering with MoreCyclopsUpgrades");

            MCUServices.Register.CyclopsCharger <CyNukeChargeManager>((SubRoot cyclops) =>
            {
                return(new CyNukeChargeManager(cyclops));
            });

            MCUServices.Register.CyclopsUpgradeHandler((SubRoot cyclops) =>
            {
                return(new CyNukeEnhancerHandler(cyclops));
            });

            MCUServices.Register.AuxCyclopsManager <CyNukeManager>((SubRoot cyclops) =>
            {
                return(new CyNukeManager(cyclops));
            });

            var harmony = new Harmony("com.cyclopsnuclearreactor.psmod");

            harmony.PatchAll(Assembly.GetExecutingAssembly());

            MCUServices.Logger.Info("Finished patching");
        }
Ejemplo n.º 2
0
        public static void Patch()
        {
            QuickLogger.Info("Started patching. Version: " + QuickLogger.GetAssemblyVersion());

#if DEBUG
            QuickLogger.DebugLogsEnabled = true;
            QuickLogger.Debug("Debug logs enabled");
#endif
            try
            {
                CyNukReactorBuildable.PatchSMLHelper();
                CyNukeEnhancerMk1.PatchSMLHelper();
                CyNukeEnhancerMk2.PatchSMLHelper();

                RegisterWithMoreCyclopsUpgrades();

                var harmony = HarmonyInstance.Create("com.cyclopsnuclearreactor.psmod");
                harmony.PatchAll(Assembly.GetExecutingAssembly());

                QuickLogger.Info("Finished patching");
            }
            catch (Exception ex)
            {
                QuickLogger.Error(ex);
            }
        }
        internal string PowerIndicatorString()
        {
            if (reactorRodData.Count == 0)
            {
                return(CyNukReactorBuildable.NoPoweMessage());
            }

            return(NumberFormatter.FormatValue(GetTotalAvailablePower()));
        }
Ejemplo n.º 4
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!
        }
        public void OnHandHover(GUIHand hand)
        {
            if (!_buildable.constructed)
            {
                return;
            }

            HandReticle main = HandReticle.main;

            int currentPower = Mathf.CeilToInt(GetTotalAvailablePower());

            string text = currentPower > 0
                ? CyNukReactorBuildable.OnHoverPoweredText(NumberFormatter.FormatValue(currentPower), this.ActiveRodCount, this.MaxActiveSlots)
                : CyNukReactorBuildable.OnHoverNoPowerText();

            main.SetInteractText(text);
            main.SetIcon(HandReticle.IconType.Hand, 1f);
        }
        internal void UpdateUpgradeLevel(int upgradeLevel)
        {
            if (upgradeLevel < 0 || upgradeLevel > MaxUpgradeLevel)
            {
                return;
            }

            if (upgradeLevel == lastKnownUpgradeLevel)
            {
                return;
            }

            if (upgradeLevel > 0)
            {
                ErrorMessage.AddMessage(CyNukReactorBuildable.UpgradedMsg());
            }

            lastKnownUpgradeLevel = upgradeLevel;
        }
        private void UpdateDisplayText(bool force = false)
        {
            if (!force)
            {
                if (Time.time < textDelay)
                {
                    return; // Slow down the text update
                }
                textDelay = Time.time + TextDelayInterval;
            }

            for (int i = 0; i < reactorRodData.Count; i++)
            {
                SlotData item = reactorRodData[i];

                if (item.InfoDisplay == null)
                {
                    continue;
                }

                if (item.HasPower())
                {
                    if (i < this.MaxActiveSlots)
                    {
                        item.InfoDisplay.text  = NumberFormatter.FormatValue(item.Charge);
                        item.InfoDisplay.color = Color.white;
                    }
                    else
                    {
                        item.InfoDisplay.text  = CyNukReactorBuildable.InactiveRodMsg();
                        item.InfoDisplay.color = Color.yellow;
                    }
                }
                else
                {
                    item.InfoDisplay.text  = CyNukReactorBuildable.NoPoweMessage();
                    item.InfoDisplay.color = Color.red;
                }
            }
        }
        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;
            }
        }
        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);
        }