Ejemplo n.º 1
0
            public static bool Prefix(ElectricalUtilityNetwork __instance, List <Wire> ___allWires, UtilityNetworkGridNode[] grid, float ___timeOverloaded, List <Wire>[] ___wireGroups)
            {
                for (int i = 0; i < ___wireGroups.Length; i++)
                {
                    List <Wire> wires = ___wireGroups[i];
                    if (wires == null)
                    {
                        continue;
                    }
                    for (int j = 0; j < wires.Count; j++)
                    {
                        Wire wire = wires[j];
                        if (wire != null)
                        {
                            wire.circuitOverloadTime = ___timeOverloaded;
                            int cell = Grid.PosToCell(wire.transform.GetPosition());
                            UtilityNetworkGridNode utilityNetworkGridNode = grid[cell];
                            utilityNetworkGridNode.networkIdx = -1;
                            grid[cell] = utilityNetworkGridNode;
                        }
                    }
                    wires.Clear();
                }

                ___allWires.Clear();
                Traverse.Create(__instance).Method("RemoveOverloadedNotification").GetValue();

                return(false);
            }
    private void CheckCircuitOverloaded(float dt, int id, float watts_used)
    {
        UtilityNetworkManager <ElectricalUtilityNetwork, Wire> electricalConduitSystem = Game.Instance.electricalConduitSystem;
        UtilityNetwork networkByID = electricalConduitSystem.GetNetworkByID(id);

        if (networkByID != null)
        {
            ElectricalUtilityNetwork electricalUtilityNetwork = (ElectricalUtilityNetwork)networkByID;
            if (electricalUtilityNetwork != null)
            {
                ElectricalUtilityNetwork electricalUtilityNetwork2 = electricalUtilityNetwork;
                CircuitInfo circuitInfo = this.circuitInfo[id];
                electricalUtilityNetwork2.UpdateOverloadTime(dt, watts_used, circuitInfo.bridgeGroups);
            }
        }
    }
Ejemplo n.º 3
0
            public static bool Prefix(ElectricalUtilityNetwork __instance, float dt, float watts_used, List <WireUtilityNetworkLink>[] bridgeGroups, ref float ___timeOverloaded, ref GameObject ___targetOverloadedWire, ref Notification ___overloadedNotification, ref float ___timeOverloadNotificationDisplayed, List <Wire>[] ___wireGroups)
            {
                Log.Spam($"UpdateOverloadTime: {___wireGroups.Length}, {bridgeGroups.Length}");

                bool        wattage_rating_exceeded = false;
                List <Wire> overloaded_wires        = null;
                List <WireUtilityNetworkLink> overloaded_bridges = null;

                for (int rating_idx = 0; rating_idx < ___wireGroups.Length; rating_idx++)
                {
                    List <Wire> wires = ___wireGroups[rating_idx];
                    List <WireUtilityNetworkLink> bridges = bridgeGroups[rating_idx];
                    Wire.WattageRating            rating  = (Wire.WattageRating)rating_idx;
                    float max_wattage = Wire.GetMaxWattageAsFloat(rating);
                    if (watts_used > max_wattage && ((bridges != null && bridges.Count > 0) || (wires != null && wires.Count > 0)))
                    {
                        wattage_rating_exceeded = true;
                        overloaded_wires        = wires;
                        overloaded_bridges      = bridges;
                        break;
                    }
                }
                overloaded_wires?.RemoveAll((Wire x) => x == null);
                overloaded_bridges?.RemoveAll((WireUtilityNetworkLink x) => x == null);
                if (wattage_rating_exceeded)
                {
                    ___timeOverloaded += dt;
                    if (!(___timeOverloaded > 6f))
                    {
                        return(false);
                    }
                    ___timeOverloaded = 0f;
                    if (___targetOverloadedWire == null)
                    {
                        if (overloaded_bridges != null && overloaded_bridges.Count > 0)
                        {
                            int random_bridge_idx = Random.Range(0, overloaded_bridges.Count);
                            ___targetOverloadedWire = overloaded_bridges[random_bridge_idx].gameObject;
                        }
                        else if (overloaded_wires != null && overloaded_wires.Count > 0)
                        {
                            int random_wire_idx = Random.Range(0, overloaded_wires.Count);
                            ___targetOverloadedWire = overloaded_wires[random_wire_idx].gameObject;
                        }
                    }
                    if (___targetOverloadedWire != null)
                    {
                        ___targetOverloadedWire.Trigger(-794517298, new BuildingHP.DamageSourceInfo
                        {
                            damage               = 1,
                            source               = STRINGS.BUILDINGS.DAMAGESOURCES.CIRCUIT_OVERLOADED,
                            popString            = STRINGS.UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.CIRCUIT_OVERLOADED,
                            takeDamageEffect     = SpawnFXHashes.BuildingSpark,
                            fullDamageEffectName = "spark_damage_kanim",
                            statusItemID         = Db.Get().BuildingStatusItems.Overloaded.Id
                        });
                    }
                    if (___overloadedNotification == null)
                    {
                        ___timeOverloadNotificationDisplayed = 0f;
                        ___overloadedNotification            = new Notification(STRINGS.MISC.NOTIFICATIONS.CIRCUIT_OVERLOADED.NAME, NotificationType.BadMinor, HashedString.Invalid, null, null, true, 0f, null, null, ___targetOverloadedWire.transform);
                        GameScheduler.Instance.Schedule("Power Tutorial", 2f, delegate
                        {
                            Tutorial.Instance.TutorialMessage(Tutorial.TutorialMessages.TM_Power);
                        });
                        Notifier notifier = Game.Instance.FindOrAdd <Notifier>();
                        notifier.Add(___overloadedNotification);
                    }
                }
                else
                {
                    ___timeOverloaded = Mathf.Max(0f, ___timeOverloaded - dt * 0.95f);
                    ___timeOverloadNotificationDisplayed += dt;
                    if (___timeOverloadNotificationDisplayed > 5f)
                    {
                        Traverse.Create(__instance).Method("RemoveOverloadedNotification").GetValue();
                    }
                }

                return(false);
            }