示例#1
0
        private void ToggleMachines(bool toggle, IPlayer player = null)
        {
            if (config.CampfireControl)
            {
                var count      = 0;
                var enumerator = CampfireMachine.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    var camp = enumerator.Current.Value;

                    if (!camp.isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (camp.Powered == toggle)
                    {
                        continue;
                    }
                    if (!camp.HasFuel)
                    {
                        continue;
                    }

                    camp.RPC("SetPoweredServer", 0, toggle);
                    count++;
                }

                var message = Lang(toggle ? "MachinesStarted" : "MachinesStopped", player?.Id, count, "fridge");
                player?.Reply(message);
                Puts(message); // TODO: Logging optional
            }

            if (config.DrillControl)
            {
                var count  = 0;
                var drills = DrillMachine.GetEnumerator();
                while (drills.MoveNext())
                {
                    var drill = drills.Current.Value;

                    if (!drill.isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (drill.Powered == toggle)
                    {
                        continue;
                    }
                    if (!drill.HasFuel)
                    {
                        continue;
                    }

                    drill.RPC("SetPoweredServer", 0, toggle);
                    count++;
                }

                var message = Lang(toggle ? "MachinesStarted" : "MachinesStopped", player?.Id, count, "fridge");
                player?.Reply(message);
                Puts(message); // TODO: Logging optional
            }

            if (config.FridgeControl)
            {
                var count      = 0;
                var enumerator = FridgeMachine.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    var fridge = enumerator.Current.Value;

                    if (!fridge.isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (fridge.Powered == toggle)
                    {
                        continue;
                    }

                    fridge.RPC("SetPoweredServer", 0, toggle);
                    count++;
                }

                var message = Lang(toggle ? "MachinesStarted" : "MachinesStopped", player?.Id, count, "fridge");
                player?.Reply(message);
                Puts(message); // TODO: Logging optional
            }

            // TODO: Combine messages into single message. Ex. "2 campfires, 3 drills, and 4 fridges stopped"

            state = toggle;
        }
示例#2
0
        void ToggleMachines(bool toggle, IPlayer player = null)
        {
            if (campfireControl)
            {
                var count      = 0;
                var enumerator = CampfireMachine.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    var camp = enumerator.Current.Value;

                    if (!camp.isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (camp.GetPowered() == toggle)
                    {
                        continue;
                    }
                    if (!camp.HasFuel)
                    {
                        continue;
                    }

                    camp.SetPoweredServer(toggle);
                    count++;
                }

                var message = toggle ? Lang("Started", player?.Id, count, "campfire") : Lang("Stopped", player?.Id, count, "campfire");
                player?.Reply(message);
                Puts(message);
            }

            if (drillControl)
            {
                var count  = 0;
                var drills = DrillMachine.GetEnumerator();
                while (drills.MoveNext())
                {
                    var drill = drills.Current.Value;

                    if (!drill.isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (drill.GetPowered() == toggle)
                    {
                        continue;
                    }
                    if (!drill.HasFuel)
                    {
                        continue;
                    }

                    drill.SetPoweredServer(toggle);
                    count++;
                }

                var message = toggle ? Lang("Started", player?.Id, count, "drill") : Lang("Stopped", player?.Id, count, "drill");
                player?.Reply(message);
                Puts(message);
            }

            if (fridgeControl)
            {
                var count      = 0;
                var enumerator = FridgeMachine.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    var fridge = enumerator.Current.Value;

                    if (!fridge.isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (fridge.GetPowered() == toggle)
                    {
                        continue;
                    }
                    if (!fridge.HasFuel)
                    {
                        continue;
                    }

                    fridge.SetPoweredServer(toggle);
                    count++;
                }

                var message = toggle ? Lang("Started", player?.Id, count, "fridge") : Lang("Stopped", player?.Id, count, "fridge");
                player?.Reply(message);
                Puts(message);
            }

            state = toggle;
        }