mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 16:23:58 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cac82d10d | ||
|
|
1e4d93bab1 | ||
|
|
5f92f2c116 |
@@ -16,7 +16,7 @@ public class HttpServerConfig
|
|||||||
public string BindAddress { get; set; } = "0.0.0.0";
|
public string BindAddress { get; set; } = "0.0.0.0";
|
||||||
public string PublicAddress { get; set; } = "127.0.0.1";
|
public string PublicAddress { get; set; } = "127.0.0.1";
|
||||||
public int Port { get; set; } = 21500;
|
public int Port { get; set; } = 21500;
|
||||||
public bool EnableLog { get; set; } = true;
|
public bool EnableLog { get; set; } = false;
|
||||||
|
|
||||||
public string GetDisplayAddress()
|
public string GetDisplayAddress()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public class CardExcel : ExcelResource
|
|||||||
[JsonProperty("profile")] public List<List<int>> Profile { get; set; } = [];
|
[JsonProperty("profile")] public List<List<int>> Profile { get; set; } = [];
|
||||||
public List<List<int>> Pieces { get; set; } = [];
|
public List<List<int>> Pieces { get; set; } = [];
|
||||||
public List<int> Attribute { get; set; } = [];
|
public List<int> Attribute { get; set; } = [];
|
||||||
|
[JsonProperty("SpineID")] public uint SpineId { get; set; }
|
||||||
public override uint GetId()
|
public override uint GetId()
|
||||||
{
|
{
|
||||||
return Icon;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@ public static class GameData
|
|||||||
public static Dictionary<uint, ArItemExcel> ArItemData { get; private set; } = [];
|
public static Dictionary<uint, ArItemExcel> ArItemData { get; private set; } = [];
|
||||||
public static Dictionary<uint, ManifestationExcel> ManifestationData { 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, 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 class GameResourceTemplateId
|
public static class GameResourceTemplateId
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public class CharacterInfo
|
|||||||
public int Exp { get; set; }
|
public int Exp { get; set; }
|
||||||
public uint Break { get; set; }
|
public uint Break { get; set; }
|
||||||
public int Evolue { get; set; }
|
public int Evolue { get; set; }
|
||||||
|
public uint ProLevel { get; set; }
|
||||||
public int Trust { get; set; }
|
public int Trust { get; set; }
|
||||||
public uint WeaponUniqueId { get; set; }
|
public uint WeaponUniqueId { get; set; }
|
||||||
public uint SkinId { get; set; }
|
public uint SkinId { get; set; }
|
||||||
@@ -45,6 +46,7 @@ public class CharacterInfo
|
|||||||
Exp = ToUInt32(Exp),
|
Exp = ToUInt32(Exp),
|
||||||
Break = Break,
|
Break = Break,
|
||||||
Evolue = ToUInt32(Evolue),
|
Evolue = ToUInt32(Evolue),
|
||||||
|
ProLevel = ProLevel,
|
||||||
Trust = ToUInt32(Trust)
|
Trust = ToUInt32(Trust)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class GameWeaponInfo : GrowableItemInfo
|
|||||||
}
|
}
|
||||||
}public class GameSkinInfo : BaseGameItemInfo
|
}public class GameSkinInfo : BaseGameItemInfo
|
||||||
{
|
{
|
||||||
public uint Level { get; set; }
|
public uint SkinType { get; set; }
|
||||||
public override Item ToProto()
|
public override Item ToProto()
|
||||||
{
|
{
|
||||||
var proto = new Item
|
var proto = new Item
|
||||||
@@ -79,6 +79,7 @@ public class GameWeaponInfo : GrowableItemInfo
|
|||||||
Count = ItemCount,
|
Count = ItemCount,
|
||||||
Flag = (uint)Flag,
|
Flag = (uint)Flag,
|
||||||
};
|
};
|
||||||
|
proto.Slots[11] = SkinType;
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ public class PlayerGameData : BaseDatabaseDataHelper
|
|||||||
public Sex Gender { get; set; } = Sex.Female;
|
public Sex Gender { get; set; } = Sex.Female;
|
||||||
public uint Vigor { get; set; } = 240;
|
public uint Vigor { get; set; } = 240;
|
||||||
[SugarColumn(IsJson = true)] public List<PlayerAttr> Attrs { get; set; } = [];
|
[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; } = [];
|
[SugarColumn(IsJson = true)] public List<ulong> ShowItems { get; set; } = [];
|
||||||
|
|
||||||
public static PlayerGameData? GetPlayerByUid(long uid)
|
public static PlayerGameData? GetPlayerByUid(long uid)
|
||||||
@@ -46,3 +47,10 @@ public class PlayerAttr
|
|||||||
public uint Sid { get; set; }
|
public uint Sid { get; set; }
|
||||||
public uint Val { 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);
|
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;
|
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);
|
?? await Player.InventoryManager!.AddSkinItem(ItemTypeEnum.TYPE_CARD_SKIN, detail, particular, level, false);
|
||||||
if (skinInfo != null) character.SkinId = skinInfo.UniqueId;
|
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);
|
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;
|
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);
|
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;
|
if (skinData == null) return null;
|
||||||
|
|
||||||
var templateId = GameResourceTemplateId.FromGdpl((uint)genre,detail,particular,level);
|
var templateId = GameResourceTemplateId.FromGdpl((uint)genre,detail,particular,level);
|
||||||
var skinInfo = new BaseGameItemInfo
|
var skinInfo = new GameSkinInfo
|
||||||
{
|
{
|
||||||
TemplateId = templateId,
|
TemplateId = templateId,
|
||||||
UniqueId = InventoryData.NextUniqueUid++,
|
UniqueId = InventoryData.NextUniqueUid++,
|
||||||
ItemType = ItemTypeEnum.TYPE_CARD_SKIN,
|
ItemType = ItemTypeEnum.TYPE_CARD_SKIN,
|
||||||
ItemCount = 1
|
ItemCount = 1
|
||||||
};
|
};
|
||||||
InventoryData.Items[skinInfo.UniqueId] = skinInfo;
|
InventoryData.Skins[skinInfo.UniqueId] = skinInfo;
|
||||||
|
|
||||||
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([skinInfo]));
|
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([skinInfo]));
|
||||||
|
|
||||||
return 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)
|
public async ValueTask<BaseGameItemInfo?> AddArItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
|
||||||
{
|
{
|
||||||
if (genre != ItemTypeEnum.TYPE_AR) return null;
|
if (genre != ItemTypeEnum.TYPE_AR) return null;
|
||||||
|
|||||||
@@ -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.Nodes;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
@@ -15,16 +16,35 @@ public class GirlSkin_ChangeSkinType : ICallGSHandler
|
|||||||
["nType"] = req?.Type ?? 1,
|
["nType"] = req?.Type ?? 1,
|
||||||
["nSkinId"] = req?.SkinId
|
["nSkinId"] = req?.SkinId
|
||||||
};
|
};
|
||||||
// TODO change type in proto Item ??
|
if (req == null)
|
||||||
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString());
|
{
|
||||||
|
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
|
internal sealed class ChangeSkinTypeParam
|
||||||
{
|
{
|
||||||
[JsonPropertyName("nType")]
|
[JsonPropertyName("nType")]
|
||||||
public int? Type { get; set; }
|
public uint Type { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("nSkinId")]
|
[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; } = [];
|
||||||
|
}
|
||||||
@@ -63,6 +63,7 @@ public class PacketNtfCallScript : BasePacket
|
|||||||
|
|
||||||
var extraSync = new NtfSyncPlayer();
|
var extraSync = new NtfSyncPlayer();
|
||||||
foreach (var item in inventory.Items.Values) 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());
|
foreach (var weapon in inventory.Weapons.Values) extraSync.Items.Add(weapon.ToProto());
|
||||||
proto.ExtraSync = extraSync;
|
proto.ExtraSync = extraSync;
|
||||||
SetData(proto);
|
SetData(proto);
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v=0.9
|
v=1.0
|
||||||
Reference in New Issue
Block a user