Exemple #1
0
        bool Initialize()
        {
            ModDebug.Log("Initializing UI");

            if (UIUtils.Instance == null)
            {
                return(false);
            }

            roadsOptionPanel = UIUtils.Instance.FindComponent <UIComponent>("RoadsOptionPanel", null, UIUtils.FindOptions.NameContains);
            if (roadsOptionPanel == null || !roadsOptionPanel.gameObject.activeInHierarchy)
            {
                return(false);
            }

            builtinTabstrip = UIUtils.Instance.FindComponent <UITabstrip>("ToolMode", roadsOptionPanel);
            if (builtinTabstrip == null || !builtinTabstrip.gameObject.activeInHierarchy)
            {
                return(false);
            }

            tabstrip = UIUtils.Instance.FindComponent <UITabstrip>(panelName);
            if (tabstrip != null)
            {
                DestroyView();
            }

            CreateView();
            if (tabstrip == null)
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
 public bool RecoverName()
 {
     if (target.name != string.Empty)
     {
         if (target.planet != null && uiPlanet != null)
         {
             target.SetPlanetOverrideName(target.name);
             Traverse.Create((object)uiPlanet).Field("nameText").GetValue <Text>().text = target.name;
             return(true);
         }
         else if (target.star != null && uiStar != null)
         {
             target.SetStarOverrideName(target.name);
             Traverse.Create((object)uiStar).Field("nameText").GetValue <Text>().text = target.name;
             return(true);
         }
         else
         {
             ModDebug.Assert(false);
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Exemple #3
0
        void CreateView()
        {
            ModDebug.Log("Creating view");

            GameObject rootObject = new GameObject(panelName);

            tabstrip = rootObject.AddComponent <UITabstrip>();

            CreateButtons();

            roadsOptionPanel.AttachUIComponent(tabstrip.gameObject);
            tabstrip.relativePosition = new Vector3(90, 38);
            tabstrip.width            = 80;
            tabstrip.selectedIndex    = -1;
            tabstrip.padding          = new RectOffset(0, 1, 0, 0);

            if (builtinModeChangedHandler == null)
            {
                builtinModeChangedHandler = (UIComponent component, int index) => {
                    if (!ignoreBuiltinTabstripEvents)
                    {
                        if (selectedToolModeChanged != null)
                        {
                            selectedToolModeChanged(ToolMode.None);
                        }
                    }
                };
            }

            builtinTabstrip.eventSelectedIndexChanged += builtinModeChangedHandler;

            // Setting selectedIndex needs to be delayed for some reason
            tabstrip.StartCoroutine(FinishCreatingView());
        }
Exemple #4
0
 private void IgnoreBuiltinTabstrip(int selectedIndex)
 {
     ignoreBuiltinTabstripEvents = true;
     ModDebug.Log("Setting builtin tabstrip mode: " + (selectedIndex));
     builtinTabstrip.selectedIndex = selectedIndex;
     ignoreBuiltinTabstripEvents   = false;
 }
 private static void Finalizer(Exception __exception)
 {
     if (__exception != null)
     {
         ModDebug.ShowError($"An exception occurred whilst trying to apply aI behaviours.", "", __exception);
     }
 }
Exemple #6
0
            /// <summary>
            /// Walk --> Fly or Arrive
            /// </summary>
            private static void Postfix(PlayerMove_Walk __instance, ref bool __result)
            {
                if (!s_NavigateInstance.enable)
                {
                    return;
                }

                if (!s_NavigateInstance.target.IsVaild())
                {
                    return;
                }

                if (s_NavigateInstance.DetermineArrive())
                {
                    ModDebug.Log("WalkModeArrive");
                    s_NavigateInstance.Arrive();
                }
                else if (__instance.mecha.thrusterLevel < 1)
                {
                    s_NavigateInstance.Arrive("驱动引擎等级过低".ModText());
                }
                else if (__instance.player.mecha.coreEnergy < s_NavigateMinEnergy.Value)
                {
                    s_NavigateInstance.Arrive("机甲能量过低".ModText());
                }
                else
                {
                    AutoStellarNavigation.Walk.TrySwitchToFly(__instance);
                    //切换至Fly Mode 中对 UpdateJump 方法进行拦截
                    __result = true;
                }
            }
Exemple #7
0
        public void GetCurrentData()
        {
            Dictionary <Data.SpawnData, int> oldValues = new Dictionary <Data.SpawnData, int>();

            foreach (Data.SpawnData dat in dataManager.Data)
            {
                oldValues.Add(dat, dat.GetNumberSpawned());
                dat.SetNumberSpawned(0);
            }

            foreach (MobileParty mb in MobileParty.All)
            {
                foreach (var dat in dataManager.Data)
                {
                    if (CampaignUtils.IsolateMobilePartyStringID(mb) == dat.PartyTemplate.StringId)
                    {
                        //increase count
                        dat.IncrementNumberSpawned();
                    }
                }
            }
            if (ConfigLoader.Instance.Config.IsDebugMode)
            {
                //display necessary debug message.
                foreach (var dat in dataManager.Data)
                {
                    if (oldValues[dat] != dat.GetNumberSpawned()) //leave a log only if a change has occured. TODO we can also detect death with these and create custom behaviour/spawn schedules accordingly ;)
                    {
                        ModDebug.ShowMessage(dat.Name + " count: " + dat.GetNumberSpawned());
                    }
                }
            }
        }
 static bool Prefix(Hero __instance, SkillObject skill, int xpAmount)
 {
     try
     {
         HeroDeveloper hd = (HeroDeveloper)(typeof(Hero).GetField("_heroDeveloper", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(__instance));
         if (hd != null)
         {
             if (xpAmount > 0)
             {
                 double multiplier  = GetMultiplier(__instance.GetSkillValue(skill));
                 int    newXpAmount = (int)Math.Ceiling(xpAmount * multiplier);
                 hd.AddSkillXp(skill, newXpAmount);
             }
             else
             {
                 hd.AddSkillXp(skill, xpAmount);
             }
         }
     }
     catch (Exception ex)
     {
         ModDebug.ShowError($"An exception occurred whilst trying to apply the hero xp multiplier.", "", ex);
     }
     return(false);
 }
Exemple #9
0
        private void ShortDistanceNavigate(PlayerMove_Sail __instance)
        {
            VectorLF3 dir = target.GetDirection(__instance.player);

            Sail.SetDir(__instance, dir);

            VectorLF3 advisePoint = VectorLF3.zero;

            if (AdvisePointIfOcclusion(__instance, ref advisePoint, shortNavUncoverRange))
            {
#if DEBUG
                ModDebug.Log("Planet Navigate ToAdvisePoint:" + advisePoint);
#endif
                dir = (advisePoint - __instance.player.uPosition).normalized;
                Sail.SetDir(__instance, dir);
                Sail.TrySpeedUp(this, __instance);
            }
            else
            {
                if (Target.IsFocusingNormalized(dir, __instance.player.uVelocity.normalized))
                {
#if DEBUG
                    ModDebug.Log("Short Navigate - Speed Up");
#endif
                    Sail.TrySpeedUp(this, __instance);
                }
                else
                {
#if DEBUG
                    ModDebug.Log("Short Navigate - No Speed Up");
#endif
                }
            }
        }
Exemple #10
0
        private void OnSettlementDaily(Settlement s)
        {
            if (s == null || !s.IsVillage)
            {
                return;
            }

            if (!settlementToDevestation.ContainsKey(s))
            {
                ErrorHandler.HandleException(new Exception("Devestation value for settlement could not be found!"));
            }

            var presentInDay = MobilePartyTrackingBehaviour.Singleton.GetSettlementDailyMobilePartyPresences(s);

            float hostileDecay = 0;

            float friendlyGain = 0;

            foreach (var mb in presentInDay)
            {
                if (mb.IsBandit)
                {
                    hostileDecay += campaignConfig.HostilePresencePerPowerDaily * mb.Party.TotalStrength;
                }
                else if (s.OwnerClan.MapFaction.IsAtWarWith(mb.Party.MapFaction))
                {
                    hostileDecay += campaignConfig.HostilePresencePerPowerDaily * mb.Party.TotalStrength;
                }
                else if (s.OwnerClan.MapFaction == mb.Party.MapFaction)
                {
                    friendlyGain += campaignConfig.FriendlyPresenceDecayPerPowerDaily * mb.Party.TotalStrength;
                }
            }

            if (friendlyGain > 0)
            {
                //ModDebug.ShowMessage("Calculating friendly presence devestation decay in " + s.Name + ". Decreasing devestation by " + friendlyGain, campaignConfig);

                ChangeDevestation(s, -friendlyGain);
            }


            if (hostileDecay > 0)
            {
                ModDebug.ShowMessage("Calculating hostile presence devestation gain in " + s.Name + ". Increasing devestation by " + hostileDecay, campaignConfig);

                ChangeDevestation(s, hostileDecay);
            }

            if (GetDevestation(s) > 0)
            {
                ModDebug.ShowMessage("Calculating daily Devestation Decay in " + s.Name + ". Decreasing devestation by " + campaignConfig.DailyDevestationDecay, campaignConfig);
                ChangeDevestation(s, -campaignConfig.DailyDevestationDecay);
            }

            if (GetDevestation(s) != 0)
            {
                ModDebug.ShowMessage("Current Devestation at " + s.Name + " is now " + settlementToDevestation[s], campaignConfig);
            }
        }
Exemple #11
0
        /// <summary>
        /// Deletes the file for the given module.
        /// </summary>
        /// <param name="moduleName">The folder name of the module to delete the file for.</param>
        /// <param name="fileName">The file name of the file to be deleted.</param>
        /// <param name="location">The location of the file to be deleted.</param>
        /// <returns>Returns true if the file was deleted successfully.</returns>
        public static bool DeleteFile(string moduleName, string fileName, Location location = Location.Modules)
        {
            bool   successful = true;
            string path       = GetPathForModule(moduleName, location);

            if (!Directory.Exists(path))
            {
                ModDebug.ShowError($"Tried to delete a file with file name {fileName} from directory \"{path}\" but the directory doesn't exist.", "Could not find directory");
                successful = false;
            }

            if (location == Location.Modules)
            {
                path = Path.Combine(path, "ModuleData", LoadablesFolderName);
            }

            string filePath = Path.Combine(path, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            return(successful);
        }
Exemple #12
0
        private static void Add(ISerialisableFile loadable)
        {
            if (loadable == null)
            {
                throw new ArgumentNullException("Tried to add something to the FileDatabase Data dictionary that was null");
            }
            if (string.IsNullOrWhiteSpace(loadable.ID))
            {
                throw new ArgumentNullException($"Loadable of type {loadable.GetType().ToString()} has missing ID field");
            }

            Type type = loadable.GetType();

            if (!Data.ContainsKey(type))
            {
                Data.Add(type, new Dictionary <string, ISerialisableFile>());
            }

            if (Data[type].ContainsKey(loadable.ID))
            {
                ModDebug.LogError($"Loader already contains Type: {type.AssemblyQualifiedName} ID: {loadable.ID}, overwriting...");
                Data[type][loadable.ID] = loadable;
            }
            else
            {
                Data[type].Add(loadable.ID, loadable);
            }
        }
Exemple #13
0
            private static void Postfix(PlayerMove_Walk __instance, ref bool __result)
            {
                if (autoNav.enable && autoNav.target.IsVaild())
                {
                    if (autoNav.DetermineArrive())
                    {
                        ModDebug.Log("WalkModeArrive");
                        autoNav.Arrive();
                    }
                    else if (
                        __instance.mecha.thrusterLevel < 1)
                    {
                        autoNav.Arrive("驱动引擎等级过低".ModText());
                    }
                    else if (__instance.player.mecha.coreEnergy < minAutoNavEnergy.Value)
                    {
                        autoNav.Arrive("机甲能量过低".ModText());
                    }
                    else
                    {
                        AutoStellarNavigation.Walk.TrySwitchToFly(__instance);
                        __result = true;
                        return;
                    }

                    __result = false;
                }
            }
Exemple #14
0
    public static void LogPlanetType(PlanetData planet)
    {
        //Gas planet range
        switch (planet.type)
        {
        case EPlanetType.Gas:
            ModDebug.Log("Gas");
            break;

        case EPlanetType.Desert:
            ModDebug.Log("Desert");
            break;

        case EPlanetType.Ice:
            ModDebug.Log("Ice");
            break;

        case EPlanetType.Ocean:
            ModDebug.Log("Ocean");
            break;

        case EPlanetType.Vocano:
            ModDebug.Log("Vocano");
            break;

        case EPlanetType.None:
            ModDebug.Log("None");
            break;
        }
        ;
    }
Exemple #15
0
 private void DailyMakeSureNoKingdom(Clan c)
 {
     if (c == null || DiplomacyUtils.GetHardCodedExceptionClans().Contains(c.StringId))
     {
         return;
     }
     try
     {
         if (dataManager == null)
         {
             GetData();
         }
         if (dataManager.Data.ContainsKey(c.StringId))
         {
             if (dataManager.Data[c.StringId].ForceNoKingdom && c.Kingdom != null)
             {
                 ChangeKingdomAction.ApplyByLeaveKingdom(c, false);
                 ModDebug.ShowMessage(c.StringId + " has forcefully been removed from parent kingdom", DebugMessageType.Diplomacy);
             }
         }
     }
     catch (Exception e)
     {
         ErrorHandler.HandleException(e, "daily make sure no kingdom process");
     }
 }
Exemple #16
0
            private static void Prefix(PlayerMove_Fly __instance)
            {
                if (autoNav.enable)
                {
                    if (__instance.player.movementState != EMovementState.Fly)
                    {
                        return;
                    }

                    if (autoNav.DetermineArrive())
                    {
                        ModDebug.Log("FlyModeArrive");
                        autoNav.Arrive();
                    }
                    else if (
                        __instance.mecha.thrusterLevel < 2)
                    {
                        autoNav.Arrive("驱动引擎等级过低".ModText());
                    }
                    else if (__instance.player.mecha.coreEnergy < minAutoNavEnergy.Value)
                    {
                        autoNav.Arrive("机甲能量过低".ModText());
                    }
                    else
                    {
                        ++__instance.controller.input1.y;

                        if (__instance.currentAltitude > sailMinAltitude)
                        {
                            AutoStellarNavigation.Fly.TrySwtichToSail(__instance);
                        }
                    }
                }
            }
Exemple #17
0
            public static bool TrySwtichToSail(PlayerMove_Fly __instance)
            {
#if DEBUG
                ModDebug.Log("Try Swtich To Sail");
#endif

                if (__instance.mecha.thrusterLevel < THRUSTER_LEVEL_SAIL)
                {
                    return(false);
                }

                //取消建造模式
                if (__instance.controller.cmd.type == ECommand.Build)
                {
                    __instance.controller.cmd.type = ECommand.None;
                }

                __instance.controller.movementStateInFrame = EMovementState.Sail;
                __instance.controller.actionSail.ResetSailState();

                GameCamera.instance.SyncForSailMode();
                GameMain.gameScenario.NotifyOnSailModeEnter();

                return(true);
            }
        public bool RegisterParty(MobileParty mb, Settlement s)
        {
            var behaviours = AI.AIManager.GetAIBehavioursForParty(mb);

            foreach (var b in behaviours)
            {
                if (!b.IsCompatible(this))
                {
                    return(false);
                }
            }
            var patrollerInstance = GetPatroller(mb);

            if (patrollerInstance.patrollerParty != null && patrollerInstance.patrolledSettlement != s)
            {
                ErrorHandler.HandleException(new Exception("The same mobile party cannot patrol around two different settlements!"));
            }
            if (patrollerInstance.patrolledSettlement == s)
            {
                return(false);
            }
            registeredPatrollers.Add(new Patroller(mb, s));
            mb.HomeSettlement = s;
            ModDebug.ShowMessage(mb.StringId + " is now engaged in patrol behaviour around " + s.Name);
            AIManager.RegisterAIBehaviour(mb, this);
            return(true);
        }
Exemple #19
0
    public static void LogCmdMode(int mode)
    {
        //Gas planet range
        switch (mode)
        {
        case -1:
            ModDebug.Log("CmdMode: Destruct Mode");
            break;

        case -2:
            ModDebug.Log("CmdMode: Upgrade Mode");
            break;

        case 1:
            ModDebug.Log("CmdMode: Normal Build Mode");
            break;

        case 2:
            ModDebug.Log("CmdMode: Build Mode - Belt");
            break;

        case 3:
            ModDebug.Log("CmdMode: Build Mode - Inserter");
            break;

        case 4:
            ModDebug.Log("CmdMode: Build Mode - Ground");
            break;
        }
        ;
    }
        //private static float GetMultiplier()
        //{
        // if (Settings.Instance.HeroSkillExperienceOverrideMultiplierEnabled)
        //return Settings.Instance.HeroSkillExperienceMultiplier;
        //else
        //    return Math.Max(1, 0.0315769 * Math.Pow(skillLevel, 1.020743));
        //}

        static bool Prefix(Hero __instance, SkillObject skill, float xpAmount)
        {
            try
            {
                if (hdFieldInfo == null)
                {
                    GetFieldInfo();
                }

                HeroDeveloper hd = (HeroDeveloper)hdFieldInfo.GetValue(__instance);

                if (hd != null)
                {
                    if (xpAmount > 0)
                    {
                        float newXpAmount = (int)Math.Ceiling(xpAmount * Settings.Instance.HeroSkillExperienceMultiplier);
                        hd.AddSkillXp(skill, newXpAmount, true, true);
                    }
                    else
                    {
                        hd.AddSkillXp(skill, xpAmount, true, true);
                    }
                }
            }
            catch (Exception ex)
            {
                ModDebug.ShowError($"An exception occurred whilst trying to apply the hero xp multiplier.", "", ex);
            }
            return(false);
        }
Exemple #21
0
        public static MobileParty SpawnParty(Settlement spawnedSettlement, Clan clan, PartyTemplateObject templateObject, MobileParty.PartyTypeEnum partyType, TextObject partyName = null, PartyTemplateObject templatePrisoners = null, bool IsInheritClan = false)
        {
            //get name and show message.
            TextObject textObject = partyName ?? clan.Name;

            ModDebug.ShowMessage("CustomSpawns: Spawning " + textObject.ToString() + " at " + spawnedSettlement.GatePosition + " in settlement " + spawnedSettlement.Name.ToString(), DebugMessageType.Spawn);

            //create.
            MobileParty mobileParty = MBObjectManager.Instance.CreateObject <MobileParty>(templateObject.StringId + "_" + 1);

            if (templatePrisoners != null)
            {
                mobileParty.InitializeMobileParty(textObject, ConstructTroopRoster(templateObject, mobileParty.Party), ConstructTroopRoster(templatePrisoners, mobileParty.Party), spawnedSettlement.GatePosition, 0);
            }
            else
            {
                mobileParty.InitializeMobileParty(textObject, ConstructTroopRoster(templateObject, mobileParty.Party), new TroopRoster(mobileParty.Party), spawnedSettlement.GatePosition, 0);
            }

            //initialize
            Clan settlementClan = spawnedSettlement.OwnerClan;

            if (IsInheritClan == true)
            {
                Spawner.InitParty(mobileParty, textObject, settlementClan, spawnedSettlement);
            }
            else
            {
                Spawner.InitParty(mobileParty, textObject, clan, spawnedSettlement);
            }

            return(mobileParty);
        }
Exemple #22
0
 static void Finalizer(Exception __exception)
 {
     if (__exception != null)
     {
         ModDebug.ShowError($"Mount and Blade Bannerlord has encountered an error and needs to close. See the error information below.",
                            "Mount and Blade Bannerlord has crashed", __exception);
     }
 }
 private void PartyRecruitAndRemovePrisoner(PartyBase mb, CharacterObject c)
 {
     if (Config.PrisonRecruitmentDebugEnabled)
     {
         ModDebug.ShowMessage("recruiting " + c.StringId + " from prisoners of party " + mb.Id);
     }
     mb.PrisonRoster.RemoveTroop(c, 1);
     mb.AddElementToMemberRoster(c, 1);
 }
Exemple #24
0
        private void OnCommonAreaFightOccured(MobileParty p1, MobileParty p2, Hero h, Settlement s)
        {
            if (p1 == null || p2 == null || s == null)
            {
                return;
            }

            ModDebug.ShowMessage("Fight at " + s.Name, DebugMessageType.Development);
        }
 void DestroyBuildTool()
 {
     ModDebug.LogClassAndMethodName(this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);
     if (buildTool != null)
     {
         ModDebug.Log("Tool destroyed");
         BuildTool21.Destroy(buildTool);
         buildTool = null;
     }
 }
Exemple #26
0
        private void OnVillageLooted(Village v)
        {
            if (v == null)
            {
                return;
            }

            ChangeDevestation(v.Settlement, campaignConfig.DevestationPerTimeLooted);

            ModDebug.ShowMessage("Successful Looting at " + v.Name + ". Increasing devestation by " + campaignConfig.DevestationPerTimeLooted, campaignConfig);
        }
Exemple #27
0
 public bool Pause()
 {
     if (enable)
     {
         ModDebug.Log("SafePause");
         enable       = false;
         isHistoryNav = true;
         return(true);
     }
     return(false);
 }
Exemple #28
0
 /// <summary>
 /// Gets a list of all mobile parties that have visited this settlement today.
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public List <MobileParty> GetSettlementDailyMobilePartyPresences(Settlement s)
 {
     if (settlementDailyPresences.ContainsKey(s))
     {
         return(settlementDailyPresences[s]);
     }
     else
     {
         ModDebug.ShowMessage("Tried to get daily presences of an invalid settlement!", DebugMessageType.Development);
         return(new List <MobileParty>());
     }
 }
Exemple #29
0
 /// <summary>
 /// Returns a list of all settlements that this party has been closest to within the day.
 /// </summary>
 /// <param name="mb"></param>
 /// <returns></returns>
 public List <Settlement> GetMobilePartyDailyPresences(MobileParty mb)
 {
     if (dailyPresences.ContainsKey(mb))
     {
         return(dailyPresences[mb]);
     }
     else
     {
         ModDebug.ShowMessage("Tried to get daily presences of an invalid mobile party!", DebugMessageType.Development);
         return(new List <Settlement>());
     }
 }
Exemple #30
0
 public bool Resume()
 {
     if (isHistoryNav == true && !enable)
     {
         ModDebug.Log("SafeResume");
         enable       = true;
         isHistoryNav = false;
         return(true);
     }
     isHistoryNav = false;
     return(false);
 }