CandyNim
Tiller
(This is copy pasted from discord so the `'s are markdown indicators to make it clear I'm quoting variable names, don't feel like removing them)
Bug: Exiting the "waiting for other players" menu in multiplayer from sleeping in a tent permanently heals the player and allows waking up in the morning in locations otherwise banned from placing tents (such as on floors in the skull cavern)
How to reproduce: Load up multiplayer, have one person enter and then exit the tent kit. If they swing a tool, notice the stamina recharging. If they stand idle, notice the eyes closing. If you wait till 2am in the skull caverns, notice how you wake up in the skull caverns.
Code Analysis: When you sleep in a tent, the variable `Game1.player.sleptInTemporaryBed.Value = true;` is set. This is used in `Farmer.Update` which runs `this.isInBed.Value = base.currentLocation.doesTileHaveProperty(base.TilePoint.X, base.TilePoint.Y, "Bed", "Back") != null || (bool)this.sleptInTemporaryBed;`. The variable `isInBed` is used in `Farmer.Update` running `regenTimer` that increases stamina and health. The variable `sleptInTemporaryBed` is used in `GameLocation.CanWakeUpHere` allowing for sleeping in locations that have AllowWakeUpWithoutBed but otherwise ban making a tent.
Possible Solution: `GameLocation.startSleep` has the following code:
```c#
if (Game1.IsMultiplayer)
{
Game1.netReady.SetLocalReady("sleep", ready: true);
Game1.dialogueUp = false;
Game1.activeClickableMenu = new ReadyCheckDialog("sleep", allowCancel: true, delegate
{
this.doSleep();
}, delegate(Farmer who)
{
if (Game1.activeClickableMenu is ReadyCheckDialog readyCheckDialog)
{
readyCheckDialog.closeDialog(who);
}
who.timeWentToBed.Value = 0;
});
}
```
The second delegate is the `OnCancel` action, and all it does is close the dialogue and set the time went to bed to 0. To solve this bug, it should additionally set `sleptInTemporaryBed.Value` to False
Bug: Exiting the "waiting for other players" menu in multiplayer from sleeping in a tent permanently heals the player and allows waking up in the morning in locations otherwise banned from placing tents (such as on floors in the skull cavern)
How to reproduce: Load up multiplayer, have one person enter and then exit the tent kit. If they swing a tool, notice the stamina recharging. If they stand idle, notice the eyes closing. If you wait till 2am in the skull caverns, notice how you wake up in the skull caverns.
Code Analysis: When you sleep in a tent, the variable `Game1.player.sleptInTemporaryBed.Value = true;` is set. This is used in `Farmer.Update` which runs `this.isInBed.Value = base.currentLocation.doesTileHaveProperty(base.TilePoint.X, base.TilePoint.Y, "Bed", "Back") != null || (bool)this.sleptInTemporaryBed;`. The variable `isInBed` is used in `Farmer.Update` running `regenTimer` that increases stamina and health. The variable `sleptInTemporaryBed` is used in `GameLocation.CanWakeUpHere` allowing for sleeping in locations that have AllowWakeUpWithoutBed but otherwise ban making a tent.
Possible Solution: `GameLocation.startSleep` has the following code:
```c#
if (Game1.IsMultiplayer)
{
Game1.netReady.SetLocalReady("sleep", ready: true);
Game1.dialogueUp = false;
Game1.activeClickableMenu = new ReadyCheckDialog("sleep", allowCancel: true, delegate
{
this.doSleep();
}, delegate(Farmer who)
{
if (Game1.activeClickableMenu is ReadyCheckDialog readyCheckDialog)
{
readyCheckDialog.closeDialog(who);
}
who.timeWentToBed.Value = 0;
});
}
```
The second delegate is the `OnCancel` action, and all it does is close the dialogue and set the time went to bed to 0. To solve this bug, it should additionally set `sleptInTemporaryBed.Value` to False