Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix v1.2.0 修复在/times all开启时,第1个玩家进服导致时间快进2分钟BUG
  • Loading branch information
1242509682 committed Oct 25, 2024
commit fd8da95690c95668c773f4e7666f995c49e2f390
4 changes: 4 additions & 0 deletions src/TimeRate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
## 更新日志

```
v1.2.0
修复当服务器没人且/times all正在开启时,
第一个玩家进入服务器导致时间快进1到2分钟的BUG。

v1.1.0
美化了菜单
优化了性能(不再发WorldInfo包)
Expand Down
4 changes: 4 additions & 0 deletions src/TimeRate/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
## Changelog

```
v1.2.0
Fixed a bug that when the server is empty and the command '/times all' is enabled,
the game time fast-forwards by 1 to 2 minutes when the first player joins the server."

v1.1.0
Improved the menu aesthetics.
Optimized performance (no longer sends WorldInfo packets).
Expand Down
20 changes: 7 additions & 13 deletions src/TimeRate/TimeRate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TimeRate : TerrariaPlugin
#region 插件信息
public override string Name => "时间加速";
public override string Author => "羽学";
public override Version Version => new Version(1, 1, 0);
public override Version Version => new Version(1, 2, 0);
public override string Description => "涡轮增压不蒸鸭";
#endregion

Expand Down Expand Up @@ -60,6 +60,8 @@ private void UpdateTimeRate(On.Terraria.Main.orig_UpdateTimeRate orig)

// 获取所有在线玩家
var plr = TShock.Players.Where(plr => plr != null && plr.Active && plr.IsLoggedIn);
var plrCount = plr.Count();

//是否全部玩家睡觉
var all = plr.All(plr => plr.TPlayer.sleeping.isSleeping);
//是否任意1人睡觉
Expand All @@ -68,22 +70,14 @@ private void UpdateTimeRate(On.Terraria.Main.orig_UpdateTimeRate orig)
//用标识决定是否发包优化时间流逝视觉
var Update = false;

if (Config.Enabled || (all && Config.All) || (one && Config.One))
if (plrCount > 0 && (Config.Enabled || (all && Config.All) || (one && Config.One)) || plrCount == 0)
{
// 设置时间加速
if (Terraria.Main.dayRate != Config.UpdateRate)
{
Update = true;
Terraria.Main.dayRate = Config.UpdateRate;
}
}
var Rate = plrCount > 0 && (Config.Enabled || (all && Config.All) || (one && Config.One)) ? Config.UpdateRate : 1;

else // 设置默认时间速率
{
if (Terraria.Main.dayRate != 1)
if (Terraria.Main.dayRate != Rate)
{
Update = true;
Terraria.Main.dayRate = 1;
Terraria.Main.dayRate = Rate;
}
}

Expand Down