コード例 #1
0
        public static bool Prefix(TechLight __instance, ref PowerRelay __result, GameObject fromObject)
        {
            PowerRelay result = null;
            float      num    = float.MaxValue;

            for (int i = 0; i < PowerRelay.relayList.Count; i++)
            {
                PowerRelay powerRelay = PowerRelay.relayList[i];
                if (powerRelay is OtherConnectionRelay && powerRelay.gameObject.activeInHierarchy && powerRelay.enabled && !powerRelay.dontConnectToRelays && !(Builder.GetGhostModel() == powerRelay.gameObject))
                {
                    float magnitude = (powerRelay.GetConnectPoint(fromObject.transform.position) - fromObject.transform.position).magnitude;
                    if (magnitude <= TechLight.connectionDistance && magnitude < num)
                    {
                        num    = magnitude;
                        result = powerRelay;
                    }
                }
            }

            if (result != null)
            {
                __result = result;
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public void Init()
        {
            isOn = true;

            techLight  = GetComponent <TechLight>();
            identifier = GetComponentInParent <PrefabIdentifier>();
            id         = identifier.Id;

            OnProtoDeserialize(null);

            initialized = true;
        }
コード例 #3
0
        static bool Prefix(TechLight __instance)
        {
            var toggle = __instance.GetComponent <FloodlightToggle>();

            var powerRelay     = (PowerRelay)PowerRelayInfo.GetValue(__instance);
            var powerPerSecond = (float)PowerPerSecInfo.GetValue(null);
            var updateInterval = (float)UpdateIntervalInfo.GetValue(null);

            var searching = (bool)SearchingField.GetValue(__instance);

            if (!__instance.placedByPlayer || !__instance.constructable.constructed)
            {
                return(false);
            }
            if (powerRelay)
            {
                if (powerRelay.GetPowerStatus() == PowerSystem.Status.Normal && toggle.isOn)
                {
                    SetLightsActiveMethod.Invoke(__instance, new object[] { true });
                    float num;
                    powerRelay.ConsumeEnergy(powerPerSecond * updateInterval, out num);
                }
                else
                {
                    SetLightsActiveMethod.Invoke(__instance, new object[] { false });
                }
            }
            else
            {
                SetLightsActiveMethod.Invoke(__instance, new object[] { false });
                if (searching)
                {
                    return(false);
                }
                SearchingField.SetValue(__instance, true);
                __instance.InvokeRepeating("FindNearestValidRelay", 0f, 2f);
            }

            return(false);
        }
コード例 #4
0
 internal void ToggleFloodLight(TechLight light)
 {
     if (light != null)
     {
         bool constructed = light.constructable.constructed;
         if (constructed)
         {
             this.isOn = !this.isOn;
             FloodlightToggle.SetLightsActiveMethod.Invoke(this.techLight, new object[]
             {
                 this.isOn
             });
         }
         else
         {
             QuickLogger.Debug("Flood Light not constructed.");
         }
     }
     else
     {
         QuickLogger.Debug("Flood Light returned null");
     }
 }
コード例 #5
0
 public TechLightPowerConsumerInfo(TechLight light) : base(light.name)
 {
     this.light = light;
 }
コード例 #6
0
 static void Prefix(TechLight __instance)
 {
     __instance.gameObject.AddComponent <FloodlightToggle>();
     Logger.Log("Added FloodlightToggle Component to TechLight!");
 }
コード例 #7
0
 public static void Prefix(TechLight __instance)
 {
     typeof(TechLight).GetField("powerPerSecond", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance).SetValue(__instance, QMultiModSettings.Instance.SpotlightPowerPerSecond);
     typeof(TechLight).GetField("updateInterval", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance).SetValue(__instance, QMultiModSettings.Instance.SpotlightUpdateInterval);
 }