Exemplo n.º 1
0
        public static void EnableNightVisionEffect(AbstractActor source)
        {
            // Skip if the green effect is disabled
            if (!Mod.Config.Toggles.ShowNightVision)
            {
                return;
            }

            ModState.IsNightVisionMode = true;

            MoodController mc = ModState.GetMoodController();

            Traverse uppT = Traverse.Create(mc).Field("unityPostProcess");
            PostProcessingBehaviour ppb = uppT.GetValue <PostProcessingBehaviour>();

            // Enable grain and set the intensity
            Traverse       grainT = Traverse.Create(ppb).Field("m_Grain");
            GrainComponent gc     = grainT.GetValue <GrainComponent>();

            GrainModel.Settings gms = gc.model.settings;
            gms.intensity     = 0.8f;
            gms.size          = 1.0f;
            gc.model.settings = gms;

            Traverse   sunlightBTT = Traverse.Create(mc).Field("sunlightBT");
            BTSunlight sunlightBT  = sunlightBTT.GetValue <BTSunlight>();

            // Disable shadows from sunlight
            //BTSunlight.SunlightSettings sunlightS = sunlightBT.sunSettings;
            //sunlightS.castShadows = false;
            //sunlightBT.sunSettings = sunlightS;
            Traverse sunlightT = Traverse.Create(sunlightBT).Field("sunLight");
            Light    sunlight  = sunlightT.GetValue <Light>();

            sunlight.shadows = LightShadows.None;

            // Set the sunlight color
            Color lightVision = Color.green;

            lightVision.a = 0.8f;
            Shader.SetGlobalColor(Shader.PropertyToID("_BT_SunlightColor"), lightVision);

            // Disable opacity from the clouds
            Shader.SetGlobalFloat(Shader.PropertyToID("_BT_CloudOpacity"), 0f);

            // Make the sunlight point straight down
            Shader.SetGlobalVector(Shader.PropertyToID("_BT_SunlightDirection"), sunlightBT.transform.up);
        }
Exemplo n.º 2
0
        public static void DisableNightVisionEffect()
        {
            // Skip if the green effect is disabled
            if (!Mod.Config.Toggles.ShowNightVision)
            {
                return;
            }

            ModState.IsNightVisionMode = false;

            MoodController mc = ModState.GetMoodController();

            // Grain will disable automatically

            // Re-enable shadows
            Traverse   sunlightBTT = Traverse.Create(mc).Field("sunlightBT");
            BTSunlight sunlightBT  = sunlightBTT.GetValue <BTSunlight>();

            // Re-enable shadows from sunlight
            BTSunlight.SunlightSettings sunlightS = sunlightBT.sunSettings;
            //sunlightS.castShadows = false;
            //sunlightBT.sunSettings = sunlightS;
            Traverse sunlightT = Traverse.Create(sunlightBT).Field("sunLight");
            Light    sunlight  = sunlightT.GetValue <Light>();

            sunlight.shadows = (sunlightS.castShadows) ? LightShadows.None : LightShadows.Soft;

            // Reset the sunlight color
            Shader.SetGlobalColor(Shader.PropertyToID("_BT_SunlightColor"), mc.currentMood.sunlight.sunColor);

            // Re-enable opacity from the clouds
            Shader.SetGlobalFloat(Shader.PropertyToID("_BT_CloudOpacity"), mc.currentMood.sunlight.cloudOpacity);

            // Point sunlight forward
            Shader.SetGlobalVector(Shader.PropertyToID("_BT_SunlightDirection"), sunlightBT.transform.forward);
        }
Exemplo n.º 3
0
        public static MapConfig ParseCurrentMap()
        {
            Mod.Log.Info?.Write("MH:PCM Parsing current map.");

            MoodController moodController = ModState.GetMoodController();

            MoodSettings moodSettings = moodController?.CurrentMood;
            TagSet       moodTags     = moodSettings?.moodTags;

            if (moodTags == null || moodTags.IsEmpty)
            {
                return(new MapConfig {
                    spotterRange = Mod.Config.Vision.BaseRangeBright,
                    visualIDRange = Mod.Config.Vision.ScanRangeHexes
                });
            }

            Mod.Log.Debug?.Write($"  - Parsing current map for mod config");
            MapConfig mapConfig = new MapConfig();

            String allTags = String.Join(", ", moodTags.ToArray());

            Mod.Log.Debug?.Write($"  - All mood tags are: {allTags}");

            float baseVision  = Mod.Config.Vision.BaseRangeBright;
            float visionMulti = 1.0f;

            foreach (string tag in moodTags)
            {
                switch (tag)
                {
                case "mood_timeMorning":
                case "mood_timeNoon":
                case "mood_timeAfternoon":
                case "mood_timeDay":
                    Mod.Log.Debug?.Write($"  - {tag}");
                    mapConfig.isDay  = true;
                    mapConfig.isDim  = false;
                    mapConfig.isDark = false;
                    break;

                case "mood_timeSunrise":
                case "mood_timeSunset":
                case "mood_timeTwilight":
                    Mod.Log.Debug?.Write($"  - {tag}");
                    if (baseVision > Mod.Config.Vision.BaseRangeDim)
                    {
                        baseVision       = Mod.Config.Vision.BaseRangeDim;
                        mapConfig.isDay  = false;
                        mapConfig.isDim  = true;
                        mapConfig.isDark = false;
                    }
                    break;

                case "mood_timeNight":
                    Mod.Log.Debug?.Write($"  - {tag}");
                    if (baseVision > Mod.Config.Vision.BaseRangeDark)
                    {
                        baseVision       = Mod.Config.Vision.BaseRangeDark;
                        mapConfig.isDay  = false;
                        mapConfig.isDim  = false;
                        mapConfig.isDark = true;
                    }
                    break;

                case "mood_weatherRain":
                    Mod.Log.Debug?.Write($"  - {tag}");
                    if (visionMulti > Mod.Config.Vision.RangeMultiRainSnow)
                    {
                        visionMulti       = Mod.Config.Vision.RangeMultiRainSnow;
                        mapConfig.hasRain = true;
                    }
                    break;

                case "mood_weatherSnow":
                    Mod.Log.Debug?.Write($"  - {tag}");
                    if (visionMulti > Mod.Config.Vision.RangeMultiRainSnow)
                    {
                        visionMulti       = Mod.Config.Vision.RangeMultiRainSnow;
                        mapConfig.hasSnow = true;
                    }
                    break;

                case "mood_fogLight":
                    Mod.Log.Debug?.Write($"  - {tag}");
                    if (visionMulti > Mod.Config.Vision.RangeMultiLightFog)
                    {
                        visionMulti           = Mod.Config.Vision.RangeMultiLightFog;
                        mapConfig.hasLightFog = true;
                    }
                    break;

                case "mood_fogHeavy":
                    Mod.Log.Debug?.Write($"  - {tag}");
                    if (visionMulti > Mod.Config.Vision.RangeMultiHeavyFog)
                    {
                        visionMulti           = Mod.Config.Vision.RangeMultiHeavyFog;
                        mapConfig.hasHeavyFog = true;
                    }
                    break;

                default:
                    break;
                }
            }

            // Calculate normal vision range
            float visRange = (float)Math.Ceiling(baseVision * 30f * visionMulti);

            Mod.Log.Info?.Write($"  Calculating vision range as Math.Ceil(baseVision:{baseVision} * 30.0 * visionMulti:{visionMulti}) = visRange:{visRange}.");
            if (visRange < Mod.Config.Vision.MinimumVisionRange())
            {
                visRange = Mod.Config.Vision.MinimumVisionRange();
            }

            float roundedVisRange = HexUtils.CountHexes(visRange, false) * 30f;

            Mod.Log.Info?.Write($"MapHelper: Vision range for map will be ==> {roundedVisRange}m (normalized from {visRange}m)");
            mapConfig.spotterRange  = roundedVisRange;
            mapConfig.visualIDRange = Math.Min(roundedVisRange, Mod.Config.Vision.ScanRangeHexes * 30.0f);

            Mod.Log.Info?.Write($"Map vision range = visual:{roundedVisRange} / visualScan:{mapConfig.visualIDRange}");

            // Calculate night vision range
            if (mapConfig.isDark)
            {
                float nightVisRange = (float)Math.Ceiling(Mod.Config.Vision.BaseRangeBright * 30f * visionMulti);
                if (nightVisRange < Mod.Config.Vision.MinimumVisionRange())
                {
                    nightVisRange = Mod.Config.Vision.MinimumVisionRange();
                }

                float roundedNightVisRange = HexUtils.CountHexes(nightVisRange, false) * 30f;
                Mod.Log.Info?.Write($"MapHelper: Night vision range for map will be ==> {roundedNightVisRange}m (normalized from {nightVisRange}m)");
                mapConfig.nightVisionSpotterRange  = roundedNightVisRange;
                mapConfig.nightVisionVisualIDRange = Math.Min(roundedNightVisRange, Mod.Config.Vision.ScanRangeHexes * 30.0f);
            }

            return(mapConfig);
        }