diff --git a/Communication/Messages/Incoming/Inventory/Purse/GetCreditsInfoEvent.cs b/Communication/Messages/Incoming/Inventory/Purse/GetCreditsInfoEvent.cs new file mode 100644 index 0000000..0e47365 --- /dev/null +++ b/Communication/Messages/Incoming/Inventory/Purse/GetCreditsInfoEvent.cs @@ -0,0 +1,30 @@ +using Tiger.Communication.Messages.Interfaces; +using Tiger.Communication.Messages.Outgoing.Notifications; +using Tiger.Communication.Messages.Outgoing.Users; +using Tiger.Communication.Messages.Types; +using Tiger.Networking.Game.Sessions; + +namespace Tiger.Communication.Messages.Incoming.Inventory.Purse; + +public class GetCreditsInfoEvent : IMessageEvent +{ + private readonly IGameSessionManager _gameSessionManager; + + public GetCreditsInfoEvent(IGameSessionManager gameSessionManager) + { + _gameSessionManager = gameSessionManager; + } + + public IncomingHeaders Header => IncomingHeaders.GetCreditsInfoEvent; + public async Task HandleAsync(GameSession gameSession, ClientMessage request) + { + if (gameSession.Habbo == null) + { + await _gameSessionManager.CloseAsync("Not logged in", gameSession); + return; + } + + await gameSession.SendComposerAsync(new CreditBalanceComposer(gameSession.Habbo.Credits)); + await gameSession.SendComposerAsync(new ActivityPointsComposer(gameSession.Habbo.Activitypoints ?? null)); + } +} \ No newline at end of file diff --git a/Communication/Messages/Outgoing/Notifications/ActivityPointsComposer.cs b/Communication/Messages/Outgoing/Notifications/ActivityPointsComposer.cs new file mode 100644 index 0000000..9bd3390 --- /dev/null +++ b/Communication/Messages/Outgoing/Notifications/ActivityPointsComposer.cs @@ -0,0 +1,29 @@ +using Tiger.Communication.Messages.Interfaces; +using Tiger.Communication.Messages.Types; +using Tiger.Game.Habbos; + +namespace Tiger.Communication.Messages.Outgoing.Notifications; + +public class ActivityPointsComposer : IMessageComposer +{ + private readonly IEnumerable? _activitypoints; + + public ActivityPointsComposer(IEnumerable? activitypoints) + { + _activitypoints = activitypoints; + } + + public OutgoingHeaders Header => OutgoingHeaders.ActivityPointsMessageComposer; + public void Compose(ServerMessage message) + { + message.AppendInt32(_activitypoints?.Count() ?? 0); + + if (_activitypoints == null) return; + + foreach (var activitypoint in _activitypoints) + { + message.AppendInt32(activitypoint.Type); + message.AppendUInt32(activitypoint.Amount); + } + } +} \ No newline at end of file diff --git a/Communication/Messages/Outgoing/Users/CreditBalanceComposer.cs b/Communication/Messages/Outgoing/Users/CreditBalanceComposer.cs new file mode 100644 index 0000000..5040a35 --- /dev/null +++ b/Communication/Messages/Outgoing/Users/CreditBalanceComposer.cs @@ -0,0 +1,20 @@ +using Tiger.Communication.Messages.Interfaces; +using Tiger.Communication.Messages.Types; + +namespace Tiger.Communication.Messages.Outgoing.Users; + +public class CreditBalanceComposer : IMessageComposer +{ + private readonly uint _credits; + + public CreditBalanceComposer(uint credits) + { + _credits = credits; + } + + public OutgoingHeaders Header => OutgoingHeaders.CreditBalanceComposer; + public void Compose(ServerMessage message) + { + message.AppendString($"{_credits}.0"); + } +} \ No newline at end of file diff --git a/Game/Habbos/Activitypoints.cs b/Game/Habbos/Activitypoints.cs new file mode 100644 index 0000000..caa37fe --- /dev/null +++ b/Game/Habbos/Activitypoints.cs @@ -0,0 +1,27 @@ +namespace Tiger.Game.Habbos; + +public class Activitypoints +{ + public virtual Habbo Habbo { get; set; } = null!; + public virtual byte Type { get; set; } + public virtual uint Amount { get; set; } + + public override bool Equals(object? obj) + { + if (obj is not Activitypoints other) + return false; + + return Habbo.Id == other.Habbo.Id && Type == other.Type; + } + + public override int GetHashCode() + { + unchecked + { + var hash = 17; + hash = hash * 23 + Habbo.Id.GetHashCode(); + hash = hash * 23 + Type.GetHashCode(); + return hash; + } + } +} \ No newline at end of file diff --git a/Game/Habbos/ActivitypointsMap.cs b/Game/Habbos/ActivitypointsMap.cs new file mode 100644 index 0000000..b6b6934 --- /dev/null +++ b/Game/Habbos/ActivitypointsMap.cs @@ -0,0 +1,16 @@ +using FluentNHibernate.Mapping; + +namespace Tiger.Game.Habbos; + +public class ActivitypointsMap : ClassMap +{ + public ActivitypointsMap() + { + Table("habbo_activitypoints"); + LazyLoad(); + CompositeId() + .KeyProperty(h => h.Type, "type") + .KeyReference(h => h.Habbo, "habbo_id"); + Map(h => h.Amount).Column("amount").Not.Nullable(); + } +} \ No newline at end of file diff --git a/Game/Habbos/Habbo.cs b/Game/Habbos/Habbo.cs index f31cfd9..883f092 100644 --- a/Game/Habbos/Habbo.cs +++ b/Game/Habbos/Habbo.cs @@ -17,4 +17,5 @@ public class Habbo public virtual uint AchievementScore { get; set; } public virtual uint? GroupId { get; set; } public virtual string? SsoTicket { get; set; } + public virtual IEnumerable? Activitypoints { get; set; } } \ No newline at end of file diff --git a/Game/Habbos/HabboMap.cs b/Game/Habbos/HabboMap.cs index 58a66e6..71211ce 100644 --- a/Game/Habbos/HabboMap.cs +++ b/Game/Habbos/HabboMap.cs @@ -23,5 +23,6 @@ public class HabboMap : ClassMap Map(h => h.AchievementScore).Column("achievement_score").Not.Nullable(); Map(h => h.GroupId).Column("group_id").Nullable(); Map(h => h.SsoTicket).Column("sso_ticket").Nullable(); + HasMany(h => h.Activitypoints).LazyLoad().Inverse().Cascade.All(); } } \ No newline at end of file diff --git a/TigerEmu.csproj b/TigerEmu.csproj index 2fedcd8..29e06e8 100644 --- a/TigerEmu.csproj +++ b/TigerEmu.csproj @@ -26,4 +26,7 @@ PreserveNewest + + +