framework to hepl when managing gacha system

This commit is contained in:
rfi 2023-12-19 21:29:56 +07:00
parent 2e8eee0977
commit 770e8fe8e1
4 changed files with 142 additions and 21 deletions

View File

@ -0,0 +1,34 @@
using MessagePack;
namespace AscNet.GameServer
{
#region MsgPackScheme
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
[MessagePackObject(true)]
public class SweepRequest
{
public int StageId { get; set; }
public int Count { get; set; }
}
[MessagePackObject(true)]
public class SweepResponse
{
public int Code { get; set; }
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#endregion
internal class AutoFightModule
{
[RequestPacketHandler("SweepRequest")]
public static void SweepRequestHandler(Session session, Packet.Request packet)
{
// TODO: Export FightSettle handler to another a function that can be used by this guy too
SweepRequest request = packet.Deserialize<SweepRequest>();
session.SendResponse(new SweepResponse() { Code = 1 }, packet.Id);
}
}
}

View File

@ -0,0 +1,80 @@
using AscNet.Common.Database;
using AscNet.Common.Util;
using AscNet.GameServer.Handlers;
using AscNet.Table.V2.client.draw;
using AscNet.Table.V2.share.character;
namespace AscNet.GameServer.Game
{
internal class DrawManager
{
public static readonly List<DrawSceneTable> drawSceneTables = TableReaderV2.Parse<DrawSceneTable>();
public static readonly List<CharacterTable> charactersTables = TableReaderV2.Parse<CharacterTable>();
#region DrawTags
public const int TagBase = 1;
public const int TagEvent = 2;
public const int TagSpecialEvent = 3;
public const int TagTargetUniframe = 4;
public const int TagCollab = 5;
public const int TagEndlessSummerBlue = 6;
public const int TagCUB = 7;
#endregion
#region Groups
public const int GroupMemberTarget = 1;
public const int GroupWeaponResearch = 2;
public const int GroupTargetWeaponResearch = 4;
public const int GroupDormitoryResearch = 6;
public const int GroupThemedTargetWeapon = 10;
public const int GroupThemedEventConstruct = 11;
public const int GroupArrivalConstruct = 12;
public const int GroupFateArrivalConstruct = 13;
public const int GroupArrivalEventConstruct = 14;
public const int GroupFateThemedConstruct = 15;
public const int GroupTargetUniframe = 16;
public const int GroupAnniversary = 17;
public const int GroupFateAnniversaryLimited = 18;
public const int GroupCollabTarget = 19;
public const int GroupFateCollabTarget = 20;
public const int GroupCollabWeaponTarget = 21;
public const int GroupCUBTarget = 22;
public const int GroupWishingTarget = 23;
public const int GroupFateWishingTarget = 24;
#endregion
private readonly Dictionary<int, int> selectedDrawUp = new();
public void SetUpDrawByGroupId(int groupId, int drawId)
{
if (selectedDrawUp.ContainsKey(groupId))
selectedDrawUp[groupId] = drawId;
else
selectedDrawUp.Add(groupId, drawId);
}
public static List<DrawInfo> GetDrawInfosByGroup(int groupId)
{
List<DrawInfo> infos = new();
switch (groupId)
{
case GroupArrivalConstruct:
// Querying every character scene that is omniframe.
infos.AddRange(drawSceneTables.Where(x => x.Type == 1 && charactersTables.Any(y => y.Type == 1 && y.Id == x.ModelId)).DistinctBy(x => x.ModelId).Select(x => new DrawInfo()
{
Id = x.Id,
UseItemId = Inventory.FreeGem,
UseItemCount = 1,
GroupId = 12,
BtnDrawCount = { 1, 10 },
Banner = "Assets/Product/Ui/Scene3DPrefab/UiMain3dXiahuo.prefab",
EndTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2
}));
break;
}
return infos;
}
}
}

View File

@ -1,4 +1,9 @@
using MessagePack; using AscNet.Common.Database;
using AscNet.Common.Util;
using AscNet.GameServer.Game;
using AscNet.Table.V2.client.draw;
using MessagePack;
using static AscNet.GameServer.Packet;
namespace AscNet.GameServer.Handlers namespace AscNet.GameServer.Handlers
{ {
@ -51,6 +56,12 @@ namespace AscNet.GameServer.Handlers
public long StartTime { get; set; } public long StartTime { get; set; }
public long EndTime { get; set; } public long EndTime { get; set; }
} }
[MessagePackObject(true)]
public class DrawGetDrawInfoListRequest
{
public int GroupId { get; set; }
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#endregion #endregion
@ -60,16 +71,19 @@ namespace AscNet.GameServer.Handlers
public static void DrawGetDrawGroupListRequestHandler(Session session, Packet.Request packet) public static void DrawGetDrawGroupListRequestHandler(Session session, Packet.Request packet)
{ {
var rsp = new DrawGetDrawGroupListResponse(); var rsp = new DrawGetDrawGroupListResponse();
rsp.DrawGroupInfoList.Add(new()
{ {
Id = 1, var drawInfos = DrawManager.GetDrawInfosByGroup(DrawManager.GroupArrivalConstruct);
SwitchDrawIdCount = 1, rsp.DrawGroupInfoList.Add(new()
UseDrawId = 1, {
Order = 1, Id = DrawManager.GroupArrivalConstruct,
Tag = 1, UseDrawId = drawInfos.Count > 0 ? drawInfos.First().Id : 0,
EndTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2, Order = 1,
BannerEndTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2 Tag = DrawManager.TagEvent,
}); EndTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2,
BannerEndTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2
});
}
session.SendResponse(rsp, packet.Id); session.SendResponse(rsp, packet.Id);
} }
@ -77,17 +91,10 @@ namespace AscNet.GameServer.Handlers
[RequestPacketHandler("DrawGetDrawInfoListRequest")] [RequestPacketHandler("DrawGetDrawInfoListRequest")]
public static void DrawGetDrawInfoListRequestHandler(Session session, Packet.Request packet) public static void DrawGetDrawInfoListRequestHandler(Session session, Packet.Request packet)
{ {
DrawGetDrawInfoListRequest request = packet.Deserialize<DrawGetDrawInfoListRequest>();
DrawGetDrawInfoListResponse rsp = new(); DrawGetDrawInfoListResponse rsp = new();
rsp.DrawInfoList.Add(new() rsp.DrawInfoList.AddRange(DrawManager.GetDrawInfosByGroup(request.GroupId));
{
Id = 101,
UseItemId = 1,
UseItemCount = 10,
GroupId = 1,
BtnDrawCount = { 1, 10 },
Banner = "Assets/Product/Ui/Scene3DPrefab/UiMain3dWuqi.prefab",
EndTime = DateTimeOffset.Now.ToUnixTimeSeconds() * 2
});
session.SendResponse(rsp, packet.Id); session.SendResponse(rsp, packet.Id);
} }

View File

@ -306,7 +306,7 @@ namespace AscNet.GameServer.Handlers
public static void FightSettleRequestHandler(Session session, Packet.Request packet) public static void FightSettleRequestHandler(Session session, Packet.Request packet)
{ {
FightSettleRequest req = MessagePackSerializer.Deserialize<FightSettleRequest>(packet.Content); FightSettleRequest req = MessagePackSerializer.Deserialize<FightSettleRequest>(packet.Content);
Table.V2.share.fuben.StageTable? stageTable = TableReaderV2.Parse<Table.V2.share.fuben.StageTable>().FirstOrDefault(x => x.StageId == req.Result.StageId); StageTable? stageTable = TableReaderV2.Parse<StageTable>().FirstOrDefault(x => x.StageId == req.Result.StageId);
if (stageTable is null) if (stageTable is null)
{ {
// FightCheckManagerSettleCodeNotMatch // FightCheckManagerSettleCodeNotMatch