mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 21:13:59 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e62fcc9b2 | ||
|
|
f4ad74e00d | ||
|
|
ccdfbee828 | ||
|
|
5d0f587fb9 | ||
|
|
94f972ff82 | ||
|
|
1b4f3531d1 |
32
Common/Data/Excel/SupportCardExcel.cs
Normal file
32
Common/Data/Excel/SupportCardExcel.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("support_card.json")]
|
||||
public class SupportCardExcel : ExcelResource
|
||||
{
|
||||
public uint Genre { get; set; }
|
||||
public uint Detail { get; set; }
|
||||
public uint Particular { get; set; }
|
||||
public uint Level { get; set; }
|
||||
public uint Icon { get; set; }
|
||||
public uint ProvideExp { get; set; }
|
||||
[JsonProperty("LevelLimitID")] public int LevelLimitId { get; set; }
|
||||
|
||||
public uint MaxLevel => LevelLimitId switch
|
||||
{
|
||||
1007 => 10,
|
||||
1008 => 13,
|
||||
1009 => 16,
|
||||
_ => 10
|
||||
};
|
||||
|
||||
public ulong TemplateId => GameResourceTemplateId.FromGdpl(Genre, Detail, Particular, Level);
|
||||
|
||||
public override uint GetId() => Icon;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.SupportCardData.Add(this);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public static class GameData
|
||||
public static Dictionary<uint, Rogue3DDifficultExcel> Rogue3DDifficultData { get; private set; } = [];
|
||||
public static Dictionary<uint, SpineExcel> SpineData { get; private set; } = [];
|
||||
public static Dictionary<uint, NodeConditionExcel> NodeConditionData { get; private set; } = [];
|
||||
public static List<SupportCardExcel> SupportCardData { get; private set; } = [];
|
||||
}
|
||||
|
||||
public static class GameResourceTemplateId
|
||||
|
||||
@@ -28,6 +28,8 @@ public class CharacterInfo
|
||||
[SugarColumn(IsJson = true)] public List<uint> UnlockedSkin { get; set; } = [];
|
||||
[SugarColumn(IsJson = true)] public List<uint> Spines { get; set; } = [];
|
||||
[SugarColumn(IsJson = true)] public List<uint> Affixs { get; set; } = [];
|
||||
// Key = EqSlot (= support card Detail), Value = support card UniqueId
|
||||
[SugarColumn(IsJson = true)] public Dictionary<uint, uint> SupportSlots { get; set; } = [];
|
||||
public long Timestamp { get; set; }
|
||||
public uint Count { get; set; } = 1;
|
||||
|
||||
@@ -55,6 +57,8 @@ public class CharacterInfo
|
||||
|
||||
proto.Slots[4] = WeaponUniqueId;
|
||||
proto.Slots[5] = SkinId;
|
||||
foreach (var (slot, uid) in SupportSlots)
|
||||
proto.Slots[slot] = uid;
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
@@ -26,24 +26,29 @@ public class BaseGameItemInfo
|
||||
public uint ItemCount { get; set; }
|
||||
public ItemTypeEnum ItemType { get; set; }
|
||||
public ItemFlagEnum Flag { get; set; } = ItemFlagEnum.FLAG_READED;
|
||||
public uint Level { get; set; }
|
||||
public uint Exp { get; set; }
|
||||
|
||||
public virtual Item ToProto()
|
||||
{
|
||||
return new Item
|
||||
var proto = new Item
|
||||
{
|
||||
Id = UniqueId,
|
||||
Template = TemplateId,
|
||||
Count = ItemCount,
|
||||
Flag = (uint)Flag
|
||||
};
|
||||
if (Level > 0 || Exp > 0)
|
||||
proto.Enhance = new Enhance { Level = Level, Exp = Exp };
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class GrowableItemInfo : BaseGameItemInfo
|
||||
{
|
||||
public bool IsLocked { get; set; }
|
||||
public uint Level { get; set; }
|
||||
public uint Exp { get; set; }
|
||||
public new uint Level { get; set; }
|
||||
public new uint Exp { get; set; }
|
||||
public uint Break { get; set; }
|
||||
public uint EquipAvatarId { get; set; }
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace MikuSB.Database.Player;
|
||||
[SugarTable("Player")]
|
||||
public class PlayerGameData : BaseDatabaseDataHelper
|
||||
{
|
||||
public const string DefaultDisplayName = "Miku";
|
||||
|
||||
public string? Name { get; set; } = "";
|
||||
public string? Signature { get; set; } = "MikuPS";
|
||||
public uint Level { get; set; } = 100;
|
||||
@@ -25,13 +27,30 @@ public class PlayerGameData : BaseDatabaseDataHelper
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string NormalizeDisplayName(string? name)
|
||||
{
|
||||
var normalized = name?.Trim();
|
||||
return string.IsNullOrWhiteSpace(normalized) ? DefaultDisplayName : normalized;
|
||||
}
|
||||
|
||||
public bool EnsureDisplayName()
|
||||
{
|
||||
var normalized = NormalizeDisplayName(Name);
|
||||
if (string.Equals(Name, normalized, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
Name = normalized;
|
||||
return true;
|
||||
}
|
||||
|
||||
public PlayerProfile ToProfileProto()
|
||||
{
|
||||
var displayName = NormalizeDisplayName(Name);
|
||||
var proto = new PlayerProfile
|
||||
{
|
||||
Pid = (uint)Uid,
|
||||
Account = Name,
|
||||
Name = Name,
|
||||
Account = displayName,
|
||||
Name = displayName,
|
||||
Level = Level,
|
||||
Sex = Gender,
|
||||
Sign = Signature,
|
||||
|
||||
@@ -110,6 +110,26 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
|
||||
return arInfo;
|
||||
}
|
||||
|
||||
public async ValueTask<BaseGameItemInfo?> AddSupportCardItem(uint detail, uint particular, uint level = 1, bool sendPacket = true)
|
||||
{
|
||||
const ItemTypeEnum genre = ItemTypeEnum.TYPE_SUPPORT;
|
||||
var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level);
|
||||
if (InventoryData.Items.Values.Any(x => x.TemplateId == templateId)) return null;
|
||||
|
||||
var info = new BaseGameItemInfo
|
||||
{
|
||||
TemplateId = templateId,
|
||||
UniqueId = InventoryData.NextUniqueUid++,
|
||||
ItemType = genre,
|
||||
ItemCount = 1
|
||||
};
|
||||
InventoryData.Items[info.UniqueId] = info;
|
||||
|
||||
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([info]));
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public async ValueTask<BaseGameItemInfo?> AddManifestationItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
|
||||
{
|
||||
if (genre != ItemTypeEnum.TYPE_MANIFESTATION) return null;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class PlayerInstance(PlayerGameData data)
|
||||
{
|
||||
// new player
|
||||
IsNewPlayer = true;
|
||||
Data.Name = AccountData.GetAccountByUid(uid)?.Username;
|
||||
Data.Name = PlayerGameData.NormalizeDisplayName(AccountData.GetAccountByUid(uid)?.Username);
|
||||
|
||||
DatabaseHelper.CreateInstance(Data);
|
||||
|
||||
@@ -66,6 +66,10 @@ public class PlayerInstance(PlayerGameData data)
|
||||
{
|
||||
await CharacterManager.AddCharacter((ItemTypeEnum)card.Genre, card.Detail, card.Particular, card.Level, sendPacket:false);
|
||||
}
|
||||
foreach (var sc in GameData.SupportCardData)
|
||||
{
|
||||
await InventoryManager.AddSupportCardItem(sc.Detail, sc.Particular, sc.Level, sendPacket: false);
|
||||
}
|
||||
foreach (var supplies in GameData.AllSuppliesData)
|
||||
{
|
||||
await InventoryManager.AddSuppliesItem(supplies, 90000, false);
|
||||
@@ -134,6 +138,7 @@ public class PlayerInstance(PlayerGameData data)
|
||||
public async ValueTask OnEnterGame()
|
||||
{
|
||||
if (!Initialized) await InitialPlayerManager();
|
||||
Data.EnsureDisplayName();
|
||||
await CharacterManager.RepairCharacterWeapons();
|
||||
await EnsureSupplies();
|
||||
}
|
||||
@@ -225,12 +230,13 @@ public class PlayerInstance(PlayerGameData data)
|
||||
|
||||
public Proto.Player ToPlayerProto()
|
||||
{
|
||||
var displayName = PlayerGameData.NormalizeDisplayName(Data.Name);
|
||||
var proto = new Proto.Player
|
||||
{
|
||||
Pid = (ulong)Data.Uid,
|
||||
Account = Data.Name,
|
||||
Provider = Data.Name,
|
||||
Name = Data.Name,
|
||||
Account = displayName,
|
||||
Provider = displayName,
|
||||
Name = displayName,
|
||||
Level = Data.Level,
|
||||
Sex = Data.Gender,
|
||||
Vigor = Data.Vigor,
|
||||
@@ -259,6 +265,11 @@ public class PlayerInstance(PlayerGameData data)
|
||||
return proto;
|
||||
}
|
||||
|
||||
public void SetDisplayName(string? name)
|
||||
{
|
||||
Data.Name = PlayerGameData.NormalizeDisplayName(name);
|
||||
}
|
||||
|
||||
public void SetShowItem(int index, ulong itemId)
|
||||
{
|
||||
if (index <= 0)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||
|
||||
[CallGSApi("SupporterCard_Equip")]
|
||||
public class SupporterCard_Equip : ICallGSHandler
|
||||
{
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player!;
|
||||
var req = JsonSerializer.Deserialize<SupporterCardEquipParam>(param);
|
||||
if (req == null || req.CardId == 0 || req.SupportCardUid == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Logistics_Equip", "{}");
|
||||
return;
|
||||
}
|
||||
|
||||
var card = player.CharacterManager.GetCharacterByGUID((uint)req.CardId);
|
||||
if (card == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Logistics_Equip", "{}");
|
||||
return;
|
||||
}
|
||||
|
||||
var slot = (uint)req.EqSlot;
|
||||
|
||||
// If an existing card is equipped in this slot and bForce is false, ask for confirmation
|
||||
if (!req.Force && req.CurrentEquippedUid != 0 && card.SupportSlots.TryGetValue(slot, out var existing) && existing != 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Logistics_Confirm", "{}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform equip
|
||||
card.SupportSlots[slot] = (uint)req.SupportCardUid;
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.CharacterManager.CharacterData);
|
||||
|
||||
var sync = new NtfSyncPlayer();
|
||||
sync.Items.Add(card.ToProto());
|
||||
|
||||
// Req_EquipChange (no Model) → Logistics_Change; Req_Equip (has Model) → Logistics_Equip
|
||||
var responseApi = string.IsNullOrEmpty(req.Model) ? "Logistics_Change" : "Logistics_Equip";
|
||||
await CallGSRouter.SendScript(connection, responseApi, "{}", sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SupporterCardEquipParam
|
||||
{
|
||||
[JsonPropertyName("EqId")]
|
||||
public int CardId { get; set; }
|
||||
|
||||
[JsonPropertyName("beEqId")]
|
||||
public int SupportCardUid { get; set; }
|
||||
|
||||
[JsonPropertyName("EqSlot")]
|
||||
public int EqSlot { get; set; }
|
||||
|
||||
[JsonPropertyName("BEqId")]
|
||||
public int CurrentEquippedUid { get; set; }
|
||||
|
||||
[JsonPropertyName("bForce")]
|
||||
public bool Force { get; set; }
|
||||
|
||||
[JsonPropertyName("Model")]
|
||||
public string? Model { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||
|
||||
[CallGSApi("SupporterCard_Upgrade")]
|
||||
public class SupporterCard_Upgrade : ICallGSHandler
|
||||
{
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player!;
|
||||
var req = JsonSerializer.Deserialize<SupporterCardUpgradeParam>(param);
|
||||
if (req == null || req.SupportCardUid == 0 || req.Materials == null || req.Materials.Count == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}");
|
||||
return;
|
||||
}
|
||||
|
||||
var supportCard = player.InventoryManager.InventoryData.Items.GetValueOrDefault((uint)req.SupportCardUid);
|
||||
if (supportCard == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}");
|
||||
return;
|
||||
}
|
||||
|
||||
var supportCardExcel = GameData.SupportCardData.FirstOrDefault(x => x.TemplateId == supportCard.TemplateId);
|
||||
var maxLevel = supportCardExcel?.MaxLevel ?? 10;
|
||||
|
||||
// Validate all materials exist with sufficient count
|
||||
foreach (var mat in req.Materials)
|
||||
{
|
||||
var item = player.InventoryManager.InventoryData.Items.GetValueOrDefault((uint)mat.Id);
|
||||
if (item == null || item.ItemCount < mat.Num)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Consume materials and accumulate exp
|
||||
var syncItems = new List<Item>();
|
||||
uint gainedExp = 0;
|
||||
|
||||
foreach (var mat in req.Materials)
|
||||
{
|
||||
var item = player.InventoryManager.InventoryData.Items[(uint)mat.Id];
|
||||
|
||||
// Look up ProvideExp: check SupportCardData first, then SuppliesData
|
||||
uint provideExp = 0;
|
||||
var scExcel = GameData.SupportCardData.FirstOrDefault(x => x.TemplateId == item.TemplateId);
|
||||
if (scExcel != null)
|
||||
provideExp = scExcel.ProvideExp;
|
||||
else if (GameData.SuppliesData.TryGetValue((uint)item.TemplateId, out var supExcel))
|
||||
provideExp = supExcel.ProvideExp;
|
||||
gainedExp += provideExp * (uint)mat.Num;
|
||||
|
||||
item.ItemCount -= (uint)mat.Num;
|
||||
var proto = item.ToProto();
|
||||
if (item.ItemCount == 0)
|
||||
{
|
||||
player.InventoryManager.InventoryData.Items.Remove(item.UniqueId);
|
||||
proto.Count = 0;
|
||||
}
|
||||
syncItems.Add(proto);
|
||||
}
|
||||
|
||||
// Apply exp and level up
|
||||
supportCard.Exp += gainedExp;
|
||||
while (supportCard.Level < maxLevel)
|
||||
{
|
||||
var expNeeded = GetExpNeeded(supportCard.Level + 1);
|
||||
if (expNeeded == 0 || supportCard.Exp < expNeeded) break;
|
||||
supportCard.Exp -= expNeeded;
|
||||
supportCard.Level++;
|
||||
}
|
||||
if (supportCard.Level >= maxLevel)
|
||||
{
|
||||
supportCard.Exp = 0;
|
||||
supportCard.Level = maxLevel;
|
||||
}
|
||||
|
||||
syncItems.Add(supportCard.ToProto());
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||
|
||||
var sync = new NtfSyncPlayer();
|
||||
sync.Items.AddRange(syncItems);
|
||||
|
||||
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}", sync);
|
||||
}
|
||||
|
||||
private static uint GetExpNeeded(uint level)
|
||||
{
|
||||
if (GameData.UpgradeExpData.TryGetValue((int)level, out var row))
|
||||
return row.SusNeedExp;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SupporterCardUpgradeParam
|
||||
{
|
||||
[JsonPropertyName("Id")]
|
||||
public int SupportCardUid { get; set; }
|
||||
|
||||
[JsonPropertyName("tbMaterials")]
|
||||
public List<UpgradeMaterial> Materials { get; set; } = [];
|
||||
}
|
||||
|
||||
internal sealed class UpgradeMaterial
|
||||
{
|
||||
[JsonPropertyName("Id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("Num")]
|
||||
public uint Num { get; set; }
|
||||
}
|
||||
@@ -43,6 +43,8 @@ public class HandlerReqLogin : Handler
|
||||
connection.State = SessionStateEnum.WAITING_FOR_LOGIN;
|
||||
var pd = DatabaseHelper.GetInstance<PlayerGameData>(account.Uid);
|
||||
connection.Player = pd == null ? new PlayerInstance(account.Uid) : new PlayerInstance(pd);
|
||||
if (connection.Player.Data.EnsureDisplayName())
|
||||
DatabaseHelper.UpdateInstance(connection.Player.Data);
|
||||
|
||||
connection.DebugFile = Path.Combine(ConfigManager.Config.Path.LogPath, "Debug/", $"{account.Uid}/",
|
||||
$"Debug-{DateTime.Now:yyyy-MM-dd HH-mm-ss}.log");
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using MikuSB.Proto;
|
||||
using Google.Protobuf;
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
|
||||
namespace MikuSB.GameServer.Server.Packet.Recv.Login;
|
||||
|
||||
@@ -7,6 +9,57 @@ public class HandlerReqRename : Handler
|
||||
{
|
||||
public override async Task OnHandle(Connection connection, byte[] data, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player;
|
||||
if (player != null)
|
||||
{
|
||||
var requestedName = ParseDisplayName(data);
|
||||
player.SetDisplayName(requestedName);
|
||||
DatabaseHelper.UpdateInstance(player.Data);
|
||||
await player.OnHeartBeat();
|
||||
}
|
||||
|
||||
await connection.SendPacket(CmdIds.RspRename);
|
||||
}
|
||||
|
||||
private static string? ParseDisplayName(byte[] data)
|
||||
{
|
||||
if (data.Length == 0)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
var input = new CodedInputStream(data);
|
||||
while (!input.IsAtEnd)
|
||||
{
|
||||
var tag = input.ReadTag();
|
||||
if (tag == 0)
|
||||
break;
|
||||
|
||||
if (WireFormat.GetTagWireType(tag) == WireFormat.WireType.LengthDelimited)
|
||||
{
|
||||
var value = input.ReadString();
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
input.SkipLastField();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fall back to raw UTF-8 payload handling below.
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var rawText = System.Text.Encoding.UTF8.GetString(data).Trim('\0', ' ', '\r', '\n', '\t');
|
||||
return string.IsNullOrWhiteSpace(rawText) ? null : rawText;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
Projects="..\MikuSB.Updater\MikuSB.Updater.csproj"
|
||||
Targets="Restore;Publish"
|
||||
RemoveProperties="PublishProfile"
|
||||
Properties="Configuration=$(Configuration);RuntimeIdentifier=$(RuntimeIdentifier);SelfContained=true;PublishSingleFile=true;PublishDir=$(_UpdaterPublishDir)" />
|
||||
Properties="Configuration=$(Configuration);RuntimeIdentifier=$(RuntimeIdentifier);SelfContained=false;PublishSingleFile=true;PublishDir=$(_UpdaterPublishDir)" />
|
||||
|
||||
<Copy
|
||||
SourceFiles="$(_UpdaterPublishDir)MikuSB.Updater.exe"
|
||||
|
||||
@@ -1 +1 @@
|
||||
v=1.0
|
||||
v=1.1
|
||||
Reference in New Issue
Block a user