mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 08:04:01 +00:00
Add character & inventory manager
This commit is contained in:
50
Common/Database/Character/CharacterData.cs
Normal file
50
Common/Database/Character/CharacterData.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using MikuSB.Proto;
|
||||
using SqlSugar;
|
||||
|
||||
namespace MikuSB.Database.Character;
|
||||
|
||||
[SugarTable("character_data")]
|
||||
public class CharacterData : BaseDatabaseDataHelper
|
||||
{
|
||||
[SugarColumn(IsJson = true)] public List<CharacterInfo> Characters { get; set; } = [];
|
||||
public uint NextCharacterGuid { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class CharacterInfo
|
||||
{
|
||||
public uint Guid { get; set; }
|
||||
public ulong TemplateId { get; set; }
|
||||
public uint Level { get; set; }
|
||||
public int Exp { get; set; }
|
||||
public uint Break { get; set; }
|
||||
public int Evolue { get; set; }
|
||||
public int Trust { get; set; }
|
||||
public uint WeaponUniqueId { get; set; }
|
||||
public uint SkinId { get; set; }
|
||||
[SugarColumn(IsJson = true)] public List<uint> UnlockedSkin { get; set; } = [];
|
||||
[SugarColumn(IsJson = true)] public List<uint> Spines { get; set; } = [];
|
||||
[SugarColumn(IsJson = true)] public List<uint> Affixs { get; set; } = [];
|
||||
public long Timestamp { get; set; }
|
||||
public uint Count { get; set; } = 1;
|
||||
|
||||
public Item ToProto()
|
||||
{
|
||||
var proto = new Item
|
||||
{
|
||||
Id = Guid,
|
||||
Template = TemplateId,
|
||||
Count = Count,
|
||||
Enhance = new Enhance
|
||||
{
|
||||
Level = Level,
|
||||
Break = Break
|
||||
}
|
||||
};
|
||||
|
||||
proto.Slots[4] = WeaponUniqueId;
|
||||
proto.Slots[5] = SkinId;
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
}
|
||||
71
Common/Database/Inventory/InventoryData.cs
Normal file
71
Common/Database/Inventory/InventoryData.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using MikuSB.Proto;
|
||||
using SqlSugar;
|
||||
|
||||
namespace MikuSB.Database.Inventory;
|
||||
|
||||
[SugarTable("inventory_data")]
|
||||
public class InventoryData : BaseDatabaseDataHelper
|
||||
{
|
||||
public uint NextUniqueUid { get; set; } = 100000;
|
||||
|
||||
[SugarColumn(IsJson = true)]
|
||||
public Dictionary<uint, BaseGameItemInfo> Items { get; set; } = []; // Key: UniqueId
|
||||
|
||||
[SugarColumn(IsJson = true)]
|
||||
public Dictionary<uint, GameWeaponInfo> Weapons { get; set; } = []; // Key: UniqueId
|
||||
|
||||
[SugarColumn(IsJson = true)]
|
||||
public Dictionary<uint, GameSkinInfo> Skins { get; set; } = []; // Key: UniqueId
|
||||
}
|
||||
|
||||
public abstract class BaseGameItemInfo
|
||||
{
|
||||
public uint UniqueId { get; set; }
|
||||
public ulong TemplateId { get; set; }
|
||||
public uint ItemCount { get; set; }
|
||||
}
|
||||
|
||||
public abstract class GrowableItemInfo : BaseGameItemInfo
|
||||
{
|
||||
public bool IsLocked { get; set; }
|
||||
public uint Level { get; set; }
|
||||
public uint Exp { get; set; }
|
||||
public uint EquipAvatarId { get; set; }
|
||||
}
|
||||
|
||||
public class GameWeaponInfo : GrowableItemInfo
|
||||
{
|
||||
public Item ToProto()
|
||||
{
|
||||
var proto = new Item
|
||||
{
|
||||
Id = UniqueId,
|
||||
Template = TemplateId,
|
||||
Count = ItemCount,
|
||||
Enhance = new Enhance
|
||||
{
|
||||
Level = Level
|
||||
}
|
||||
};
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
|
||||
public class GameSkinInfo : BaseGameItemInfo
|
||||
{
|
||||
public uint Level { get; set; }
|
||||
public Item ToProto()
|
||||
{
|
||||
var proto = new Item
|
||||
{
|
||||
Id = UniqueId,
|
||||
Template = TemplateId,
|
||||
Count = ItemCount,
|
||||
Enhance = new Enhance
|
||||
{
|
||||
Level = Level
|
||||
}
|
||||
};
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using MikuSB.Util.Extensions;
|
||||
using SqlSugar;
|
||||
using MikuSB.Proto;
|
||||
|
||||
namespace MikuSB.Database.Player;
|
||||
|
||||
@@ -12,61 +13,18 @@ public class PlayerGameData : BaseDatabaseDataHelper
|
||||
public int Exp { get; set; } = 0;
|
||||
public long RegisterTime { get; set; } = Extensions.GetUnixSec();
|
||||
public long LastActiveTime { get; set; }
|
||||
[SugarColumn(IsJson = true)] public List<PlayerAttrs> Attrs { get; set; } = [];
|
||||
public Sex Gender { get; set; } = Sex.Female;
|
||||
[SugarColumn(IsJson = true)] public List<PlayerAttr> Attrs { get; set; } = [];
|
||||
|
||||
public static PlayerGameData? GetPlayerByUid(long uid)
|
||||
{
|
||||
var result = DatabaseHelper.GetInstance<PlayerGameData>((int)uid);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Proto.Player ToProto()
|
||||
{
|
||||
var proto = new Proto.Player
|
||||
{
|
||||
Pid = (ulong)Uid,
|
||||
Account = Name,
|
||||
Name = Name,
|
||||
Level = Level,
|
||||
};
|
||||
|
||||
foreach (var x in Attrs)
|
||||
{
|
||||
uint gid = x.Gid;
|
||||
uint sid = x.Sid;
|
||||
uint val = x.Val;
|
||||
|
||||
if (gid == 0)
|
||||
{
|
||||
proto.Attrs[sid] = val;
|
||||
continue;
|
||||
}
|
||||
|
||||
proto.Attrs[ToPackedAttrKey(gid, sid)] = val;
|
||||
proto.Attrs[ToShiftedAttrKey(gid, sid)] = val;
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
private static uint ToPackedAttrKey(uint gid, uint sid)
|
||||
{
|
||||
if (gid == 0)
|
||||
return sid;
|
||||
|
||||
return (gid * 10000) + sid;
|
||||
}
|
||||
|
||||
private static uint ToShiftedAttrKey(uint gid, uint sid)
|
||||
{
|
||||
if (gid == 0)
|
||||
return sid;
|
||||
|
||||
return (gid << 16) | sid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PlayerAttrs
|
||||
public class PlayerAttr
|
||||
{
|
||||
public uint Gid { get; set; }
|
||||
public uint Sid { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user