示例#1
0
        private IEnumerator HandleUpgradeButton()
        {
            //borrowed from Magico13's KCT :)
            yield return(new WaitForFixedUpdate());

            SpaceCenterBuilding hostBuilding = GetMember <SpaceCenterBuilding>("host");

            overriddenFacility = hostBuilding.Facility;
            Debug.Log("[Bureaucracy]: Trying to override upgrade button of menu for " + hostBuilding.facilityName);
            Button button = GetMember <Button>("UpgradeButton");

            if (button == null)
            {
                Debug.Log("[Bureaucracy]: Could not find UpgradeButton by name, using index instead.");
                button = GetMember <Button>(2);
            }
            if (button != null)
            {
                Debug.Log("[Bureaucracy]: Found upgrade button, overriding it.");
                button.onClick = new Button.ButtonClickedEvent(); //Clear existing KSP listener
                button.onClick.AddListener(HandleUpgrade);
            }
            else
            {
                throw new Exception("[Bureaucracy]: UpgradeButton not found. Cannot override.");
            }
        }
示例#2
0
        public void SetActive()
        {
            try
            {
                EnsureMassAndSizeInitialized();

                KCTDebug.Log($"Switching to LaunchPad: {name} lvl: {level} destroyed? {IsDestroyed}");
                KCTGameStates.ActiveKSC.ActiveLaunchPadID = KCTGameStates.ActiveKSC.LaunchPads.IndexOf(this);

                //set the level to this level
                if (Utilities.CurrentGameIsCareer())
                {
                    UpgradeableFacility facility = GetUpgradeableFacilityReference();
                    KCTEvents.AllowedToUpgrade = true;
                    facility.SetLevel(level);
                }

                //set the destroyed state to this destroyed state
                UpdateLaunchpadDestructionState(false);
            }
            catch (Exception ex)
            {
                KCTDebug.LogError("Error while calling SetActive: " + ex);
            }
        }
示例#3
0
 public void StartUpgrade(UpgradeableFacility facilityToUpgrade)
 {
     Upgrade   = new FacilityUpgradeEvent(facilityToUpgrade.id, this);
     Upgrading = true;
     ScreenMessages.PostScreenMessage("[Bureaucracy]: Upgrade of " + Name + " requested");
     Debug.Log("[Bureaucracy]: Upgrade of " + Name + " requested for " + Upgrade.OriginalCost);
 }
        public void FacilityUpgraded(UpgradeableFacility facility, int level)
        {
            if (System.IgnoreEvents)
            {
                return;
            }

            LunaLog.Log($"Facility {facility.id} upgraded to level: {level}");
            System.MessageSender.SendFacilityUpgradeMessage(facility.id, level);
        }
示例#5
0
        public void FacilityUpgraded(UpgradeableFacility building, int level)
        {
            if (System.BuildingIdToIgnore == building.id)
            {
                return;
            }

            System.MessageSender.SendFacilityUpgradeMsg(building.id, level);
            SystemsContainer.Get <ScenarioSystem>().SendScenarioModules();
        }
示例#6
0
        /// <summary>
        /// If we call facility.SetLevel() then we woud trigger the KSP event and send a message to the server.
        /// Therefore we add the id to the ignore field so the event FacilityUpgraded doesn't send a network message
        /// </summary>
        public void UpgradeFacilityWithoutSendingMessage(UpgradeableFacility facility, int level)
        {
            if (facility == null || facility.FacilityLevel == level)
            {
                return;
            }

            BuildingIdToIgnore = facility.id;
            facility.setLevel(level);
            BuildingIdToIgnore = string.Empty;
        }
示例#7
0
        void OnKSCFacilityUpgraded(UpgradeableFacility facility, int level)
        {
            lastFacility     = facility;
            lastFacilityTime = Time.realtimeSinceStartup;

            Popup popup = popups.LastOrDefault();

            if (popup != null)
            {
                popup.referencePosition = facility.transform;
                popup.initialized       = true;
            }
        }
示例#8
0
        private BureaucracyFacility UpgradeableToActualFacility(UpgradeableFacility facility)
        {
            for (int i = 0; i < Facilities.Count; i++)
            {
                BureaucracyFacility bf = Facilities.ElementAt(i);
                if (!facility.id.Contains(bf.Name))
                {
                    continue;
                }
                return(bf);
            }

            return(null);
        }
示例#9
0
        public override void OnEventCompleted()
        {
            List <UpgradeableFacility> facilitiesToUpgrade = GetFacilityById(facilityId);

            for (int i = 0; i < facilitiesToUpgrade.Count; i++)
            {
                UpgradeableFacility facilityToUpgrade = facilitiesToUpgrade.ElementAt(i);
                if (facilityToUpgrade.FacilityLevel != levelRequested - 1 && Directory.Exists(KSPUtil.ApplicationRootPath + "/GameData/KerbalConstructionTime"))
                {
                    UpgradeHeld = true;
                    kctWarning  = GenerateKctWarning(facilityToUpgrade.FacilityLevel);
                    return;
                }
                facilityToUpgrade.SetLevel(levelRequested);
                UpgradeHeld = false;
            }
            parentFacility.OnUpgradeCompleted();
        }
示例#10
0
        public FacilityUpgradeEvent(string id, BureaucracyFacility passingFacility)
        {
            facilityId = id;
            List <UpgradeableFacility> upgradeables = GetFacilityById(id);

            for (int i = 0; i < upgradeables.Count; i++)
            {
                UpgradeableFacility potentialUpgrade = upgradeables.ElementAt(i);
                if (potentialUpgrade.GetUpgradeCost() <= 0)
                {
                    continue;
                }
                remainingInvestment = potentialUpgrade.GetUpgradeCost();
                originalCost        = potentialUpgrade.GetUpgradeCost();
                levelRequested      = potentialUpgrade.FacilityLevel + 1;
                break;
            }
            parentFacility = passingFacility;
        }
        public override bool RequirementMet(ConfiguredContract contract)
        {
            IEnumerable <UpgradeableFacility> facilities = UnityEngine.Object.FindObjectsOfType <UpgradeableFacility>().
                                                           Where <UpgradeableFacility>(f => f.name == facility);

            if (facilities.Count() > 0)
            {
                UpgradeableFacility upgradeableFacility = facilities.First <UpgradeableFacility>();

                int level = upgradeableFacility.FacilityLevel;
                return(level >= minLevel && level <= maxLevel);
            }
            else
            {
                // Should only get here if the facility name entered was bad
                LoggingUtil.LogError(this, "Coudn't read find facility with name '" + facility + "'!");
                return(false);
            }
        }
示例#12
0
        public void StartUpgrade(UpgradeableFacility facility)
        {
            BureaucracyFacility facilityToUpgrade = UpgradeableToActualFacility(facility);

            if (facilityToUpgrade == null)
            {
                Debug.Log("[Bureaucracy]: Upgrade of " + facility.id + " requested but no facility found");
                UiController.Instance.errorWindow = UiController.Instance.GeneralError("Can't find facility " + facility.id + " - please report this (with your KSP.log) on the Bureaucracy forum thread");
                return;
            }

            Debug.Log("[Bureaucracy]: Upgrade of " + facility.id + " requested");
            if (facilityToUpgrade.IsDestroyed())
            {
                Debug.Log("[Bureaucracy]: " + facility.id + " is destroyed. Aborting upgrade");
                ScreenMessages.PostScreenMessage("[Bureaucracy]: Can't upgrade " + facilityToUpgrade.Name + " Building is destroyed");
                return;
            }

            if (facilityToUpgrade.Upgrading && facilityToUpgrade.Upgrade.UpgradeHeld)
            {
                facilityToUpgrade.Upgrade.OnEventCompleted();
                return;
            }
            if (facilityToUpgrade.Upgrading)
            {
                if (facilityToUpgrade.IsPriority)
                {
                    warningDialog = DrawWarningDialog(facilityToUpgrade);
                    return;
                }
                Debug.Log("[Bureaucracy]: " + facility.id + " is already being upgraded. Prioritising");
                SetPriority(facilityToUpgrade, true);
                ScreenMessages.PostScreenMessage("Upgrade of " + facilityToUpgrade.Name + " prioritised");
                return;
            }

            facilityToUpgrade.StartUpgrade(facility);
        }
示例#13
0
        void OnKSCFacilityUpgraded(UpgradeableFacility facility, int level)
        {
            lastFacility = facility;
            lastFacilityTime = Time.realtimeSinceStartup;

            Popup popup = popups.LastOrDefault();
            if (popup != null)
            {
                popup.referencePosition = facility.transform;
                popup.initialized = true;
            }
        }
示例#14
0
 void FixFlags(UpgradeableFacility data0, int data1)
 {
     FixFlags();
 }
示例#15
0
 /// <summary>
 /// Reloads the collection of places where kerbals can be placed.
 /// </summary>
 private void MapRefresh(UpgradeableFacility data0, int data1)
 {
     $"Refreshing map due to new facility upgrade".Debug();
     _map.RefreshLocations();
 }