예제 #1
0
            static void Postfix(MechRepresentation __instance, Mech mech)
            {
                if (!chassisScaleFactors.ContainsKey(mech.MechDef.ChassisID))
                {
                    return;
                }

                Logger.Debug($"[MechRepresentation_Init_POSTFIX] Rescaling...");

                string identifier    = mech.MechDef.ChassisID;
                float  fallbackScale = combatScaleDefault;

                Vector3 adjustedLocalScale = GetScaleVector(identifier, fallbackScale);

                Logger.Debug($"[MechRepresentation_Init_POSTFIX] {identifier}: {adjustedLocalScale}");

                Vector3[] originalLOSSourcePositions = Traverse.Create(mech).Field("originalLOSSourcePositions").GetValue <Vector3[]>();
                Vector3[] originalLOSTargetPositions = Traverse.Create(mech).Field("originalLOSTargetPositions").GetValue <Vector3[]>();
                Vector3[] adjustedSourcePositions    = LOSSourcePositions(identifier, originalLOSSourcePositions, adjustedLocalScale);
                Vector3[] adjustedTargetPositions    = LOSTargetPositions(identifier, originalLOSTargetPositions, adjustedLocalScale);

                Traverse.Create(mech).Field("originalLOSSourcePositions").SetValue(adjustedSourcePositions);
                Traverse.Create(mech).Field("originalLOSTargetPositions").SetValue(adjustedTargetPositions);
                Traverse.Create(__instance.thisTransform).Property("localScale").SetValue(adjustedLocalScale);
            }
        static void Postfix(
            Mech mech,
            Transform parentTransform,
            bool isParented,
            MechRepresentation __instance)
        {
            Logger.Debug("mech size initialization");
            var identifier     = mech.MechDef.ChassisID;
            var sizeMultiplier = SizeMultiplier.Get(mech.MechDef.Chassis);

            Logger.Debug($"{identifier}: {sizeMultiplier}");
            var originalLOSSourcePositions = Traverse.Create(mech).Field("originalLOSSourcePositions").GetValue <Vector3[]>();
            var originalLOSTargetPositions = Traverse.Create(mech).Field("originalLOSTargetPositions").GetValue <Vector3[]>();
            var newSourcePositions         = ModSettings.LOSSourcePositions(identifier, originalLOSSourcePositions, sizeMultiplier);
            var newTargetPositions         = ModSettings.LOSTargetPositions(identifier, originalLOSTargetPositions, sizeMultiplier);

            Traverse.Create(mech).Field("originalLOSSourcePositions").SetValue(newSourcePositions);
            Traverse.Create(mech).Field("originalLOSTargetPositions").SetValue(newTargetPositions);
            Traverse.Create(__instance.thisTransform).Property("localScale").SetValue(sizeMultiplier);
        }
예제 #3
0
        public static void Postfix(MechRepresentation __instance)
        {
            try
            {
                if (!settings.BlipLights)
                {
                    return;
                }

                // memoize all mech lights (should capture new spawns too)
                if (!lightTracker.ContainsKey(__instance.parentMech.GUID))
                {
                    var transforms = __instance.GetComponentsInChildren <Transform>(true)
                                     .Where(x => x.name.Contains("headlight")).ToList();
                    Log($"Adding mech {__instance.parentMech.MechDef.Name} with {transforms.Count} lights");
                    lightTracker.Add(__instance.parentMech.GUID, transforms);
                }

                // Update() runs over by several frames after loading/restarting a mission
                // so hooking separately those is problematic because it repopulates with bad data
                // have to deal with it inline
                var lights = lightTracker[__instance.parentMech.GUID].Where(x => x != null).ToList();
                if (lights.Count == 0)
                {
                    Log(new string('>', 100) + " Invalid mechs in dictionary, clearing");
                    lightTracker.Clear();
                    headlightsOn = true;
                    return;
                }

                // player controlled lights
                if (__instance.pilotRep.pilot.Team.LocalPlayerControlsTeam)
                {
                    // Where clause should return Count 0 if the lights are already set, skipping SetActive()
                    foreach (var light in lights.Where(x => x.gameObject.activeSelf != headlightsOn))
                    {
                        light.gameObject.SetActive(headlightsOn);
                    }
                }

                try
                {
                    var localPlayerTeam = UnityGameInstance.BattleTechGame.Combat.LocalPlayerTeam;
                    var visibilityLevel = localPlayerTeam.VisibilityToTarget(__instance.parentActor);
                    if (visibilityLevel == VisibilityLevel.None || visibilityLevel == VisibilityLevel.LOSFull)
                    {
                        return;
                    }

                    // enemy mech is a blip, lights on
                    lights.Do(light => light.gameObject.SetActive(true));
                }
                catch (NullReferenceException)
                {
                    // do nothing (harmless NREs at load)
                }
            }
            catch (Exception ex)
            {
                Log(ex);
            }
        }