Пример #1
0
        internal void ToggleBed(string command, string[] args)
        {
            string MethodName = MethodBase.GetCurrentMethod().GetCustomAttribute <CommandName>().Name;

            if (!Game1.IsMasterGame) // We aren't the host
            {
                ModEntry.LogError(Translation.GetString("command.failed.nothost"));
                return;
            }

            if (args.Length == 0 || args.Length > 2)
            {
                CallHelp(MethodName);
            }
            else
            {
                string FarmerName = args[0];
                Farmer Who        = ModEntry.Config.GetCurrentFarm().GetFarmer(FarmerName);
                if (Who is null)
                {
                    ModEntry.LogError(Translation.GetString("error.farmernamenotfound", new { FarmerName }));
                    return;
                }

                bool DoLeft  = false;
                bool DoRight = false;

                if (args.Length == 1)
                {
                    DoLeft  = true;
                    DoRight = true;
                }
                else
                {
                    if (args[1].Equals("left", StringComparison.OrdinalIgnoreCase))
                    {
                        DoLeft = true;
                    }
                    else if (args[1].Equals("right", StringComparison.OrdinalIgnoreCase))
                    {
                        DoRight = true;
                    }
                    else
                    {
                        CallHelp(MethodName);
                        return;
                    }
                }
                Bed bedData = 0;
                if (DoLeft)
                {
                    Who.ToggleLeftBed();
                    bedData |= Bed.LEFT;
                    ModEntry.Log(Translation.GetString("command.togglebed.left.toggledo" + (Who.ShowLeftBed ? "n" : "ff"), new { FarmerName }));
                }
                if (DoRight)
                {
                    Who.ToggleRightBed();
                    bedData |= Bed.RIGHT;
                    ModEntry.Log(Translation.GetString("command.togglebed.right.toggledo" + (Who.ShowRightBed ? "n" : "ff"), new { FarmerName }));
                }

                if (DoLeft || DoRight)
                {
                    Multiplayer.TogglePacket packet = new Multiplayer.TogglePacket(FarmerName, bedData);
                    Helper.Multiplayer.SendMessage(packet, Multiplayer.TogglePacket.StringType, new[] { Helper.ModRegistry.ModID });
                    ModEntry.Config.Save();
                }
            }
        }