Compare commits

..

7 Commits
v3.0 ... v3.1

Author SHA1 Message Date
Kei-Luna
e628a010be Update version.txt 2026-05-15 16:45:00 +09:00
Kei-Luna
738a7d4e14 Improved the system so that affixes are correctly applied when obtaining support cards using the give command. 2026-05-15 16:17:36 +09:00
Kei-Luna
0058ba0db6 Support Card Affix 2026-05-15 16:07:36 +09:00
Kei-Luna
46d945f3ce Fix SupporterCard_Upgrade 2026-05-15 15:11:53 +09:00
Kei-Luna
e5ecdc7f2a Rename the log file 2026-05-15 14:47:41 +09:00
Kei-Luna
30c52b6aa8 account delete command 2026-05-15 14:12:40 +09:00
Kei-Luna
3ffb7ebf29 Small fix(login system) 2026-05-15 14:05:58 +09:00
15 changed files with 241 additions and 18 deletions

View 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;
}
}

View 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;
}
}

View File

@@ -11,7 +11,9 @@ public class SupportCardExcel : ExcelResource
public uint Level { get; set; }
public uint Icon { get; set; }
public uint ProvideExp { get; set; }
public uint Color { get; set; }
[JsonProperty("LevelLimitID")] public int LevelLimitId { get; set; }
[JsonProperty("AffixPool")] public List<int> AffixPool { get; set; } = [];
public uint MaxLevel => LevelLimitId switch
{
@@ -21,6 +23,12 @@ public class SupportCardExcel : ExcelResource
_ => 10
};
// Number of affixes granted initially
public int InitialAffixCount => Color >= 5 ? 2 : 1;
// Total maximum affixes (including ones unlocked at max level)
public int TotalAffixCount => Color >= 5 ? 3 : 2;
public ulong TemplateId => GameResourceTemplateId.FromGdpl(Genre, Detail, Particular, Level);
public override uint GetId() => Icon;

View File

@@ -23,6 +23,8 @@ public static class GameData
public static Dictionary<uint, SpineExcel> SpineData { get; private set; } = [];
public static Dictionary<uint, NodeConditionExcel> NodeConditionData { get; private set; } = [];
public static List<SupportCardExcel> SupportCardData { get; private set; } = [];
public static Dictionary<int, SupportAffixExcel> SupportAffixData { get; private set; } = [];
public static Dictionary<int, SupportAffixPoolExcel> SupportAffixPoolData { 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, ProfileExcel> ProfileData { get; private set; } = [];

View File

@@ -106,6 +106,8 @@ public class GameSkinInfo : BaseGameItemInfo
public class GameSupportCardInfo : BaseGameItemInfo
{
public uint AffixId { get; set; }
[SugarColumn(IsJson = true)] public List<uint> Affixs { get; set; } = [];
public override Item ToProto()
{
var proto = new Item
@@ -120,6 +122,7 @@ public class GameSupportCardInfo : BaseGameItemInfo
Exp = Exp
}
};
proto.Enhance.Affixs.AddRange(Affixs);
proto.Slots[(uint)ItemSupportCardSlotTypeEnum.SLOT_AFFIXINDEX] = AffixId;
return proto;
}

View File

@@ -222,9 +222,16 @@ public class HelpTextCHS
public class AccountTextCHS
{
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 CreateFailed => "创建账号映射失败: {0}";
public string Deleted => "已删除账号映射: {0} -> UID {1}";
public string DeleteFailed => "删除账号映射失败: {0}";
public string DeleteOnline => "账号在线时无法删除: {0} -> UID {1}";
public string NotFound => "未找到账号: {0}";
}
/// <summary>

View File

@@ -222,9 +222,16 @@ public class HelpTextCHT
public class AccountTextCHT
{
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 CreateFailed => "建立帳號映射失敗: {0}";
public string Deleted => "已刪除帳號映射: {0} -> UID {1}";
public string DeleteFailed => "刪除帳號映射失敗: {0}";
public string DeleteOnline => "帳號在線時無法刪除: {0} -> UID {1}";
public string NotFound => "未找到帳號: {0}";
}
/// <summary>

View File

@@ -188,9 +188,16 @@ public class HelpTextEN
public class AccountTextEN
{
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 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>

View File

@@ -2,6 +2,7 @@ using MikuSB.Database;
using MikuSB.Database.Account;
using MikuSB.Enums.Player;
using MikuSB.Internationalization;
using MikuSB.GameServer.Server;
using System.Text;
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")]
public async ValueTask List(CommandArg arg)
{

View File

@@ -4,6 +4,7 @@ using MikuSB.Database;
using MikuSB.Database.Inventory;
using MikuSB.Enums.Item;
using MikuSB.GameServer.Game.Player;
using MikuSB.GameServer.Game.Support;
using MikuSB.GameServer.Server.Packet.Send.Misc;
namespace MikuSB.GameServer.Game.Inventory;
@@ -135,7 +136,18 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
ItemType = genre,
ItemCount = 1,
Level = cardLevel,
AffixId = 1,
};
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;
info.Affixs.Add(affixId);
info.Affixs.Add(tier);
}
InventoryData.SupportCards[info.UniqueId] = info;
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([info]));

View File

@@ -0,0 +1,40 @@
using MikuSB.Data;
namespace MikuSB.GameServer.Game.Support;
public static class SupportAffixService
{
// Returns (affixId, tier) - both 1-based. Returns (0,0) if pool not found.
public static (uint AffixId, uint Tier) GenerateRandomAffix(int poolId)
{
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 affixId = selectedAffixs[Random.Shared.Next(selectedAffixs.Count)];
var tierCount = GameData.SupportAffixData.GetValueOrDefault(affixId)?.TierCount ?? 5;
var tier = (uint)(Random.Shared.Next(tierCount) + 1);
return ((uint)affixId, tier);
}
}

View File

@@ -1,5 +1,6 @@
using MikuSB.Data;
using MikuSB.Database;
using MikuSB.GameServer.Game.Support;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
@@ -19,7 +20,7 @@ public class SupporterCard_Upgrade : ICallGSHandler
return;
}
var supportCard = player.InventoryManager.InventoryData.Items.GetValueOrDefault((uint)req.SupportCardUid);
var supportCard = player.InventoryManager.GetSupportCardItem((uint)req.SupportCardUid);
if (supportCard == null)
{
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}");
@@ -68,10 +69,11 @@ public class SupporterCard_Upgrade : ICallGSHandler
}
// Apply exp and level up
if (supportCard.Level == 0) supportCard.Level = 1;
supportCard.Exp += gainedExp;
while (supportCard.Level < maxLevel)
{
var expNeeded = GetExpNeeded(supportCard.Level + 1);
var expNeeded = GetExpNeeded(supportCard.Level);
if (expNeeded == 0 || supportCard.Exp < expNeeded) break;
supportCard.Exp -= expNeeded;
supportCard.Level++;
@@ -80,6 +82,23 @@ public class SupporterCard_Upgrade : ICallGSHandler
{
supportCard.Exp = 0;
supportCard.Level = maxLevel;
// Unlock next affix slot when reaching max level for the first time
if (supportCardExcel != null)
{
var currentSlots = supportCard.Affixs.Count / 2;
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)
{
supportCard.Affixs.Add(affixId);
supportCard.Affixs.Add(tier);
}
}
}
}
syncItems.Add(supportCard.ToProto());

View File

@@ -22,16 +22,35 @@ public class LoaderManager : MikuSB
public static void InitConfig()
{
// Initialize log
var counter = 0;
FileInfo file;
while (true)
var logDir = ConfigManager.Config.Path.LogPath;
var logFile = new FileInfo(Path.Combine(logDir, "Server.log"));
logFile.Directory?.Create();
if (logFile.Exists)
{
file = new FileInfo(ConfigManager.Config.Path.LogPath + $"/{DateTime.Now:yyyy-MM-dd}-{++counter}.log");
if (file is not { Exists: false, Directory: not null }) continue;
file.Directory.Create();
break;
// Read start time from first log line, fall back to file creation time
DateTime logStartTime;
try
{
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
try

View File

@@ -270,13 +270,13 @@ public class RouteController : ControllerBase
var finalEmail = email ?? form_email ?? await GetJsonBodyValue("email");
if (!string.IsNullOrWhiteSpace(finalEmail))
{
var username = finalEmail.Split('@')[0];
var accountData = AccountData.GetAccountByUserName(username);
var normalizedEmail = finalEmail.Trim();
var accountData = AccountData.GetAccountByEmail(normalizedEmail);
if (accountData == null)
{
if (!ConfigManager.Config.ServerOption.AutoCreateUser) return BuildLoginFailedResponse("Account not found.");
AccountData.CreateAccount(username, 0, "123456");
accountData = AccountData.GetAccountByUserName(username)!;
AccountData.CreateAccount(normalizedEmail, 0, "123456");
accountData = AccountData.GetAccountByEmail(normalizedEmail)!;
}
var finalUidValue = accountData.Uid.ToString();

View File

@@ -1 +1 @@
v=3.0
v=3.1