forked from PGR/ascnet
1
0
Fork 0

gather reward partial impl

This commit is contained in:
rfi 2023-12-07 22:56:45 +07:00
parent 5824edbf4f
commit fce32e4d72
3 changed files with 86 additions and 0 deletions

View File

@ -109,6 +109,9 @@ namespace AscNet.Common.Database
[BsonRequired] [BsonRequired]
public List<HeadPortraitList> HeadPortraits { get; set; } public List<HeadPortraitList> HeadPortraits { get; set; }
[BsonElement("gather_rewards")]
public List<int> GatherRewards { get; set; } = new();
[BsonElement("team_groups")] [BsonElement("team_groups")]
[BsonRequired] [BsonRequired]
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)]

View File

@ -1025,6 +1025,13 @@ namespace AscNet.Common.MsgPack
} }
[global::MessagePack.MessagePackObject(true)]
public class NotifyGatherReward
{
public Int32 Id { get; set; }
}
[global::MessagePack.MessagePackObject(true)] [global::MessagePack.MessagePackObject(true)]
public class NotifyDrawTicketData public class NotifyDrawTicketData
{ {

View File

@ -0,0 +1,76 @@
using MessagePack;
using AscNet.Common.MsgPack;
using AscNet.Table.V2.share.exhibition;
using AscNet.Common.Util;
using AscNet.Table.V2.share.reward;
namespace AscNet.GameServer.Handlers
{
#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 GatherRewardRequest
{
public int Id;
}
[MessagePackObject(true)]
public class GatherRewardResponse
{
public int Code;
public List<RewardGoods> RewardGoods { get; set; } = new();
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#endregion
internal class ExhibitionModule
{
[RequestPacketHandler("GatherRewardRequest")]
public static void HandleGatherRewardRequestHandler(Session session, Packet.Request packet)
{
GatherRewardRequest req = MessagePackSerializer.Deserialize<GatherRewardRequest>(packet.Content);
ExhibitionRewardTable? exhibitionReward = TableReaderV2.Parse<ExhibitionRewardTable>().Find(x => x.Id == req.Id);
IEnumerable<RewardGoodsTable> rewards = TableReaderV2.Parse<RewardGoodsTable>().Where(x => (TableReaderV2.Parse<RewardTable>().Find(x => x.Id == exhibitionReward?.RewardId)?.SubIds ?? new List<int>()).Contains(x.Id));
GatherRewardResponse rsp = new();
foreach (var rewardGoods in rewards)
{
int rewardTypeVal = (int)MathF.Floor((rewardGoods.TemplateId > 0 ? rewardGoods.TemplateId : rewardGoods.Id) / 1000000) + 1;
RewardType rewardType = RewardType.Item;
try
{
rewardType = (RewardType)Enum.ToObject(typeof(RewardType), rewardTypeVal);
}
catch (Exception)
{
session.log.Error($"Failed to convert {rewardTypeVal} to {nameof(RewardType)} enum object!");
}
rsp.RewardGoods.Add(new()
{
Id = rewardGoods.Id,
TemplateId = rewardGoods.TemplateId,
Count = rewardGoods.Count,
RewardType = rewardTypeVal
});
switch (rewardType)
{
case RewardType.Item:
NotifyItemDataList notifyItemData = new()
{
ItemDataList = { session.inventory.Do(rewardGoods.TemplateId, rewardGoods.Count) }
};
session.SendPush(notifyItemData);
break;
default:
break;
}
}
session.player.GatherRewards.Add(req.Id);
session.SendPush(new NotifyGatherReward() { Id = req.Id });
session.SendResponse(rsp, packet.Id);
}
}
}