add badge

This commit is contained in:
Naruse
2026-04-29 12:41:45 +08:00
parent 9b8fa5d7c8
commit 5f173ce8d2
2 changed files with 44 additions and 0 deletions

View File

@@ -210,6 +210,7 @@ public class PlayerInstance(PlayerGameData data)
Sex = Data.Gender,
Vigor = Data.Vigor,
Solutions = { LineupManager.LineupData.LineupInfo.Values.Select(x => x.ToProto()) },
Badges = { InventoryManager.InventoryData.Items.Values.Where(x => x.ItemType == ItemTypeEnum.TYPE_BADGE).Select(x => (ulong)x.UniqueId) }
};
foreach (var chara in CharacterManager.CharacterData.Characters) proto.Items.Add(chara.ToProto());

View File

@@ -0,0 +1,43 @@
using MikuSB.Enums.Player;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
[CallGSApi("PlayerSetting_SetShowBadge")]
public class PlayerSetting_SetShowBadge : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var player = connection.Player!;
var req = JsonSerializer.Deserialize<SetShowBadgeParam>(param);
if (req == null)
{
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowBadge", "{\"err\":\"error.BadParam\"}");
return;
}
var slots = new[]
{
ProfileShowItemTypeEnum.SHOWITEM_BADGE1,
ProfileShowItemTypeEnum.SHOWITEM_BADGE2,
ProfileShowItemTypeEnum.SHOWITEM_BADGE3
};
for (int i = 0; i < slots.Length; i++)
{
var uniqueId = i < req.Badges.Count ? req.Badges[i] : 0;
player.SetShowItem((int)slots[i], uniqueId);
}
var sync = new NtfSyncPlayer();
sync.ShowItems.AddRange(player.Data.ShowItems);
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowBadge", "null", sync);
}
}
internal sealed class SetShowBadgeParam
{
[JsonPropertyName("tbBadge")]
public List<uint> Badges { get; set; } = [];
}