mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 08:23:58 +00:00
Compare commits
19 Commits
5aa5ef92d0
...
v3.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
125dadd224 | ||
|
|
cfca2f970c | ||
|
|
9a9ae13da0 | ||
|
|
1938095ea5 | ||
|
|
132355d76b | ||
|
|
5a8e45a44c | ||
|
|
def4b8ae68 | ||
|
|
686794a68c | ||
|
|
3bc30812aa | ||
|
|
f8f7311997 | ||
|
|
e628a010be | ||
|
|
738a7d4e14 | ||
|
|
0058ba0db6 | ||
|
|
46d945f3ce | ||
|
|
e5ecdc7f2a | ||
|
|
30c52b6aa8 | ||
|
|
3ffb7ebf29 | ||
|
|
400db16f39 | ||
|
|
42b1ad1024 |
32
Common/Data/Excel/BossPvpBossChallengeExcel.cs
Normal file
32
Common/Data/Excel/BossPvpBossChallengeExcel.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("challenge/bosspvp/boss_challenge.json")]
|
||||||
|
public class BossPvpBossChallengeExcel : ExcelResource
|
||||||
|
{
|
||||||
|
public uint ID { get; set; }
|
||||||
|
public string StartTime { get; set; } = "";
|
||||||
|
public string EndTime { get; set; } = "";
|
||||||
|
public List<uint> tbTaskID { get; set; } = [];
|
||||||
|
|
||||||
|
[JsonExtensionData] public IDictionary<string, JToken> ExtraData { get; set; } = new Dictionary<string, JToken>();
|
||||||
|
|
||||||
|
[JsonIgnore] public List<uint> BossIds { get; private set; } = [];
|
||||||
|
|
||||||
|
public override uint GetId() => ID;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
BossIds = ExtraData
|
||||||
|
.Where(x => x.Key.StartsWith("Boss", StringComparison.Ordinal) && int.TryParse(x.Key[4..], out _))
|
||||||
|
.OrderBy(x => int.Parse(x.Key[4..], CultureInfo.InvariantCulture))
|
||||||
|
.Select(x => x.Value.Type == JTokenType.Integer ? x.Value.Value<uint>() : 0u)
|
||||||
|
.Where(x => x > 0)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
GameData.BossPvpBossChallengeData[ID] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Common/Data/Excel/BossPvpBossExcel.cs
Normal file
17
Common/Data/Excel/BossPvpBossExcel.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("challenge/bosspvp/boss.json")]
|
||||||
|
public class BossPvpBossExcel : ExcelResource
|
||||||
|
{
|
||||||
|
public uint ID { get; set; }
|
||||||
|
public uint LevelID { get; set; }
|
||||||
|
public uint BossID { get; set; }
|
||||||
|
public List<List<int>> BossLevel { get; set; } = [];
|
||||||
|
|
||||||
|
public override uint GetId() => ID;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.BossPvpBossData[ID] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Common/Data/Excel/BossPvpNumExcel.cs
Normal file
15
Common/Data/Excel/BossPvpNumExcel.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("challenge/bosspvp/num.json")]
|
||||||
|
public class BossPvpNumExcel : ExcelResource
|
||||||
|
{
|
||||||
|
public uint Week { get; set; }
|
||||||
|
public uint Num { get; set; }
|
||||||
|
|
||||||
|
public override uint GetId() => Week;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.BossPvpNumData[Week] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
46
Common/Data/Excel/GachaExcel.cs
Normal file
46
Common/Data/Excel/GachaExcel.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using MikuSB.Util;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("gacha/gacha.json")]
|
||||||
|
public class GachaExcel : ExcelResource
|
||||||
|
{
|
||||||
|
public uint ID { get; set; }
|
||||||
|
public List<string>? Pool { get; set; }
|
||||||
|
public uint Probability { get; set; }
|
||||||
|
public uint ProbabilityTen { get; set; }
|
||||||
|
public JToken? ProtectNum { get; set; }
|
||||||
|
public JToken? UpNum { get; set; }
|
||||||
|
public uint? ProtectTag { get; set; }
|
||||||
|
public uint? ProtectType { get; set; }
|
||||||
|
public JToken? ProtectCount { get; set; }
|
||||||
|
public uint? UpSelect { get; set; }
|
||||||
|
|
||||||
|
public override uint GetId() => ID;
|
||||||
|
public override void Loaded() => GameData.GachaData[ID] = this;
|
||||||
|
|
||||||
|
public override void AfterAllDone()
|
||||||
|
{
|
||||||
|
foreach (var poolName in Pool ?? [])
|
||||||
|
{
|
||||||
|
if (GameData.GachaPoolData.ContainsKey(poolName)) continue;
|
||||||
|
var path = ConfigManager.Config.Path.ResourcePath + "/gacha/pool/" + poolName + ".json";
|
||||||
|
if (!File.Exists(path)) continue;
|
||||||
|
var json = File.ReadAllText(path);
|
||||||
|
var items = JsonConvert.DeserializeObject<List<GachaPoolItem>>(json) ?? [];
|
||||||
|
GameData.GachaPoolData[poolName] = items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GachaPoolItem
|
||||||
|
{
|
||||||
|
public int ID { get; set; }
|
||||||
|
public int Rarity { get; set; }
|
||||||
|
public List<uint> GDPL { get; set; } = [];
|
||||||
|
public int Weight { get; set; }
|
||||||
|
public int? UPTag { get; set; }
|
||||||
|
public int? UPSelectTag { get; set; }
|
||||||
|
}
|
||||||
18
Common/Data/Excel/GachaProbabilityExcel.cs
Normal file
18
Common/Data/Excel/GachaProbabilityExcel.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("gacha/probability.json")]
|
||||||
|
public class GachaProbabilityExcel : ExcelResource
|
||||||
|
{
|
||||||
|
public uint ID { get; set; }
|
||||||
|
public int Rarity1 { get; set; }
|
||||||
|
public int Rarity2 { get; set; }
|
||||||
|
public int Rarity3 { get; set; }
|
||||||
|
public int Rarity4 { get; set; }
|
||||||
|
public int Rarity5 { get; set; }
|
||||||
|
public int Rarity6 { get; set; }
|
||||||
|
|
||||||
|
public int[] Weights => [Rarity1, Rarity2, Rarity3, Rarity4, Rarity5, Rarity6];
|
||||||
|
|
||||||
|
public override uint GetId() => ID;
|
||||||
|
public override void Loaded() => GameData.GachaProbabilityData[ID] = this;
|
||||||
|
}
|
||||||
14
Common/Data/Excel/RoleLevelExcel.cs
Normal file
14
Common/Data/Excel/RoleLevelExcel.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("challenge/role/level.json")]
|
||||||
|
public class RoleLevelExcel : ExcelResource
|
||||||
|
{
|
||||||
|
public uint ID { get; set; }
|
||||||
|
|
||||||
|
public override uint GetId() => ID;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.RoleLevelData[ID] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
Common/Data/Excel/SupportAffixExcel.cs
Normal file
27
Common/Data/Excel/SupportAffixExcel.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("item/support/affix.json")]
|
||||||
|
public class SupportAffixExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("ID")] public int Id { get; set; }
|
||||||
|
[JsonExtensionData] public IDictionary<string, JToken> ExtraData { get; set; } = new Dictionary<string, JToken>();
|
||||||
|
|
||||||
|
public int TierCount =>
|
||||||
|
ExtraData
|
||||||
|
.Where(x => x.Key != "ID" && x.Key != "Sift" && x.Key != "Comment")
|
||||||
|
.Select(x => x.Value)
|
||||||
|
.OfType<JObject>()
|
||||||
|
.Select(x => x.Count)
|
||||||
|
.DefaultIfEmpty(0)
|
||||||
|
.Max();
|
||||||
|
|
||||||
|
public override uint GetId() => (uint)Id;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.SupportAffixData[Id] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
Common/Data/Excel/SupportAffixPoolExcel.cs
Normal file
35
Common/Data/Excel/SupportAffixPoolExcel.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("item/support/affix_pool.json")]
|
||||||
|
public class SupportAffixPoolExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("ID")] public int Id { get; set; }
|
||||||
|
public List<int> AffixGroup1 { get; set; } = [];
|
||||||
|
public int Weight1 { get; set; }
|
||||||
|
public List<int> AffixGroup2 { get; set; } = [];
|
||||||
|
public int Weight2 { get; set; }
|
||||||
|
public List<int> AffixGroup3 { get; set; } = [];
|
||||||
|
public int Weight3 { get; set; }
|
||||||
|
public List<int> AffixGroup4 { get; set; } = [];
|
||||||
|
public int Weight4 { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<(IReadOnlyList<int> Affixs, int Weight)> Groups
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (AffixGroup1.Count > 0 && Weight1 > 0) yield return (AffixGroup1, Weight1);
|
||||||
|
if (AffixGroup2.Count > 0 && Weight2 > 0) yield return (AffixGroup2, Weight2);
|
||||||
|
if (AffixGroup3.Count > 0 && Weight3 > 0) yield return (AffixGroup3, Weight3);
|
||||||
|
if (AffixGroup4.Count > 0 && Weight4 > 0) yield return (AffixGroup4, Weight4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override uint GetId() => (uint)Id;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.SupportAffixPoolData[Id] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace MikuSB.Data.Excel;
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
@@ -11,7 +12,12 @@ public class SupportCardExcel : ExcelResource
|
|||||||
public uint Level { get; set; }
|
public uint Level { get; set; }
|
||||||
public uint Icon { get; set; }
|
public uint Icon { get; set; }
|
||||||
public uint ProvideExp { get; set; }
|
public uint ProvideExp { get; set; }
|
||||||
|
public uint Color { get; set; }
|
||||||
[JsonProperty("LevelLimitID")] public int LevelLimitId { get; set; }
|
[JsonProperty("LevelLimitID")] public int LevelLimitId { get; set; }
|
||||||
|
[JsonProperty("AffixPool")] public List<int> AffixPool { get; set; } = [];
|
||||||
|
[JsonProperty("AffixCost")] public JToken? AffixCostRaw { get; set; }
|
||||||
|
[JsonProperty("InitialAffixCost")] public JToken? InitialAffixCostRaw { get; set; }
|
||||||
|
[JsonProperty("FixedAffixCost")] public JToken? FixedAffixCostRaw { get; set; }
|
||||||
|
|
||||||
public uint MaxLevel => LevelLimitId switch
|
public uint MaxLevel => LevelLimitId switch
|
||||||
{
|
{
|
||||||
@@ -21,6 +27,19 @@ public class SupportCardExcel : ExcelResource
|
|||||||
_ => 10
|
_ => 10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public int InitialAffixCount => Color >= 5 ? 2 : 1;
|
||||||
|
|
||||||
|
public int TotalAffixCount => Color >= 5 ? 3 : 2;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public IReadOnlyList<uint> AffixCost => ParseFlatCost(AffixCostRaw);
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public IReadOnlyList<IReadOnlyList<uint>> InitialAffixCost => ParseNestedCost(InitialAffixCostRaw);
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public IReadOnlyList<uint> FixedAffixCost => ParseFlatCost(FixedAffixCostRaw);
|
||||||
|
|
||||||
public ulong TemplateId => GameResourceTemplateId.FromGdpl(Genre, Detail, Particular, Level);
|
public ulong TemplateId => GameResourceTemplateId.FromGdpl(Genre, Detail, Particular, Level);
|
||||||
|
|
||||||
public override uint GetId() => Icon;
|
public override uint GetId() => Icon;
|
||||||
@@ -29,4 +48,23 @@ public class SupportCardExcel : ExcelResource
|
|||||||
{
|
{
|
||||||
GameData.SupportCardData.Add(this);
|
GameData.SupportCardData.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IReadOnlyList<uint> ParseFlatCost(JToken? token)
|
||||||
|
{
|
||||||
|
if (token is not JArray array)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
return array.Select(x => x.Value<uint>()).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IReadOnlyList<IReadOnlyList<uint>> ParseNestedCost(JToken? token)
|
||||||
|
{
|
||||||
|
if (token is not JArray outer)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
var result = new List<IReadOnlyList<uint>>();
|
||||||
|
foreach (var entry in outer.OfType<JArray>())
|
||||||
|
result.Add(entry.Select(x => x.Value<uint>()).ToArray());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
Common/Data/Excel/SupportFixedExcel.cs
Normal file
18
Common/Data/Excel/SupportFixedExcel.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("item/support/fixed.json")]
|
||||||
|
public class SupportFixedExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("ID")] public int Id { get; set; }
|
||||||
|
public int Num { get; set; }
|
||||||
|
public List<uint> Item { get; set; } = [];
|
||||||
|
|
||||||
|
public override uint GetId() => (uint)Id;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.SupportFixedData[Id] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ public static class GameData
|
|||||||
public static Dictionary<int, BreakLevelLimitExcel> BreakLevelLimitData { get; private set; } = [];
|
public static Dictionary<int, BreakLevelLimitExcel> BreakLevelLimitData { get; private set; } = [];
|
||||||
public static Dictionary<int, RecycleExcel> RecycleData { get; private set; } = [];
|
public static Dictionary<int, RecycleExcel> RecycleData { get; private set; } = [];
|
||||||
public static Dictionary<uint, ChapterLevelExcel> ChapterLevelData { get; private set; } = [];
|
public static Dictionary<uint, ChapterLevelExcel> ChapterLevelData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, RoleLevelExcel> RoleLevelData { get; private set; } = [];
|
||||||
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; } = [];
|
||||||
@@ -23,8 +24,14 @@ public static class GameData
|
|||||||
public static Dictionary<uint, SpineExcel> SpineData { get; private set; } = [];
|
public static Dictionary<uint, SpineExcel> SpineData { get; private set; } = [];
|
||||||
public static Dictionary<uint, NodeConditionExcel> NodeConditionData { get; private set; } = [];
|
public static Dictionary<uint, NodeConditionExcel> NodeConditionData { get; private set; } = [];
|
||||||
public static List<SupportCardExcel> SupportCardData { get; private set; } = [];
|
public static List<SupportCardExcel> SupportCardData { get; private set; } = [];
|
||||||
|
public static Dictionary<int, SupportAffixExcel> SupportAffixData { get; private set; } = [];
|
||||||
|
public static Dictionary<int, SupportAffixPoolExcel> SupportAffixPoolData { get; private set; } = [];
|
||||||
|
public static Dictionary<int, SupportFixedExcel> SupportFixedData { get; private set; } = [];
|
||||||
public static Dictionary<uint, WeaponSkinExcel> WeaponSkinData { get; private set; } = [];
|
public static Dictionary<uint, WeaponSkinExcel> WeaponSkinData { get; private set; } = [];
|
||||||
public static Dictionary<uint, DailyLevelExcel> DailyLevelData { get; private set; } = [];
|
public static Dictionary<uint, DailyLevelExcel> DailyLevelData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, BossPvpBossChallengeExcel> BossPvpBossChallengeData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, BossPvpBossExcel> BossPvpBossData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, BossPvpNumExcel> BossPvpNumData { get; private set; } = [];
|
||||||
public static Dictionary<uint, ProfileExcel> ProfileData { get; private set; } = [];
|
public static Dictionary<uint, ProfileExcel> ProfileData { get; private set; } = [];
|
||||||
public static Dictionary<uint, CardSkinPartsExcel> CardSkinPartsData { get; private set; } = [];
|
public static Dictionary<uint, CardSkinPartsExcel> CardSkinPartsData { get; private set; } = [];
|
||||||
public static Dictionary<uint, CallItemExcel> CallItemData { get; private set; } = [];
|
public static Dictionary<uint, CallItemExcel> CallItemData { get; private set; } = [];
|
||||||
@@ -32,6 +39,9 @@ public static class GameData
|
|||||||
public static Dictionary<uint, GuideExcel> GuideData { get; private set; } = [];
|
public static Dictionary<uint, GuideExcel> GuideData { get; private set; } = [];
|
||||||
public static Dictionary<uint, DormGiftExcel> DormGiftData { get; private set; } = [];
|
public static Dictionary<uint, DormGiftExcel> DormGiftData { get; private set; } = [];
|
||||||
public static Dictionary<uint, HouseFurniturePosExcel> HouseFurniturePosData { get; private set; } = [];
|
public static Dictionary<uint, HouseFurniturePosExcel> HouseFurniturePosData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, GachaExcel> GachaData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, GachaProbabilityExcel> GachaProbabilityData { get; private set; } = [];
|
||||||
|
public static Dictionary<string, List<GachaPoolItem>> GachaPoolData { get; private set; } = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GameResourceTemplateId
|
public static class GameResourceTemplateId
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using MikuSB.Enums.Item;
|
using MikuSB.Enums.Item;
|
||||||
using MikuSB.Proto;
|
using MikuSB.Proto;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
@@ -10,19 +10,19 @@ public class InventoryData : BaseDatabaseDataHelper
|
|||||||
public uint NextUniqueUid { get; set; } = 100000;
|
public uint NextUniqueUid { get; set; } = 100000;
|
||||||
|
|
||||||
[SugarColumn(IsJson = true)]
|
[SugarColumn(IsJson = true)]
|
||||||
public Dictionary<uint, BaseGameItemInfo> Items { get; set; } = []; // Key: UniqueId
|
public Dictionary<uint, BaseGameItemInfo> Items { get; set; } = [];
|
||||||
|
|
||||||
[SugarColumn(IsJson = true)]
|
[SugarColumn(IsJson = true)]
|
||||||
public Dictionary<uint, GameWeaponInfo> Weapons { get; set; } = []; // Key: UniqueId
|
public Dictionary<uint, GameWeaponInfo> Weapons { get; set; } = [];
|
||||||
|
|
||||||
[SugarColumn(IsJson = true)]
|
[SugarColumn(IsJson = true)]
|
||||||
public Dictionary<uint, GameSkinInfo> Skins { get; set; } = []; // Key: UniqueId
|
public Dictionary<uint, GameSkinInfo> Skins { get; set; } = [];
|
||||||
|
|
||||||
[SugarColumn(IsJson = true)]
|
[SugarColumn(IsJson = true)]
|
||||||
public Dictionary<uint, GameSupportCardInfo> SupportCards { get; set; } = []; // Key: UniqueId
|
public Dictionary<uint, GameSupportCardInfo> SupportCards { get; set; } = [];
|
||||||
|
|
||||||
[SugarColumn(IsJson = true)]
|
[SugarColumn(IsJson = true)]
|
||||||
public Dictionary<uint, uint> SkinTypesBySkinId { get; set; } = []; // Key: nSkinId, Value: client nType
|
public Dictionary<uint, uint> SkinTypesBySkinId { get; set; } = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BaseGameItemInfo
|
public class BaseGameItemInfo
|
||||||
@@ -63,6 +63,7 @@ public abstract class GrowableItemInfo : BaseGameItemInfo
|
|||||||
public class GameWeaponInfo : GrowableItemInfo
|
public class GameWeaponInfo : GrowableItemInfo
|
||||||
{
|
{
|
||||||
[SugarColumn(IsJson = true)] public Dictionary<uint, ulong> PartSlots { get; set; } = [];
|
[SugarColumn(IsJson = true)] public Dictionary<uint, ulong> PartSlots { get; set; } = [];
|
||||||
|
|
||||||
public override Item ToProto()
|
public override Item ToProto()
|
||||||
{
|
{
|
||||||
var proto = new Item
|
var proto = new Item
|
||||||
@@ -79,14 +80,17 @@ public class GameWeaponInfo : GrowableItemInfo
|
|||||||
Evolue = Evolue
|
Evolue = Evolue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
foreach (var (slot, uid) in PartSlots) proto.Slots[slot] = uid;
|
foreach (var (slot, uid) in PartSlots)
|
||||||
|
proto.Slots[slot] = uid;
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GameSkinInfo : BaseGameItemInfo
|
public class GameSkinInfo : BaseGameItemInfo
|
||||||
{
|
{
|
||||||
[SugarColumn(IsJson = true)] public Dictionary<uint, ulong> PartSlots { get; set; } = [];
|
[SugarColumn(IsJson = true)] public Dictionary<uint, ulong> PartSlots { get; set; } = [];
|
||||||
public uint SkinType { get; set; }
|
public uint SkinType { get; set; }
|
||||||
|
|
||||||
public override Item ToProto()
|
public override Item ToProto()
|
||||||
{
|
{
|
||||||
var proto = new Item
|
var proto = new Item
|
||||||
@@ -97,15 +101,17 @@ public class GameSkinInfo : BaseGameItemInfo
|
|||||||
Flag = (uint)Flag,
|
Flag = (uint)Flag,
|
||||||
};
|
};
|
||||||
proto.Slots[(uint)ItemSkinSlotTypeEnum.SLOT_CARD_SKIL_TYPE] = Math.Min(SkinType, 1);
|
proto.Slots[(uint)ItemSkinSlotTypeEnum.SLOT_CARD_SKIL_TYPE] = Math.Min(SkinType, 1);
|
||||||
foreach (var (slot, uid) in PartSlots) proto.Slots[slot] = uid;
|
foreach (var (slot, uid) in PartSlots)
|
||||||
|
proto.Slots[slot] = uid;
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class GameSupportCardInfo : BaseGameItemInfo
|
public class GameSupportCardInfo : BaseGameItemInfo
|
||||||
{
|
{
|
||||||
public uint AffixId { get; set; }
|
public uint AffixId { get; set; }
|
||||||
|
[SugarColumn(IsJson = true)] public List<uint> Affixs { get; set; } = [];
|
||||||
|
|
||||||
public override Item ToProto()
|
public override Item ToProto()
|
||||||
{
|
{
|
||||||
var proto = new Item
|
var proto = new Item
|
||||||
@@ -120,6 +126,7 @@ public class GameSupportCardInfo : BaseGameItemInfo
|
|||||||
Exp = Exp
|
Exp = Exp
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
proto.Enhance.Affixs.AddRange(Affixs);
|
||||||
proto.Slots[(uint)ItemSupportCardSlotTypeEnum.SLOT_AFFIXINDEX] = AffixId;
|
proto.Slots[(uint)ItemSupportCardSlotTypeEnum.SLOT_AFFIXINDEX] = AffixId;
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,9 +222,16 @@ public class HelpTextCHS
|
|||||||
public class AccountTextCHS
|
public class AccountTextCHS
|
||||||
{
|
{
|
||||||
public string Desc => "管理 SDK 登录使用的账号映射";
|
public string Desc => "管理 SDK 登录使用的账号映射";
|
||||||
public string Usage => "用法: /account create <邮箱> <UID>";
|
public string Usage =>
|
||||||
|
"用法: /account create <邮箱> <UID>\n" +
|
||||||
|
"用法: /account delete <邮箱|UID>\n" +
|
||||||
|
"用法: /account list";
|
||||||
public string Created => "已创建账号映射: {0} -> UID {1}";
|
public string Created => "已创建账号映射: {0} -> UID {1}";
|
||||||
public string CreateFailed => "创建账号映射失败: {0}";
|
public string CreateFailed => "创建账号映射失败: {0}";
|
||||||
|
public string Deleted => "已删除账号映射: {0} -> UID {1}";
|
||||||
|
public string DeleteFailed => "删除账号映射失败: {0}";
|
||||||
|
public string DeleteOnline => "账号在线时无法删除: {0} -> UID {1}";
|
||||||
|
public string NotFound => "未找到账号: {0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -222,9 +222,16 @@ public class HelpTextCHT
|
|||||||
public class AccountTextCHT
|
public class AccountTextCHT
|
||||||
{
|
{
|
||||||
public string Desc => "管理 SDK 登入使用的帳號映射";
|
public string Desc => "管理 SDK 登入使用的帳號映射";
|
||||||
public string Usage => "用法: /account create <郵箱> <UID>";
|
public string Usage =>
|
||||||
|
"用法: /account create <郵箱> <UID>\n" +
|
||||||
|
"用法: /account delete <郵箱|UID>\n" +
|
||||||
|
"用法: /account list";
|
||||||
public string Created => "已建立帳號映射: {0} -> UID {1}";
|
public string Created => "已建立帳號映射: {0} -> UID {1}";
|
||||||
public string CreateFailed => "建立帳號映射失敗: {0}";
|
public string CreateFailed => "建立帳號映射失敗: {0}";
|
||||||
|
public string Deleted => "已刪除帳號映射: {0} -> UID {1}";
|
||||||
|
public string DeleteFailed => "刪除帳號映射失敗: {0}";
|
||||||
|
public string DeleteOnline => "帳號在線時無法刪除: {0} -> UID {1}";
|
||||||
|
public string NotFound => "未找到帳號: {0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -188,9 +188,16 @@ public class HelpTextEN
|
|||||||
public class AccountTextEN
|
public class AccountTextEN
|
||||||
{
|
{
|
||||||
public string Desc => "Manage account mappings for SDK logins";
|
public string Desc => "Manage account mappings for SDK logins";
|
||||||
public string Usage => "Usage: /account create <email> <uid>";
|
public string Usage =>
|
||||||
|
"Usage: /account create <email> <uid>\n" +
|
||||||
|
"Usage: /account delete <email|uid>\n" +
|
||||||
|
"Usage: /account list";
|
||||||
public string Created => "Created account mapping: {0} -> UID {1}";
|
public string Created => "Created account mapping: {0} -> UID {1}";
|
||||||
public string CreateFailed => "Failed to create account mapping: {0}";
|
public string CreateFailed => "Failed to create account mapping: {0}";
|
||||||
|
public string Deleted => "Deleted account mapping: {0} -> UID {1}";
|
||||||
|
public string DeleteFailed => "Failed to delete account mapping: {0}";
|
||||||
|
public string DeleteOnline => "Cannot delete account while online: {0} -> UID {1}";
|
||||||
|
public string NotFound => "Account not found: {0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ public static class ConfigManager
|
|||||||
//LoadHotfixData();
|
//LoadHotfixData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SaveConfig()
|
||||||
|
{
|
||||||
|
SaveData(Config, ConfigFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
private static void LoadConfigData()
|
private static void LoadConfigData()
|
||||||
{
|
{
|
||||||
var file = new FileInfo(ConfigFilePath);
|
var file = new FileInfo(ConfigFilePath);
|
||||||
@@ -43,9 +48,26 @@ public static class ConfigManager
|
|||||||
Config = JsonConvert.DeserializeObject<ConfigContainer>(json)!;
|
Config = JsonConvert.DeserializeObject<ConfigContainer>(json)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Config.Loader.Arguments = NormalizeLoaderArguments(Config.Loader.Arguments);
|
||||||
SaveData(Config, ConfigFilePath);
|
SaveData(Config, ConfigFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string[] NormalizeLoaderArguments(string[]? arguments)
|
||||||
|
{
|
||||||
|
var result = new List<string>(arguments ?? []);
|
||||||
|
var userDataDirectory = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "Client_User_Data"));
|
||||||
|
Directory.CreateDirectory(userDataDirectory);
|
||||||
|
|
||||||
|
var userDirArgument = $"-userdir={userDataDirectory}";
|
||||||
|
var existingIndex = result.FindIndex(x => x.StartsWith("-userdir=", StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (existingIndex >= 0)
|
||||||
|
result[existingIndex] = userDirArgument;
|
||||||
|
else
|
||||||
|
result.Add(userDirArgument);
|
||||||
|
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
private static void LoadHotfixData()
|
private static void LoadHotfixData()
|
||||||
{
|
{
|
||||||
var file = new FileInfo(HotfixFilePath);
|
var file = new FileInfo(HotfixFilePath);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using MikuSB.Database;
|
|||||||
using MikuSB.Database.Account;
|
using MikuSB.Database.Account;
|
||||||
using MikuSB.Enums.Player;
|
using MikuSB.Enums.Player;
|
||||||
using MikuSB.Internationalization;
|
using MikuSB.Internationalization;
|
||||||
|
using MikuSB.GameServer.Server;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace MikuSB.GameServer.Command.Commands;
|
namespace MikuSB.GameServer.Command.Commands;
|
||||||
@@ -37,6 +38,42 @@ public class CommandAccount : ICommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[CommandMethod("delete")]
|
||||||
|
public async ValueTask Delete(CommandArg arg)
|
||||||
|
{
|
||||||
|
if (!await arg.CheckArgCnt(1))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var identifier = arg.Args[0].Trim();
|
||||||
|
var account = int.TryParse(identifier, out var uid) && uid > 0
|
||||||
|
? AccountData.GetAccountByUid(uid)
|
||||||
|
: AccountData.GetAccountByUserName(identifier);
|
||||||
|
|
||||||
|
if (account == null)
|
||||||
|
{
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.NotFound", identifier));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Listener.GetActiveConnection(account.Uid) != null)
|
||||||
|
{
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.DeleteOnline", account.Username,
|
||||||
|
account.Uid.ToString()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountData.DeleteAccount(account.Uid);
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.Deleted", account.Username,
|
||||||
|
account.Uid.ToString()));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.DeleteFailed", ex.Message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[CommandMethod("list")]
|
[CommandMethod("list")]
|
||||||
public async ValueTask List(CommandArg arg)
|
public async ValueTask List(CommandArg arg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using MikuSB.Database;
|
|||||||
using MikuSB.Database.Inventory;
|
using MikuSB.Database.Inventory;
|
||||||
using MikuSB.Enums.Item;
|
using MikuSB.Enums.Item;
|
||||||
using MikuSB.GameServer.Game.Player;
|
using MikuSB.GameServer.Game.Player;
|
||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
using MikuSB.GameServer.Server.Packet.Send.Misc;
|
using MikuSB.GameServer.Server.Packet.Send.Misc;
|
||||||
|
|
||||||
namespace MikuSB.GameServer.Game.Inventory;
|
namespace MikuSB.GameServer.Game.Inventory;
|
||||||
@@ -135,7 +136,17 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
|
|||||||
ItemType = genre,
|
ItemType = genre,
|
||||||
ItemCount = 1,
|
ItemCount = 1,
|
||||||
Level = cardLevel,
|
Level = cardLevel,
|
||||||
|
AffixId = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var affixCount = cardLevel >= spCard.MaxLevel ? spCard.TotalAffixCount : spCard.InitialAffixCount;
|
||||||
|
for (int i = 0; i < affixCount && i < spCard.AffixPool.Count; i++)
|
||||||
|
{
|
||||||
|
var (affixId, tier) = SupportAffixService.GenerateRandomAffix(spCard.AffixPool[i]);
|
||||||
|
if (affixId == 0) continue;
|
||||||
|
SupportAffixStateService.SetAffix(info, i + 1, affixId, tier);
|
||||||
|
}
|
||||||
|
|
||||||
InventoryData.SupportCards[info.UniqueId] = info;
|
InventoryData.SupportCards[info.UniqueId] = info;
|
||||||
|
|
||||||
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([info]));
|
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([info]));
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ public class PlayerInstance(PlayerGameData data)
|
|||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Proto.Player ToPlayerProto()
|
public Proto.Player ToPlayerProto(bool includeSupportCards = true)
|
||||||
{
|
{
|
||||||
BuildPlayerAttr();
|
BuildPlayerAttr();
|
||||||
var displayName = PlayerGameData.NormalizeDisplayName(Data.Name);
|
var displayName = PlayerGameData.NormalizeDisplayName(Data.Name);
|
||||||
@@ -217,7 +217,10 @@ public class PlayerInstance(PlayerGameData data)
|
|||||||
foreach (var item in InventoryManager.InventoryData.Items.Values) proto.Items.Add(item.ToProto());
|
foreach (var item in InventoryManager.InventoryData.Items.Values) proto.Items.Add(item.ToProto());
|
||||||
foreach (var skin in InventoryManager.InventoryData.Skins.Values) proto.Items.Add(skin.ToProto());
|
foreach (var skin in InventoryManager.InventoryData.Skins.Values) proto.Items.Add(skin.ToProto());
|
||||||
foreach (var weapon in InventoryManager.InventoryData.Weapons.Values) proto.Items.Add(weapon.ToProto());
|
foreach (var weapon in InventoryManager.InventoryData.Weapons.Values) proto.Items.Add(weapon.ToProto());
|
||||||
foreach (var card in InventoryManager.InventoryData.SupportCards.Values) proto.Items.Add(card.ToProto());
|
if (includeSupportCards)
|
||||||
|
{
|
||||||
|
foreach (var card in InventoryManager.InventoryData.SupportCards.Values) proto.Items.Add(card.ToProto());
|
||||||
|
}
|
||||||
foreach (var x in Data.Attrs)
|
foreach (var x in Data.Attrs)
|
||||||
{
|
{
|
||||||
uint gid = x.Gid;
|
uint gid = x.Gid;
|
||||||
@@ -422,6 +425,14 @@ public class PlayerInstance(PlayerGameData data)
|
|||||||
yield return (22, levelId, 1_700_000_000);
|
yield return (22, levelId, 1_700_000_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Role fragment chapters use Condition.PRE_LEVEL against Launch.GPASSID as well.
|
||||||
|
// Mark every role level as cleared so character-specific stages beyond the first one unlock.
|
||||||
|
foreach (var levelId in GameData.RoleLevelData.Keys)
|
||||||
|
{
|
||||||
|
yield return (21, levelId, 7);
|
||||||
|
yield return (22, levelId, 1_700_000_000);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var guide in GameData.GuideData.Values)
|
foreach (var guide in GameData.GuideData.Values)
|
||||||
{
|
{
|
||||||
yield return (4, guide.ID, 999);
|
yield return (4, guide.ID, 999);
|
||||||
|
|||||||
50
GameServer/Game/Support/SupportAffixService.cs
Normal file
50
GameServer/Game/Support/SupportAffixService.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Game.Support;
|
||||||
|
|
||||||
|
public static class SupportAffixService
|
||||||
|
{
|
||||||
|
public static (uint AffixId, uint Tier) GenerateRandomAffix(int poolId, IEnumerable<uint>? excludedAffixIds = null)
|
||||||
|
{
|
||||||
|
if (!GameData.SupportAffixPoolData.TryGetValue(poolId, out var pool))
|
||||||
|
return (0, 0);
|
||||||
|
|
||||||
|
var groups = pool.Groups.ToList();
|
||||||
|
if (groups.Count == 0)
|
||||||
|
return (0, 0);
|
||||||
|
|
||||||
|
var totalWeight = groups.Sum(x => x.Weight);
|
||||||
|
var roll = Random.Shared.Next(totalWeight);
|
||||||
|
var cumulative = 0;
|
||||||
|
var selectedAffixs = groups[0].Affixs;
|
||||||
|
|
||||||
|
foreach (var (affixIds, weight) in groups)
|
||||||
|
{
|
||||||
|
cumulative += weight;
|
||||||
|
if (roll < cumulative)
|
||||||
|
{
|
||||||
|
selectedAffixs = affixIds;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedAffixs.Count == 0)
|
||||||
|
return (0, 0);
|
||||||
|
|
||||||
|
var excluded = excludedAffixIds?.ToHashSet() ?? [];
|
||||||
|
var candidates = selectedAffixs.Where(x => !excluded.Contains((uint)x)).ToList();
|
||||||
|
if (candidates.Count == 0)
|
||||||
|
candidates = selectedAffixs.ToList();
|
||||||
|
|
||||||
|
var affixId = candidates[Random.Shared.Next(candidates.Count)];
|
||||||
|
var tierCount = GameData.SupportAffixData.GetValueOrDefault(affixId)?.TierCount ?? 5;
|
||||||
|
var tier = (uint)(Random.Shared.Next(tierCount) + 1);
|
||||||
|
return ((uint)affixId, tier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint GenerateTier(uint affixId)
|
||||||
|
{
|
||||||
|
var tierCount = GameData.SupportAffixData.GetValueOrDefault((int)affixId)?.TierCount ?? 5;
|
||||||
|
return (uint)(Random.Shared.Next(tierCount) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
70
GameServer/Game/Support/SupportAffixStateService.cs
Normal file
70
GameServer/Game/Support/SupportAffixStateService.cs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
using MikuSB.Database.Inventory;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Game.Support;
|
||||||
|
|
||||||
|
public static class SupportAffixStateService
|
||||||
|
{
|
||||||
|
public const int PairSize = 2;
|
||||||
|
public const int MaxLogicalSlots = 5;
|
||||||
|
public const int ActiveThirdAffixSlot = 3;
|
||||||
|
public const int PendingMaxAffixSlot = 4;
|
||||||
|
public const int PendingInitialAffixSlot = 5;
|
||||||
|
|
||||||
|
public static void EnsureCapacity(GameSupportCardInfo card, int logicalSlot = MaxLogicalSlots)
|
||||||
|
{
|
||||||
|
var minCount = Math.Clamp(logicalSlot, 1, MaxLogicalSlots) * PairSize;
|
||||||
|
while (card.Affixs.Count < minCount)
|
||||||
|
card.Affixs.Add(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (uint AffixId, uint Tier) GetAffix(GameSupportCardInfo card, int logicalSlot)
|
||||||
|
{
|
||||||
|
if (logicalSlot < 1 || logicalSlot > MaxLogicalSlots)
|
||||||
|
return (0, 0);
|
||||||
|
|
||||||
|
var index = (logicalSlot - 1) * PairSize;
|
||||||
|
if (card.Affixs.Count <= index + 1)
|
||||||
|
return (0, 0);
|
||||||
|
|
||||||
|
return (card.Affixs[index], card.Affixs[index + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HasAffix(GameSupportCardInfo card, int logicalSlot)
|
||||||
|
{
|
||||||
|
var (affixId, tier) = GetAffix(card, logicalSlot);
|
||||||
|
return affixId > 0 && tier > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetAffix(GameSupportCardInfo card, int logicalSlot, uint affixId, uint tier)
|
||||||
|
{
|
||||||
|
if (logicalSlot < 1 || logicalSlot > MaxLogicalSlots)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EnsureCapacity(card, logicalSlot);
|
||||||
|
var index = (logicalSlot - 1) * PairSize;
|
||||||
|
card.Affixs[index] = affixId;
|
||||||
|
card.Affixs[index + 1] = tier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ClearAffix(GameSupportCardInfo card, int logicalSlot)
|
||||||
|
{
|
||||||
|
SetAffix(card, logicalSlot, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CopyAffix(GameSupportCardInfo card, int fromSlot, int toSlot)
|
||||||
|
{
|
||||||
|
var (affixId, tier) = GetAffix(card, fromSlot);
|
||||||
|
SetAffix(card, toSlot, affixId, tier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint GetVisibleInitialAffixIndex(GameSupportCardInfo card)
|
||||||
|
{
|
||||||
|
return HasAffix(card, PendingInitialAffixSlot) ? card.AffixId : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void NormalizePendingState(GameSupportCardInfo card)
|
||||||
|
{
|
||||||
|
if (!HasAffix(card, PendingInitialAffixSlot))
|
||||||
|
card.AffixId = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
|
||||||
|
[CallGSApi("BossPvpLogic_EnterLevel")]
|
||||||
|
public class BossPvpLogic_EnterLevel : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var response = BossPvpShared.HandleEnterLevel(param);
|
||||||
|
await CallGSRouter.SendScript(connection, "BossPvpLogic_EnterLevel", System.Text.Json.JsonSerializer.Serialize(response));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
|
||||||
|
[CallGSApi("BossPvpLogic_GetOpenID")]
|
||||||
|
public class BossPvpLogic_GetOpenID : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var (response, sync) = await BossPvpShared.HandleGetOpenIdAsync(connection);
|
||||||
|
await CallGSRouter.SendScript(connection, "BossPvpLogic_GetOpenID", System.Text.Json.JsonSerializer.Serialize(response), sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
|
||||||
|
[CallGSApi("BossPvpLogic_GetReward")]
|
||||||
|
public class BossPvpLogic_GetReward : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var response = BossPvpShared.HandleGetReward(param);
|
||||||
|
await CallGSRouter.SendScript(connection, "BossPvpLogic_GetReward", System.Text.Json.JsonSerializer.Serialize(response));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
|
||||||
|
[CallGSApi("BossPvpLogic_LevelFail")]
|
||||||
|
public class BossPvpLogic_LevelFail : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var node = System.Text.Json.Nodes.JsonNode.Parse(param);
|
||||||
|
var (response, sync) = BossPvpShared.HandleFail(connection.Player!, node);
|
||||||
|
await CallGSRouter.SendScript(connection, "BossPvpLogic_LevelFail", response.ToJsonString(), sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
|
||||||
|
[CallGSApi("BossPvpLogic_LevelMopup")]
|
||||||
|
public class BossPvpLogic_LevelMopup : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var (response, sync) = BossPvpShared.HandleMopup(connection.Player!, param);
|
||||||
|
await CallGSRouter.SendScript(connection, "BossPvpLogic_LevelMopup", System.Text.Json.JsonSerializer.Serialize(response), sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
|
||||||
|
[CallGSApi("BossPvpLogic_LevelSettlement")]
|
||||||
|
public class BossPvpLogic_LevelSettlement : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var node = System.Text.Json.Nodes.JsonNode.Parse(param);
|
||||||
|
var (response, sync) = BossPvpShared.HandleSettlement(connection.Player!, node);
|
||||||
|
await CallGSRouter.SendScript(connection, "BossPvpLogic_LevelSettlement", response.ToJsonString(), sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
|
||||||
|
[CallGSApi("BossPvpLogic_Record")]
|
||||||
|
public class BossPvpLogic_Record : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var (response, sync) = BossPvpShared.HandleRecord(connection.Player!, param);
|
||||||
|
await CallGSRouter.SendScript(connection, "BossPvpLogic_Record", System.Text.Json.JsonSerializer.Serialize(response), sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
500
GameServer/Server/CallGS/Handlers/BossPvp/BossPvpShared.cs
Normal file
500
GameServer/Server/CallGS/Handlers/BossPvp/BossPvpShared.cs
Normal file
@@ -0,0 +1,500 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Data.Excel;
|
||||||
|
using MikuSB.Database.Inventory;
|
||||||
|
using MikuSB.GameServer.Game.Player;
|
||||||
|
using MikuSB.GameServer.Server.CallGS;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
|
||||||
|
internal static class BossPvpShared
|
||||||
|
{
|
||||||
|
private const uint GroupId = 51;
|
||||||
|
private const uint ActivitySubId = 0;
|
||||||
|
private const uint ChallengeNumSid = 1;
|
||||||
|
private const uint DiffStartId = 10;
|
||||||
|
private const uint LevelStartSid = 100;
|
||||||
|
private const uint LevelStride = 10;
|
||||||
|
private const uint BossLineup1 = 15;
|
||||||
|
private const uint BossLineup2 = 16;
|
||||||
|
|
||||||
|
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||||
|
{
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
||||||
|
};
|
||||||
|
|
||||||
|
public static async ValueTask<(object Response, NtfSyncPlayer Sync)> HandleGetOpenIdAsync(Connection connection)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
await EnsureBossLineupsAsync(player);
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
var season = GetOpenSeason();
|
||||||
|
var seasonId = season?.ID ?? 1u;
|
||||||
|
|
||||||
|
SetStr(player, ActivitySubId, seasonId.ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
SetStr(player, ChallengeNumSid, GetDailyChallengeNum().ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
|
||||||
|
if (season != null)
|
||||||
|
{
|
||||||
|
for (var index = 0; index < season.BossIds.Count; index++)
|
||||||
|
{
|
||||||
|
var bossLevelId = season.BossIds[index];
|
||||||
|
EnsureStr(player, DiffStartId + (uint)(index + 1), "0", sync);
|
||||||
|
EnsureStr(player, GetBossSid(bossLevelId, 1), EmptySnapshotJson(), sync);
|
||||||
|
EnsureStr(player, GetBossSid(bossLevelId, 2), EmptySnapshotJson(), sync);
|
||||||
|
EnsureStr(player, GetBossSid(bossLevelId, 3), EmptySnapshotJson(), sync);
|
||||||
|
EnsureStr(player, GetBossSid(bossLevelId, 4), "0", sync);
|
||||||
|
EnsureStr(player, GetBossSid(bossLevelId, 5), "0", sync);
|
||||||
|
EnsureStr(player, GetBossSid(bossLevelId, 6), "0", sync);
|
||||||
|
EnsureStr(player, GetBossSid(bossLevelId, 7), "0", sync);
|
||||||
|
EnsureStr(player, GetBossSid(bossLevelId, 8), "0", sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = new
|
||||||
|
{
|
||||||
|
nID = seasonId,
|
||||||
|
tbTimeCfg = new[]
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
nStartTime = -1,
|
||||||
|
nEndTime = -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (response, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object HandleEnterLevel(string? param)
|
||||||
|
{
|
||||||
|
var req = Deserialize<EnterLevelParam>(param);
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
nSeed = Random.Shared.Next(1, int.MaxValue),
|
||||||
|
nID = req?.NId ?? 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (object Response, NtfSyncPlayer Sync) HandleRecord(PlayerInstance player, string? param)
|
||||||
|
{
|
||||||
|
var req = Deserialize<RecordParam>(param);
|
||||||
|
if (req == null)
|
||||||
|
{
|
||||||
|
return (new { bRecord = false }, new NtfSyncPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
if (req.BRecord)
|
||||||
|
{
|
||||||
|
var historyScore = ReadInt(player, GetBossSid(req.NId, 4));
|
||||||
|
var currentScore = ComputeIntegral(req.NId, req.NDiff, req.ResidueTime);
|
||||||
|
if (currentScore >= historyScore)
|
||||||
|
{
|
||||||
|
WriteBestRun(player, req.NId, req.NTeamId, req.NTime, currentScore, sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new { bRecord = req.BRecord }, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (JsonNode Response, NtfSyncPlayer Sync) HandleSettlement(PlayerInstance player, JsonNode? param)
|
||||||
|
{
|
||||||
|
var req = param?.Deserialize<SettlementParam>(JsonOptions);
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
if (req == null)
|
||||||
|
{
|
||||||
|
return (new JsonObject(), sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalSid = GetBossSid(req.NId, 7);
|
||||||
|
var successSid = GetBossSid(req.NId, 6);
|
||||||
|
var diffSid = GetBossSid(req.NId, 8);
|
||||||
|
|
||||||
|
SetStr(player, totalSid, (ReadInt(player, totalSid) + 1).ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
SetStr(player, successSid, (ReadInt(player, successSid) + 1).ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
|
||||||
|
var clearedDiff = Math.Max(ReadInt(player, diffSid), req.NDiff);
|
||||||
|
SetStr(player, diffSid, clearedDiff.ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
|
||||||
|
var positionSid = TryGetPositionDiffSid(req.NId);
|
||||||
|
if (positionSid != null)
|
||||||
|
{
|
||||||
|
var newPositionDiff = Math.Max(ReadInt(player, positionSid.Value), req.NDiff);
|
||||||
|
SetStr(player, positionSid.Value, newPositionDiff.ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
var score = ComputeIntegral(req.NId, req.NDiff, req.ResidueTime);
|
||||||
|
if (score > ReadInt(player, GetBossSid(req.NId, 4)))
|
||||||
|
{
|
||||||
|
WriteBestRun(player, req.NId, req.NTeamId, req.NTime, score, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new JsonObject(), sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (JsonNode Response, NtfSyncPlayer Sync) HandleFail(PlayerInstance player, JsonNode? param)
|
||||||
|
{
|
||||||
|
var req = param?.Deserialize<FailParam>(JsonOptions);
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
if (req == null)
|
||||||
|
{
|
||||||
|
return (new JsonObject(), sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalSid = GetBossSid(req.NId, 7);
|
||||||
|
SetStr(player, totalSid, (ReadInt(player, totalSid) + 1).ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
|
||||||
|
return (new JsonObject(), sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (object Response, NtfSyncPlayer Sync) HandleMopup(PlayerInstance player, string? param)
|
||||||
|
{
|
||||||
|
var req = Deserialize<MopupParam>(param);
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
if (req == null)
|
||||||
|
{
|
||||||
|
return (new { }, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalSid = GetBossSid(req.NId, 7);
|
||||||
|
var successSid = GetBossSid(req.NId, 6);
|
||||||
|
var diffSid = GetBossSid(req.NId, 8);
|
||||||
|
|
||||||
|
SetStr(player, totalSid, (ReadInt(player, totalSid) + 1).ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
SetStr(player, successSid, (ReadInt(player, successSid) + 1).ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
|
||||||
|
var clearedDiff = Math.Max(ReadInt(player, diffSid), req.NDiff);
|
||||||
|
SetStr(player, diffSid, clearedDiff.ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
|
||||||
|
var positionSid = TryGetPositionDiffSid(req.NId);
|
||||||
|
if (positionSid != null)
|
||||||
|
{
|
||||||
|
var newPositionDiff = Math.Max(ReadInt(player, positionSid.Value), req.NDiff + 1);
|
||||||
|
SetStr(player, positionSid.Value, newPositionDiff.ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
var score = ComputeIntegral(req.NId, req.NDiff, 0);
|
||||||
|
if (score > ReadInt(player, GetBossSid(req.NId, 4)))
|
||||||
|
{
|
||||||
|
WriteBestRun(player, req.NId, 0, 0, score, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new { }, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object HandleGetReward(string? param)
|
||||||
|
{
|
||||||
|
_ = Deserialize<RewardParam>(param);
|
||||||
|
return new { tbAward = Array.Empty<object>() };
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async ValueTask EnsureBossLineupsAsync(PlayerInstance player)
|
||||||
|
{
|
||||||
|
var lineups = player.LineupManager.LineupData.LineupInfo;
|
||||||
|
var baseLineup = lineups.GetValueOrDefault(1) ?? lineups.Values.FirstOrDefault();
|
||||||
|
if (baseLineup == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lineups.ContainsKey((int)BossLineup1))
|
||||||
|
{
|
||||||
|
await player.LineupManager.UpdateLineup((int)BossLineup1, baseLineup.Member1, baseLineup.Member2, baseLineup.Member3, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lineups.ContainsKey((int)BossLineup2))
|
||||||
|
{
|
||||||
|
await player.LineupManager.UpdateLineup((int)BossLineup2, baseLineup.Member1, baseLineup.Member2, baseLineup.Member3, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteBestRun(PlayerInstance player, uint bossLevelId, uint lineupId, double finishTime, int score, NtfSyncPlayer sync)
|
||||||
|
{
|
||||||
|
var snapshots = CaptureLineupSnapshots(player, lineupId);
|
||||||
|
SetStr(player, GetBossSid(bossLevelId, 1), System.Text.Json.JsonSerializer.Serialize(snapshots[0], JsonOptions), sync);
|
||||||
|
SetStr(player, GetBossSid(bossLevelId, 2), System.Text.Json.JsonSerializer.Serialize(snapshots[1], JsonOptions), sync);
|
||||||
|
SetStr(player, GetBossSid(bossLevelId, 3), System.Text.Json.JsonSerializer.Serialize(snapshots[2], JsonOptions), sync);
|
||||||
|
SetStr(player, GetBossSid(bossLevelId, 4), score.ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
SetStr(player, GetBossSid(bossLevelId, 5), Math.Max(0, (int)Math.Floor(finishTime)).ToString(CultureInfo.InvariantCulture), sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BossPvpRoleSnapshot[] CaptureLineupSnapshots(PlayerInstance player, uint lineupId)
|
||||||
|
{
|
||||||
|
var lineups = player.LineupManager.LineupData.LineupInfo;
|
||||||
|
var lineup = lineups.GetValueOrDefault((int)lineupId)
|
||||||
|
?? lineups.GetValueOrDefault((int)BossLineup1)
|
||||||
|
?? lineups.GetValueOrDefault(1)
|
||||||
|
?? lineups.Values.FirstOrDefault();
|
||||||
|
|
||||||
|
if (lineup == null)
|
||||||
|
{
|
||||||
|
return [new(), new(), new()];
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
[
|
||||||
|
CaptureRoleSnapshot(player, lineup.Member1),
|
||||||
|
CaptureRoleSnapshot(player, lineup.Member2),
|
||||||
|
CaptureRoleSnapshot(player, lineup.Member3)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BossPvpRoleSnapshot CaptureRoleSnapshot(PlayerInstance player, uint characterGuid)
|
||||||
|
{
|
||||||
|
if (characterGuid == 0)
|
||||||
|
{
|
||||||
|
return new BossPvpRoleSnapshot();
|
||||||
|
}
|
||||||
|
|
||||||
|
var character = player.CharacterManager.GetCharacterByGUID(characterGuid);
|
||||||
|
if (character == null)
|
||||||
|
{
|
||||||
|
return new BossPvpRoleSnapshot();
|
||||||
|
}
|
||||||
|
|
||||||
|
var snapshot = new BossPvpRoleSnapshot
|
||||||
|
{
|
||||||
|
Role = character.Guid,
|
||||||
|
Weapon = character.WeaponUniqueId
|
||||||
|
};
|
||||||
|
|
||||||
|
var weapon = player.InventoryManager.GetWeaponItem(character.WeaponUniqueId);
|
||||||
|
if (weapon != null)
|
||||||
|
{
|
||||||
|
snapshot.Wgdpl = BuildWeaponGdpl(weapon);
|
||||||
|
snapshot.Wslot = weapon.PartSlots;
|
||||||
|
}
|
||||||
|
|
||||||
|
var supports = character.SupportSlots
|
||||||
|
.OrderBy(x => x.Key)
|
||||||
|
.Select(x => x.Value)
|
||||||
|
.Where(x => x != 0)
|
||||||
|
.Take(3)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
if (supports.Length > 0)
|
||||||
|
{
|
||||||
|
snapshot.S1 = supports[0];
|
||||||
|
snapshot.Sgdpl1 = BuildSupportGdpl(player.InventoryManager.GetSupportCardItem(supports[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (supports.Length > 1)
|
||||||
|
{
|
||||||
|
snapshot.S2 = supports[1];
|
||||||
|
snapshot.Sgdpl2 = BuildSupportGdpl(player.InventoryManager.GetSupportCardItem(supports[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (supports.Length > 2)
|
||||||
|
{
|
||||||
|
snapshot.S3 = supports[2];
|
||||||
|
snapshot.Sgdpl3 = BuildSupportGdpl(player.InventoryManager.GetSupportCardItem(supports[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<uint> BuildWeaponGdpl(GameWeaponInfo weapon)
|
||||||
|
{
|
||||||
|
var gdpl = DecodeGdpl(weapon.TemplateId);
|
||||||
|
gdpl.Add(weapon.Level);
|
||||||
|
gdpl.Add(weapon.Evolue);
|
||||||
|
return gdpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<uint> BuildSupportGdpl(GameSupportCardInfo? support)
|
||||||
|
{
|
||||||
|
if (support == null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var gdpl = DecodeGdpl(support.TemplateId);
|
||||||
|
gdpl.Add(support.Level);
|
||||||
|
gdpl.Add(0);
|
||||||
|
return gdpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<uint> DecodeGdpl(ulong templateId)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
[
|
||||||
|
(uint)(templateId & 0xFFFF),
|
||||||
|
(uint)((templateId >> 16) & 0xFFFF),
|
||||||
|
(uint)((templateId >> 32) & 0xFFFF),
|
||||||
|
(uint)((templateId >> 48) & 0xFFFF)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int ComputeIntegral(uint bossLevelId, int diff, int residueTime)
|
||||||
|
{
|
||||||
|
if (!GameData.BossPvpBossData.TryGetValue(bossLevelId, out var boss) || diff <= 0 || diff > boss.BossLevel.Count)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var info = boss.BossLevel[diff - 1];
|
||||||
|
if (info.Count == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var multiplier = info.Count > 2 ? info[2] : 0;
|
||||||
|
var baseScore = info.Count > 3 ? info[3] : 0;
|
||||||
|
var residueScore = info.Count > 4 ? info[4] : 0;
|
||||||
|
var total = (baseScore + residueScore * Math.Max(0, residueTime)) * multiplier;
|
||||||
|
return (int)Math.Floor(total + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint? TryGetPositionDiffSid(uint bossLevelId)
|
||||||
|
{
|
||||||
|
var season = GetOpenSeason();
|
||||||
|
if (season == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var index = season.BossIds.FindIndex(x => x == bossLevelId);
|
||||||
|
return index >= 0 ? DiffStartId + (uint)(index + 1) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BossPvpBossChallengeExcel? GetOpenSeason()
|
||||||
|
{
|
||||||
|
var now = DateTimeOffset.Now;
|
||||||
|
var current = GameData.BossPvpBossChallengeData.Values
|
||||||
|
.OrderBy(x => x.ID)
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
{
|
||||||
|
var startAt = ParseBossTime(x.StartTime);
|
||||||
|
var endAt = ParseBossTime(x.EndTime);
|
||||||
|
return startAt != null && endAt != null && now >= startAt && now <= endAt;
|
||||||
|
});
|
||||||
|
|
||||||
|
return current ?? GameData.BossPvpBossChallengeData.Values.OrderBy(x => x.ID).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetDailyChallengeNum()
|
||||||
|
{
|
||||||
|
var now = DateTime.Now;
|
||||||
|
if (now.Hour < 4)
|
||||||
|
{
|
||||||
|
now = now.AddHours(-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
var week = now.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)now.DayOfWeek;
|
||||||
|
return GameData.BossPvpNumData.TryGetValue((uint)week, out var count) ? count.Num : 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int ReadInt(PlayerInstance player, uint sid)
|
||||||
|
{
|
||||||
|
var attr = player.Data.StrAttrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == sid)?.Val;
|
||||||
|
return int.TryParse(attr, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) ? value : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void EnsureStr(PlayerInstance player, uint sid, string value, NtfSyncPlayer sync)
|
||||||
|
{
|
||||||
|
var attr = player.Data.StrAttrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == sid);
|
||||||
|
if (attr != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetStr(player, sid, value, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetStr(PlayerInstance player, uint sid, string value, NtfSyncPlayer sync)
|
||||||
|
{
|
||||||
|
player.SetStrAttr(GroupId, sid, value);
|
||||||
|
sync.CustomStr[player.ToShiftedAttrKey(GroupId, sid)] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetBossSid(uint bossLevelId, uint offset) => (LevelStride * bossLevelId) + LevelStartSid + offset;
|
||||||
|
|
||||||
|
private static string EmptySnapshotJson() => System.Text.Json.JsonSerializer.Serialize(new BossPvpRoleSnapshot(), JsonOptions);
|
||||||
|
|
||||||
|
private static T? Deserialize<T>(string? param)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(param))
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return System.Text.Json.JsonSerializer.Deserialize<T>(param, JsonOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DateTimeOffset? ParseBossTime(string? value)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var raw = value.Trim().Trim('[', ']');
|
||||||
|
if (!DateTime.TryParseExact(raw, "yyyyMMddHHmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out var localTime))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DateTimeOffset(localTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class EnterLevelParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nID")] public uint NId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class RecordParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nID")] public uint NId { get; set; }
|
||||||
|
[JsonPropertyName("nDiff")] public int NDiff { get; set; }
|
||||||
|
[JsonPropertyName("nTime")] public double NTime { get; set; }
|
||||||
|
[JsonPropertyName("ResidueTime")] public int ResidueTime { get; set; }
|
||||||
|
[JsonPropertyName("bRecord")] public bool BRecord { get; set; }
|
||||||
|
[JsonPropertyName("nTeamID")] public uint NTeamId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class SettlementParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nID")] public uint NId { get; set; }
|
||||||
|
[JsonPropertyName("nDiff")] public int NDiff { get; set; }
|
||||||
|
[JsonPropertyName("nTime")] public double NTime { get; set; }
|
||||||
|
[JsonPropertyName("ResidueTime")] public int ResidueTime { get; set; }
|
||||||
|
[JsonPropertyName("nTeamID")] public uint NTeamId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class FailParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nID")] public uint NId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class MopupParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nID")] public uint NId { get; set; }
|
||||||
|
[JsonPropertyName("nDiff")] public int NDiff { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class RewardParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("tbTaskID")] public List<uint> TaskIds { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class BossPvpRoleSnapshot
|
||||||
|
{
|
||||||
|
[JsonPropertyName("role")] public uint Role { get; set; }
|
||||||
|
[JsonPropertyName("weapon")] public uint Weapon { get; set; }
|
||||||
|
[JsonPropertyName("s1")] public uint S1 { get; set; }
|
||||||
|
[JsonPropertyName("s2")] public uint S2 { get; set; }
|
||||||
|
[JsonPropertyName("s3")] public uint S3 { get; set; }
|
||||||
|
[JsonPropertyName("wgdpl")] public List<uint> Wgdpl { get; set; } = [];
|
||||||
|
[JsonPropertyName("wslot")] public Dictionary<uint, ulong> Wslot { get; set; } = [];
|
||||||
|
[JsonPropertyName("sgdpl1")] public List<uint> Sgdpl1 { get; set; } = [];
|
||||||
|
[JsonPropertyName("sgdpl2")] public List<uint> Sgdpl2 { get; set; } = [];
|
||||||
|
[JsonPropertyName("sgdpl3")] public List<uint> Sgdpl3 { get; set; } = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using MikuSB.GameServer.Server.CallGS.Handlers.BossPvp;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
|
||||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Chapter;
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Chapter;
|
||||||
|
|
||||||
@@ -10,17 +12,20 @@ public class Chapter_DealLevelSettlement : ICallGSHandler
|
|||||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
{
|
{
|
||||||
var req = JsonSerializer.Deserialize<DealLevelSettlementParam>(param);
|
var req = JsonSerializer.Deserialize<DealLevelSettlementParam>(param);
|
||||||
|
NtfSyncPlayer? extraSync = null;
|
||||||
var response = new JsonObject
|
var response = new JsonObject
|
||||||
{
|
{
|
||||||
["sCmd"] = req?.SCmd ?? "Chapter_LevelSettlement",
|
["sCmd"] = req?.SCmd ?? "Chapter_LevelSettlement",
|
||||||
["tbParam"] = BuildSettlementPayload(req?.SCmd, req?.TbParam)
|
["tbParam"] = BuildSettlementPayload(connection, req?.SCmd, req?.TbParam, out extraSync)
|
||||||
};
|
};
|
||||||
|
|
||||||
await CallGSRouter.SendScript(connection, "Chapter_DealLevelSettlement", response.ToJsonString());
|
await CallGSRouter.SendScript(connection, "Chapter_DealLevelSettlement", response.ToJsonString(), extraSync!);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonNode BuildSettlementPayload(string? sCmd, JsonNode? tbParam)
|
private static JsonNode BuildSettlementPayload(Connection connection, string? sCmd, JsonNode? tbParam, out NtfSyncPlayer? extraSync)
|
||||||
{
|
{
|
||||||
|
extraSync = null;
|
||||||
|
|
||||||
if (string.Equals(sCmd, "Chapter_LevelSettlement", StringComparison.Ordinal))
|
if (string.Equals(sCmd, "Chapter_LevelSettlement", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
return new JsonArray();
|
return new JsonArray();
|
||||||
@@ -37,6 +42,20 @@ public class Chapter_DealLevelSettlement : ICallGSHandler
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.Equals(sCmd, "BossPvpLogic_LevelSettlement", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
var (response, sync) = BossPvpShared.HandleSettlement(connection.Player!, tbParam);
|
||||||
|
extraSync = sync;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.Equals(sCmd, "BossPvpLogic_LevelFail", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
var (response, sync) = BossPvpShared.HandleFail(connection.Player!, tbParam);
|
||||||
|
extraSync = sync;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
return tbParam?.DeepClone() ?? new JsonObject();
|
return tbParam?.DeepClone() ?? new JsonObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
552
GameServer/Server/CallGS/Handlers/Gacha/Gacha_Launch.cs
Normal file
552
GameServer/Server/CallGS/Handlers/Gacha/Gacha_Launch.cs
Normal file
@@ -0,0 +1,552 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Data.Excel;
|
||||||
|
using MikuSB.Database;
|
||||||
|
using MikuSB.Database.Player;
|
||||||
|
using MikuSB.Enums.Item;
|
||||||
|
using MikuSB.GameServer.Game.Player;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Gacha;
|
||||||
|
|
||||||
|
[CallGSApi("Gacha_Launch")]
|
||||||
|
public class Gacha_Launch : ICallGSHandler
|
||||||
|
{
|
||||||
|
private const uint GachaGid = 5;
|
||||||
|
private const uint GachaSgid = 42;
|
||||||
|
private const uint SidTotalTime = 1;
|
||||||
|
private const uint SidDailyTotalTime = 2;
|
||||||
|
private const uint Interval = 10;
|
||||||
|
private const uint SidTimeInheritStart = 20000;
|
||||||
|
private const uint SidTimeNotInheritStart = 10;
|
||||||
|
private const uint SidAddTimeItem = 1;
|
||||||
|
private const uint SidAddTimeProb = 2;
|
||||||
|
private const uint SidAddProtectType = 3;
|
||||||
|
private const uint SidAddTotalTime = 7;
|
||||||
|
private const int UpSelectIndex = 0;
|
||||||
|
private const int UpSelectGetFlagIndex = 1;
|
||||||
|
private static readonly Random Rng = new();
|
||||||
|
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
var req = JsonSerializer.Deserialize<GachaLaunchParam>(param);
|
||||||
|
if (req == null || req.NId == 0 || req.NTime is not (1 or 10))
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_Launch", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GameData.GachaData.TryGetValue((uint)req.NId, out var gachaCfg))
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_Launch", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var poolNames = (gachaCfg.Pool ?? [])
|
||||||
|
.Where(GameData.GachaPoolData.ContainsKey)
|
||||||
|
.ToList();
|
||||||
|
var allPoolItems = poolNames
|
||||||
|
.SelectMany(p => GameData.GachaPoolData[p])
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (allPoolItems.Count == 0 || !GameData.GachaProbabilityData.TryGetValue(gachaCfg.Probability, out var baseProbCfg))
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_Launch", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pityState = LoadPityState(player, gachaCfg);
|
||||||
|
var upSelectState = LoadUpSelectState(player, gachaCfg);
|
||||||
|
var config = BuildRuntimeConfig(gachaCfg, poolNames);
|
||||||
|
var awards = new List<List<uint>>();
|
||||||
|
var tbNew = new List<int>();
|
||||||
|
var tbTrigger = new List<bool>();
|
||||||
|
var syncItems = new List<Item>();
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
|
||||||
|
for (int i = 0; i < req.NTime; i++)
|
||||||
|
{
|
||||||
|
var forceTopUp = config.UpTarget != null && pityState.ProtectType == 2;
|
||||||
|
var hitHardPity = config.ProtectThreshold > 0 && pityState.ItemCount + 1 >= config.ProtectThreshold;
|
||||||
|
var useTenGuarantee = gachaCfg.ProbabilityTen != 0
|
||||||
|
&& pityState.TenCount + 1 >= 10
|
||||||
|
&& !HasGuaranteedTenRarity(config, awards);
|
||||||
|
|
||||||
|
GachaProbabilityExcel probCfg = baseProbCfg;
|
||||||
|
if (useTenGuarantee && GameData.GachaProbabilityData.TryGetValue(gachaCfg.ProbabilityTen, out var tenProbCfg))
|
||||||
|
probCfg = tenProbCfg;
|
||||||
|
|
||||||
|
GachaPoolItem? item;
|
||||||
|
bool trigger = false;
|
||||||
|
|
||||||
|
if (hitHardPity)
|
||||||
|
{
|
||||||
|
item = PickGuaranteedItem(gachaCfg, config, preferUp: forceTopUp);
|
||||||
|
trigger = item != null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var rarity = RollRarity(probCfg);
|
||||||
|
item = forceTopUp && config.UpTarget != null && rarity >= config.TopRarity
|
||||||
|
? PickGuaranteedItem(gachaCfg, config, preferUp: true)
|
||||||
|
: PickItem(allPoolItems, rarity);
|
||||||
|
trigger = forceTopUp && item != null && config.UpTarget != null && item.Rarity == config.UpTarget.Rarity;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item != null && upSelectState.SelectedItem != null && item.Rarity >= config.TopRarity)
|
||||||
|
{
|
||||||
|
bool forceSelected = upSelectState.GuaranteedNext;
|
||||||
|
bool shouldSelect = forceSelected || Rng.Next(100) < 50;
|
||||||
|
if (shouldSelect)
|
||||||
|
{
|
||||||
|
var selectedItem = FindExactItem(allPoolItems, upSelectState.SelectedItem);
|
||||||
|
if (selectedItem != null && selectedItem.Rarity >= config.TopRarity)
|
||||||
|
item = selectedItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item == null || item.GDPL.Count < 4)
|
||||||
|
{
|
||||||
|
tbTrigger.Add(false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var g = item.GDPL[0];
|
||||||
|
var d = item.GDPL[1];
|
||||||
|
var p = item.GDPL[2];
|
||||||
|
var l = item.GDPL[3];
|
||||||
|
|
||||||
|
awards.Add([g, d, p, l]);
|
||||||
|
tbTrigger.Add(trigger);
|
||||||
|
|
||||||
|
UpdatePityState(pityState, config, item);
|
||||||
|
UpdateUpSelectState(upSelectState, config, item);
|
||||||
|
|
||||||
|
var itemType = (ItemTypeEnum)g;
|
||||||
|
switch (itemType)
|
||||||
|
{
|
||||||
|
case ItemTypeEnum.TYPE_CARD:
|
||||||
|
{
|
||||||
|
var alreadyOwned = player.CharacterManager.GetCharacterGDPL(itemType, (int)d, (int)p) != null;
|
||||||
|
if (!alreadyOwned)
|
||||||
|
{
|
||||||
|
var charInfo = await player.CharacterManager.AddCharacter(itemType, d, p, sendPacket: false);
|
||||||
|
if (charInfo != null)
|
||||||
|
{
|
||||||
|
syncItems.Add(charInfo.ToProto());
|
||||||
|
tbNew.Add(awards.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ItemTypeEnum.TYPE_WEAPON:
|
||||||
|
{
|
||||||
|
var weaponInfo = await player.InventoryManager.AddWeaponItem(itemType, d, p, l, sendPacket: false);
|
||||||
|
if (weaponInfo != null) syncItems.Add(weaponInfo.ToProto());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ItemTypeEnum.TYPE_SUPPORT:
|
||||||
|
{
|
||||||
|
var cardInfo = await player.InventoryManager.AddSupportCardItem(d, p, l, sendPacket: false);
|
||||||
|
if (cardInfo != null) syncItems.Add(cardInfo.ToProto());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (awards.Count == 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_Launch", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SavePityState(player, gachaCfg, pityState, awards.Count, sync);
|
||||||
|
SaveUpSelectState(player, gachaCfg, upSelectState, sync);
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.CharacterManager.CharacterData);
|
||||||
|
|
||||||
|
sync.Items.AddRange(syncItems);
|
||||||
|
|
||||||
|
var rsp = BuildResponse(req.NId, awards, tbNew, tbTrigger);
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_Launch", rsp, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HasGuaranteedTenRarity(GachaRuntimeConfig config, List<List<uint>> awards)
|
||||||
|
{
|
||||||
|
if (awards.Count == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int windowStart = awards.Count >= 9 ? awards.Count - 9 : 0;
|
||||||
|
for (int i = windowStart; i < awards.Count; i++)
|
||||||
|
{
|
||||||
|
var award = awards[i];
|
||||||
|
if (award.Count < 4)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var template = FindPoolItemByGdpl(config.AllPoolItems, award);
|
||||||
|
if (template != null && template.Rarity >= config.TenGuaranteeRarity)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GachaPoolItem? FindPoolItemByGdpl(List<GachaPoolItem> pool, List<uint> gdpl) =>
|
||||||
|
pool.FirstOrDefault(x =>
|
||||||
|
x.GDPL.Count >= 4 &&
|
||||||
|
x.GDPL[0] == gdpl[0] &&
|
||||||
|
x.GDPL[1] == gdpl[1] &&
|
||||||
|
x.GDPL[2] == gdpl[2] &&
|
||||||
|
x.GDPL[3] == gdpl[3]);
|
||||||
|
|
||||||
|
private static GachaPoolItem? FindExactItem(List<GachaPoolItem> pool, uint[] gdpl) =>
|
||||||
|
pool.FirstOrDefault(x =>
|
||||||
|
x.GDPL.Count >= 4 &&
|
||||||
|
x.GDPL[0] == gdpl[0] &&
|
||||||
|
x.GDPL[1] == gdpl[1] &&
|
||||||
|
x.GDPL[2] == gdpl[2] &&
|
||||||
|
x.GDPL[3] == gdpl[3]);
|
||||||
|
|
||||||
|
private static GachaRuntimeConfig BuildRuntimeConfig(GachaExcel gachaCfg, List<string> poolNames)
|
||||||
|
{
|
||||||
|
var allPoolItems = poolNames.SelectMany(name => GameData.GachaPoolData[name]).ToList();
|
||||||
|
var protectPools = ParsePoolRarities(gachaCfg.ProtectNum);
|
||||||
|
var upTarget = ParseSinglePoolRarity(gachaCfg.UpNum);
|
||||||
|
var topRarity = new[] { upTarget?.Rarity ?? 0 }.Concat(protectPools.Select(x => x.Rarity)).Max();
|
||||||
|
if (topRarity <= 0)
|
||||||
|
topRarity = allPoolItems.Count == 0 ? 0 : allPoolItems.Max(x => x.Rarity);
|
||||||
|
|
||||||
|
return new GachaRuntimeConfig
|
||||||
|
{
|
||||||
|
AllPoolItems = allPoolItems,
|
||||||
|
ProtectThreshold = ParseThreshold(gachaCfg.ProtectNum),
|
||||||
|
ProtectPools = protectPools,
|
||||||
|
UpTarget = upTarget,
|
||||||
|
TopRarity = topRarity,
|
||||||
|
TenGuaranteeRarity = 4
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int ParseThreshold(JToken? token)
|
||||||
|
{
|
||||||
|
if (token is not JArray arr || arr.Count == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return arr[0]?.Value<int>() ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<PoolRarityRef> ParsePoolRarities(JToken? token)
|
||||||
|
{
|
||||||
|
var result = new List<PoolRarityRef>();
|
||||||
|
if (token is not JArray arr || arr.Count < 2 || arr[1] is not JArray entries)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
foreach (var entry in entries.OfType<JArray>())
|
||||||
|
{
|
||||||
|
if (entry.Count < 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var poolName = entry[0]?.Value<string>();
|
||||||
|
var rarity = entry[1]?.Value<int>() ?? 0;
|
||||||
|
if (string.IsNullOrWhiteSpace(poolName) || rarity <= 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
result.Add(new PoolRarityRef(poolName, rarity));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PoolRarityRef? ParseSinglePoolRarity(JToken? token)
|
||||||
|
{
|
||||||
|
if (token is not JArray arr || arr.Count < 2 || arr[1] is not JArray entry || entry.Count < 2)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var poolName = entry[0]?.Value<string>();
|
||||||
|
var rarity = entry[1]?.Value<int>() ?? 0;
|
||||||
|
return string.IsNullOrWhiteSpace(poolName) || rarity <= 0 ? null : new PoolRarityRef(poolName, rarity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GachaPityState LoadPityState(PlayerInstance player, GachaExcel gachaCfg)
|
||||||
|
{
|
||||||
|
var baseSid = GetBaseSid(gachaCfg);
|
||||||
|
return new GachaPityState
|
||||||
|
{
|
||||||
|
ItemCount = (int)GetAttr(player, GachaGid, baseSid + SidAddTimeItem),
|
||||||
|
TenCount = (int)GetAttr(player, GachaGid, baseSid + SidAddTimeProb),
|
||||||
|
ProtectType = Math.Max(1, (int)GetAttr(player, GachaGid, baseSid + SidAddProtectType)),
|
||||||
|
PoolTotalTime = (int)GetAttr(player, GachaGid, baseSid + SidAddTotalTime)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SavePityState(PlayerInstance player, GachaExcel gachaCfg, GachaPityState state, int drawCount, NtfSyncPlayer sync)
|
||||||
|
{
|
||||||
|
var baseSid = GetBaseSid(gachaCfg);
|
||||||
|
|
||||||
|
SetAttr(player, sync, GachaGid, SidTotalTime, GetAttr(player, GachaGid, SidTotalTime) + (uint)drawCount);
|
||||||
|
SetAttr(player, sync, GachaGid, SidDailyTotalTime, GetAttr(player, GachaGid, SidDailyTotalTime) + (uint)drawCount);
|
||||||
|
SetAttr(player, sync, GachaGid, baseSid + SidAddTimeItem, (uint)state.ItemCount);
|
||||||
|
SetAttr(player, sync, GachaGid, baseSid + SidAddTimeProb, (uint)state.TenCount);
|
||||||
|
SetAttr(player, sync, GachaGid, baseSid + SidAddProtectType, (uint)Math.Max(1, state.ProtectType));
|
||||||
|
SetAttr(player, sync, GachaGid, baseSid + SidAddTotalTime, (uint)(state.PoolTotalTime + drawCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GachaUpSelectState LoadUpSelectState(PlayerInstance player, GachaExcel gachaCfg)
|
||||||
|
{
|
||||||
|
if (gachaCfg.UpSelect != 1)
|
||||||
|
return new GachaUpSelectState();
|
||||||
|
|
||||||
|
var raw = player.Data.StrAttrs.FirstOrDefault(x => x.Gid == GachaSgid && x.Sid == gachaCfg.ID)?.Val;
|
||||||
|
if (string.IsNullOrWhiteSpace(raw))
|
||||||
|
return new GachaUpSelectState();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var state = JArray.Parse(raw);
|
||||||
|
uint[]? selected = null;
|
||||||
|
if (state.Count > UpSelectIndex && state[UpSelectIndex] is JArray selectedArray && selectedArray.Count >= 4)
|
||||||
|
{
|
||||||
|
selected =
|
||||||
|
[
|
||||||
|
selectedArray[0]?.Value<uint>() ?? 0,
|
||||||
|
selectedArray[1]?.Value<uint>() ?? 0,
|
||||||
|
selectedArray[2]?.Value<uint>() ?? 0,
|
||||||
|
selectedArray[3]?.Value<uint>() ?? 0
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GachaUpSelectState
|
||||||
|
{
|
||||||
|
SelectedItem = selected,
|
||||||
|
GuaranteedNext = state.Count > UpSelectGetFlagIndex && (state[UpSelectGetFlagIndex]?.Value<int>() ?? 0) == 1,
|
||||||
|
RawState = state
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new GachaUpSelectState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SaveUpSelectState(PlayerInstance player, GachaExcel gachaCfg, GachaUpSelectState state, NtfSyncPlayer sync)
|
||||||
|
{
|
||||||
|
if (gachaCfg.UpSelect != 1 || state.RawState == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EnsureArraySize(state.RawState, 2);
|
||||||
|
state.RawState[UpSelectGetFlagIndex] = state.GuaranteedNext ? 1 : 0;
|
||||||
|
|
||||||
|
var value = state.RawState.ToString(Newtonsoft.Json.Formatting.None);
|
||||||
|
player.SetStrAttr(GachaSgid, gachaCfg.ID, value);
|
||||||
|
sync.CustomStr[player.ToShiftedAttrKey(GachaSgid, gachaCfg.ID)] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetBaseSid(GachaExcel gachaCfg)
|
||||||
|
{
|
||||||
|
if (gachaCfg.ProtectTag.HasValue)
|
||||||
|
return SidTimeInheritStart + (gachaCfg.ProtectTag.Value * Interval);
|
||||||
|
|
||||||
|
return SidTimeNotInheritStart + (gachaCfg.ID * Interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetAttr(PlayerInstance player, uint gid, uint sid) =>
|
||||||
|
player.Data.Attrs.FirstOrDefault(x => x.Gid == gid && x.Sid == sid)?.Val ?? 0;
|
||||||
|
|
||||||
|
private static void SetAttr(PlayerInstance player, NtfSyncPlayer sync, uint gid, uint sid, uint value)
|
||||||
|
{
|
||||||
|
var attr = player.Data.Attrs.FirstOrDefault(x => x.Gid == gid && x.Sid == sid);
|
||||||
|
if (attr == null)
|
||||||
|
{
|
||||||
|
attr = new PlayerAttr { Gid = gid, Sid = sid };
|
||||||
|
player.Data.Attrs.Add(attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
attr.Val = value;
|
||||||
|
sync.Custom[player.ToPackedAttrKey(gid, sid)] = value;
|
||||||
|
sync.Custom[player.ToShiftedAttrKey(gid, sid)] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdatePityState(GachaPityState state, GachaRuntimeConfig config, GachaPoolItem item)
|
||||||
|
{
|
||||||
|
if (item.Rarity >= config.TenGuaranteeRarity)
|
||||||
|
state.TenCount = 0;
|
||||||
|
else
|
||||||
|
state.TenCount++;
|
||||||
|
|
||||||
|
if (item.Rarity >= config.TopRarity)
|
||||||
|
{
|
||||||
|
state.ItemCount = 0;
|
||||||
|
if (config.UpTarget != null)
|
||||||
|
state.ProtectType = IsFromPool(item, config.UpTarget) ? 1 : 2;
|
||||||
|
else
|
||||||
|
state.ProtectType = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state.ItemCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateUpSelectState(GachaUpSelectState state, GachaRuntimeConfig config, GachaPoolItem item)
|
||||||
|
{
|
||||||
|
if (state.SelectedItem == null || item.Rarity < config.TopRarity)
|
||||||
|
return;
|
||||||
|
|
||||||
|
state.GuaranteedNext = !MatchesGdpl(item, state.SelectedItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool MatchesGdpl(GachaPoolItem item, uint[] gdpl) =>
|
||||||
|
item.GDPL.Count >= 4 &&
|
||||||
|
item.GDPL[0] == gdpl[0] &&
|
||||||
|
item.GDPL[1] == gdpl[1] &&
|
||||||
|
item.GDPL[2] == gdpl[2] &&
|
||||||
|
item.GDPL[3] == gdpl[3];
|
||||||
|
|
||||||
|
private static void EnsureArraySize(JArray state, int size)
|
||||||
|
{
|
||||||
|
while (state.Count < size)
|
||||||
|
state.Add(JValue.CreateNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsFromPool(GachaPoolItem item, PoolRarityRef target) =>
|
||||||
|
item.Rarity == target.Rarity &&
|
||||||
|
GameData.GachaPoolData.TryGetValue(target.PoolName, out var pool) &&
|
||||||
|
pool.Any(x => x.ID == item.ID);
|
||||||
|
|
||||||
|
private static int RollRarity(GachaProbabilityExcel prob)
|
||||||
|
{
|
||||||
|
var weights = prob.Weights;
|
||||||
|
int total = weights.Sum();
|
||||||
|
int roll = Rng.Next(total);
|
||||||
|
int cumulative = 0;
|
||||||
|
for (int i = 0; i < weights.Length; i++)
|
||||||
|
{
|
||||||
|
cumulative += weights[i];
|
||||||
|
if (roll < cumulative)
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GachaPoolItem? PickGuaranteedItem(GachaExcel gachaCfg, GachaRuntimeConfig config, bool preferUp)
|
||||||
|
{
|
||||||
|
if (preferUp && config.UpTarget != null)
|
||||||
|
{
|
||||||
|
var upItem = PickItemFromPool(config.UpTarget.PoolName, config.UpTarget.Rarity);
|
||||||
|
if (upItem != null)
|
||||||
|
return upItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var poolRef in config.ProtectPools)
|
||||||
|
{
|
||||||
|
var item = PickItemFromPool(poolRef.PoolName, poolRef.Rarity);
|
||||||
|
if (item != null)
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PickItem(config.AllPoolItems, config.TopRarity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GachaPoolItem? PickItemFromPool(string poolName, int rarity)
|
||||||
|
{
|
||||||
|
if (!GameData.GachaPoolData.TryGetValue(poolName, out var pool))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return PickItem(pool, rarity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GachaPoolItem? PickItem(List<GachaPoolItem> pool, int rarity)
|
||||||
|
{
|
||||||
|
var candidates = pool.Where(x => x.Rarity == rarity).ToList();
|
||||||
|
if (candidates.Count == 0)
|
||||||
|
{
|
||||||
|
candidates = pool.Where(x => x.Rarity == rarity - 1).ToList();
|
||||||
|
if (candidates.Count == 0)
|
||||||
|
return pool.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
int total = candidates.Sum(x => x.Weight);
|
||||||
|
if (total <= 0)
|
||||||
|
return candidates[Rng.Next(candidates.Count)];
|
||||||
|
|
||||||
|
int roll = Rng.Next(total);
|
||||||
|
int cumulative = 0;
|
||||||
|
foreach (var item in candidates)
|
||||||
|
{
|
||||||
|
cumulative += item.Weight;
|
||||||
|
if (roll < cumulative)
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidates.Last();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildResponse(int nId, List<List<uint>> awards, List<int> tbNew, List<bool> tbTrigger)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append("{\"nId\":");
|
||||||
|
sb.Append(nId);
|
||||||
|
sb.Append(",\"tbAwards\":[");
|
||||||
|
for (int i = 0; i < awards.Count; i++)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
sb.Append(',');
|
||||||
|
|
||||||
|
sb.Append('[');
|
||||||
|
sb.Append(string.Join(',', awards[i]));
|
||||||
|
sb.Append(']');
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append("],\"nBoxCount\":0,\"tbNew\":[");
|
||||||
|
sb.Append(string.Join(',', tbNew));
|
||||||
|
sb.Append("],\"tbTrigger\":[");
|
||||||
|
sb.Append(string.Join(',', tbTrigger.Select(b => b ? "true" : "false")));
|
||||||
|
sb.Append("]}");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GachaLaunchParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nId")]
|
||||||
|
public int NId { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("bPickUp")]
|
||||||
|
public bool BPickUp { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("nTime")]
|
||||||
|
public int NTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GachaPityState
|
||||||
|
{
|
||||||
|
public int ItemCount { get; set; }
|
||||||
|
public int TenCount { get; set; }
|
||||||
|
public int ProtectType { get; set; } = 1;
|
||||||
|
public int PoolTotalTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GachaRuntimeConfig
|
||||||
|
{
|
||||||
|
public List<GachaPoolItem> AllPoolItems { get; set; } = [];
|
||||||
|
public int ProtectThreshold { get; set; }
|
||||||
|
public List<PoolRarityRef> ProtectPools { get; set; } = [];
|
||||||
|
public PoolRarityRef? UpTarget { get; set; }
|
||||||
|
public int TopRarity { get; set; }
|
||||||
|
public int TenGuaranteeRarity { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GachaUpSelectState
|
||||||
|
{
|
||||||
|
public uint[]? SelectedItem { get; set; }
|
||||||
|
public bool GuaranteedNext { get; set; }
|
||||||
|
public JArray? RawState { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed record PoolRarityRef(string PoolName, int Rarity);
|
||||||
82
GameServer/Server/CallGS/Handlers/Gacha/Gacha_UpSelect.cs
Normal file
82
GameServer/Server/CallGS/Handlers/Gacha/Gacha_UpSelect.cs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Database;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Gacha;
|
||||||
|
|
||||||
|
[CallGSApi("Gacha_UpSelect")]
|
||||||
|
public class Gacha_UpSelect : ICallGSHandler
|
||||||
|
{
|
||||||
|
private const uint GachaStrGid = 42;
|
||||||
|
private const int UpSelectIndex = 0;
|
||||||
|
private const int UpSelectGetFlagIndex = 1;
|
||||||
|
private const int UpPickPoolIndex = 2;
|
||||||
|
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var req = JsonSerializer.Deserialize<GachaUpSelectParam>(param);
|
||||||
|
var player = connection.Player!;
|
||||||
|
if (req == null || req.NId == 0 || req.Gdpl == null || req.Gdpl.Count < 4)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_UpSelect", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GameData.GachaData.TryGetValue((uint)req.NId, out var gachaCfg) || gachaCfg.UpSelect != 1)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_UpSelect", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var valid = (gachaCfg.Pool ?? [])
|
||||||
|
.Where(GameData.GachaPoolData.ContainsKey)
|
||||||
|
.SelectMany(name => GameData.GachaPoolData[name])
|
||||||
|
.Any(item =>
|
||||||
|
item.UPSelectTag == 1 &&
|
||||||
|
item.GDPL.Count >= 4 &&
|
||||||
|
item.GDPL[0] == req.Gdpl[0] &&
|
||||||
|
item.GDPL[1] == req.Gdpl[1] &&
|
||||||
|
item.GDPL[2] == req.Gdpl[2] &&
|
||||||
|
item.GDPL[3] == req.Gdpl[3]);
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_UpSelect", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var existing = player.Data.StrAttrs.FirstOrDefault(x => x.Gid == GachaStrGid && x.Sid == (uint)req.NId)?.Val;
|
||||||
|
var state = string.IsNullOrWhiteSpace(existing) ? new JArray() : JArray.Parse(existing);
|
||||||
|
|
||||||
|
EnsureArraySize(state, 3);
|
||||||
|
state[UpSelectIndex] = new JArray(req.Gdpl);
|
||||||
|
state[UpSelectGetFlagIndex] = 0;
|
||||||
|
if (state[UpPickPoolIndex] == null)
|
||||||
|
state[UpPickPoolIndex] = 0;
|
||||||
|
|
||||||
|
player.SetStrAttr(GachaStrGid, (uint)req.NId, state.ToString(Newtonsoft.Json.Formatting.None));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
sync.CustomStr[player.ToShiftedAttrKey(GachaStrGid, (uint)req.NId)] = state.ToString(Newtonsoft.Json.Formatting.None);
|
||||||
|
await CallGSRouter.SendScript(connection, "Gacha_UpSelect", "{}", sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void EnsureArraySize(JArray state, int size)
|
||||||
|
{
|
||||||
|
while (state.Count < size)
|
||||||
|
state.Add(JValue.CreateNull());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GachaUpSelectParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nId")]
|
||||||
|
public int NId { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("gdpl")]
|
||||||
|
public List<uint>? Gdpl { get; set; }
|
||||||
|
}
|
||||||
296
GameServer/Server/CallGS/Handlers/Girl/GirlCard_UpdateLevel.cs
Normal file
296
GameServer/Server/CallGS/Handlers/Girl/GirlCard_UpdateLevel.cs
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Database;
|
||||||
|
using MikuSB.Database.Inventory;
|
||||||
|
using MikuSB.Database.Player;
|
||||||
|
using MikuSB.Enums.Item;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
|
||||||
|
|
||||||
|
[CallGSApi("GirlCard_UpdateLevel")]
|
||||||
|
public class GirlCard_UpdateLevel : ICallGSHandler
|
||||||
|
{
|
||||||
|
private const uint CashGroupId = 1;
|
||||||
|
private const uint SilverMoneyType = 3;
|
||||||
|
private const uint SilverSid = SilverMoneyType * 2 + 1;
|
||||||
|
private const uint RoleMaxLevel = 80;
|
||||||
|
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
var req = JsonSerializer.Deserialize<GirlCardUpdateLevelParam>(param);
|
||||||
|
if (req == null || req.Id == 0 || req.Materials == null || req.Materials.Count == 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var card = player.CharacterManager.GetCharacterByGUID((uint)req.Id);
|
||||||
|
if (card == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cardTemplate = GameData.CardData.Values.FirstOrDefault(x =>
|
||||||
|
GameResourceTemplateId.FromGdpl(x.Genre, x.Detail, x.Particular, x.Level) == card.TemplateId);
|
||||||
|
if (cardTemplate == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var levelCap = GetCardLevelCap(player.Data.Level, cardTemplate.LevelLimitID);
|
||||||
|
if (levelCap == 0)
|
||||||
|
{
|
||||||
|
levelCap = card.Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (card.Level >= RoleMaxLevel)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"tip.card_max_level\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var requestedMaterials = new Dictionary<uint, uint>();
|
||||||
|
foreach (var row in req.Materials)
|
||||||
|
{
|
||||||
|
if (row == null || row.Id == 0 || row.Num == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
requestedMaterials[(uint)row.Id] = requestedMaterials.GetValueOrDefault((uint)row.Id) + row.Num;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestedMaterials.Count == 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"tip.material_not_enough\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong totalExp = 0;
|
||||||
|
ulong totalSilverCost = 0;
|
||||||
|
foreach (var (itemId, count) in requestedMaterials)
|
||||||
|
{
|
||||||
|
var item = player.InventoryManager.GetNormalItem(itemId);
|
||||||
|
if (item == null || item.ItemCount < count)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"tip.material_not_enough\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GameData.SuppliesData.TryGetValue((uint)item.TemplateId, out var supplies) || supplies.ProvideExp == 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalExp += (ulong)supplies.ProvideExp * count;
|
||||||
|
totalSilverCost += (ulong)supplies.ConsumeGold * count;
|
||||||
|
}
|
||||||
|
|
||||||
|
var silverAttr = GetOrCreateAttr(player.Data, CashGroupId, SilverSid);
|
||||||
|
if ((ulong)silverAttr.Val < totalSilverCost)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"tip.material_not_enough\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var syncItems = new List<Item>();
|
||||||
|
foreach (var (itemId, count) in requestedMaterials)
|
||||||
|
{
|
||||||
|
var item = player.InventoryManager.GetNormalItem(itemId)!;
|
||||||
|
item.ItemCount -= count;
|
||||||
|
|
||||||
|
if (item.ItemCount == 0)
|
||||||
|
{
|
||||||
|
player.InventoryManager.InventoryData.Items.Remove(item.UniqueId);
|
||||||
|
syncItems.Add(BuildRemovedProto(item));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
syncItems.Add(item.ToProto());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
silverAttr.Val -= checked((uint)totalSilverCost);
|
||||||
|
|
||||||
|
var (newLevel, newExp) = ApplyCardExp(card.Level, card.Exp, totalExp, levelCap);
|
||||||
|
card.Level = newLevel;
|
||||||
|
card.Exp = checked((int)newExp);
|
||||||
|
syncItems.Add(card.ToProto());
|
||||||
|
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.CharacterManager.CharacterData);
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
sync.Items.AddRange(syncItems);
|
||||||
|
sync.Custom[player.ToPackedAttrKey(CashGroupId, SilverSid)] = silverAttr.Val;
|
||||||
|
sync.Custom[player.ToShiftedAttrKey(CashGroupId, SilverSid)] = silverAttr.Val;
|
||||||
|
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "null", sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PlayerAttr GetOrCreateAttr(PlayerGameData data, uint gid, uint sid)
|
||||||
|
{
|
||||||
|
var attr = data.Attrs.FirstOrDefault(x => x.Gid == gid && x.Sid == sid);
|
||||||
|
if (attr != null)
|
||||||
|
return attr;
|
||||||
|
|
||||||
|
attr = new PlayerAttr
|
||||||
|
{
|
||||||
|
Gid = gid,
|
||||||
|
Sid = sid,
|
||||||
|
Val = 0
|
||||||
|
};
|
||||||
|
data.Attrs.Add(attr);
|
||||||
|
return attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Item BuildRemovedProto(BaseGameItemInfo item)
|
||||||
|
{
|
||||||
|
var proto = item.ToProto();
|
||||||
|
proto.Count = 0;
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetCardLevelCap(uint playerLevel, int levelLimitId)
|
||||||
|
{
|
||||||
|
var limits = LoadCardLevelLimit(levelLimitId);
|
||||||
|
if (limits.Count == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint nearestAccountLevel = 0;
|
||||||
|
uint nearestCardLevel = 0;
|
||||||
|
|
||||||
|
foreach (var (accountLevel, cardLevel) in limits)
|
||||||
|
{
|
||||||
|
if (accountLevel < playerLevel)
|
||||||
|
{
|
||||||
|
nearestAccountLevel = accountLevel;
|
||||||
|
nearestCardLevel = cardLevel;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accountLevel == playerLevel)
|
||||||
|
return Math.Min(cardLevel, RoleMaxLevel);
|
||||||
|
|
||||||
|
var distance = accountLevel - nearestAccountLevel;
|
||||||
|
if (distance == 0)
|
||||||
|
return Math.Min(cardLevel, RoleMaxLevel);
|
||||||
|
|
||||||
|
var percent = (playerLevel - nearestAccountLevel) / (double)distance;
|
||||||
|
var interpolated = (uint)Math.Floor(nearestCardLevel + ((cardLevel - nearestCardLevel) * percent));
|
||||||
|
return Math.Min(interpolated, RoleMaxLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.Min(nearestCardLevel, RoleMaxLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<(uint AccountLevel, uint CardLevel)> LoadCardLevelLimit(int levelLimitId)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(
|
||||||
|
AppContext.BaseDirectory,
|
||||||
|
"Resources",
|
||||||
|
"item",
|
||||||
|
"level_limit.json");
|
||||||
|
|
||||||
|
if (!File.Exists(path))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
using var doc = JsonDocument.Parse(File.ReadAllText(path));
|
||||||
|
var result = new List<(uint AccountLevel, uint CardLevel)>();
|
||||||
|
|
||||||
|
foreach (var row in doc.RootElement.EnumerateArray())
|
||||||
|
{
|
||||||
|
if (!row.TryGetProperty("ID", out var idProp) || idProp.GetInt32() != levelLimitId)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!row.TryGetProperty("Type", out var typeProp) || typeProp.GetInt32() != 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!row.TryGetProperty("Limit", out var limitProp) || limitProp.ValueKind != JsonValueKind.Object)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var property in limitProp.EnumerateObject())
|
||||||
|
{
|
||||||
|
if (!uint.TryParse(property.Name, out var accountLevel))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint cardLevel;
|
||||||
|
if (property.Value.ValueKind == JsonValueKind.Number)
|
||||||
|
{
|
||||||
|
cardLevel = property.Value.GetUInt32();
|
||||||
|
}
|
||||||
|
else if (property.Value.ValueKind == JsonValueKind.String &&
|
||||||
|
uint.TryParse(property.Value.GetString(), out var parsed))
|
||||||
|
{
|
||||||
|
cardLevel = parsed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Add((accountLevel, cardLevel));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Sort((a, b) => a.AccountLevel.CompareTo(b.AccountLevel));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static (uint Level, ulong Exp) ApplyCardExp(uint level, int currentExp, ulong addedExp, uint levelCap)
|
||||||
|
{
|
||||||
|
var destLevel = level == 0 ? 1u : level;
|
||||||
|
var destExp = (ulong)Math.Max(0, currentExp) + addedExp;
|
||||||
|
|
||||||
|
if (levelCap > 0 && destLevel >= levelCap)
|
||||||
|
return (destLevel, destExp);
|
||||||
|
|
||||||
|
while (destLevel < RoleMaxLevel)
|
||||||
|
{
|
||||||
|
var needExp = GetCardNeedExp(destLevel);
|
||||||
|
if (needExp == 0 || destExp < needExp)
|
||||||
|
break;
|
||||||
|
|
||||||
|
destExp -= needExp;
|
||||||
|
destLevel++;
|
||||||
|
|
||||||
|
if (levelCap > 0 && destLevel >= levelCap)
|
||||||
|
return (levelCap, destExp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (destLevel, destExp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetCardNeedExp(uint currentLevel)
|
||||||
|
{
|
||||||
|
if (GameData.UpgradeExpData.TryGetValue((int)currentLevel, out var row))
|
||||||
|
return row.CardNeedExp;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GirlCardUpdateLevelParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("tbMaterials")]
|
||||||
|
public List<GirlCardLevelMaterial> Materials { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GirlCardLevelMaterial
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("Num")]
|
||||||
|
public uint Num { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Data.Excel;
|
||||||
|
using MikuSB.Database;
|
||||||
|
using MikuSB.Database.Inventory;
|
||||||
|
using MikuSB.Database.Player;
|
||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||||
|
|
||||||
|
internal static class SupporterCardAffixShared
|
||||||
|
{
|
||||||
|
public const uint BaseGid = 150;
|
||||||
|
public const uint FixedResetSid = 1;
|
||||||
|
|
||||||
|
public static SupportCardExcel? GetExcel(GameSupportCardInfo card)
|
||||||
|
{
|
||||||
|
return GameData.SupportCardData.FirstOrDefault(x => x.TemplateId == card.TemplateId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task SendResetResponse(Connection connection, NtfSyncPlayer? sync = null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "SupporterCard_ResetAffix", "null", sync!);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task SendSelectResponse(Connection connection, NtfSyncPlayer? sync = null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "SupporterCard_SelectAffix", "null", sync!);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Item> ConsumeCostItems(Connection connection, IEnumerable<IReadOnlyList<uint>> costs)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
var syncItems = new List<Item>();
|
||||||
|
|
||||||
|
foreach (var cost in costs)
|
||||||
|
{
|
||||||
|
if (cost.Count < 5)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var templateId = GameResourceTemplateId.FromGdpl(cost);
|
||||||
|
var item = player.InventoryManager.InventoryData.Items.Values.FirstOrDefault(x => x.TemplateId == templateId);
|
||||||
|
if (item == null || item.ItemCount < cost[4])
|
||||||
|
throw new InvalidOperationException("support affix material not enough");
|
||||||
|
|
||||||
|
item.ItemCount -= cost[4];
|
||||||
|
var proto = item.ToProto();
|
||||||
|
if (item.ItemCount == 0)
|
||||||
|
{
|
||||||
|
player.InventoryManager.InventoryData.Items.Remove(item.UniqueId);
|
||||||
|
proto.Count = 0;
|
||||||
|
}
|
||||||
|
syncItems.Add(proto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return syncItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HasEnoughItems(Connection connection, IEnumerable<IReadOnlyList<uint>> costs)
|
||||||
|
{
|
||||||
|
var items = connection.Player!.InventoryManager.InventoryData.Items.Values;
|
||||||
|
return costs.All(cost =>
|
||||||
|
{
|
||||||
|
if (cost.Count < 5)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var templateId = GameResourceTemplateId.FromGdpl(cost);
|
||||||
|
var item = items.FirstOrDefault(x => x.TemplateId == templateId);
|
||||||
|
return item != null && item.ItemCount >= cost[4];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayerAttr GetOrCreateAttr(PlayerGameData data, uint gid, uint sid)
|
||||||
|
{
|
||||||
|
var attr = data.Attrs.FirstOrDefault(x => x.Gid == gid && x.Sid == sid);
|
||||||
|
if (attr != null)
|
||||||
|
return attr;
|
||||||
|
|
||||||
|
attr = new PlayerAttr { Gid = gid, Sid = sid, Val = 0 };
|
||||||
|
data.Attrs.Add(attr);
|
||||||
|
return attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetAttr(Connection connection, NtfSyncPlayer sync, uint gid, uint sid, uint value)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
var attr = GetOrCreateAttr(player.Data, gid, sid);
|
||||||
|
attr.Val = value;
|
||||||
|
sync.Custom[player.ToPackedAttrKey(gid, sid)] = value;
|
||||||
|
sync.Custom[player.ToShiftedAttrKey(gid, sid)] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<uint> GetActiveAffixIds(GameSupportCardInfo card, params int[] ignoreSlots)
|
||||||
|
{
|
||||||
|
var ignored = ignoreSlots.ToHashSet();
|
||||||
|
for (var slot = 1; slot <= SupportAffixStateService.ActiveThirdAffixSlot; slot++)
|
||||||
|
{
|
||||||
|
if (ignored.Contains(slot))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var (affixId, _) = SupportAffixStateService.GetAffix(card, slot);
|
||||||
|
if (affixId > 0)
|
||||||
|
yield return affixId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Save(Connection connection)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class SupporterCardIdParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Id")]
|
||||||
|
public int SupportCardUid { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class SupporterCardSelectParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Id")]
|
||||||
|
public int SupportCardUid { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("SelectNew")]
|
||||||
|
public bool SelectNew { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class SupporterCardResetInitialParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Id")]
|
||||||
|
public int SupportCardUid { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("Index")]
|
||||||
|
public int Index { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("FixedId")]
|
||||||
|
public uint FixedId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class SupporterCardSelectInitialParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Id")]
|
||||||
|
public int SupportCardUid { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("Index")]
|
||||||
|
public int Index { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("SelectNew")]
|
||||||
|
public bool SelectNew { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||||
|
|
||||||
|
[CallGSApi("SupporterCard_FixedResetInitialAffix")]
|
||||||
|
public class SupporterCard_FixedResetInitialAffix : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
await SupporterCard_ResetInitialAffix.Reset(connection, param, fixedMode: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||||
|
|
||||||
|
[CallGSApi("SupporterCard_ReceiveFixedItem")]
|
||||||
|
public class SupporterCard_ReceiveFixedItem : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
if (!GameData.SupportFixedData.TryGetValue(1, out var fixedCfg) || fixedCfg.Item.Count < 5 || fixedCfg.Num <= 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "SupporterCard_ReceiveFixedItem", "{}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var attr = SupporterCardAffixShared.GetOrCreateAttr(player.Data, SupporterCardAffixShared.BaseGid, SupporterCardAffixShared.FixedResetSid);
|
||||||
|
var claimCount = attr.Val / (uint)fixedCfg.Num;
|
||||||
|
if (claimCount == 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "SupporterCard_ReceiveFixedItem", "{}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
attr.Val %= (uint)fixedCfg.Num;
|
||||||
|
|
||||||
|
var rewardTemplateId = (uint)GameResourceTemplateId.FromGdpl(fixedCfg.Item);
|
||||||
|
var rewardItem = GameData.SuppliesData.GetValueOrDefault(rewardTemplateId);
|
||||||
|
if (rewardItem == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "SupporterCard_ReceiveFixedItem", "{}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var granted = await player.InventoryManager.AddSuppliesItem(rewardItem, claimCount * fixedCfg.Item[4], sendPacket: false);
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
if (granted != null)
|
||||||
|
sync.Items.Add(granted.ToProto());
|
||||||
|
SupporterCardAffixShared.SetAttr(connection, sync, SupporterCardAffixShared.BaseGid, SupporterCardAffixShared.FixedResetSid, attr.Val);
|
||||||
|
SupporterCardAffixShared.Save(connection);
|
||||||
|
|
||||||
|
var arg = new JsonObject
|
||||||
|
{
|
||||||
|
["tbRewards"] = new JsonArray(
|
||||||
|
(int)fixedCfg.Item[0],
|
||||||
|
(int)fixedCfg.Item[1],
|
||||||
|
(int)fixedCfg.Item[2],
|
||||||
|
(int)fixedCfg.Item[3],
|
||||||
|
(int)(claimCount * fixedCfg.Item[4]))
|
||||||
|
}.ToJsonString();
|
||||||
|
|
||||||
|
await CallGSRouter.SendScript(connection, "SupporterCard_ReceiveFixedItem", arg, sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||||
|
|
||||||
|
[CallGSApi("SupporterCard_ResetAffix")]
|
||||||
|
public class SupporterCard_ResetAffix : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var req = JsonSerializer.Deserialize<SupporterCardIdParam>(param);
|
||||||
|
var card = req == null ? null : connection.Player!.InventoryManager.GetSupportCardItem((uint)req.SupportCardUid);
|
||||||
|
var excel = card == null ? null : SupporterCardAffixShared.GetExcel(card);
|
||||||
|
if (card == null || excel == null || excel.AffixCost.Count < 5 || !SupportAffixStateService.HasAffix(card, SupportAffixStateService.ActiveThirdAffixSlot))
|
||||||
|
{
|
||||||
|
await SupporterCardAffixShared.SendResetResponse(connection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var costs = new[] { excel.AffixCost };
|
||||||
|
if (!SupporterCardAffixShared.HasEnoughItems(connection, costs))
|
||||||
|
{
|
||||||
|
await SupporterCardAffixShared.SendResetResponse(connection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
sync.Items.AddRange(SupporterCardAffixShared.ConsumeCostItems(connection, costs));
|
||||||
|
var excluded = SupporterCardAffixShared.GetActiveAffixIds(card, SupportAffixStateService.ActiveThirdAffixSlot);
|
||||||
|
var (affixId, tier) = SupportAffixService.GenerateRandomAffix(excel.AffixPool[SupportAffixStateService.ActiveThirdAffixSlot - 1], excluded);
|
||||||
|
SupportAffixStateService.SetAffix(card, SupportAffixStateService.PendingMaxAffixSlot, affixId, tier);
|
||||||
|
sync.Items.Add(card.ToProto());
|
||||||
|
|
||||||
|
SupporterCardAffixShared.Save(connection);
|
||||||
|
await SupporterCardAffixShared.SendResetResponse(connection, sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||||
|
|
||||||
|
[CallGSApi("SupporterCard_ResetInitialAffix")]
|
||||||
|
public class SupporterCard_ResetInitialAffix : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
await Reset(connection, param, fixedMode: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static async Task Reset(Connection connection, string param, bool fixedMode)
|
||||||
|
{
|
||||||
|
var req = JsonSerializer.Deserialize<SupporterCardResetInitialParam>(param);
|
||||||
|
var card = req == null ? null : connection.Player!.InventoryManager.GetSupportCardItem((uint)req.SupportCardUid);
|
||||||
|
var excel = card == null ? null : SupporterCardAffixShared.GetExcel(card);
|
||||||
|
if (req == null || card == null || excel == null || req.Index is < 1 or > 2 || excel.AffixPool.Count < req.Index)
|
||||||
|
{
|
||||||
|
await SupporterCardAffixShared.SendResetResponse(connection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var costs = fixedMode ? new[] { excel.FixedAffixCost } : excel.InitialAffixCost;
|
||||||
|
if (!costs.Any() || !SupporterCardAffixShared.HasEnoughItems(connection, costs))
|
||||||
|
{
|
||||||
|
await SupporterCardAffixShared.SendResetResponse(connection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
sync.Items.AddRange(SupporterCardAffixShared.ConsumeCostItems(connection, costs));
|
||||||
|
|
||||||
|
uint affixId;
|
||||||
|
uint tier;
|
||||||
|
if (fixedMode && req.FixedId > 0)
|
||||||
|
{
|
||||||
|
affixId = req.FixedId;
|
||||||
|
tier = SupportAffixService.GenerateTier(affixId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var excluded = SupporterCardAffixShared.GetActiveAffixIds(card, req.Index);
|
||||||
|
(affixId, tier) = SupportAffixService.GenerateRandomAffix(excel.AffixPool[req.Index - 1], excluded);
|
||||||
|
}
|
||||||
|
|
||||||
|
SupportAffixStateService.SetAffix(card, SupportAffixStateService.PendingInitialAffixSlot, affixId, tier);
|
||||||
|
card.AffixId = (uint)req.Index;
|
||||||
|
|
||||||
|
var attr = SupporterCardAffixShared.GetOrCreateAttr(connection.Player!.Data, SupporterCardAffixShared.BaseGid, SupporterCardAffixShared.FixedResetSid);
|
||||||
|
attr.Val += 1;
|
||||||
|
SupporterCardAffixShared.SetAttr(connection, sync, SupporterCardAffixShared.BaseGid, SupporterCardAffixShared.FixedResetSid, attr.Val);
|
||||||
|
|
||||||
|
sync.Items.Add(card.ToProto());
|
||||||
|
SupporterCardAffixShared.Save(connection);
|
||||||
|
await SupporterCardAffixShared.SendResetResponse(connection, sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||||
|
|
||||||
|
[CallGSApi("SupporterCard_SelectAffix")]
|
||||||
|
public class SupporterCard_SelectAffix : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var req = JsonSerializer.Deserialize<SupporterCardSelectParam>(param);
|
||||||
|
var card = req == null ? null : connection.Player!.InventoryManager.GetSupportCardItem((uint)req.SupportCardUid);
|
||||||
|
if (card == null || !SupportAffixStateService.HasAffix(card, SupportAffixStateService.PendingMaxAffixSlot))
|
||||||
|
{
|
||||||
|
await SupporterCardAffixShared.SendSelectResponse(connection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req!.SelectNew)
|
||||||
|
SupportAffixStateService.CopyAffix(card, SupportAffixStateService.PendingMaxAffixSlot, SupportAffixStateService.ActiveThirdAffixSlot);
|
||||||
|
|
||||||
|
SupportAffixStateService.ClearAffix(card, SupportAffixStateService.PendingMaxAffixSlot);
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
sync.Items.Add(card.ToProto());
|
||||||
|
SupporterCardAffixShared.Save(connection);
|
||||||
|
await SupporterCardAffixShared.SendSelectResponse(connection, sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.SupporterCard;
|
||||||
|
|
||||||
|
[CallGSApi("SupporterCard_SelectInitialAffix")]
|
||||||
|
public class SupporterCard_SelectInitialAffix : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var req = JsonSerializer.Deserialize<SupporterCardSelectInitialParam>(param);
|
||||||
|
var card = req == null ? null : connection.Player!.InventoryManager.GetSupportCardItem((uint)req.SupportCardUid);
|
||||||
|
if (req == null || card == null || req.Index is < 1 or > 2 || card.AffixId != req.Index || !SupportAffixStateService.HasAffix(card, SupportAffixStateService.PendingInitialAffixSlot))
|
||||||
|
{
|
||||||
|
await SupporterCardAffixShared.SendSelectResponse(connection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.SelectNew)
|
||||||
|
SupportAffixStateService.CopyAffix(card, SupportAffixStateService.PendingInitialAffixSlot, req.Index);
|
||||||
|
|
||||||
|
SupportAffixStateService.ClearAffix(card, SupportAffixStateService.PendingInitialAffixSlot);
|
||||||
|
card.AffixId = 0;
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
sync.Items.Add(card.ToProto());
|
||||||
|
SupporterCardAffixShared.Save(connection);
|
||||||
|
await SupporterCardAffixShared.SendSelectResponse(connection, sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using MikuSB.Data;
|
using MikuSB.Data;
|
||||||
using MikuSB.Database;
|
using MikuSB.Database;
|
||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
using MikuSB.Proto;
|
using MikuSB.Proto;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
@@ -19,7 +20,7 @@ public class SupporterCard_Upgrade : ICallGSHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportCard = player.InventoryManager.InventoryData.Items.GetValueOrDefault((uint)req.SupportCardUid);
|
var supportCard = player.InventoryManager.GetSupportCardItem((uint)req.SupportCardUid);
|
||||||
if (supportCard == null)
|
if (supportCard == null)
|
||||||
{
|
{
|
||||||
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}");
|
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}");
|
||||||
@@ -68,10 +69,11 @@ public class SupporterCard_Upgrade : ICallGSHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply exp and level up
|
// Apply exp and level up
|
||||||
|
if (supportCard.Level == 0) supportCard.Level = 1;
|
||||||
supportCard.Exp += gainedExp;
|
supportCard.Exp += gainedExp;
|
||||||
while (supportCard.Level < maxLevel)
|
while (supportCard.Level < maxLevel)
|
||||||
{
|
{
|
||||||
var expNeeded = GetExpNeeded(supportCard.Level + 1);
|
var expNeeded = GetExpNeeded(supportCard.Level);
|
||||||
if (expNeeded == 0 || supportCard.Exp < expNeeded) break;
|
if (expNeeded == 0 || supportCard.Exp < expNeeded) break;
|
||||||
supportCard.Exp -= expNeeded;
|
supportCard.Exp -= expNeeded;
|
||||||
supportCard.Level++;
|
supportCard.Level++;
|
||||||
@@ -80,6 +82,21 @@ public class SupporterCard_Upgrade : ICallGSHandler
|
|||||||
{
|
{
|
||||||
supportCard.Exp = 0;
|
supportCard.Exp = 0;
|
||||||
supportCard.Level = maxLevel;
|
supportCard.Level = maxLevel;
|
||||||
|
|
||||||
|
// Unlock next affix slot when reaching max level for the first time
|
||||||
|
if (supportCardExcel != null)
|
||||||
|
{
|
||||||
|
var currentSlots = Enumerable.Range(1, SupportAffixStateService.ActiveThirdAffixSlot)
|
||||||
|
.Count(slot => SupportAffixStateService.HasAffix(supportCard, slot));
|
||||||
|
var totalSlots = supportCardExcel.TotalAffixCount;
|
||||||
|
if (currentSlots < totalSlots && currentSlots < supportCardExcel.AffixPool.Count)
|
||||||
|
{
|
||||||
|
var poolId = supportCardExcel.AffixPool[currentSlots];
|
||||||
|
var (affixId, tier) = SupportAffixService.GenerateRandomAffix(poolId);
|
||||||
|
if (affixId > 0)
|
||||||
|
SupportAffixStateService.SetAffix(supportCard, currentSlots + 1, affixId, tier);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncItems.Add(supportCard.ToProto());
|
syncItems.Add(supportCard.ToProto());
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace MikuSB.GameServer.Server.Packet.Recv.Login;
|
|||||||
public class HandlerReqLogin : Handler
|
public class HandlerReqLogin : Handler
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = new("ReqLogin");
|
private static readonly Logger Logger = new("ReqLogin");
|
||||||
|
private const int SupportCardLoginSplitThreshold = 2000;
|
||||||
|
|
||||||
private static string? ExtractSdkAuthToken(string? token)
|
private static string? ExtractSdkAuthToken(string? token)
|
||||||
{
|
{
|
||||||
@@ -80,7 +81,10 @@ public class HandlerReqLogin : Handler
|
|||||||
$"Debug-{DateTime.Now:yyyy-MM-dd HH-mm-ss}.log");
|
$"Debug-{DateTime.Now:yyyy-MM-dd HH-mm-ss}.log");
|
||||||
await connection.Player.OnEnterGame();
|
await connection.Player.OnEnterGame();
|
||||||
connection.Player.Connection = connection;
|
connection.Player.Connection = connection;
|
||||||
await connection.SendPacket(new PacketRspLogin(connection.Player!));
|
var splitSupportCards = connection.Player.InventoryManager.InventoryData.SupportCards.Count > SupportCardLoginSplitThreshold;
|
||||||
|
await connection.SendPacket(new PacketRspLogin(connection.Player!, !splitSupportCards));
|
||||||
|
if (splitSupportCards)
|
||||||
|
await SendSupportCardsOnLogin(connection);
|
||||||
await connection.SendPacket(new PacketNtfCallScript(connection.Player!));
|
await connection.SendPacket(new PacketNtfCallScript(connection.Player!));
|
||||||
await SendDebugLoginState(connection);
|
await SendDebugLoginState(connection);
|
||||||
|
|
||||||
@@ -90,6 +94,22 @@ public class HandlerReqLogin : Handler
|
|||||||
await SendGirlSkinTypeOnLogin(connection);
|
await SendGirlSkinTypeOnLogin(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task SendSupportCardsOnLogin(Connection connection)
|
||||||
|
{
|
||||||
|
var player = connection.Player;
|
||||||
|
if (player == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var supportCards = player.InventoryManager.InventoryData.SupportCards.Values.ToList();
|
||||||
|
Logger.Info($"Split support card sync on login: total={supportCards.Count}, chunkSize={SupportCardLoginSplitThreshold}");
|
||||||
|
|
||||||
|
foreach (var chunk in supportCards.Chunk(SupportCardLoginSplitThreshold))
|
||||||
|
{
|
||||||
|
var packet = new PacketNtfCallScript(chunk.ToList());
|
||||||
|
await connection.SendPacket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void ApplySavedGirlSkinTypes(PlayerInstance player)
|
private static void ApplySavedGirlSkinTypes(PlayerInstance player)
|
||||||
{
|
{
|
||||||
var inventoryData = player.InventoryManager.InventoryData;
|
var inventoryData = player.InventoryManager.InventoryData;
|
||||||
|
|||||||
@@ -10,18 +10,41 @@ public class PacketRspLogin : BasePacket
|
|||||||
{
|
{
|
||||||
private static readonly Logger Logger = new("RspLogin");
|
private static readonly Logger Logger = new("RspLogin");
|
||||||
|
|
||||||
public PacketRspLogin(PlayerInstance player) : base(CmdIds.RspLogin)
|
public PacketRspLogin(PlayerInstance player, bool includeSupportCards = true) : base(CmdIds.RspLogin)
|
||||||
{
|
{
|
||||||
|
var characterCount = player.CharacterManager.CharacterData.Characters.Count;
|
||||||
|
var itemCount = player.InventoryManager.InventoryData.Items.Count;
|
||||||
|
var skinCount = player.InventoryManager.InventoryData.Skins.Count;
|
||||||
|
var weaponCount = player.InventoryManager.InventoryData.Weapons.Count;
|
||||||
|
var supportCardCount = player.InventoryManager.InventoryData.SupportCards.Count;
|
||||||
|
var attrCount = player.Data.Attrs.Count;
|
||||||
|
var strAttrCount = player.Data.StrAttrs.Count;
|
||||||
|
var showItemCount = player.Data.ShowItems.Count;
|
||||||
|
|
||||||
var proto = new RspLogin
|
var proto = new RspLogin
|
||||||
{
|
{
|
||||||
Timestamp = (uint)Extensions.GetUnixSec(),
|
Timestamp = (uint)Extensions.GetUnixSec(),
|
||||||
WorldChannel = 1,
|
WorldChannel = 1,
|
||||||
AreaId = 1,
|
AreaId = 1,
|
||||||
Data = player.ToPlayerProto(),
|
Data = player.ToPlayerProto(includeSupportCards),
|
||||||
NeedRename = false
|
NeedRename = false
|
||||||
};
|
};
|
||||||
|
|
||||||
var bytes = Google.Protobuf.MessageExtensions.ToByteArray(proto);
|
var bytes = Google.Protobuf.MessageExtensions.ToByteArray(proto);
|
||||||
|
Logger.Info(
|
||||||
|
"RspLogin content: " +
|
||||||
|
$"characters={characterCount}, " +
|
||||||
|
$"items={itemCount}, " +
|
||||||
|
$"skins={skinCount}, " +
|
||||||
|
$"weapons={weaponCount}, " +
|
||||||
|
$"supportCards={supportCardCount}, " +
|
||||||
|
$"supportCardsInRspLogin={(includeSupportCards ? supportCardCount : 0)}, " +
|
||||||
|
$"attrs={attrCount}, " +
|
||||||
|
$"strAttrs={strAttrCount}, " +
|
||||||
|
$"showItems={showItemCount}, " +
|
||||||
|
$"protoItems={proto.Data.Items.Count}, " +
|
||||||
|
$"protoAttrs={proto.Data.Attrs.Count}, " +
|
||||||
|
$"protoStrAttrs={proto.Data.StrAttrs.Count}");
|
||||||
Logger.Info($"RspLogin proto size: {bytes.Length} bytes");
|
Logger.Info($"RspLogin proto size: {bytes.Length} bytes");
|
||||||
|
|
||||||
SetData(bytes);
|
SetData(bytes);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using MikuSB.Database.Character;
|
using MikuSB.Database.Character;
|
||||||
using MikuSB.Database.Inventory;
|
using MikuSB.Database.Inventory;
|
||||||
|
using MikuSB.Enums.Item;
|
||||||
using MikuSB.GameServer.Game.Player;
|
using MikuSB.GameServer.Game.Player;
|
||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
using MikuSB.Proto;
|
using MikuSB.Proto;
|
||||||
using MikuSB.TcpSharp;
|
using MikuSB.TcpSharp;
|
||||||
|
|
||||||
@@ -10,14 +12,14 @@ public class PacketNtfCallScript : BasePacket
|
|||||||
{
|
{
|
||||||
public PacketNtfCallScript(List<CharacterInfo> characters) : base(CmdIds.NtfScript)
|
public PacketNtfCallScript(List<CharacterInfo> characters) : base(CmdIds.NtfScript)
|
||||||
{
|
{
|
||||||
var proto = new NtfCallScript
|
var proto = new NtfCallScript
|
||||||
{
|
{
|
||||||
Api = "",
|
Api = "",
|
||||||
Arg = "{}",
|
Arg = "{}",
|
||||||
ExtraSync = new NtfSyncPlayer
|
ExtraSync = new NtfSyncPlayer
|
||||||
{
|
{
|
||||||
Items = { characters.Select(x => x.ToProto()) }
|
Items = { characters.Select(x => x.ToProto()) }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SetData(proto);
|
SetData(proto);
|
||||||
@@ -61,7 +63,7 @@ public class PacketNtfCallScript : BasePacket
|
|||||||
Arg = "{}",
|
Arg = "{}",
|
||||||
ExtraSync = new NtfSyncPlayer
|
ExtraSync = new NtfSyncPlayer
|
||||||
{
|
{
|
||||||
Items = { cards.Select(x => x.ToProto()) }
|
Items = { cards.Select(ToSupportCardProto) }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,7 +97,7 @@ public class PacketNtfCallScript : BasePacket
|
|||||||
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 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());
|
||||||
foreach (var supportCard in inventory.SupportCards.Values) extraSync.Items.Add(supportCard.ToProto());
|
foreach (var supportCard in inventory.SupportCards.Values) extraSync.Items.Add(ToSupportCardProto(supportCard));
|
||||||
proto.ExtraSync = extraSync;
|
proto.ExtraSync = extraSync;
|
||||||
SetData(proto);
|
SetData(proto);
|
||||||
}
|
}
|
||||||
@@ -128,4 +130,12 @@ public class PacketNtfCallScript : BasePacket
|
|||||||
|
|
||||||
SetData(proto);
|
SetData(proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Item ToSupportCardProto(GameSupportCardInfo card)
|
||||||
|
{
|
||||||
|
SupportAffixStateService.NormalizePendingState(card);
|
||||||
|
var proto = card.ToProto();
|
||||||
|
proto.Slots[(uint)ItemSupportCardSlotTypeEnum.SLOT_AFFIXINDEX] = SupportAffixStateService.GetVisibleInitialAffixIndex(card);
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,11 +293,14 @@ public sealed class LaunchOptions
|
|||||||
public static LaunchOptions FromConfig(IEnumerable<string>? extraGameArguments = null)
|
public static LaunchOptions FromConfig(IEnumerable<string>? extraGameArguments = null)
|
||||||
{
|
{
|
||||||
var config = ConfigManager.Config;
|
var config = ConfigManager.Config;
|
||||||
|
var serverBaseDirectory = AppContext.BaseDirectory;
|
||||||
var gamePath = ResolvePath(config.Loader.GamePath, AppContext.BaseDirectory);
|
var gamePath = ResolvePath(config.Loader.GamePath, AppContext.BaseDirectory);
|
||||||
var patchPaths = ResolvePatchPaths(config.Loader.PatchPaths, AppContext.BaseDirectory);
|
var patchPaths = ResolvePatchPaths(config.Loader.PatchPaths, serverBaseDirectory);
|
||||||
var gameArgs = new List<string>(config.Loader.Arguments ?? []);
|
var gameArgs = new List<string>(config.Loader.Arguments ?? []);
|
||||||
if (extraGameArguments is not null)
|
if (extraGameArguments is not null)
|
||||||
gameArgs.AddRange(extraGameArguments.Where(x => !string.IsNullOrWhiteSpace(x)));
|
gameArgs.AddRange(extraGameArguments.Where(x => !string.IsNullOrWhiteSpace(x)));
|
||||||
|
gameArgs = EnsureUserDirArgument(gameArgs, serverBaseDirectory);
|
||||||
|
PersistResolvedArgumentsIfChanged(config, gameArgs);
|
||||||
|
|
||||||
var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
if (config.Loader.SetAllProxy && config.Proxy.Enabled)
|
if (config.Loader.SetAllProxy && config.Proxy.Enabled)
|
||||||
@@ -330,6 +333,31 @@ public sealed class LaunchOptions
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<string> EnsureUserDirArgument(List<string> gameArgs, string baseDirectory)
|
||||||
|
{
|
||||||
|
var userDataDirectory = Path.GetFullPath(Path.Combine(baseDirectory, "Client_User_Data"));
|
||||||
|
Directory.CreateDirectory(userDataDirectory);
|
||||||
|
|
||||||
|
var userDirArgument = $"-userdir={userDataDirectory}";
|
||||||
|
var existingIndex = gameArgs.FindIndex(x => x.StartsWith("-userdir=", StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (existingIndex >= 0)
|
||||||
|
gameArgs[existingIndex] = userDirArgument;
|
||||||
|
else
|
||||||
|
gameArgs.Add(userDirArgument);
|
||||||
|
|
||||||
|
return gameArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PersistResolvedArgumentsIfChanged(Configuration.ConfigContainer config, List<string> gameArgs)
|
||||||
|
{
|
||||||
|
var currentArgs = config.Loader.Arguments ?? [];
|
||||||
|
if (currentArgs.SequenceEqual(gameArgs, StringComparer.Ordinal))
|
||||||
|
return;
|
||||||
|
|
||||||
|
config.Loader.Arguments = gameArgs.ToArray();
|
||||||
|
ConfigManager.SaveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
private static string? ResolvePath(string? value, string baseDirectory)
|
private static string? ResolvePath(string? value, string baseDirectory)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value))
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
|||||||
@@ -22,16 +22,35 @@ public class LoaderManager : MikuSB
|
|||||||
public static void InitConfig()
|
public static void InitConfig()
|
||||||
{
|
{
|
||||||
// Initialize log
|
// Initialize log
|
||||||
var counter = 0;
|
var logDir = ConfigManager.Config.Path.LogPath;
|
||||||
FileInfo file;
|
var logFile = new FileInfo(Path.Combine(logDir, "Server.log"));
|
||||||
while (true)
|
logFile.Directory?.Create();
|
||||||
|
|
||||||
|
if (logFile.Exists)
|
||||||
{
|
{
|
||||||
file = new FileInfo(ConfigManager.Config.Path.LogPath + $"/{DateTime.Now:yyyy-MM-dd}-{++counter}.log");
|
// Read start time from first log line, fall back to file creation time
|
||||||
if (file is not { Exists: false, Directory: not null }) continue;
|
DateTime logStartTime;
|
||||||
file.Directory.Create();
|
try
|
||||||
break;
|
{
|
||||||
|
var firstLine = File.ReadLines(logFile.FullName).FirstOrDefault() ?? "";
|
||||||
|
// Format: [HH:mm:ss] ...
|
||||||
|
var timeStr = firstLine.Length >= 10 ? firstLine[1..9] : "";
|
||||||
|
var dateStr = logFile.CreationTime.ToString("yyyy-MM-dd");
|
||||||
|
logStartTime = DateTime.TryParse($"{dateStr} {timeStr}", out var parsed)
|
||||||
|
? parsed
|
||||||
|
: logFile.CreationTime;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
logStartTime = logFile.CreationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
var backupName = $"Server-backup-{logStartTime:yyyy.MM.dd-HH.mm.ss}.log";
|
||||||
|
var backupFile = new FileInfo(Path.Combine(logDir, backupName));
|
||||||
|
logFile.MoveTo(backupFile.FullName, overwrite: true);
|
||||||
}
|
}
|
||||||
Logger.SetLogFile(file);
|
|
||||||
|
Logger.SetLogFile(new FileInfo(Path.Combine(logDir, "Server.log")));
|
||||||
|
|
||||||
// Init all directories
|
// Init all directories
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class MikuSB
|
|||||||
var time = DateTime.Now;
|
var time = DateTime.Now;
|
||||||
IConsole.InitConsole();
|
IConsole.InitConsole();
|
||||||
LoaderManager.InitConfig();
|
LoaderManager.InitConfig();
|
||||||
|
ShowAntiScamWarning();
|
||||||
if (await UpdateService.TryStartSelfUpdateAsync())
|
if (await UpdateService.TryStartSelfUpdateAsync())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -65,6 +66,16 @@ public class MikuSB
|
|||||||
await ProcessExit(Volatile.Read(ref _exitCode));
|
await ProcessExit(Volatile.Read(ref _exitCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ShowAntiScamWarning()
|
||||||
|
{
|
||||||
|
Logger.Warn("============================================================");
|
||||||
|
Logger.Warn("MikuSB is completely free and open source.");
|
||||||
|
Logger.Warn("If you paid anyone for this server, you were scammed.");
|
||||||
|
Logger.Warn("Request a refund immediately and report the seller to us.");
|
||||||
|
Logger.Warn("Discord: https://discord.gg/aMwCu9JyUR");
|
||||||
|
Logger.Warn("============================================================");
|
||||||
|
}
|
||||||
|
|
||||||
#region Exit
|
#region Exit
|
||||||
|
|
||||||
private static void RegisterExitEvent()
|
private static void RegisterExitEvent()
|
||||||
@@ -109,4 +120,4 @@ public class MikuSB
|
|||||||
}
|
}
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
日本語のドキュメントは [README_jp.md](README_jp.md) にあります。
|
日本語のドキュメントは [README_jp.md](README_jp.md) にあります。
|
||||||
|
|
||||||
|
## Scam Warning
|
||||||
|
|
||||||
|
MikuSB is completely free and open source.
|
||||||
|
If anyone sold you this server or charged money to provide it, that was a scam.
|
||||||
|
Request a refund immediately and report the seller to us on Discord with any relevant proof or purchase details.
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
- `SdkServer`
|
- `SdkServer`
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
English documentation is available in [README.md](README.md).
|
English documentation is available in [README.md](README.md).
|
||||||
|
|
||||||
|
## 詐欺に関する警告
|
||||||
|
|
||||||
|
MikuSB は完全無料のオープンソースです。
|
||||||
|
このサーバーを誰かから有料で販売された場合、それは詐欺です。
|
||||||
|
すぐに返金を申請し、購入記録や証拠とあわせて Discord で私たちに通報してください。
|
||||||
|
|
||||||
## 概要
|
## 概要
|
||||||
|
|
||||||
- `SdkServer`
|
- `SdkServer`
|
||||||
|
|||||||
@@ -270,13 +270,13 @@ public class RouteController : ControllerBase
|
|||||||
var finalEmail = email ?? form_email ?? await GetJsonBodyValue("email");
|
var finalEmail = email ?? form_email ?? await GetJsonBodyValue("email");
|
||||||
if (!string.IsNullOrWhiteSpace(finalEmail))
|
if (!string.IsNullOrWhiteSpace(finalEmail))
|
||||||
{
|
{
|
||||||
var username = finalEmail.Split('@')[0];
|
var normalizedEmail = finalEmail.Trim();
|
||||||
var accountData = AccountData.GetAccountByUserName(username);
|
var accountData = AccountData.GetAccountByEmail(normalizedEmail);
|
||||||
if (accountData == null)
|
if (accountData == null)
|
||||||
{
|
{
|
||||||
if (!ConfigManager.Config.ServerOption.AutoCreateUser) return BuildLoginFailedResponse("Account not found.");
|
if (!ConfigManager.Config.ServerOption.AutoCreateUser) return BuildLoginFailedResponse("Account not found.");
|
||||||
AccountData.CreateAccount(username, 0, "123456");
|
AccountData.CreateAccount(normalizedEmail, 0, "123456");
|
||||||
accountData = AccountData.GetAccountByUserName(username)!;
|
accountData = AccountData.GetAccountByEmail(normalizedEmail)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
var finalUidValue = accountData.Uid.ToString();
|
var finalUidValue = accountData.Uid.ToString();
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v=2.9
|
v=3.7
|
||||||
Reference in New Issue
Block a user