Ejemplo n.º 1
0
        private void InitializeUpgradeHandlers()
        {
            if (Initialized)
            {
                return;
            }

            QuickLogger.Debug($"UpgradeManager adding new UpgradeHandlers from external mods");
            // First, register upgrades from other mods.
            foreach (KeyValuePair <CreateUpgradeHandler, string> pair in HandlerCreators)
            {
                CreateUpgradeHandler upgradeHandlerCreator = pair.Key;
                string         assemblyName = pair.Value;
                UpgradeHandler upgrade      = upgradeHandlerCreator.Invoke(Cyclops);

                if (upgrade == null)
                {
                    QuickLogger.Warning($"UpgradeHandler from '{assemblyName}' was null");
                }
                else if (!KnownsUpgradeModules.ContainsKey(upgrade.TechType))
                {
                    upgrade.RegisterSelf(KnownsUpgradeModules);
                    upgrade.SourceMod = assemblyName;
                }
                else
                {
                    QuickLogger.Warning($"Duplicate UpgradeHandler for '{upgrade.TechType.AsString()}' from '{assemblyName}' was blocked");
                }
            }

            // Next, if no external mod has provided an UpgradeHandler for the vanilla upgrades, they will be added here.
            // This is to allow other mods to provide new functionality to the original upgrades.

            QuickLogger.Debug($"UpgradeManager adding default UpgradeHandlers for unmanaged vanilla upgrades");

            string mcuAssemblyName = QuickLogger.GetAssemblyName();

            for (int i = 0; i < vanillaUpgrades.OriginalUpgradeIDs.Count; i++)
            {
                TechType upgradeID = vanillaUpgrades.OriginalUpgradeIDs[i];
                if (!KnownsUpgradeModules.ContainsKey(upgradeID))
                {
                    UpgradeHandler vanillaUpgrade = vanillaUpgrades.CreateUpgradeHandler(upgradeID, Cyclops);
                    vanillaUpgrade.RegisterSelf(KnownsUpgradeModules);
                    vanillaUpgrade.SourceMod = mcuAssemblyName;
                }
            }

            upgradeHandlers = new UpgradeHandler[KnownsUpgradeModules.Count];

            int u = 0;

            foreach (UpgradeHandler upgrade in KnownsUpgradeModules.Values)
            {
                upgradeHandlers[u++] = upgrade;
            }

            QuickLogger.Debug("Attaching events to Engine Room Upgrade Console");

            if (engineRoomUpgradeConsole == null)
            {
                engineRoomUpgradeConsole = Cyclops.upgradeConsole.modules;
            }

            AttachEquipmentEvents(ref engineRoomUpgradeConsole);

            engineRoomUpgradeSlots = new UpgradeSlot[AuxiliaryUpgradeConsole.TotalSlots]
            {
                new UpgradeSlot(engineRoomUpgradeConsole, "Module1"),
                new UpgradeSlot(engineRoomUpgradeConsole, "Module2"),
                new UpgradeSlot(engineRoomUpgradeConsole, "Module3"),
                new UpgradeSlot(engineRoomUpgradeConsole, "Module4"),
                new UpgradeSlot(engineRoomUpgradeConsole, "Module5"),
                new UpgradeSlot(engineRoomUpgradeConsole, "Module6")
            };

            Initialized       = true;
            TooLateToRegister = true;
        }