mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 05:03:58 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e62fcc9b2 | ||
|
|
f4ad74e00d | ||
|
|
ccdfbee828 | ||
|
|
5d0f587fb9 | ||
|
|
94f972ff82 | ||
|
|
1b4f3531d1 | ||
|
|
1cac82d10d | ||
|
|
1e4d93bab1 | ||
|
|
5f92f2c116 | ||
|
|
16d1413cd8 | ||
|
|
00d5f35c30 | ||
|
|
7e45bd8dcb | ||
|
|
ac5762fc42 | ||
|
|
12df57b273 | ||
|
|
c109c82a91 |
@@ -16,7 +16,7 @@ public class HttpServerConfig
|
||||
public string BindAddress { get; set; } = "0.0.0.0";
|
||||
public string PublicAddress { get; set; } = "127.0.0.1";
|
||||
public int Port { get; set; } = 21500;
|
||||
public bool EnableLog { get; set; } = true;
|
||||
public bool EnableLog { get; set; } = false;
|
||||
|
||||
public string GetDisplayAddress()
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ public class CardExcel : ExcelResource
|
||||
[JsonProperty("profile")] public List<List<int>> Profile { get; set; } = [];
|
||||
public List<List<int>> Pieces { get; set; } = [];
|
||||
public List<int> Attribute { get; set; } = [];
|
||||
[JsonProperty("SpineID")] public uint SpineId { get; set; }
|
||||
public override uint GetId()
|
||||
{
|
||||
return Icon;
|
||||
|
||||
41
Common/Data/Excel/NodeConditionExcel.cs
Normal file
41
Common/Data/Excel/NodeConditionExcel.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
// nodecondition.json: NodeConditionId → NodeXCost per sub-node (1-9)
|
||||
[ResourceEntity("nodecondition.json")]
|
||||
public class NodeConditionExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("ID")] public uint Id { get; set; }
|
||||
|
||||
[JsonProperty("Node1Cost")] public List<List<int>> Node1Cost { get; set; } = [];
|
||||
[JsonProperty("Node2Cost")] public List<List<int>> Node2Cost { get; set; } = [];
|
||||
[JsonProperty("Node3Cost")] public List<List<int>> Node3Cost { get; set; } = [];
|
||||
[JsonProperty("Node4Cost")] public List<List<int>> Node4Cost { get; set; } = [];
|
||||
[JsonProperty("Node5Cost")] public List<List<int>> Node5Cost { get; set; } = [];
|
||||
[JsonProperty("Node6Cost")] public List<List<int>> Node6Cost { get; set; } = [];
|
||||
[JsonProperty("Node7Cost")] public List<List<int>> Node7Cost { get; set; } = [];
|
||||
[JsonProperty("Node8Cost")] public List<List<int>> Node8Cost { get; set; } = [];
|
||||
[JsonProperty("Node9Cost")] public List<List<int>> Node9Cost { get; set; } = [];
|
||||
|
||||
public List<List<int>> GetNodeCost(int subIdx) => subIdx switch
|
||||
{
|
||||
1 => Node1Cost,
|
||||
2 => Node2Cost,
|
||||
3 => Node3Cost,
|
||||
4 => Node4Cost,
|
||||
5 => Node5Cost,
|
||||
6 => Node6Cost,
|
||||
7 => Node7Cost,
|
||||
8 => Node8Cost,
|
||||
9 => Node9Cost,
|
||||
_ => []
|
||||
};
|
||||
|
||||
public override uint GetId() => Id;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.NodeConditionData[Id] = this;
|
||||
}
|
||||
}
|
||||
35
Common/Data/Excel/SpineExcel.cs
Normal file
35
Common/Data/Excel/SpineExcel.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
// spine.json: SpineId → Node{i}Req (nodecondition ID per master node index)
|
||||
[ResourceEntity("spine.json")]
|
||||
public class SpineExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("ID")] public uint Id { get; set; }
|
||||
|
||||
[JsonProperty("Node1Req")] public uint Node1Req { get; set; }
|
||||
[JsonProperty("Node2Req")] public uint Node2Req { get; set; }
|
||||
[JsonProperty("Node3Req")] public uint Node3Req { get; set; }
|
||||
[JsonProperty("Node4Req")] public uint Node4Req { get; set; }
|
||||
[JsonProperty("Node5Req")] public uint Node5Req { get; set; }
|
||||
[JsonProperty("Node6Req")] public uint Node6Req { get; set; }
|
||||
|
||||
public uint GetNodeReq(int mastIdx) => mastIdx switch
|
||||
{
|
||||
1 => Node1Req,
|
||||
2 => Node2Req,
|
||||
3 => Node3Req,
|
||||
4 => Node4Req,
|
||||
5 => Node5Req,
|
||||
6 => Node6Req,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
public override uint GetId() => Id;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.SpineData[Id] = this;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@ public static class GameData
|
||||
public static Dictionary<uint, ArItemExcel> ArItemData { get; private set; } = [];
|
||||
public static Dictionary<uint, ManifestationExcel> ManifestationData { get; private set; } = [];
|
||||
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
|
||||
|
||||
@@ -19,6 +19,7 @@ public class CharacterInfo
|
||||
public int Exp { get; set; }
|
||||
public uint Break { get; set; }
|
||||
public int Evolue { get; set; }
|
||||
public uint ProLevel { get; set; }
|
||||
public int Trust { get; set; }
|
||||
public uint WeaponUniqueId { get; set; }
|
||||
public uint SkinId { get; set; }
|
||||
@@ -27,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;
|
||||
|
||||
@@ -45,6 +48,7 @@ public class CharacterInfo
|
||||
Exp = ToUInt32(Exp),
|
||||
Break = Break,
|
||||
Evolue = ToUInt32(Evolue),
|
||||
ProLevel = ProLevel,
|
||||
Trust = ToUInt32(Trust)
|
||||
}
|
||||
};
|
||||
@@ -53,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; }
|
||||
}
|
||||
@@ -69,7 +74,7 @@ public class GameWeaponInfo : GrowableItemInfo
|
||||
}
|
||||
}public class GameSkinInfo : BaseGameItemInfo
|
||||
{
|
||||
public uint Level { get; set; }
|
||||
public uint SkinType { get; set; }
|
||||
public override Item ToProto()
|
||||
{
|
||||
var proto = new Item
|
||||
@@ -79,6 +84,7 @@ public class GameWeaponInfo : GrowableItemInfo
|
||||
Count = ItemCount,
|
||||
Flag = (uint)Flag,
|
||||
};
|
||||
proto.Slots[11] = SkinType;
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -16,6 +18,7 @@ public class PlayerGameData : BaseDatabaseDataHelper
|
||||
public Sex Gender { get; set; } = Sex.Female;
|
||||
public uint Vigor { get; set; } = 240;
|
||||
[SugarColumn(IsJson = true)] public List<PlayerAttr> Attrs { get; set; } = [];
|
||||
[SugarColumn(IsJson = true)] public List<PlayerStrAttr> StrAttrs { get; set; } = [];
|
||||
[SugarColumn(IsJson = true)] public List<ulong> ShowItems { get; set; } = [];
|
||||
|
||||
public static PlayerGameData? GetPlayerByUid(long uid)
|
||||
@@ -24,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,
|
||||
@@ -45,4 +65,11 @@ public class PlayerAttr
|
||||
public uint Gid { get; set; }
|
||||
public uint Sid { get; set; }
|
||||
public uint Val { get; set; }
|
||||
}
|
||||
|
||||
public class PlayerStrAttr
|
||||
{
|
||||
public uint Gid { get; set; }
|
||||
public uint Sid { get; set; }
|
||||
public string Val { get; set; } = "";
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class CharacterManager(PlayerInstance player) : BasePlayerManager(player)
|
||||
var weaponInfo = await Player.InventoryManager!.AddWeaponItem((ItemTypeEnum)CharacterExcel.DefaultWeaponGPDL[0], CharacterExcel.DefaultWeaponGPDL[1], CharacterExcel.DefaultWeaponGPDL[2], CharacterExcel.DefaultWeaponGPDL[3],sendPacket:false);
|
||||
if (weaponInfo != null) character.WeaponUniqueId = weaponInfo.UniqueId;
|
||||
|
||||
var skinInfo = Player.InventoryManager!.GetNormalItemGDPL(ItemTypeEnum.TYPE_CARD_SKIN, detail, particular, level)
|
||||
var skinInfo = Player.InventoryManager!.GetSkinItemGDPL(ItemTypeEnum.TYPE_CARD_SKIN, detail, particular, level)
|
||||
?? await Player.InventoryManager!.AddSkinItem(ItemTypeEnum.TYPE_CARD_SKIN, detail, particular, level, false);
|
||||
if (skinInfo != null) character.SkinId = skinInfo.UniqueId;
|
||||
|
||||
|
||||
@@ -51,27 +51,43 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
|
||||
return InventoryData.Weapons.Values.FirstOrDefault(x => x.TemplateId == templateId);
|
||||
}
|
||||
|
||||
public async ValueTask<BaseGameItemInfo?> AddSkinItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
|
||||
public async ValueTask<GameSkinInfo?> AddSkinItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
|
||||
{
|
||||
if (genre != ItemTypeEnum.TYPE_CARD_SKIN) return null;
|
||||
var skinData = GameData.CardSkinData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level);
|
||||
if (skinData == null) return null;
|
||||
|
||||
var templateId = GameResourceTemplateId.FromGdpl((uint)genre,detail,particular,level);
|
||||
var skinInfo = new BaseGameItemInfo
|
||||
var skinInfo = new GameSkinInfo
|
||||
{
|
||||
TemplateId = templateId,
|
||||
UniqueId = InventoryData.NextUniqueUid++,
|
||||
ItemType = ItemTypeEnum.TYPE_CARD_SKIN,
|
||||
ItemCount = 1
|
||||
};
|
||||
InventoryData.Items[skinInfo.UniqueId] = skinInfo;
|
||||
InventoryData.Skins[skinInfo.UniqueId] = skinInfo;
|
||||
|
||||
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([skinInfo]));
|
||||
|
||||
return skinInfo;
|
||||
}
|
||||
|
||||
public GameSkinInfo? GetSkinItem(uint uniqueId)
|
||||
{
|
||||
return InventoryData.Skins.GetValueOrDefault(uniqueId);
|
||||
}
|
||||
|
||||
public GameSkinInfo? GetSkinItemByTemplateId(ulong templateId)
|
||||
{
|
||||
return InventoryData.Skins.Values.FirstOrDefault(x => x.TemplateId == templateId);
|
||||
}
|
||||
|
||||
public GameSkinInfo? GetSkinItemGDPL(ItemTypeEnum genre, uint detail, uint particular, uint level)
|
||||
{
|
||||
var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level);
|
||||
return InventoryData.Skins.Values.FirstOrDefault(x => x.TemplateId == templateId);
|
||||
}
|
||||
|
||||
public async ValueTask<BaseGameItemInfo?> AddArItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
|
||||
{
|
||||
if (genre != ItemTypeEnum.TYPE_AR) return null;
|
||||
@@ -94,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,52 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
|
||||
|
||||
[CallGSApi("GirlCard_ProLevelPromote")]
|
||||
public class GirlCard_ProLevelPromote : ICallGSHandler
|
||||
{
|
||||
private const uint MaxProLevel = 3;
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player!;
|
||||
var req = JsonSerializer.Deserialize<ProLevelPromoteParam>(param);
|
||||
if (req == null || req.CardId == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlCard_ProLevelPromote", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var card = player.CharacterManager.GetCharacterByGUID((uint)req.CardId);
|
||||
if (card == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlCard_ProLevelPromote", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (card.ProLevel >= MaxProLevel)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlCard_ProLevelPromote", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
card.ProLevel++;
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.CharacterManager.CharacterData);
|
||||
|
||||
var sync = new NtfSyncPlayer();
|
||||
sync.Items.Add(card.ToProto());
|
||||
|
||||
// s2c callback takes no params — return empty arg
|
||||
await CallGSRouter.SendScript(connection, "GirlCard_ProLevelPromote", "{}", sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ProLevelPromoteParam
|
||||
{
|
||||
[JsonPropertyName("nID")]
|
||||
public int CardId { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -15,16 +16,35 @@ public class GirlSkin_ChangeSkinType : ICallGSHandler
|
||||
["nType"] = req?.Type ?? 1,
|
||||
["nSkinId"] = req?.SkinId
|
||||
};
|
||||
// TODO change type in proto Item ??
|
||||
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString());
|
||||
if (req == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString());
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
var skinData = player.InventoryManager.GetSkinItem(req.SkinId);
|
||||
if (skinData == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString());
|
||||
return;
|
||||
}
|
||||
|
||||
skinData.SkinType = req.Type;
|
||||
var sync = new NtfSyncPlayer
|
||||
{
|
||||
Items = { skinData.ToProto() }
|
||||
};
|
||||
|
||||
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString(), sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ChangeSkinTypeParam
|
||||
{
|
||||
[JsonPropertyName("nType")]
|
||||
public int? Type { get; set; }
|
||||
public uint Type { get; set; }
|
||||
|
||||
[JsonPropertyName("nSkinId")]
|
||||
public uint? SkinId { get; set; }
|
||||
public uint SkinId { get; set; }
|
||||
}
|
||||
|
||||
182
GameServer/Server/CallGS/Handlers/Girl/GirlSpine_ChildUnLock.cs
Normal file
182
GameServer/Server/CallGS/Handlers/Girl/GirlSpine_ChildUnLock.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Database.Player;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
|
||||
|
||||
// Spine node encoding: (MastIdx << 8) | SubIdx stored as uint in CharacterInfo.Spines
|
||||
// GetStrAttribute(Gid=30, Sid=Detail) stores JSON: { "<Particular>": { "ns": <MastIdx>, "tbn": [0,0], "tbr": [] } }
|
||||
[CallGSApi("GirlSpine_ChildUnLock")]
|
||||
public class GirlSpine_ChildUnLock : ICallGSHandler
|
||||
{
|
||||
private const uint SpineStrAttrGid = 30;
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player!;
|
||||
var req = JsonSerializer.Deserialize<ChildUnLockParam>(param);
|
||||
if (req == null || req.CardId == 0 || req.Info == null || req.Materials == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var card = player.CharacterManager.GetCharacterByGUID((uint)req.CardId);
|
||||
if (card == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var mastIdx = req.Info.Indx;
|
||||
var subIdx = req.Info.InSubIdx;
|
||||
if (mastIdx <= 0 || subIdx <= 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Spines[MastIdx-1] is a bitmask; bit (SubIdx-1) = 1 means that sub-node is unlocked.
|
||||
// GetSpine(MastIdx, SubIdx) checks (Spines[MastIdx-1] & (1 << (SubIdx-1))) != 0
|
||||
int spineListIdx = mastIdx - 1;
|
||||
uint spineBit = 1u << (subIdx - 1);
|
||||
|
||||
while (card.Spines.Count <= spineListIdx)
|
||||
card.Spines.Add(0);
|
||||
|
||||
if ((card.Spines[spineListIdx] & spineBit) != 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", "{\"sErr\":\"tip.girlcard_alread_break\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Consume materials
|
||||
var requestedMaterials = new Dictionary<ulong, uint>();
|
||||
foreach (var row in req.Materials)
|
||||
{
|
||||
if (row == null || row.Count < 5) continue;
|
||||
var genre = (uint)Math.Max(0, row[0]);
|
||||
var detail = (uint)Math.Max(0, row[1]);
|
||||
var particular = (uint)Math.Max(0, row[2]);
|
||||
var level = (uint)Math.Max(0, row[3]);
|
||||
var count = (uint)Math.Max(0, row[4]);
|
||||
if (genre == 0 || detail == 0 || particular == 0 || level == 0 || count == 0) continue;
|
||||
var tid = GameResourceTemplateId.FromGdpl(genre, detail, particular, level);
|
||||
requestedMaterials[tid] = requestedMaterials.GetValueOrDefault(tid) + count;
|
||||
}
|
||||
|
||||
var syncItems = new List<Item>();
|
||||
foreach (var (tid, count) in requestedMaterials)
|
||||
{
|
||||
var item = player.InventoryManager.InventoryData.Items.Values.FirstOrDefault(x => x.TemplateId == tid);
|
||||
if (item == null || item.ItemCount < count)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", "{\"sErr\":\"tip.not_material\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (tid, count) in requestedMaterials)
|
||||
{
|
||||
var item = player.InventoryManager.InventoryData.Items.Values.First(x => x.TemplateId == tid);
|
||||
item.ItemCount -= count;
|
||||
var proto = item.ToProto();
|
||||
if (item.ItemCount == 0)
|
||||
{
|
||||
player.InventoryManager.InventoryData.Items.Remove(item.UniqueId);
|
||||
proto.Count = 0;
|
||||
}
|
||||
syncItems.Add(proto);
|
||||
}
|
||||
|
||||
// Unlock the spine node by setting the corresponding bit
|
||||
card.Spines[spineListIdx] |= spineBit;
|
||||
syncItems.Add(card.ToProto());
|
||||
|
||||
// Extract Detail and Particular from TemplateId for StrAttr
|
||||
var cardDetail = (uint)((card.TemplateId >> 16) & 0xFFFF);
|
||||
var cardParticular = (uint)((card.TemplateId >> 32) & 0xFFFF);
|
||||
|
||||
// Build and persist StrAttr JSON: { "<particular>": { "ns": mastIdx, "tbn": [0,0], "tbr": [] } }
|
||||
UpdateSpineStrAttr(player.Data, cardDetail, cardParticular, mastIdx);
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||
DatabaseHelper.SaveDatabaseType(player.CharacterManager.CharacterData);
|
||||
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||
|
||||
// Send NtfSetStrAttr so client's GetStrAttribute(30, Detail) returns fresh data
|
||||
var strAttrData = GetSpineStrAttrJson(player.Data, cardDetail);
|
||||
var ntfStrAttr = new NtfSetStrAttr { Gid = SpineStrAttrGid, Sid = cardDetail, Val = strAttrData };
|
||||
await connection.Player!.SendPacket(CmdIds.NtfSetStrAttr, ntfStrAttr);
|
||||
|
||||
var sync = new NtfSyncPlayer();
|
||||
sync.Items.AddRange(syncItems);
|
||||
|
||||
var rsp = $"{{\"tb\":{{\"D\":{cardDetail},\"pId\":{req.CardId},\"MastIdx\":{mastIdx},\"SubIdx\":{subIdx}}}}}";
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", rsp, sync);
|
||||
}
|
||||
|
||||
private static void UpdateSpineStrAttr(PlayerGameData data, uint detail, uint particular, int mastIdx)
|
||||
{
|
||||
var existing = data.StrAttrs.FirstOrDefault(x => x.Gid == SpineStrAttrGid && x.Sid == detail);
|
||||
if (existing == null)
|
||||
{
|
||||
existing = new PlayerStrAttr { Gid = SpineStrAttrGid, Sid = detail, Val = "{}" };
|
||||
data.StrAttrs.Add(existing);
|
||||
}
|
||||
|
||||
var root = JsonSerializer.Deserialize<Dictionary<string, SpineStrData>>(existing.Val)
|
||||
?? new Dictionary<string, SpineStrData>();
|
||||
|
||||
var key = particular.ToString();
|
||||
if (!root.TryGetValue(key, out var entry))
|
||||
entry = new SpineStrData();
|
||||
|
||||
entry.Ns = mastIdx;
|
||||
root[key] = entry;
|
||||
|
||||
existing.Val = JsonSerializer.Serialize(root);
|
||||
}
|
||||
|
||||
private static string GetSpineStrAttrJson(PlayerGameData data, uint detail)
|
||||
{
|
||||
var existing = data.StrAttrs.FirstOrDefault(x => x.Gid == SpineStrAttrGid && x.Sid == detail);
|
||||
return existing?.Val ?? "{}";
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ChildUnLockParam
|
||||
{
|
||||
[JsonPropertyName("pId")]
|
||||
public int CardId { get; set; }
|
||||
|
||||
[JsonPropertyName("tbInfo")]
|
||||
public NodeInfo? Info { get; set; }
|
||||
|
||||
[JsonPropertyName("tbMat")]
|
||||
public List<List<int>> Materials { get; set; } = [];
|
||||
}
|
||||
|
||||
internal sealed class NodeInfo
|
||||
{
|
||||
[JsonPropertyName("Indx")]
|
||||
public int Indx { get; set; }
|
||||
|
||||
[JsonPropertyName("InSubIdx")]
|
||||
public int InSubIdx { get; set; }
|
||||
}
|
||||
|
||||
internal sealed class SpineStrData
|
||||
{
|
||||
[JsonPropertyName("ns")]
|
||||
public int Ns { get; set; } = 0;
|
||||
|
||||
[JsonPropertyName("tbn")]
|
||||
public List<int> Tbn { get; set; } = [0, 0];
|
||||
|
||||
[JsonPropertyName("tbr")]
|
||||
public List<int> Tbr { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
|
||||
|
||||
[CallGSApi("GirlSpine_UnlockNodeOneKey")]
|
||||
public class GirlSpine_UnlockNodeOneKey : ICallGSHandler
|
||||
{
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player!;
|
||||
var req = JsonSerializer.Deserialize<OneKeyUnlockParam>(param);
|
||||
if (req == null || req.CardId == 0 || req.MastIdx <= 0 || req.SubIdxList == null || req.SubIdxList.Count == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var card = player.CharacterManager.GetCharacterByGUID((uint)req.CardId);
|
||||
if (card == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Look up costs from config: CardExcel → SpineId → SpineExcel → NodeConditionId → NodeConditionExcel
|
||||
var cardTemplateId = card.TemplateId;
|
||||
var cardDetail = (uint)((cardTemplateId >> 16) & 0xFFFF);
|
||||
var cardParticular = (uint)((cardTemplateId >> 32) & 0xFFFF);
|
||||
|
||||
var cardExcel = GameData.CardData.Values.FirstOrDefault(
|
||||
x => x.Detail == cardDetail && x.Particular == cardParticular);
|
||||
|
||||
var requestedMaterials = new Dictionary<ulong, uint>();
|
||||
|
||||
if (cardExcel != null && GameData.SpineData.TryGetValue(cardExcel.SpineId, out var spineExcel))
|
||||
{
|
||||
var nodeCondId = spineExcel.GetNodeReq(req.MastIdx);
|
||||
if (nodeCondId != 0 && GameData.NodeConditionData.TryGetValue(nodeCondId, out var nodeCond))
|
||||
{
|
||||
int spineListIdx = req.MastIdx - 1;
|
||||
while (card.Spines.Count <= spineListIdx) card.Spines.Add(0);
|
||||
var currentMask = card.Spines[spineListIdx];
|
||||
|
||||
foreach (var subIdx in req.SubIdxList)
|
||||
{
|
||||
if (subIdx <= 0) continue;
|
||||
uint bit = 1u << (subIdx - 1);
|
||||
if ((currentMask & bit) != 0) continue; // already unlocked, skip cost
|
||||
|
||||
foreach (var row in nodeCond.GetNodeCost(subIdx))
|
||||
{
|
||||
if (row.Count < 5) continue;
|
||||
var tid = GameResourceTemplateId.FromGdpl(
|
||||
(uint)row[0], (uint)row[1], (uint)row[2], (uint)row[3]);
|
||||
requestedMaterials[tid] = requestedMaterials.GetValueOrDefault(tid) + (uint)row[4];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate materials
|
||||
foreach (var (tid, count) in requestedMaterials)
|
||||
{
|
||||
var item = player.InventoryManager.InventoryData.Items.Values.FirstOrDefault(x => x.TemplateId == tid);
|
||||
if (item == null || item.ItemCount < count)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", "{\"sErr\":\"tip.not_material\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Consume materials
|
||||
var syncItems = new List<Item>();
|
||||
foreach (var (tid, count) in requestedMaterials)
|
||||
{
|
||||
var item = player.InventoryManager.InventoryData.Items.Values.First(x => x.TemplateId == tid);
|
||||
item.ItemCount -= count;
|
||||
var proto = item.ToProto();
|
||||
if (item.ItemCount == 0)
|
||||
{
|
||||
player.InventoryManager.InventoryData.Items.Remove(item.UniqueId);
|
||||
proto.Count = 0;
|
||||
}
|
||||
syncItems.Add(proto);
|
||||
}
|
||||
|
||||
// Unlock all specified sub-nodes
|
||||
int mastSpineIdx = req.MastIdx - 1;
|
||||
while (card.Spines.Count <= mastSpineIdx) card.Spines.Add(0);
|
||||
foreach (var subIdx in req.SubIdxList)
|
||||
{
|
||||
if (subIdx <= 0) continue;
|
||||
card.Spines[mastSpineIdx] |= 1u << (subIdx - 1);
|
||||
}
|
||||
syncItems.Add(card.ToProto());
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||
DatabaseHelper.SaveDatabaseType(player.CharacterManager.CharacterData);
|
||||
|
||||
var sync = new NtfSyncPlayer();
|
||||
sync.Items.AddRange(syncItems);
|
||||
|
||||
// No s2c handler exists for GirlSpine_UnlockNodeOneKey — reuse GirlSpine_ChildUnLock
|
||||
// which calls UI.CloseConnection() and triggers OnNerveNodeUp to refresh the UI.
|
||||
var lastSubIdx = req.SubIdxList.Count > 0 ? req.SubIdxList[^1] : 9;
|
||||
var rsp = $"{{\"tb\":{{\"D\":{cardDetail},\"pId\":{req.CardId},\"MastIdx\":{req.MastIdx},\"SubIdx\":{lastSubIdx}}}}}";
|
||||
await CallGSRouter.SendScript(connection, "GirlSpine_ChildUnLock", rsp, sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class OneKeyUnlockParam
|
||||
{
|
||||
[JsonPropertyName("pId")]
|
||||
public int CardId { get; set; }
|
||||
|
||||
[JsonPropertyName("nIdx")]
|
||||
public int MastIdx { get; set; }
|
||||
|
||||
[JsonPropertyName("tbOneKey")]
|
||||
public List<int> SubIdxList { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using MikuSB.Database.Player;
|
||||
using MikuSB.GameServer.Server.CallGS.Handlers.Misc;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Preview;
|
||||
|
||||
[CallGSApi("RecordConfession")]
|
||||
public class RecordConfession : ICallGSHandler
|
||||
{
|
||||
private const int MainSceneGID = 132;
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var req = JsonSerializer.Deserialize<RecordConfessionParam>(param);
|
||||
if (req == null) return;
|
||||
var sid = req.Id + 10;
|
||||
var player = connection.Player!;
|
||||
var attr = player.Data.Attrs
|
||||
.FirstOrDefault(x => x.Gid == MainSceneGID && x.Sid == sid);
|
||||
if (attr == null)
|
||||
{
|
||||
attr = new PlayerAttr
|
||||
{
|
||||
Gid = MainSceneGID,
|
||||
Sid = sid,
|
||||
Val = 1
|
||||
};
|
||||
player.Data.Attrs.Add(attr);
|
||||
}
|
||||
var sync = new NtfSyncPlayer();
|
||||
sync.Custom[player.ToPackedAttrKey(MainSceneGID, sid)] = attr.Val;
|
||||
sync.Custom[player.ToShiftedAttrKey(MainSceneGID, sid)] = attr.Val;
|
||||
await CallGSRouter.SendScript(connection, "RecordConfession", "{}", sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class RecordConfessionParam
|
||||
{
|
||||
[JsonPropertyName("nIdx")]
|
||||
public uint Id { get; set; }
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@ public class PacketNtfCallScript : BasePacket
|
||||
};
|
||||
|
||||
var extraSync = new NtfSyncPlayer();
|
||||
foreach (var item in inventory.Items.Values) if ((item.TemplateId & 0xFFFF) != 5) extraSync.Items.Add(item.ToProto());
|
||||
foreach (var item in inventory.Items.Values) extraSync.Items.Add(item.ToProto());
|
||||
foreach (var skin in inventory.Skins.Values) extraSync.Items.Add(skin.ToProto());
|
||||
foreach (var weapon in inventory.Weapons.Values) extraSync.Items.Add(weapon.ToProto());
|
||||
proto.ExtraSync = extraSync;
|
||||
SetData(proto);
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -11,7 +11,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
<SelfContained>false</SelfContained>
|
||||
<PublishSingleFile>false</PublishSingleFile>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<PublishTrimmed>false</PublishTrimmed>
|
||||
|
||||
@@ -16,7 +16,10 @@ public static class UpdateService
|
||||
private static readonly string RepositoryOwner = "MikuLeaks";
|
||||
private static readonly string RepositoryName = "MikuSB";
|
||||
private static readonly string AssetName = "MikuSB-win-x64.zip";
|
||||
private static readonly int TimeoutSeconds = 5;
|
||||
private static readonly int ReleaseCheckTimeoutSeconds = 10;
|
||||
private static readonly int PackageDownloadTimeoutSeconds = 300;
|
||||
private static readonly int ResourceDownloadTimeoutSeconds = 300;
|
||||
private static readonly int ChecksumDownloadTimeoutSeconds = 30;
|
||||
private static readonly string ResourceArchiveUrl =
|
||||
"https://github.com/Kei-Luna/MikuSB-Resource/archive/refs/heads/main.zip";
|
||||
private static readonly string[] RequiredResourceFiles =
|
||||
@@ -50,8 +53,9 @@ public static class UpdateService
|
||||
Logger.Info($"Current build version: {BuildVersion.Current}");
|
||||
|
||||
using var client = CreateHttpClient();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(1, TimeoutSeconds)));
|
||||
var release = await GetLatestReleaseAsync(client, cts.Token);
|
||||
using var releaseCts =
|
||||
new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(1, ReleaseCheckTimeoutSeconds)));
|
||||
var release = await GetLatestReleaseAsync(client, releaseCts.Token);
|
||||
if (release == null)
|
||||
return false;
|
||||
|
||||
@@ -78,18 +82,18 @@ public static class UpdateService
|
||||
|
||||
var packagePath = Path.Combine(tempRoot, asset.Name);
|
||||
Logger.Info($"Downloading update {release.TagName}.");
|
||||
await DownloadFileAsync(client, asset.DownloadUrl, packagePath, cts.Token);
|
||||
await DownloadFileAsync(client, asset.DownloadUrl, packagePath, PackageDownloadTimeoutSeconds);
|
||||
|
||||
var resourcePackagePath = Path.Combine(tempRoot, "MikuSB-Resource-main.zip");
|
||||
Logger.Info("Downloading resource package.");
|
||||
await DownloadFileAsync(client, ResourceArchiveUrl, resourcePackagePath, cts.Token);
|
||||
await DownloadFileAsync(client, ResourceArchiveUrl, resourcePackagePath, ResourceDownloadTimeoutSeconds);
|
||||
|
||||
var checksumAsset = release.Assets.FirstOrDefault(x =>
|
||||
string.Equals(x.Name, AssetName + ".sha256", StringComparison.OrdinalIgnoreCase));
|
||||
if (checksumAsset != null)
|
||||
{
|
||||
var checksumPath = Path.Combine(tempRoot, checksumAsset.Name);
|
||||
await DownloadFileAsync(client, checksumAsset.DownloadUrl, checksumPath, cts.Token);
|
||||
await DownloadFileAsync(client, checksumAsset.DownloadUrl, checksumPath, ChecksumDownloadTimeoutSeconds);
|
||||
VerifySha256(packagePath, checksumPath);
|
||||
}
|
||||
|
||||
@@ -166,12 +170,11 @@ public static class UpdateService
|
||||
private static async Task DownloadAndInstallResourcesAsync()
|
||||
{
|
||||
using var client = CreateHttpClient();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(1, TimeoutSeconds)));
|
||||
var tempRoot = Path.Combine(Path.GetTempPath(), "MikuSB", "resources", Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(tempRoot);
|
||||
|
||||
var resourcePackagePath = Path.Combine(tempRoot, "MikuSB-Resource-main.zip");
|
||||
await DownloadFileAsync(client, ResourceArchiveUrl, resourcePackagePath, cts.Token);
|
||||
await DownloadFileAsync(client, ResourceArchiveUrl, resourcePackagePath, ResourceDownloadTimeoutSeconds);
|
||||
InstallResourcesFromArchive(resourcePackagePath,
|
||||
Path.Combine(AppContext.BaseDirectory, ConfigManager.Config.Path.ResourcePath));
|
||||
}
|
||||
@@ -214,7 +217,7 @@ public static class UpdateService
|
||||
{
|
||||
var client = new HttpClient
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(Math.Max(1, TimeoutSeconds))
|
||||
Timeout = Timeout.InfiniteTimeSpan
|
||||
};
|
||||
|
||||
client.DefaultRequestHeaders.UserAgent.Add(
|
||||
@@ -251,14 +254,15 @@ public static class UpdateService
|
||||
HttpClient client,
|
||||
string downloadUrl,
|
||||
string destinationPath,
|
||||
CancellationToken cancellationToken)
|
||||
int timeoutSeconds)
|
||||
{
|
||||
using var response = await client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(1, timeoutSeconds)));
|
||||
using var response = await client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cts.Token);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
await using var source = await response.Content.ReadAsStreamAsync(cancellationToken);
|
||||
await using var source = await response.Content.ReadAsStreamAsync(cts.Token);
|
||||
await using var destination = File.Create(destinationPath);
|
||||
await source.CopyToAsync(destination, cancellationToken);
|
||||
await source.CopyToAsync(destination, cts.Token);
|
||||
}
|
||||
|
||||
private static void CopyDirectory(string sourceDirectory, string targetDirectory)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# MikuSB
|
||||
|
||||
Snowbreak: Containment Zone private server reimplementation written in C#.
|
||||
<strong>MikuSB</strong> is a server emulator of a certain dungeon anime game.
|
||||
`SdkServer`, `GameServer`, and an optional local HTTP/HTTPS proxy are started from a single `net9.0` application.
|
||||
|
||||
[Discord](https://discord.gg/aMwCu9JyUR)
|
||||
@@ -86,7 +86,6 @@ It is not intended for unauthorized access to, interference with, or commercial
|
||||
|
||||
## Legal Disclaimer
|
||||
MikuSB was developed for educational and research purposes.
|
||||
- This project is not affiliated with or endorsed by SEASUN GAMES PTE. LTD.
|
||||
- All trademarks, copyrights, and other intellectual property related to the original game and its associated franchise belong to their respective owners.
|
||||
- This repository does not include any copyrighted game assets, binaries, or master data.
|
||||
- Use this software at your own risk. The authors assume no responsibility for any damages or legal consequences resulting from its use.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# MikuSB
|
||||
|
||||
Snowbreak: Containment Zone 向けの C# 製プライベートサーバー再実装です。
|
||||
<strong>MikuSB</strong>は、あるダンジョンアニメゲームのサーバーエミュレーターです。
|
||||
`SdkServer`、`GameServer`、任意のローカル HTTP/HTTPS プロキシを 1 つの `net9.0` アプリとして起動します。
|
||||
|
||||
[Discord](https://discord.gg/aMwCu9JyUR)
|
||||
@@ -87,7 +87,6 @@ dotnet build
|
||||
|
||||
## 法的免責事項
|
||||
MikuSBは教育および研究目的で開発されました。
|
||||
- このプロジェクトはSEASUN GAMES PTE. LTD. と一切関係が無く、承認も受けていません。
|
||||
- 元のゲーム及び関連フランチャイズに関するすべての商標、著作権知的財産権はそれぞれの所有者に帰属します。
|
||||
- このリポジトリには、著作権で保護されたゲームアセット、バイナリ、マスターデータは一切含まれていません。
|
||||
- 自己責任でご利用下さい。 著者は、本ソフトウェアによって生じるいかなる損害または法的結果についても一切責任を負いません。
|
||||
|
||||
@@ -1 +1 @@
|
||||
v=0.5
|
||||
v=1.1
|
||||
Reference in New Issue
Block a user