예제 #1
0
        /// <summary>
        /// generates unique name by adding prefix.
        /// </summary>
        /// <param name="excludeCurrent">
        /// set to true when renaming
        /// set to false when cloning.
        /// </param>
        public static string GetUniqueNetInfoName(string name, bool excludeCurrent = false)
        {
            string strippedName = PackageHelper.StripName(name);

            if (excludeCurrent && strippedName == name)
            {
                return(name);
            }
            string finalName = strippedName;

            for (int i = 0; PrefabCollection <NetInfo> .LoadedExists(finalName); i++)
            {
                finalName = $"instance{i}." + strippedName;
                if (i > 1000)
                {
                    throw new Exception("Infinite loop");
                }
            }
            return(finalName);
        }
        /// <summary>
        /// 刷新建筑里程碑
        /// </summary>
        /// <param name="name">建筑名称</param>
        /// <param name="milestoneInfo">新的里程碑进度</param>
        /// <param name="config">配置信息</param>
        /// <param name="inGroup">是否在组</param>
        private void RefreshBuildingMilestone(string name, MilestoneInfo milestoneInfo, ModConfigModel config, bool inGroup = false)
        {
            if (config.BuildingExistsRoads.Contains(name) || config.BuildingContainedRoads.Contains(name))
            {
                RefreshRoadMilestone(name, milestoneInfo, config);
            }
            else if (config.BuildingGroups.TryGetValue(name, out List <string> buildingGroup) && !inGroup)
            {
                foreach (string buildingName in buildingGroup)
                {
                    RefreshBuildingMilestone(buildingName, milestoneInfo, config, true);
                }
            }
            else if (PrefabCollection <BuildingInfo> .LoadedExists(name))
            {
                BuildingInfo building = PrefabCollection <BuildingInfo> .FindLoaded(name);

                if (milestoneInfo.GetLevel() < building.GetUnlockMilestone().GetLevel())
                {
                    building.m_UnlockMilestone = milestoneInfo;
                }
                RefreshRelatedMilestone(name, building.category, building.m_class.m_service, building.m_class.m_subService, milestoneInfo);
            }
        }
        /// <summary>
        /// 刷新道路里程碑
        /// </summary>
        /// <param name="name">道路名称</param>
        /// <param name="milestoneInfo">新的里程碑进度</param>
        /// <param name="config">配置信息</param>
        /// <param name="inGroup">是否在组</param>
        private void RefreshRoadMilestone(string name, MilestoneInfo milestoneInfo, ModConfigModel config, bool inGroup = false)
        {
            if (config.RoadExistsBuildings.Contains(name))
            {
                RefreshBuildingMilestone(name, milestoneInfo, config);
            }
            else if (config.RoadGroups.TryGetValue(name, out List <string> roadGroup) && !inGroup)
            {
                foreach (string roadName in roadGroup)
                {
                    RefreshRoadMilestone(roadName, milestoneInfo, config, true);
                }
            }
            else if (PrefabCollection <NetInfo> .LoadedExists(name))
            {
                NetInfo net = PrefabCollection <NetInfo> .FindLoaded(name);

                if (milestoneInfo.GetLevel() < net.GetUnlockMilestone().GetLevel())
                {
                    net.m_UnlockMilestone = milestoneInfo;
                }
                RefreshRelatedMilestone(name, net.category, net.m_class.m_service, net.m_class.m_subService, net.m_UnlockMilestone);
            }
        }