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:
@@ -14,6 +14,7 @@ public class HttpServerConfig
|
||||
public string BindAddress { get; set; } = "0.0.0.0";
|
||||
public string PublicAddress { get; set; } = "127.0.0.1";
|
||||
public int Port { get; set; } = 21500;
|
||||
public bool EnableLog { get; set; } = true;
|
||||
|
||||
public string GetDisplayAddress()
|
||||
{
|
||||
|
||||
31
Common/Data/Excel/CardExcel.cs
Normal file
31
Common/Data/Excel/CardExcel.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("card.json")]
|
||||
public class CardExcel : ExcelResource
|
||||
{
|
||||
public uint Genre { get; set; }
|
||||
public uint Detail { get; set; }
|
||||
public uint Particular { get; set; }
|
||||
public uint Level { get; set; }
|
||||
public uint Icon { get; set; }
|
||||
public uint InitBreak { get; set; }
|
||||
public int BreakMatID { get; set; }
|
||||
public int LevelLimitID { get; set; }
|
||||
public int GrowupID { get; set; }
|
||||
public int AppearID { get; set; }
|
||||
public List<uint> DefaultWeaponGPDL { get; set; } = [];
|
||||
[JsonProperty("profile")] public List<List<int>> Profile { get; set; } = [];
|
||||
public List<List<int>> Pieces { get; set; } = [];
|
||||
public List<int> Attribute { get; set; } = [];
|
||||
public override uint GetId()
|
||||
{
|
||||
return Icon;
|
||||
}
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.CardData.Add(Icon, this);
|
||||
}
|
||||
}
|
||||
24
Common/Data/Excel/CardSkinExcel.cs
Normal file
24
Common/Data/Excel/CardSkinExcel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("card_skin.json")]
|
||||
public class CardSkinExcel : ExcelResource
|
||||
{
|
||||
public uint Genre { get; set; }
|
||||
public uint Detail { get; set; }
|
||||
public uint Particular { get; set; }
|
||||
public uint Level { get; set; }
|
||||
public uint Icon { get; set; }
|
||||
public int AppearID { get; set; }
|
||||
[JsonProperty("profile")] public List<List<int>> Profile { get; set; } = [];
|
||||
public override uint GetId()
|
||||
{
|
||||
return Icon;
|
||||
}
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.CardSkinData.Add(Icon, this);
|
||||
}
|
||||
}
|
||||
29
Common/Data/Excel/WeaponExcel.cs
Normal file
29
Common/Data/Excel/WeaponExcel.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("weapon.json")]
|
||||
public class WeaponExcel : ExcelResource
|
||||
{
|
||||
public uint Genre { get; set; }
|
||||
public uint Detail { get; set; }
|
||||
public uint Particular { get; set; }
|
||||
public uint Level { get; set; }
|
||||
public int Class { get; set; }
|
||||
public uint Icon { get; set; }
|
||||
public int EvolutionMatID { get; set; }
|
||||
public int BreakMatID { get; set; }
|
||||
public int LevelLimitID { get; set; }
|
||||
public int BreakLimitID { get; set; }
|
||||
public int AppearID { get; set; }
|
||||
public List<int> DefaultSkillID { get; set; } = [];
|
||||
public List<int> WeaponPartsLimit { get; set; } = [];
|
||||
public string I18n { get; set; } = "";
|
||||
public override uint GetId()
|
||||
{
|
||||
return (uint)I18n.GetHashCode();
|
||||
}
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.WeaponData.Add(GetId(), this);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,19 @@
|
||||
namespace MikuSB.Data;
|
||||
using MikuSB.Data.Excel;
|
||||
|
||||
namespace MikuSB.Data;
|
||||
|
||||
public static class GameData
|
||||
{
|
||||
public static Dictionary<uint, CardExcel> CardData { get; private set; } = [];
|
||||
public static Dictionary<uint, WeaponExcel> WeaponData { get; private set; } = [];
|
||||
public static Dictionary<uint, CardSkinExcel> CardSkinData { get; private set; } = [];
|
||||
}
|
||||
|
||||
public static class GameResourceTemplateId
|
||||
{
|
||||
public static ulong FromGdpl(uint genre, uint detail, uint particular, uint level) =>
|
||||
((ulong)genre << 48) | ((ulong)detail << 32) | ((ulong)particular << 16) | level;
|
||||
|
||||
public static ulong FromGdpl(IReadOnlyList<uint> gdpl) =>
|
||||
gdpl.Count >= 4 ? FromGdpl(gdpl[0], gdpl[1], gdpl[2], gdpl[3]) : 0;
|
||||
}
|
||||
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; }
|
||||
|
||||
28
Common/Enums/Item/ItemTypeEnum.cs
Normal file
28
Common/Enums/Item/ItemTypeEnum.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace MikuSB.Enums.Item;
|
||||
|
||||
public enum ItemTypeEnum
|
||||
{
|
||||
TYPE_CARD = 1, // 角色卡
|
||||
TYPE_WEAPON = 2, // 武器卡
|
||||
TYPE_SUPPORT = 3, // 后勤卡
|
||||
TYPE_USEABLE = 4, // 可使用道具
|
||||
TYPE_SUPPLIES = 5, // 消耗类道具
|
||||
TYPE_WEAPON_PART = 6, // 武器配件
|
||||
TYPE_CARD_SKIN = 7, // 角色皮肤
|
||||
TYPE_HOUSE = 8, // 宿舍家具
|
||||
TYPE_PROFILE = 9, // 头像
|
||||
TYPE_FRAME = 10, // 头像框
|
||||
TYPE_BADGE = 11, // 勋章
|
||||
TYPE_COVER = 12, // 封面
|
||||
TYPE_NAMECARD = 13, // 名片
|
||||
TYPE_EXPRESSION = 14, // 表情
|
||||
TYPE_BUBBLE = 15, // 聊天气泡
|
||||
TYPE_ANALYST = 16, // 墨镜分析员
|
||||
TYPE_WEAPON_SKIN = 17, //武器皮肤
|
||||
TYPE_MONSTER_CARD = 18, //怪物卡
|
||||
TYPE_MANIFESTATION = 19, //角色皮肤互动场景道具
|
||||
TYPE_CARD_SKIN_PART = 20, //角色皮肤部件
|
||||
TYPE_MAIN_SCENE = 21, //主界面场景道具
|
||||
TYPE_AR = 24, //AR道具
|
||||
TYPE_CALL = 25, //电话陪伴道具
|
||||
}
|
||||
Reference in New Issue
Block a user