mirror of
https://github.com/MikuLeaks/KianaBH3.git
synced 2025-12-13 05:14:46 +01:00
Init enter game
This commit is contained in:
150
Common/Database/Account/AccountData.cs
Normal file
150
Common/Database/Account/AccountData.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using KianaBH.Enums.Player;
|
||||
using KianaBH.Util;
|
||||
using KianaBH.Util.Extensions;
|
||||
using KianaBH.Util.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace KianaBH.Database.Account;
|
||||
|
||||
[SugarTable("Account")]
|
||||
public class AccountData : BaseDatabaseDataHelper
|
||||
{
|
||||
public string Username { get; set; } = "";
|
||||
public string Password { get; set; } = "";
|
||||
public BanTypeEnum BanType { get; set; }
|
||||
|
||||
[SugarColumn(IsJson = true)] public List<PermEnum> Permissions { get; set; } = [];
|
||||
|
||||
[SugarColumn(IsNullable = true)] public string? ComboToken { get; set; }
|
||||
|
||||
#region GetAccount
|
||||
|
||||
public static AccountData? GetAccountByUserName(string username)
|
||||
{
|
||||
AccountData? result = null;
|
||||
DatabaseHelper.GetAllInstance<AccountData>()?.ForEach(account =>
|
||||
{
|
||||
if (account.Username == username) result = account;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public static AccountData? GetAccountByUid(int uid, bool force = false)
|
||||
{
|
||||
var result = DatabaseHelper.GetInstance<AccountData>(uid, force);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Account
|
||||
|
||||
public static void CreateAccount(string username, int uid, string password)
|
||||
{
|
||||
var newUid = uid;
|
||||
if (uid == 0)
|
||||
{
|
||||
newUid = 100001;
|
||||
while (GetAccountByUid(newUid) != null) newUid++;
|
||||
}
|
||||
|
||||
var account = new AccountData
|
||||
{
|
||||
Uid = newUid,
|
||||
Username = username,
|
||||
Password = "",
|
||||
Permissions = [.. ConfigManager.Config.ServerOption.DefaultPermissions
|
||||
.Select(perm => Enum.TryParse(perm, out PermEnum result) ? result : (PermEnum?)null)
|
||||
.Where(result => result.HasValue).Select(result => result!.Value)]
|
||||
};
|
||||
SetPassword(account, password);
|
||||
|
||||
DatabaseHelper.CreateInstance(account);
|
||||
}
|
||||
|
||||
public static void DeleteAccount(int uid)
|
||||
{
|
||||
if (GetAccountByUid(uid) == null) return;
|
||||
DatabaseHelper.DeleteAllInstance(uid);
|
||||
}
|
||||
|
||||
public static void SetPassword(AccountData account, string password)
|
||||
{
|
||||
if (password.Length > 0)
|
||||
account.Password = Extensions.GetSha256Hash(password);
|
||||
else
|
||||
account.Password = "";
|
||||
}
|
||||
|
||||
public static bool VerifyPassword(AccountData account, string password)
|
||||
=> account.Password == Extensions.GetSha256Hash(password);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Permission
|
||||
|
||||
public static bool HasPerm(PermEnum[] perms, int uid)
|
||||
{
|
||||
if (uid == (int)ServerEnum.Console) return true;
|
||||
var account = GetAccountByUid(uid);
|
||||
if (account?.Permissions == null) return false;
|
||||
if (account.Permissions.Contains(PermEnum.Admin)) return true;
|
||||
|
||||
return perms.Any(account.Permissions.Contains);
|
||||
}
|
||||
|
||||
public static void AddPerm(PermEnum[] perms, int uid)
|
||||
{
|
||||
if (uid == (int)ServerEnum.Console) return;
|
||||
var account = GetAccountByUid(uid);
|
||||
if (account == null) return;
|
||||
|
||||
account.Permissions ??= [];
|
||||
foreach (var perm in perms)
|
||||
{
|
||||
if (!account.Permissions.Contains(perm))
|
||||
{
|
||||
account.Permissions = [.. account.Permissions, perm];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemovePerm(PermEnum[] perms, int uid)
|
||||
{
|
||||
if (uid == (int)ServerEnum.Console) return;
|
||||
var account = GetAccountByUid(uid);
|
||||
if (account == null) return;
|
||||
if (account.Permissions == null) return;
|
||||
|
||||
foreach (var perm in perms)
|
||||
{
|
||||
if (account.Permissions.Contains(perm))
|
||||
{
|
||||
account.Permissions = account.Permissions.Except([perm]).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CleanPerm(int uid)
|
||||
{
|
||||
if (uid == (int)ServerEnum.Console) return;
|
||||
var account = GetAccountByUid(uid);
|
||||
if (account == null) return;
|
||||
|
||||
account.Permissions = [];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Token
|
||||
|
||||
public string GenerateComboToken()
|
||||
{
|
||||
ComboToken = Crypto.CreateSessionKey(Uid.ToString());
|
||||
DatabaseHelper.UpdateInstance(this);
|
||||
return ComboToken;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
95
Common/Database/Avatar/AvatarData.cs
Normal file
95
Common/Database/Avatar/AvatarData.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using SqlSugar;
|
||||
using KianaBH.Proto;
|
||||
|
||||
namespace KianaBH.Database.Avatar;
|
||||
|
||||
[SugarTable("Avatar")]
|
||||
public class AvatarData : BaseDatabaseDataHelper
|
||||
{
|
||||
[SugarColumn(IsJson = true)] public List<AvatarInfo> Avatars { get; set; } = [];
|
||||
}
|
||||
|
||||
public class AvatarInfo
|
||||
{
|
||||
public int AvatarId { get; set; }
|
||||
public int Star { get; set; }
|
||||
public int Level { get; set; }
|
||||
public int Exp { get; set; }
|
||||
public int Fragment { get; set; }
|
||||
public int WeaponUniqueId { get; set; }
|
||||
public int StigmataUniqueId1 { get; set; }
|
||||
public int StigmataUniqueId2 { get; set; }
|
||||
public int StigmataUniqueId3 { get; set; }
|
||||
public List<AvatarSkill> SkillList { get; set; } = [];
|
||||
public int TouchGoodFeel { get; set; }
|
||||
public int TodayHasAddGoodFeel { get; set; }
|
||||
public int StageGoodFeel { get; set; }
|
||||
public List<int> DressList { get; set; } = [];
|
||||
public int DressId { get; set; }
|
||||
public AvatarBindEquipMode Mode { get; set; } = AvatarBindEquipMode.AvatarBindEquipCommon;
|
||||
public AvatarArtifactDetail? AvatarArtifact { get; set; }
|
||||
public int SubStar { get; set; }
|
||||
public long Timestamp { get; set; }
|
||||
public Proto.Avatar ToProto()
|
||||
{
|
||||
var proto = new Proto.Avatar
|
||||
{
|
||||
AvatarId = (uint)AvatarId,
|
||||
Star = (uint)Star,
|
||||
Level = (uint)Level,
|
||||
Exp = (uint)Exp,
|
||||
Fragment = (uint)Fragment,
|
||||
WeaponUniqueId = (uint)WeaponUniqueId,
|
||||
StigmataUniqueId1 = (uint)StigmataUniqueId1,
|
||||
StigmataUniqueId2 = (uint)StigmataUniqueId2,
|
||||
StigmataUniqueId3 = (uint)StigmataUniqueId3,
|
||||
TouchGoodfeel = (uint)TouchGoodFeel,
|
||||
TodayHasAddGoodfeel = (uint)TodayHasAddGoodFeel,
|
||||
StageGoodfeel = (uint)StageGoodFeel,
|
||||
DressId = (uint)DressId,
|
||||
Mode = Mode,
|
||||
SubStar = (uint)SubStar,
|
||||
};
|
||||
|
||||
foreach (var dressId in DressList)
|
||||
{
|
||||
proto.DressList.Add((uint)dressId);
|
||||
}
|
||||
|
||||
foreach (var skill in SkillList)
|
||||
{
|
||||
var avatarSkill = new Proto.AvatarSkill
|
||||
{
|
||||
SkillId = (uint)skill.SkillId
|
||||
};
|
||||
|
||||
avatarSkill.SubSkillList.AddRange(skill.SubSkillList.Select(x => new Proto.AvatarSubSkill
|
||||
{
|
||||
SubSkillId = (uint)x.SubSkillId,
|
||||
Level = x.Level,
|
||||
IsMask = x.IsMask
|
||||
}));
|
||||
|
||||
proto.SkillList.Add(avatarSkill);
|
||||
}
|
||||
return proto;
|
||||
}
|
||||
|
||||
}
|
||||
public class AvatarSkill
|
||||
{
|
||||
public int SkillId { get; set; }
|
||||
public List<AvatarSubSkill> SubSkillList { get; set; } = [];
|
||||
}
|
||||
public class AvatarSubSkill
|
||||
{
|
||||
public int SubSkillId { get; set; }
|
||||
public uint Level { get; set; }
|
||||
public bool IsMask { get; set; }
|
||||
}
|
||||
public class AvatarArtifactDetail
|
||||
{
|
||||
public int ArtifactId { get; set; }
|
||||
public int ArtifactLevel { get; set; }
|
||||
public bool IsArtifactSwitchOn { get; set; }
|
||||
}
|
||||
8
Common/Database/BaseDatabaseDataHelper.cs
Normal file
8
Common/Database/BaseDatabaseDataHelper.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace KianaBH.Database;
|
||||
|
||||
public abstract class BaseDatabaseDataHelper
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)] public int Uid { get; set; }
|
||||
}
|
||||
28
Common/Database/Client/ClientData.cs
Normal file
28
Common/Database/Client/ClientData.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Google.Protobuf;
|
||||
using KianaBH.Proto;
|
||||
using SqlSugar;
|
||||
|
||||
namespace KianaBH.Database.Client;
|
||||
|
||||
[SugarTable("client_data")]
|
||||
public class ClientData : BaseDatabaseDataHelper
|
||||
{
|
||||
[SugarColumn(IsJson = true)] public List<ClientDBData> Clients { get; set; } = [];
|
||||
}
|
||||
|
||||
public class ClientDBData
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public ClientDataType Type { get; set; } = ClientDataType.ClientDataNone;
|
||||
public byte[] Data { get; set; } = Array.Empty<byte>();
|
||||
public Proto.ClientData ToProto()
|
||||
{
|
||||
var proto = new Proto.ClientData
|
||||
{
|
||||
Id = Id,
|
||||
Type = Type,
|
||||
Data = ByteString.CopyFrom(Data)
|
||||
};
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
32
Common/Database/CustomSerializeService.cs
Normal file
32
Common/Database/CustomSerializeService.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
|
||||
namespace KianaBH.Database;
|
||||
|
||||
public class CustomSerializeService : ISerializeService
|
||||
{
|
||||
private readonly JsonSerializerSettings _jsonSettings;
|
||||
|
||||
public CustomSerializeService()
|
||||
{
|
||||
_jsonSettings = new JsonSerializerSettings
|
||||
{
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore // ignore default values
|
||||
};
|
||||
}
|
||||
|
||||
public string SerializeObject(object value)
|
||||
{
|
||||
return JsonConvert.SerializeObject(value, _jsonSettings);
|
||||
}
|
||||
|
||||
public T DeserializeObject<T>(string value)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(value)!;
|
||||
}
|
||||
|
||||
public string SugarSerializeObject(object value)
|
||||
{
|
||||
return JsonConvert.SerializeObject(value, _jsonSettings);
|
||||
}
|
||||
}
|
||||
307
Common/Database/DatabaseHelper.cs
Normal file
307
Common/Database/DatabaseHelper.cs
Normal file
@@ -0,0 +1,307 @@
|
||||
using KianaBH.Database.Account;
|
||||
using KianaBH.Internationalization;
|
||||
using KianaBH.Util;
|
||||
using SqlSugar;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Globalization;
|
||||
|
||||
namespace KianaBH.Database;
|
||||
|
||||
public class DatabaseHelper
|
||||
{
|
||||
public static Logger logger = new("Database");
|
||||
public static SqlSugarScope? sqlSugarScope;
|
||||
public static readonly ConcurrentDictionary<int, List<BaseDatabaseDataHelper>> UidInstanceMap = [];
|
||||
public static readonly List<int> ToSaveUidList = [];
|
||||
public static long LastSaveTick = DateTime.UtcNow.Ticks;
|
||||
public static Thread? SaveThread;
|
||||
public static bool LoadAccount;
|
||||
public static bool LoadAllData;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
logger.Info(I18NManager.Translate("Server.ServerInfo.LoadingItem", I18NManager.Translate("Word.Database")));
|
||||
var f = new FileInfo(ConfigManager.Config.Path.DatabasePath + "/" + ConfigManager.Config.GameServer.DatabaseName);
|
||||
if (!f.Exists && f.Directory != null) f.Directory.Create();
|
||||
|
||||
sqlSugarScope = new SqlSugarScope(new ConnectionConfig
|
||||
{
|
||||
ConnectionString = $"Data Source={f.FullName};",
|
||||
DbType = DbType.Sqlite,
|
||||
IsAutoCloseConnection = true,
|
||||
ConfigureExternalServices = new ConfigureExternalServices
|
||||
{
|
||||
SerializeService = new CustomSerializeService()
|
||||
}
|
||||
});
|
||||
|
||||
InitializeSqlite();
|
||||
|
||||
var baseType = typeof(BaseDatabaseDataHelper);
|
||||
var assembly = typeof(BaseDatabaseDataHelper).Assembly;
|
||||
var types = assembly.GetTypes().Where(t => t.IsSubclassOf(baseType));
|
||||
|
||||
var list = sqlSugarScope.Queryable<AccountData>().ToList();
|
||||
foreach (var inst in list)
|
||||
{
|
||||
if (!UidInstanceMap.TryGetValue(inst.Uid, out var value))
|
||||
{
|
||||
value = [];
|
||||
UidInstanceMap[inst.Uid] = value;
|
||||
}
|
||||
|
||||
value.Add(inst); // add to the map
|
||||
}
|
||||
|
||||
// start dispatch server
|
||||
LoadAccount = true;
|
||||
|
||||
var res = Parallel.ForEach(list, account =>
|
||||
{
|
||||
Parallel.ForEach(types, t =>
|
||||
{
|
||||
if (t == typeof(AccountData)) return; // skip the account data
|
||||
|
||||
try
|
||||
{
|
||||
typeof(DatabaseHelper).GetMethod(nameof(InitializeTable))?.MakeGenericMethod(t)
|
||||
.Invoke(null, [account.Uid]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error("Database initialization error: ", e);
|
||||
}
|
||||
|
||||
}); // cache the data
|
||||
});
|
||||
|
||||
while (!res.IsCompleted)
|
||||
{
|
||||
}
|
||||
|
||||
LastSaveTick = DateTime.UtcNow.Ticks;
|
||||
|
||||
SaveThread = new Thread(() =>
|
||||
{
|
||||
while (true) CalcSaveDatabase();
|
||||
});
|
||||
SaveThread.Start();
|
||||
|
||||
LoadAllData = true;
|
||||
}
|
||||
|
||||
public static void InitializeTable<T>(int uid) where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
var list = sqlSugarScope?.Queryable<T>()
|
||||
.Select(x => x)
|
||||
.Select<T>()
|
||||
.Where(x => x.Uid == uid)
|
||||
.ToList();
|
||||
|
||||
foreach (var inst in list!.Select(instance => (instance as BaseDatabaseDataHelper)!))
|
||||
{
|
||||
if (!UidInstanceMap.TryGetValue(inst.Uid, out var value))
|
||||
{
|
||||
value = [];
|
||||
UidInstanceMap[inst.Uid] = value;
|
||||
}
|
||||
|
||||
value.Add(inst); // add to the map
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitializeSqlite()
|
||||
{
|
||||
var baseType = typeof(BaseDatabaseDataHelper);
|
||||
var assembly = typeof(BaseDatabaseDataHelper).Assembly;
|
||||
var types = assembly.GetTypes().Where(t => t.IsSubclassOf(baseType));
|
||||
foreach (var type in types)
|
||||
typeof(DatabaseHelper).GetMethod("InitializeSqliteTable")?.MakeGenericMethod(type).Invoke(null, null);
|
||||
}
|
||||
|
||||
// DO NOT DEL ReSharper disable once UnusedMember.Global
|
||||
public static void InitializeSqliteTable<T>() where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
sqlSugarScope?.CodeFirst.InitTables<T>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
public static T? GetInstance<T>(int uid, bool forceReload = false) where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!forceReload && UidInstanceMap.TryGetValue(uid, out var value))
|
||||
{
|
||||
var instance = value.OfType<T>().FirstOrDefault();
|
||||
if (instance != null) return instance;
|
||||
}
|
||||
var t = sqlSugarScope?.Queryable<T>()
|
||||
.Where(x => x.Uid == uid)
|
||||
.ToList();
|
||||
|
||||
if (t is { Count: > 0 })
|
||||
{
|
||||
var instance = t[0];
|
||||
|
||||
if (!UidInstanceMap.TryGetValue(uid, out var list))
|
||||
{
|
||||
list = new List<BaseDatabaseDataHelper>();
|
||||
UidInstanceMap[uid] = list;
|
||||
}
|
||||
else
|
||||
{
|
||||
list.RemoveAll(i => i is T);
|
||||
}
|
||||
|
||||
list.Add(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error("Unsupported type", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static T GetInstanceOrCreateNew<T>(int uid) where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
var instance = GetInstance<T>(uid);
|
||||
if (instance != null) return instance;
|
||||
|
||||
instance = new T
|
||||
{
|
||||
Uid = uid
|
||||
};
|
||||
CreateInstance(instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static List<T>? GetAllInstance<T>() where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
return sqlSugarScope?.Queryable<T>()
|
||||
.Select(x => x)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error("Unsupported type", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateInstance<T>(T instance) where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
sqlSugarScope?.Updateable(instance).ExecuteCommand();
|
||||
}
|
||||
|
||||
public static void CreateInstance<T>(T instance) where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
sqlSugarScope?.Insertable(instance).ExecuteCommand();
|
||||
if (!UidInstanceMap.TryGetValue(instance.Uid, out var value))
|
||||
{
|
||||
value = [];
|
||||
UidInstanceMap[instance.Uid] = value;
|
||||
}
|
||||
value.Add(instance);
|
||||
}
|
||||
|
||||
public static void DeleteInstance<T>(int key) where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
sqlSugarScope?.Deleteable<T>().Where(x => x.Uid == key).ExecuteCommand();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error("An error occurred while delete the database", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteAllInstance(int key)
|
||||
{
|
||||
|
||||
var value = UidInstanceMap[key];
|
||||
var baseType = typeof(BaseDatabaseDataHelper);
|
||||
var assembly = typeof(BaseDatabaseDataHelper).Assembly;
|
||||
var types = assembly.GetTypes().Where(t => t.IsSubclassOf(baseType));
|
||||
foreach (var type in types)
|
||||
{
|
||||
var instance = value.Find(x => x.GetType() == type);
|
||||
if (instance != null)
|
||||
typeof(DatabaseHelper).GetMethod("DeleteInstance")?.MakeGenericMethod(type)
|
||||
.Invoke(null, [key]);
|
||||
}
|
||||
|
||||
if (UidInstanceMap.TryRemove(key, out var instances))
|
||||
ToSaveUidList.RemoveAll(x => x == key);
|
||||
}
|
||||
|
||||
// Auto save per 5 min
|
||||
public static void CalcSaveDatabase()
|
||||
{
|
||||
if (LastSaveTick + TimeSpan.TicksPerMinute * 5 > DateTime.UtcNow.Ticks) return;
|
||||
SaveDatabase();
|
||||
}
|
||||
|
||||
public static void SaveDatabase()
|
||||
{
|
||||
try
|
||||
{
|
||||
var prev = DateTime.Now;
|
||||
var list = ToSaveUidList.ToList(); // copy the list to avoid the exception
|
||||
foreach (var uid in list)
|
||||
{
|
||||
var value = UidInstanceMap[uid];
|
||||
var baseType = typeof(BaseDatabaseDataHelper);
|
||||
var assembly = typeof(BaseDatabaseDataHelper).Assembly;
|
||||
var types = assembly.GetTypes().Where(t => t.IsSubclassOf(baseType));
|
||||
foreach (var type in types)
|
||||
{
|
||||
var instance = value.Find(x => x.GetType() == type);
|
||||
if (instance != null)
|
||||
typeof(DatabaseHelper).GetMethod("SaveDatabaseType")?.MakeGenericMethod(type)
|
||||
.Invoke(null, [instance]);
|
||||
}
|
||||
}
|
||||
|
||||
var t = (DateTime.Now - prev).TotalSeconds;
|
||||
logger.Info(I18NManager.Translate("Server.ServerInfo.SaveDatabase",
|
||||
Math.Round(t, 2).ToString(CultureInfo.InvariantCulture)));
|
||||
|
||||
ToSaveUidList.Clear();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error("An error occurred while saving the database", e);
|
||||
}
|
||||
|
||||
LastSaveTick = DateTime.UtcNow.Ticks;
|
||||
}
|
||||
|
||||
// DO NOT DEL ReSharper save database from cache
|
||||
public static void SaveDatabaseType<T>(T instance) where T : BaseDatabaseDataHelper, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
sqlSugarScope?.Updateable(instance).ExecuteCommand();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error("An error occurred while saving the database", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
75
Common/Database/Inventory/InventoryData.cs
Normal file
75
Common/Database/Inventory/InventoryData.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using KianaBH.Proto;
|
||||
using SqlSugar;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace KianaBH.Database.Inventory;
|
||||
|
||||
[SugarTable("InventoryData")]
|
||||
public class InventoryData : BaseDatabaseDataHelper
|
||||
{
|
||||
[SugarColumn(IsJson = true)] public List<ItemData> MaterialItems { get; set; } = [];
|
||||
|
||||
[SugarColumn(IsJson = true)] public List<ItemData> WeaponItems { get; set; } = [];
|
||||
|
||||
[SugarColumn(IsJson = true)] public List<ItemData> StigmataItems { get; set; } = [];
|
||||
|
||||
public int NextUniqueId { get; set; } = 100;
|
||||
}
|
||||
|
||||
public class ItemData
|
||||
{
|
||||
public int UniqueId { get; set; }
|
||||
public int ItemId { get; set; }
|
||||
public int SubItemId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public int Level { get; set; }
|
||||
public int Exp { get; set; }
|
||||
public bool Locked { get; set; }
|
||||
public bool AffixIdentify { get; set; }
|
||||
public uint CancelLockedTime { get; set; }
|
||||
public bool Extracted { get; set; }
|
||||
public int SlotNum { get; set; }
|
||||
public int Refine { get; set; }
|
||||
public int Promote { get; set; }
|
||||
public int Homology { get; set; }
|
||||
public List<int> QuantumBranchLists { get; set; } = [];
|
||||
public List<Rune> RuneLists { get; set; } = [];
|
||||
public List<Rune> WaitSelectRuneLists { get; set; } = [];
|
||||
public List<RuneGroup> WaitSelectRuneGroupLists { get; set; } = [];
|
||||
public int EquipAvatar { get; set; }
|
||||
|
||||
|
||||
public Material ToMaterialProto()
|
||||
{
|
||||
return new Material
|
||||
{
|
||||
Id = (uint)ItemId,
|
||||
Num = (uint)Count
|
||||
};
|
||||
}
|
||||
|
||||
public Weapon ToWeaponProto()
|
||||
{
|
||||
return new Weapon
|
||||
{
|
||||
Id = (uint)ItemId,
|
||||
UniqueId = (uint)UniqueId,
|
||||
Level = (uint)Level,
|
||||
Exp = (uint)Exp,
|
||||
IsProtected = Locked,
|
||||
IsExtracted = Extracted,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class RuneGroup
|
||||
{
|
||||
public int UniqueId { get; set; }
|
||||
public List<Rune> RuneLists { get; set; } = [];
|
||||
}
|
||||
|
||||
public class Rune
|
||||
{
|
||||
public int RuneId { get; set; }
|
||||
public int Strength { get; set; }
|
||||
}
|
||||
19
Common/Database/Lineup/LineupData.cs
Normal file
19
Common/Database/Lineup/LineupData.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace KianaBH.Database.Lineup;
|
||||
|
||||
[SugarTable("Lineup")]
|
||||
public class LineupData : BaseDatabaseDataHelper
|
||||
{
|
||||
[SugarColumn(IsJson = true)] public Dictionary<int, LineupInfo> Lineups { get; set; } = [];
|
||||
}
|
||||
|
||||
public class LineupInfo
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public uint AstraMateId { get; set; }
|
||||
public bool IsUsingAstraMate { get; set; }
|
||||
public List<uint> AvatarIds { get; set; } = [];
|
||||
public List<uint> ElfIds { get; set; } = [];
|
||||
}
|
||||
9
Common/Database/Player/GuideData.cs
Normal file
9
Common/Database/Player/GuideData.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace KianaBH.Database.Player;
|
||||
|
||||
[SugarTable("player_guide")]
|
||||
public class GuideData : BaseDatabaseDataHelper
|
||||
{
|
||||
[SugarColumn(IsJson = true)] public List<uint> GuideFinishList { get; set; } = [];
|
||||
}
|
||||
73
Common/Database/Player/PlayerData.cs
Normal file
73
Common/Database/Player/PlayerData.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Drawing;
|
||||
using KianaBH.Proto;
|
||||
using KianaBH.Util;
|
||||
using KianaBH.Util.Extensions;
|
||||
using SqlSugar;
|
||||
|
||||
namespace KianaBH.Database.Player;
|
||||
|
||||
[SugarTable("Player")]
|
||||
public class PlayerData : BaseDatabaseDataHelper
|
||||
{
|
||||
public string? Name { get; set; } = "";
|
||||
public string? Signature { get; set; } = "KianaPS";
|
||||
public uint Level { get; set; } = 88;
|
||||
public uint Exp { get; set; } = 0;
|
||||
public uint HCoin { get; set; } = 0;
|
||||
public uint Stamina { get; set; } = 240;
|
||||
public uint HeadIcon { get; set; } = 161090;
|
||||
public uint HeadFrame { get; set; } = 200001;
|
||||
public uint WarshipId { get; set; } = 400004;
|
||||
public uint PhonePendantId { get; set; } = 350005;
|
||||
public uint AssistantAvatarId { get; set; } = 101;
|
||||
public uint BirthDay { get; set; } = 0;
|
||||
[SugarColumn(IsJson = true)] public WarshipAvatarData WarshipAvatar { get; set; } = new();
|
||||
[SugarColumn(IsNullable = true)] public long LastActiveTime { get; set; }
|
||||
public long RegisterTime { get; set; } = Extensions.GetUnixSec();
|
||||
|
||||
public static PlayerData? GetPlayerByUid(long uid)
|
||||
{
|
||||
var result = DatabaseHelper.GetInstance<PlayerData>((int)uid);
|
||||
return result;
|
||||
}
|
||||
public GetMainDataRsp ToProto()
|
||||
{
|
||||
return new GetMainDataRsp
|
||||
{
|
||||
IsAll = true,
|
||||
AssistantAvatarId = 0,
|
||||
Birthday = BirthDay,
|
||||
Nickname = Name,
|
||||
Level = Level,
|
||||
Exp = Exp,
|
||||
Hcoin = HCoin,
|
||||
CustomHeadId = HeadIcon,
|
||||
RegisterTime = (uint)RegisterTime,
|
||||
WarshipAvatar = new Proto.WarshipAvatarData
|
||||
{
|
||||
WarshipFirstAvatarId = 0,
|
||||
WarshipSecondAvatarId = 0,
|
||||
},
|
||||
SelfDesc = Signature,
|
||||
UseFrameId = HeadFrame,
|
||||
OnPhonePendantId = PhonePendantId,
|
||||
Stamina = Stamina,
|
||||
StaminaRecoverConfigTime = GameConstants.STAMINA_RECOVERY_TIME,
|
||||
StaminaRecoverLeftTime = GameConstants.STAMINA_RECOVERY_TIME,
|
||||
EquipmentSizeLimit = GameConstants.INVENTORY_MAX_EQUIPMENT,
|
||||
TypeList = { Enumerable.Range(2, 38).Select(i => (uint)i) },
|
||||
LevelLockId = 1,
|
||||
WarshipTheme = new WarshipThemeData
|
||||
{
|
||||
WarshipId=0
|
||||
},
|
||||
TotalLoginDays = 1
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class WarshipAvatarData
|
||||
{
|
||||
public uint FirstAvatarId { get; set; } = 101;
|
||||
public uint SecondAvatarId { get; set; } = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user