feat: Converts OnLogin to a coded generated event (#2070)

This commit is contained in:
Kamron Batman 2025-01-17 15:21:45 -08:00 • committed by GitHub
parent 3b698de556
commit 66a257ece2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 127 additions and 122 deletions

View file

@ -1,5 +1,7 @@
using System;
using ModernUO.CodeGeneratedEvents;
using Server.Items;
using Server.Mobiles;
using Server.Network;
namespace Server
@ -55,10 +57,8 @@ namespace Server
}
}
public static void OnLogin(Mobile m)
{
m.CheckLightLevels(true);
}
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm) => pm.CheckLightLevels(true);
public static int ComputeLevelFor(Mobile from)
{

View file

@ -1,17 +1,18 @@
using Server.Mobiles;
using Server.Network;
namespace Server.Misc
{
public static class LoginStats
{
public static void OnLogin(Mobile m)
public static void OnLogin(PlayerMobile pm)
{
var userCount = NetState.Instances.Count;
var itemCount = World.Items.Count;
var mobileCount = World.Mobiles.Count;
m.SendMessage(
$"Welcome, {m.Name}! There {(userCount == 1 ? "is" : "are")} currently {userCount} user{(userCount == 1 ? "" : "s")} " +
pm.SendMessage(
$"Welcome, {pm.Name}! There {(userCount == 1 ? "is" : "are")} currently {userCount} user{(userCount == 1 ? "" : "s")} " +
$"online, with {itemCount} item{(itemCount == 1 ? "" : "s")} and {mobileCount} mobile{(mobileCount == 1 ? "" : "s")} in the world."
);
}

View file

@ -2,8 +2,10 @@ using System;
using System.Collections.Generic;
using System.Net;
using System.Text.RegularExpressions;
using ModernUO.CodeGeneratedEvents;
using ModernUO.Serialization;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
using Server.Prompts;
@ -125,14 +127,15 @@ public partial class ShardPoller : Item
Options[^1] = option;
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
if (_activePollers.Count == 0)
{
return;
}
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => EventSink_Login_Callback(m));
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => EventSink_Login_Callback(pm));
}
private static void EventSink_Login_Callback(Mobile from)

View file

@ -82,17 +82,19 @@ public static class StaminaSystem
RemoveEntry(m as IHasSteps);
}
public static void OnLogin(Mobile m)
[OnEvent(nameof(PlayerMobile.PlayerLoginEvent))]
public static void OnLogin(PlayerMobile pm)
{
bool exists;
if (EnableMountStamina)
{
// Start idle for mount
ref var stepsTaken = ref GetStepsTaken(m.Mount, out var exists);
ref var stepsTaken = ref GetStepsTaken(pm.Mount, out exists);
if (exists)
{
if (stepsTaken.Steps <= 0 || Core.Now >= stepsTaken.IdleStartTime + ResetDuration)
{
_stepsTaken.Remove(m.Mount);
_stepsTaken.Remove(pm.Mount);
}
else
{
@ -100,16 +102,13 @@ public static class StaminaSystem
}
}
_resetHash.Remove(m.Mount);
_resetHash.Remove(pm.Mount);
}
if (m is PlayerMobile pm)
ref var regenStepsTaken = ref RegenSteps(pm, out exists);
if (exists)
{
ref var stepsTaken = ref RegenSteps(pm, out var exists);
if (exists)
{
stepsTaken.IdleStartTime = Core.Now;
}
regenStepsTaken.IdleStartTime = Core.Now;
}
}