Attempt to fix time accel on server

Part of #5
This commit is contained in:
zontreck 2025-05-03 13:57:36 -07:00
parent e56a123cb8
commit 12d10a9a3c
4 changed files with 8 additions and 58 deletions

View file

@ -15,21 +15,5 @@ public class ASUModClient : ModSystem
public override void StartClientSide(ICoreClientAPI api)
{
CAPI = api;
api.Network.RegisterChannel("asutimeaccel")
.RegisterMessageType<ASUTimeAcceleration>()
.SetMessageHandler<ASUTimeAcceleration>(onReceiveTimeAccel);
}
private void onReceiveTimeAccel(ASUTimeAcceleration packet)
{
// Time acceleration handler
accel = packet.Sleeping;
CAPI.Logger.Notification("Time acceleration: " + packet.Sleeping);
if (accel)
{
CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000);
}
else CAPI.World.Calendar.RemoveTimeSpeedModifier("asu_psp");
}
}

View file

@ -96,10 +96,6 @@ namespace AriasServerUtils
//api.Event.PlayerLeave += OnPlayerDC;
ServerNetworkChannel = api.Network.RegisterChannel("asutimeaccel")
.RegisterMessageType<ASUTimeAcceleration>();
api.ChatCommands.Create("setspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleSetSpawn);
api.ChatCommands.Create("spawn").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSpawn);
@ -273,18 +269,15 @@ namespace AriasServerUtils
{
Hours = API.World.Calendar.TotalHours;
SleepingPlayers.Add(isp.Entity);
API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}");
EntityAgent Agent = isp.Entity;
EntityBehaviorTiredness ebt = Agent.GetBehavior("tiredness") as EntityBehaviorTiredness;
EntityBehaviorTiredness ebt = Agent.GetBehavior<EntityBehaviorTiredness>();
ebt.IsSleeping = true;
ebt.Tiredness = 100;
Sleeping = true;
ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration
{
Sleeping = true
});
API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000);
}
@ -307,11 +300,6 @@ namespace AriasServerUtils
OriginalSpeed = 0.5f;
ebt.IsSleeping = true;
ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration
{
Sleeping = true
});
API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000);
SendMessageTo(isp, "Applied calendar speed multiplier");
@ -322,11 +310,6 @@ namespace AriasServerUtils
OriginalSpeed = 0;
ebt.IsSleeping = false;
ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration
{
Sleeping = false
});
API.World.Calendar.RemoveTimeSpeedModifier("asu_psp");
SendMessageTo(isp, "Restored default calendar speed");
@ -341,7 +324,8 @@ namespace AriasServerUtils
if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server!
if (Sleeping)
{
if (API.World.Calendar.TotalHours - Hours >= 7)
API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}");
if (API.World.Calendar.TotalHours - Hours >= 6)
{
Sleeping = false;
foreach (var player in SleepingPlayers)
@ -353,12 +337,6 @@ namespace AriasServerUtils
SleepingPlayers.Clear();
ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration
{
Sleeping = false
});
API.World.Calendar.RemoveTimeSpeedModifier("asu_psp");
API.Logger.Notification("Stopping PSP Time Acceleration");
@ -407,11 +385,6 @@ namespace AriasServerUtils
if (Percentage >= config.PlayerSleepingPercentage)
{
ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration
{
Sleeping = true
});
API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000);
// Call the API to make sleep happen

View file

@ -3,8 +3,8 @@
"modid": "ariasserverutils",
"name": "Aria's Server Utilities",
"authors": ["zontreck"],
"description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:53 PM MST",
"version": "1.0.10-dev.3",
"description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 1:56 PM MST",
"version": "1.0.10-dev.9",
"dependencies": {
"game": ""
}

View file

@ -1,7 +0,0 @@
using System;
[Serializable]
public class ASUTimeAcceleration
{
public bool Sleeping = false;
}