From 2827c53d142d50d12dd3bf0dc35ea2415348f0ad Mon Sep 17 00:00:00 2001 From: milimoe <110188673+milimoe@users.noreply.github.com> Date: Fri, 4 Apr 2025 23:39:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=A8=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=A1=A8=E3=80=81=E6=9F=A5=E8=AF=A2=E5=B8=B8=E9=87=8F=E7=B1=BB?= =?UTF-8?q?=20(#118)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 补充数据库表 * 更新sqlite * 添加商店相关的数据库常量类 * add Update_UpdateRoomMaster * 修改常量类 * 添加 NOTICE 文件 * 添加市场、报价、库存的数据库常量类 * 优化表结构和查询常量类 * 添加 UserCenter 和 Inventory 相关枚举;数据表和 Query 常量类修改 * 添加报价的核心操作 * 涉及库存的物品获取应该使用 Guid 而不是 ItemId --------- Co-authored-by: yeziuku --- Api/Utility/Factory.cs | 4 +- Api/Utility/StringExtension.cs | 9 + Entity/Item/Item.cs | 8 +- Entity/System/Inventory.cs | 13 +- Entity/System/MarketItem.cs | 28 ++ Entity/System/Offer.cs | 22 ++ FunGame.Core.csproj | 30 +- Library/Common/JsonConverter/UserConverter.cs | 4 +- Library/Constant/ConstantSet.cs | 43 ++- Library/Constant/FunGameInfo.cs | 28 +- Library/Constant/StateEnum.cs | 23 ++ Library/Constant/TypeEnum.cs | 74 +++- Library/SQLScript/Common/ApiTokens.cs | 43 +++ Library/SQLScript/Common/Common.cs | 97 ------ Library/SQLScript/Common/Configs.cs | 37 ++ Library/SQLScript/Common/ServerLoginLogs.cs | 26 ++ Library/SQLScript/Common/UserLogs.cs | 48 +++ Library/SQLScript/Common/UserSignIns.cs | 43 +++ Library/SQLScript/Constant.cs | 28 ++ Library/SQLScript/Entity/GoodsItemsQuery.cs | 39 +++ Library/SQLScript/Entity/GoodsPricesQuery.cs | 49 +++ Library/SQLScript/Entity/GoodsQuery.cs | 61 ++++ Library/SQLScript/Entity/InventoriesQuery.cs | 78 +++++ Library/SQLScript/Entity/MarketItemsQuery.cs | 120 +++++++ Library/SQLScript/Entity/OfferItemsQuery.cs | 69 ++++ Library/SQLScript/Entity/OffersQuery.cs | 75 +++++ Library/SQLScript/Entity/RoomQuery.cs | 136 ++++++-- Library/SQLScript/Entity/StoreGoodsQuery.cs | 65 ++++ Library/SQLScript/Entity/StoreQuery.cs | 70 ++++ .../SQLScript/Entity/UserCharactersQuery.cs | 150 +++++++++ Library/SQLScript/Entity/UserItemsQuery.cs | 187 +++++++++++ Library/SQLScript/Entity/UserQuery.cs | 8 +- Library/SQLScript/fungame.sql | 315 +++++++++++++++--- Library/SQLScript/fungame_sqlite.sql | 257 ++++++++++++-- NOTICE | 16 + 35 files changed, 2077 insertions(+), 226 deletions(-) create mode 100644 Entity/System/MarketItem.cs create mode 100644 Entity/System/Offer.cs create mode 100644 Library/SQLScript/Common/ApiTokens.cs delete mode 100644 Library/SQLScript/Common/Common.cs create mode 100644 Library/SQLScript/Common/Configs.cs create mode 100644 Library/SQLScript/Common/ServerLoginLogs.cs create mode 100644 Library/SQLScript/Common/UserLogs.cs create mode 100644 Library/SQLScript/Common/UserSignIns.cs create mode 100644 Library/SQLScript/Constant.cs create mode 100644 Library/SQLScript/Entity/GoodsItemsQuery.cs create mode 100644 Library/SQLScript/Entity/GoodsPricesQuery.cs create mode 100644 Library/SQLScript/Entity/GoodsQuery.cs create mode 100644 Library/SQLScript/Entity/InventoriesQuery.cs create mode 100644 Library/SQLScript/Entity/MarketItemsQuery.cs create mode 100644 Library/SQLScript/Entity/OfferItemsQuery.cs create mode 100644 Library/SQLScript/Entity/OffersQuery.cs create mode 100644 Library/SQLScript/Entity/StoreGoodsQuery.cs create mode 100644 Library/SQLScript/Entity/StoreQuery.cs create mode 100644 Library/SQLScript/Entity/UserCharactersQuery.cs create mode 100644 Library/SQLScript/Entity/UserItemsQuery.cs create mode 100644 NOTICE diff --git a/Api/Utility/Factory.cs b/Api/Utility/Factory.cs index 84ab01e..2a3fdfd 100644 --- a/Api/Utility/Factory.cs +++ b/Api/Utility/Factory.cs @@ -458,7 +458,7 @@ namespace Milimoe.FunGame.Core.Api.Utility User roomMaster = General.UnknownUserInstance; if (dsUser != null && dsUser.Tables.Count > 0) { - DataRow[] rows = dsUser.Tables[0].Select($"{UserQuery.Column_UID} = {(long)drRoom[RoomQuery.Column_RoomMaster]}"); + DataRow[] rows = dsUser.Tables[0].Select($"{UserQuery.Column_Id} = {(long)drRoom[RoomQuery.Column_RoomMaster]}"); if (rows.Length > 0) { roomMaster = GetUser(rows[0]); @@ -537,7 +537,7 @@ namespace Milimoe.FunGame.Core.Api.Utility { if (dr != null) { - long Id = (long)dr[UserQuery.Column_UID]; + long Id = (long)dr[UserQuery.Column_Id]; string Username = (string)dr[UserQuery.Column_Username]; if (!DateTime.TryParse(dr[UserQuery.Column_RegTime].ToString(), out DateTime RegTime)) { diff --git a/Api/Utility/StringExtension.cs b/Api/Utility/StringExtension.cs index 8399f95..b2d6dd2 100644 --- a/Api/Utility/StringExtension.cs +++ b/Api/Utility/StringExtension.cs @@ -15,5 +15,14 @@ { return Encryption.HmacSha512(text, key.ToLower()); } + + public static bool EqualsGuid(this string str, object? value) + { + if (str.ToLower().Replace("-", "").Equals(value?.ToString()?.ToLower().Replace("-", ""))) + { + return true; + } + return false; + } } } diff --git a/Entity/Item/Item.cs b/Entity/Item/Item.cs index 8964831..43d6697 100644 --- a/Entity/Item/Item.cs +++ b/Entity/Item/Item.cs @@ -55,6 +55,11 @@ namespace Milimoe.FunGame.Core.Entity } } + /// + /// 锁定后无法被出售和交易且不能被手动移出库存 + /// + public bool IsLock { get; set; } = false; + /// /// 是否允许装备 /// [ 注意:这个不是用来判断是不是装备类型的,判断装备类型时,请判断他们的 ] @@ -95,7 +100,7 @@ namespace Milimoe.FunGame.Core.Entity /// /// 快捷键 /// - public char Key { get; set; } = '/'; + public int Key { get; set; } = '/'; /// /// 是否是主动物品 @@ -590,6 +595,7 @@ namespace Milimoe.FunGame.Core.Entity /// public void SetPropertyToItemModuleNew(Item newbyFactory) { + newbyFactory.IsLock = IsLock; newbyFactory.WeaponType = WeaponType; newbyFactory.EquipSlotType = EquipSlotType; newbyFactory.Equipable = Equipable; diff --git a/Entity/System/Inventory.cs b/Entity/System/Inventory.cs index 95a6e91..322ba49 100644 --- a/Entity/System/Inventory.cs +++ b/Entity/System/Inventory.cs @@ -15,7 +15,17 @@ namespace Milimoe.FunGame.Core.Entity /// /// 库存的名称,默认为 “的库存”;可更改 /// - public string Name { get; set; } = ""; + public string Name + { + get + { + return _customName.Trim() == "" ? User.Username + "的库存" : _customName; + } + set + { + _customName = value; + } + } /// /// 库存属于哪个玩家 @@ -77,6 +87,7 @@ namespace Milimoe.FunGame.Core.Entity public Dictionary Training { get; set; } = []; private Character? _character; + private string _customName = ""; internal Inventory(User user) { diff --git a/Entity/System/MarketItem.cs b/Entity/System/MarketItem.cs new file mode 100644 index 0000000..3ba5340 --- /dev/null +++ b/Entity/System/MarketItem.cs @@ -0,0 +1,28 @@ +using Milimoe.FunGame.Core.Api.Utility; +using Milimoe.FunGame.Core.Interface.Entity; +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Core.Entity +{ + public class MarketItem : BaseEntity + { + public User User { get; set; } + public Item Item { get; set; } + public double Price { get; set; } = 0; + public DateTime CreateTime { get; set; } = DateTime.Now; + public DateTime? FinishTime { get; set; } = null; + public MarketItemState Status { get; set; } = MarketItemState.Listed; + public User? Buyer { get; set; } = null; + + public override bool Equals(IBaseEntity? other) + { + return other is MarketItem && other?.Id == Id; + } + + public MarketItem() + { + User = Factory.GetUser(); + Item = Factory.GetItem(); + } + } +} diff --git a/Entity/System/Offer.cs b/Entity/System/Offer.cs new file mode 100644 index 0000000..1162a64 --- /dev/null +++ b/Entity/System/Offer.cs @@ -0,0 +1,22 @@ +using Milimoe.FunGame.Core.Interface.Entity; +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Core.Entity +{ + public class Offer : BaseEntity + { + public long Offeror { get; set; } = 0; + public long Offeree { get; set; } = 0; + public HashSet OfferorItems { get; set; } = []; + public HashSet OffereeItems { get; set; } = []; + public DateTime CreateTime { get; set; } = DateTime.Now; + public DateTime? FinishTime { get; set; } = null; + public OfferState Status { get; set; } = OfferState.Created; + public int NegotiatedTimes { get; set; } = 0; + + public override bool Equals(IBaseEntity? other) + { + return other is Offer && other?.Id == Id; + } + } +} diff --git a/FunGame.Core.csproj b/FunGame.Core.csproj index df0babf..9ad266f 100644 --- a/FunGame.Core.csproj +++ b/FunGame.Core.csproj @@ -6,17 +6,28 @@ enable enable bin\ - Milimoe - Milimoe - 1.0 - 1.0 - ..\bin - Core + $(Author) + Project Redbud + 1.0.0 + 1.0.0 + bin + FunGame Core Milimoe.$(MSBuildProjectName.Replace(" ", "_")) true $(MSBuildProjectName) True + True + Project Redbud and Contributors + ProjectRedbud.$(AssemblyName) + https://github.com/project-redbud/FunGame-Core + https://github.com/project-redbud + LGPL-3.0-or-later + True + README.md + 1.0.0-rc.1 + $([System.DateTime]::Now.ToString("MMdd")) + $(VersionPrefix) @@ -29,4 +40,11 @@ 1701;1702;CS1591;CS1587;IDE0130 + + + True + \ + + + diff --git a/Library/Common/JsonConverter/UserConverter.cs b/Library/Common/JsonConverter/UserConverter.cs index a2487fd..6f0af6e 100644 --- a/Library/Common/JsonConverter/UserConverter.cs +++ b/Library/Common/JsonConverter/UserConverter.cs @@ -18,7 +18,7 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter { switch (propertyName) { - case UserQuery.Column_UID: + case UserQuery.Column_Id: result.Id = reader.GetInt64(); break; case UserQuery.Column_Username: @@ -91,7 +91,7 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter { writer.WriteStartObject(); - writer.WriteNumber(UserQuery.Column_UID, value.Id); + writer.WriteNumber(UserQuery.Column_Id, value.Id); writer.WriteString(UserQuery.Column_Username, value.Username); writer.WriteString(UserQuery.Column_RegTime, value.RegTime.ToString(General.GeneralDateTimeFormat)); writer.WriteString(UserQuery.Column_LastTime, value.LastTime.ToString(General.GeneralDateTimeFormat)); diff --git a/Library/Constant/ConstantSet.cs b/Library/Constant/ConstantSet.cs index 9c53918..9f9dd2a 100644 --- a/Library/Constant/ConstantSet.cs +++ b/Library/Constant/ConstantSet.cs @@ -146,9 +146,29 @@ namespace Milimoe.FunGame.Core.Library.Constant public const string Room_GetRoomPlayerCount = "Room::GetRoomPlayerCount"; public const string Room_UpdateRoomMaster = "Room::UpdateRoomMaster"; /** - * Gaming + * UserCenter */ - public const string Gaming = "Gaming"; + public const string UserCenter_GetUserProfile = "UserCenter::GetUserProfile"; + public const string UserCenter_GetUserStatistics = "UserCenter::GetUserStatistics"; + public const string UserCenter_UpdateUser = "UserCenter::UpdateUser"; + public const string UserCenter_UpdatePassword = "UserCenter::UpdatePassword"; + public const string UserCenter_DailySignIn = "UserCenter::DailySignIn"; + /** + * Inventory + */ + public const string Inventory_GetStore = "Inventory::GetStore"; + public const string Inventory_GetMarket = "Inventory::GetMarket"; + public const string Inventory_StoreBuy = "Inventory::StoreBuy"; + public const string Inventory_MarketBuy = "Inventory::MarketBuy"; + public const string Inventory_GetInventory = "Inventory::GetInventory"; + public const string Inventory_Use = "Inventory::Use"; + public const string Inventory_StoreSell = "Inventory::StoreSell"; + public const string Inventory_MarketSell = "Inventory::MarketSell"; + public const string Inventory_UpdateMarketPrice = "Inventory::UpdateMarketPrice"; + public const string Inventory_GetOffer = "Inventory::GetOffer"; + public const string Inventory_MakeOffer = "Inventory::MakeOffer"; + public const string Inventory_ReviseOffer = "Inventory::ReviseOffer"; + public const string Inventory_RespondOffer = "Inventory::RespondOffer"; /// /// 获取Type的等效字符串 @@ -177,7 +197,24 @@ namespace Milimoe.FunGame.Core.Library.Constant DataRequestType.Room_GetRoomSettings => Room_GetRoomSettings, DataRequestType.Room_GetRoomPlayerCount => Room_GetRoomPlayerCount, DataRequestType.Room_UpdateRoomMaster => Room_UpdateRoomMaster, - DataRequestType.Gaming => Gaming, + DataRequestType.UserCenter_GetUserProfile => UserCenter_GetUserProfile, + DataRequestType.UserCenter_GetUserStatistics => UserCenter_GetUserStatistics, + DataRequestType.UserCenter_UpdateUser => UserCenter_UpdateUser, + DataRequestType.UserCenter_UpdatePassword => UserCenter_UpdatePassword, + DataRequestType.UserCenter_DailySignIn => UserCenter_DailySignIn, + DataRequestType.Inventory_GetStore => Inventory_GetStore, + DataRequestType.Inventory_GetMarket => Inventory_GetMarket, + DataRequestType.Inventory_StoreBuy => Inventory_StoreBuy, + DataRequestType.Inventory_MarketBuy => Inventory_MarketBuy, + DataRequestType.Inventory_GetInventory => Inventory_GetInventory, + DataRequestType.Inventory_Use => Inventory_Use, + DataRequestType.Inventory_StoreSell => Inventory_StoreSell, + DataRequestType.Inventory_MarketSell => Inventory_MarketSell, + DataRequestType.Inventory_UpdateMarketPrice => Inventory_UpdateMarketPrice, + DataRequestType.Inventory_GetOffer => Inventory_GetOffer, + DataRequestType.Inventory_MakeOffer => Inventory_MakeOffer, + DataRequestType.Inventory_ReviseOffer => Inventory_ReviseOffer, + DataRequestType.Inventory_RespondOffer => Inventory_RespondOffer, _ => UnKnown }; } diff --git a/Library/Constant/FunGameInfo.cs b/Library/Constant/FunGameInfo.cs index 79c5f97..6da4479 100644 --- a/Library/Constant/FunGameInfo.cs +++ b/Library/Constant/FunGameInfo.cs @@ -11,7 +11,8 @@ FunGame_Server } - public const string FunGame_CopyRight = @"©2025 Milimoe. 米粒的糖果屋"; + public const string FunGame_CopyRight_Core = "©2023-Present Project Redbud and Contributors.\r\n©2022-2023 Milimoe."; + public const string FunGame_CopyRight_Desktop = "©2025 Milimoe. 米粒的糖果屋"; /// /// 添加-debug启动项将开启DebugMode(仅适用于Desktop或Console) @@ -19,14 +20,21 @@ /// public static bool FunGame_DebugMode { get; set; } = false; + /// + /// 核心库的版本号 + /// + public static string FunGame_Version { get; } = $"{FunGame_Version_Major}.{FunGame_Version_Minor}{FunGame_VersionPatch}"; + public const string FunGame_Core = "FunGame Core"; public const string FunGame_Core_Api = "FunGame Core Api"; public const string FunGame_Console = "FunGame Console"; public const string FunGame_Desktop = "FunGame Desktop"; public const string FunGame_Server = "FunGame Server Console"; - public const string FunGame_Version = "v1.0"; - public const string FunGame_VersionPatch = ""; + public const int FunGame_Version_Major = 1; + public const int FunGame_Version_Minor = 0; + public const string FunGame_VersionPatch = ".0-rc.1"; + public const string FunGame_Version_Build = ""; public const string FunGameCoreTitle = @" _____ _ _ _ _ ____ _ __ __ _____ ____ ___ ____ _____ | ___| | | | \ | |/ ___| / \ | \/ | ____| / ___/ _ \| _ \| ____| @@ -41,7 +49,8 @@ | _| | |_| | |\ | |_| |/ ___ \| | | | |___ ___) | |___| _ < \ V / | |___| _ < |_| \___/|_| \_|\____/_/ \_\_| |_|_____| |____/|_____|_| \_\ \_/ |_____|_| \_\ "; - public static string GetInfo(FunGame FunGameType) + + public static string GetInfo(FunGame FunGameType, int major = 0, int minor = 0, string patch = "") { string type = FunGameType switch { @@ -52,7 +61,16 @@ FunGame.FunGame_Server => FunGame_Server, _ => "" }; - return type + " [版本: " + FunGame_Version + FunGame_VersionPatch + "]\n" + (type.Equals(FunGame_Desktop) ? @"©" : "(C)") + "2022-Present Milimoe. 保留所有权利\n"; + if (major == 0) major = FunGame_Version_Major; + if (minor == 0) minor = FunGame_Version_Minor; + if (patch == "") patch = FunGame_VersionPatch; + if (patch != "" && !patch.StartsWith('.')) patch = $".{patch}"; + return $"{FunGame_Core} [核心库版本: {FunGame_Version}]\r\n" + + $"{(type.Equals(FunGame_Desktop) ? @"©" : "(C)")}2023-Present Project Redbud and Contributors.\r\n" + + $"{(type.Equals(FunGame_Desktop) ? @"©" : "(C)")}2022-2023 Milimoe.\r\n" + + $"\r\nThis software is released under the LGPLv3 license. See LICENSE for details.\r\n\r\n" + + $"{type} [版本:{major}.{minor}{patch}]\r\n{(type.Equals(FunGame_Desktop) ? @"©" : "(C)")}2022-Present Milimoe.\r\n" + + $"\r\nThis software is released under the MIT license. See LICENSE for details.\r\n"; } } } diff --git a/Library/Constant/StateEnum.cs b/Library/Constant/StateEnum.cs index 49094ad..1134224 100644 --- a/Library/Constant/StateEnum.cs +++ b/Library/Constant/StateEnum.cs @@ -103,4 +103,27 @@ namespace Milimoe.FunGame.Core.Library.Constant InProgress, Ended } + + public enum OfferState + { + Created, + Cancelled, + PendingOfferorConfirmation, + PendingOffereeConfirmation, + OfferorConfirmed, + OffereeConfirmed, + Sent, + Negotiating, + NegotiationAccepted, + Rejected, + Completed, + Expired + } + + public enum MarketItemState + { + Listed, + Delisted, + Purchased + } } diff --git a/Library/Constant/TypeEnum.cs b/Library/Constant/TypeEnum.cs index 3745131..aa9e895 100644 --- a/Library/Constant/TypeEnum.cs +++ b/Library/Constant/TypeEnum.cs @@ -105,7 +105,24 @@ namespace Milimoe.FunGame.Core.Library.Constant Room_GetRoomSettings, Room_GetRoomPlayerCount, Room_UpdateRoomMaster, - Gaming + UserCenter_GetUserProfile, + UserCenter_GetUserStatistics, + UserCenter_UpdateUser, + UserCenter_UpdatePassword, + UserCenter_DailySignIn, + Inventory_GetStore, + Inventory_GetMarket, + Inventory_StoreBuy, + Inventory_MarketBuy, + Inventory_GetInventory, + Inventory_Use, + Inventory_StoreSell, + Inventory_MarketSell, + Inventory_UpdateMarketPrice, + Inventory_GetOffer, + Inventory_MakeOffer, + Inventory_ReviseOffer, + Inventory_RespondOffer, } /// @@ -820,4 +837,59 @@ namespace Milimoe.FunGame.Core.Library.Constant Error, Critical } + + public enum OfferActionType + { + /// + /// 报价发起方修改报价, + /// 如果当前状态为 (已创建) 和 (协商中), + /// 则状态转为 (等待发起方确认) + /// + OfferorRevise, + + /// + /// 报价发起方确认报价,状态转为 (发起方已确认) + /// + OfferorConfirm, + + /// + /// 报价发起方发送报价,状态转为 (已发送) + /// + OfferorSend, + + /// + /// 报价接收方修改报价,状态转为 (等待接收方确认) + /// + OffereeRevise, + + /// + /// 报价接收方确认报价,状态转为 (接收方已确认) + /// + OffereeConfirm, + + /// + /// 报价接收方发送报价,状态转为 (协商中) + /// + OffereeSend, + + /// + /// 报价发起方同意接收方的协商,状态转为 (协商已接受) + /// + OfferorAccept, + + /// + /// 报价发起方手动取消了报价,状态转为 (已取消) + /// + OfferorCancel, + + /// + /// 报价接收方同意报价,状态转为 (已完成) + /// + OffereeAccept, + + /// + /// 报价接收方拒绝报价,状态转为 (已拒绝) + /// + OffereeReject + } } diff --git a/Library/SQLScript/Common/ApiTokens.cs b/Library/SQLScript/Common/ApiTokens.cs new file mode 100644 index 0000000..c394e25 --- /dev/null +++ b/Library/SQLScript/Common/ApiTokens.cs @@ -0,0 +1,43 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Common +{ + public class ApiTokens : Constant + { + public const string TableName = "ApiTokens"; + public const string Column_TokenID = "TokenID"; + public const string Column_SecretKey = "SecretKey"; + public const string Column_Reference1 = "Reference1"; + public const string Column_Reference2 = "Reference2"; + + public static string Insert_APIToken(SQLHelper SQLHelper, string TokenID, string SecretKey = "", string Reference1 = "", string Reference2 = "") + { + SQLHelper.Parameters["@TokenID"] = TokenID; + SQLHelper.Parameters["@SecretKey"] = SecretKey; + SQLHelper.Parameters["@Reference1"] = Reference1; + SQLHelper.Parameters["@Reference2"] = Reference2; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_TokenID}, {Column_SecretKey}, {Column_Reference1}, {Column_Reference2}) {Command_Values} (@TokenID, @SecretKey, @Reference1, @Reference2)"; + } + + public static string Select_GetAPIToken(SQLHelper SQLHelper, string TokenID) + { + SQLHelper.Parameters["@TokenID"] = TokenID; + return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_TokenID} = @TokenID"; + } + + public static string Select_GetAPISecretKey(SQLHelper SQLHelper, string SecretKey) + { + SQLHelper.Parameters["@SecretKey"] = SecretKey; + return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_SecretKey} = @SecretKey"; + } + + public static string Update_APIToken(SQLHelper SQLHelper, string TokenID, string SecretKey, string Reference1 = "", string Reference2 = "") + { + SQLHelper.Parameters["@TokenID"] = TokenID; + SQLHelper.Parameters["@SecretKey"] = SecretKey; + SQLHelper.Parameters["@Reference1"] = Reference1; + SQLHelper.Parameters["@Reference2"] = Reference2; + return $"{Command_Update} {TableName} {Command_Set} {Column_TokenID} = @TokenID, {Column_SecretKey} = @SecretKey, {Column_Reference1} = @Reference1, {Column_Reference2} = @Reference2 {Command_Where} {Column_TokenID} = @TokenID"; + } + } +} diff --git a/Library/SQLScript/Common/Common.cs b/Library/SQLScript/Common/Common.cs deleted file mode 100644 index 5a477dd..0000000 --- a/Library/SQLScript/Common/Common.cs +++ /dev/null @@ -1,97 +0,0 @@ -using Milimoe.FunGame.Core.Api.Transmittal; - -namespace Milimoe.FunGame.Core.Library.SQLScript -{ - public class Constant - { - /** - * Commands - */ - public const string Command_Select = "Select"; - public const string Command_Update = "Update"; - public const string Command_Delete = "Delete"; - public const string Command_Insert = "Insert"; - public const string Command_From = "From"; - public const string Command_Set = "Set"; - public const string Command_Into = "Into"; - public const string Command_Where = "Where"; - public const string Command_All = "*"; - public const string Command_Values = "Values"; - public const string Command_And = "And"; - public const string Command_Or = "Or"; - public const string Command_As = "As"; - public const string Command_LeftJoin = "Left Join"; - public const string Command_InnerJoin = "Inner Join"; - public const string Command_RightJoin = "Right Join"; - public const string Command_CrossJoin = "Cross Join"; - public const string Command_On = "On"; - public const string Command_In = "In"; - } -} - -namespace Milimoe.FunGame.Core.Library.SQLScript.Common -{ - public class ServerLoginLogs : Constant - { - public const string TableName = "ServerLoginLogs"; - public const string Column_ServerName = "ServerName"; - public const string Column_ServerKey = "ServerKey"; - public const string Column_LoginTime = "LoginTime"; - public const string Column_LastTime = "LastTime"; - - public static string Insert_ServerLoginLogs(SQLHelper SQLHelper, string ServerName, string ServerKey) - { - SQLHelper.Parameters["@ServerName"] = ServerName; - SQLHelper.Parameters["@ServerKey"] = ServerKey; - SQLHelper.Parameters["@LoginTime"] = DateTime.Now; - return $"{Command_Insert} {Command_Into} {TableName} ({Column_ServerName}, {Column_ServerKey}, {Column_LoginTime}) {Command_Values} (@ServerName, @ServerKey, @LoginTime)"; - } - - public static string Select_GetLastLoginTime() - { - return $"{Command_Select} Max({Column_LoginTime}) {Column_LastTime} {Command_From} {TableName}"; - } - } -} - -namespace Milimoe.FunGame.Core.Library.SQLScript.Common -{ - public class ApiTokens : Constant - { - public const string TableName = "ApiTokens"; - public const string Column_TokenID = "TokenID"; - public const string Column_SecretKey = "SecretKey"; - public const string Column_Reference1 = "Reference1"; - public const string Column_Reference2 = "Reference2"; - - public static string Insert_APIToken(SQLHelper SQLHelper, string TokenID, string SecretKey = "", string Reference1 = "", string Reference2 = "") - { - SQLHelper.Parameters["@TokenID"] = TokenID; - SQLHelper.Parameters["@SecretKey"] = SecretKey; - SQLHelper.Parameters["@Reference1"] = Reference1; - SQLHelper.Parameters["@Reference2"] = Reference2; - return $"{Command_Insert} {Command_Into} {TableName} ({Column_TokenID}, {Column_SecretKey}, {Column_Reference1}, {Column_Reference2}) {Command_Values} (@TokenID, @SecretKey, @Reference1, @Reference2)"; - } - - public static string Select_GetAPIToken(SQLHelper SQLHelper, string TokenID) - { - SQLHelper.Parameters["@TokenID"] = TokenID; - return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_TokenID} = @TokenID"; - } - - public static string Select_GetAPISecretKey(SQLHelper SQLHelper, string SecretKey) - { - SQLHelper.Parameters["@SecretKey"] = SecretKey; - return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_SecretKey} = @SecretKey"; - } - - public static string Update_GetAPIToken(SQLHelper SQLHelper, string TokenID, string SecretKey, string Reference1 = "", string Reference2 = "") - { - SQLHelper.Parameters["@TokenID"] = TokenID; - SQLHelper.Parameters["@SecretKey"] = SecretKey; - SQLHelper.Parameters["@Reference1"] = Reference1; - SQLHelper.Parameters["@Reference2"] = Reference2; - return $"{Command_Update} {TableName} {Command_Set} {Column_TokenID} = @TokenID, {Column_SecretKey} = @SecretKey, {Column_Reference1} = @Reference1, {Column_Reference2} = @Reference2 {Command_Where} {Column_TokenID} = @TokenID"; - } - } -} diff --git a/Library/SQLScript/Common/Configs.cs b/Library/SQLScript/Common/Configs.cs new file mode 100644 index 0000000..88b55cc --- /dev/null +++ b/Library/SQLScript/Common/Configs.cs @@ -0,0 +1,37 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Common +{ + public class Configs : Constant + { + public const string TableName = "Configs"; + public const string Column_Id = "Id"; + public const string Column_Content = "Content"; + public const string Column_Description = "Description"; + public const string Column_UpdateTime = "UpdateTime"; + + public static string Insert_Config(SQLHelper SQLHelper, string Id, string Content, string Description = "") + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@Content"] = Content; + SQLHelper.Parameters["@Description"] = Description; + SQLHelper.Parameters["@UpdateTime"] = DateTime.Now; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_Id}, {Column_Content}, {Column_Description}, {Column_UpdateTime}) {Command_Values} (@Id, @Content, @Description, @UpdateTime)"; + } + + public static string Select_GetConfig(SQLHelper SQLHelper, string Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Update_Config(SQLHelper SQLHelper, string Id, string Content, string Description) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@Content"] = Content; + SQLHelper.Parameters["@Description"] = Description; + SQLHelper.Parameters["@UpdateTime"] = DateTime.Now; + return $"{Command_Update} {TableName} {Command_Set} {Column_Id} = @Id, {Column_Content} = @Content, {Column_Description} = @Description, {Column_UpdateTime} = @UpdateTime {Command_Where} {Column_Id} = @Id"; + } + } +} diff --git a/Library/SQLScript/Common/ServerLoginLogs.cs b/Library/SQLScript/Common/ServerLoginLogs.cs new file mode 100644 index 0000000..3327b62 --- /dev/null +++ b/Library/SQLScript/Common/ServerLoginLogs.cs @@ -0,0 +1,26 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Common +{ + public class ServerLoginLogs : Constant + { + public const string TableName = "ServerLoginLogs"; + public const string Column_ServerName = "ServerName"; + public const string Column_ServerKey = "ServerKey"; + public const string Column_LoginTime = "LoginTime"; + public const string Column_LastTime = "LastTime"; + + public static string Insert_ServerLoginLog(SQLHelper SQLHelper, string ServerName, string ServerKey) + { + SQLHelper.Parameters["@ServerName"] = ServerName; + SQLHelper.Parameters["@ServerKey"] = ServerKey; + SQLHelper.Parameters["@LoginTime"] = DateTime.Now; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_ServerName}, {Column_ServerKey}, {Column_LoginTime}) {Command_Values} (@ServerName, @ServerKey, @LoginTime)"; + } + + public static string Select_GetLastLoginTime() + { + return $"{Command_Select} Max({Column_LoginTime}) {Column_LastTime} {Command_From} {TableName}"; + } + } +} diff --git a/Library/SQLScript/Common/UserLogs.cs b/Library/SQLScript/Common/UserLogs.cs new file mode 100644 index 0000000..ace5df2 --- /dev/null +++ b/Library/SQLScript/Common/UserLogs.cs @@ -0,0 +1,48 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Common +{ + public class UserLogs : Constant + { + public const string TableName = "UserLogs"; + public const string Column_Id = "Id"; + public const string Column_UserId = "UserId"; + public const string Column_Title = "Title"; + public const string Column_Description = "Description"; + public const string Column_Remark = "Remark"; + public const string Column_CreateTime = "CreateTime"; + + public static string Insert_UserLog(SQLHelper SQLHelper, long UserId, string Title, string Description = "", string Remark = "") + { + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Title"] = Title; + SQLHelper.Parameters["@Description"] = Description; + SQLHelper.Parameters["@Remark"] = Remark; + SQLHelper.Parameters["@CreateTime"] = DateTime.Now; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_UserId}, {Column_Title}, {Column_Description}, {Column_Remark}, {Column_CreateTime}) {Command_Values} (@UserId, @Title, @Description, @Remark, @CreateTime)"; + } + + public static string Select_GetUserLog(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Select_GetUserLogsByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Update_UserLog(SQLHelper SQLHelper, long Id, long UserId, string Title, string Description, string Remark) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Title"] = Title; + SQLHelper.Parameters["@Description"] = Description; + SQLHelper.Parameters["@Remark"] = Remark; + SQLHelper.Parameters["@CreateTime"] = DateTime.Now; + return $"{Command_Update} {TableName} {Command_Set} {Column_UserId} = @UserId, {Column_Title} = @Title, {Column_Description} = @Description, {Column_Remark} = @Remark, {Column_CreateTime} = @CreateTime {Command_Where} {Column_Id} = @Id"; + } + } +} diff --git a/Library/SQLScript/Common/UserSignIns.cs b/Library/SQLScript/Common/UserSignIns.cs new file mode 100644 index 0000000..6d22bfe --- /dev/null +++ b/Library/SQLScript/Common/UserSignIns.cs @@ -0,0 +1,43 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Common +{ + public class UserSignIns : Constant + { + public const string TableName = "UserSignIns"; + public const string Column_UserId = "UserId"; + public const string Column_LastTime = "LastTime"; + public const string Column_Days = "Days"; + public const string Column_IsSigned = "IsSigned"; + + public static string Insert_NewUserSignIn(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@LastTime"] = DBNull.Value; + SQLHelper.Parameters["@Days"] = 0; + SQLHelper.Parameters["@IsSigned"] = 0; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_UserId}, {Column_LastTime}, {Column_Days}, {Column_IsSigned}) {Command_Values} (@UserId, @LastTime, @Days, @IsSigned)"; + } + + public static string Select_GetUserSignIn(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Update_UserSignIn(SQLHelper SQLHelper, long UserId, int Days) + { + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@LastTime"] = DateTime.Now; + SQLHelper.Parameters["@Days"] = Days; + SQLHelper.Parameters["@IsSigned"] = 1; + return $"{Command_Update} {TableName} {Command_Set} {Column_LastTime} = @LastTime, {Column_Days} = @Days, {Column_IsSigned} = @IsSigned {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Update_ResetStatus(SQLHelper SQLHelper) + { + SQLHelper.Parameters["@IsSigned"] = 0; + return $"{Command_Update} {TableName} {Command_Set} {Column_IsSigned} = @IsSigned"; + } + } +} diff --git a/Library/SQLScript/Constant.cs b/Library/SQLScript/Constant.cs new file mode 100644 index 0000000..6b74931 --- /dev/null +++ b/Library/SQLScript/Constant.cs @@ -0,0 +1,28 @@ +namespace Milimoe.FunGame.Core.Library.SQLScript +{ + public class Constant + { + /** + * Commands + */ + public const string Command_Select = "Select"; + public const string Command_Update = "Update"; + public const string Command_Delete = "Delete"; + public const string Command_Insert = "Insert"; + public const string Command_From = "From"; + public const string Command_Set = "Set"; + public const string Command_Into = "Into"; + public const string Command_Where = "Where"; + public const string Command_All = "*"; + public const string Command_Values = "Values"; + public const string Command_And = "And"; + public const string Command_Or = "Or"; + public const string Command_As = "As"; + public const string Command_LeftJoin = "Left Join"; + public const string Command_InnerJoin = "Inner Join"; + public const string Command_RightJoin = "Right Join"; + public const string Command_CrossJoin = "Cross Join"; + public const string Command_On = "On"; + public const string Command_In = "In"; + } +} diff --git a/Library/SQLScript/Entity/GoodsItemsQuery.cs b/Library/SQLScript/Entity/GoodsItemsQuery.cs new file mode 100644 index 0000000..69dfe42 --- /dev/null +++ b/Library/SQLScript/Entity/GoodsItemsQuery.cs @@ -0,0 +1,39 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class GoodsItemsQuery : Constant + { + public const string TableName = "GoodsItems"; + public const string Column_Id = "Id"; + public const string Column_GoodsId = "GoodsId"; + public const string Column_ItemId = "ItemId"; + + public const string Select_GoodsItems = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + + public static string Select_GoodsItemsByGoodsId(SQLHelper SQLHelper, long GoodsId) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + return $"{Select_GoodsItems} {Command_Where} {Column_GoodsId} = @GoodsId"; + } + + public static string Insert_GoodsItem(SQLHelper SQLHelper, long GoodsId, long ItemId) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + SQLHelper.Parameters["@ItemId"] = ItemId; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_GoodsId}, {Column_ItemId}) {Command_Values} (@GoodsId, @ItemId)"; + } + + public static string Delete_GoodsItem(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_GoodsItemByGoodsId(SQLHelper SQLHelper, long GoodsId) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_GoodsId} = @GoodsId"; + } + } +} diff --git a/Library/SQLScript/Entity/GoodsPricesQuery.cs b/Library/SQLScript/Entity/GoodsPricesQuery.cs new file mode 100644 index 0000000..6a3af0e --- /dev/null +++ b/Library/SQLScript/Entity/GoodsPricesQuery.cs @@ -0,0 +1,49 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class GoodsPricesQuery : Constant + { + public const string TableName = "GoodsPrices"; + public const string Column_Id = "Id"; + public const string Column_GoodsId = "GoodsId"; + public const string Column_Currency = "Currency"; + public const string Column_Price = "Price"; + + public const string Select_GoodsPrices = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + + public static string Select_GoodsPricesByGoodsId(SQLHelper SQLHelper, long GoodsId) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + return $"{Select_GoodsPrices} {Command_Where} {Column_GoodsId} = @GoodsId"; + } + + public static string Insert_GoodsPrice(SQLHelper SQLHelper, long GoodsId, string Currency, double Price) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + SQLHelper.Parameters["@Currency"] = Currency; + SQLHelper.Parameters["@Price"] = Price; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_GoodsId}, {Column_Currency}, {Column_Price}) {Command_Values} (@GoodsId, @Currency, @Price)"; + } + + public static string Update_GoodsPrice(SQLHelper SQLHelper, long GoodsId, string Currency, double Price) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + SQLHelper.Parameters["@Currency"] = Currency; + SQLHelper.Parameters["@Price"] = Price; + return $"{Command_Update} {TableName} {Command_Set} {Column_GoodsId} = @GoodsId, {Column_Price} = @Price {Command_Where} {Column_Currency} = @Currency"; + } + + public static string Delete_GoodsPrice(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_GoodsPriceByGoodsId(SQLHelper SQLHelper, long GoodsId) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_GoodsId} = @GoodsId"; + } + } +} diff --git a/Library/SQLScript/Entity/GoodsQuery.cs b/Library/SQLScript/Entity/GoodsQuery.cs new file mode 100644 index 0000000..235f858 --- /dev/null +++ b/Library/SQLScript/Entity/GoodsQuery.cs @@ -0,0 +1,61 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class GoodsQuery : Constant + { + public const string TableName = "Goods"; + public const string Column_Id = "Id"; + public const string Column_Name = "Name"; + public const string Column_Description = "Description"; + public const string Column_Stock = "Stock"; + + public const string Select_Goods = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + public const string Select_GoodsWithItemAndPrice = $"{Command_Select} {TableName}.{Column_Id}, {TableName}.{Column_Name}, {TableName}.{Column_Description}, {TableName}.{Column_Stock}, " + + $"{GoodsItemsQuery.TableName}.{GoodsItemsQuery.Column_ItemId}, {GoodsPricesQuery.TableName}.{GoodsPricesQuery.Column_Currency}, {GoodsPricesQuery.TableName}.{GoodsPricesQuery.Column_Price} " + + $"{Command_From} {TableName} \r\n" + + $"{Command_LeftJoin} {GoodsItemsQuery.TableName} {Command_On} {GoodsItemsQuery.TableName}.{GoodsItemsQuery.Column_GoodsId} = {TableName}.{Column_Id}\r\n" + + $"{Command_LeftJoin} {GoodsPricesQuery.TableName} {Command_On} {GoodsPricesQuery.TableName}.{GoodsPricesQuery.Column_GoodsId} = {TableName}.{Column_Id}"; + + public static string Select_GoodsById(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Select_Goods} {Command_Where} {Column_Id} = @Id"; + } + + public static string Insert_Goods(SQLHelper SQLHelper, string Name, string Description, int Stock) + { + SQLHelper.Parameters["@Name"] = Name; + SQLHelper.Parameters["@Description"] = Description; + SQLHelper.Parameters["@Stock"] = Stock; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_Name}, {Column_Description}, {Column_Stock}) {Command_Values} (@Name, @Description, @Stock)"; + } + + public static string Update_Goods(SQLHelper SQLHelper, long Id, string Name, string Description, int Stock) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@Name"] = Name; + SQLHelper.Parameters["@Description"] = Description; + SQLHelper.Parameters["@Stock"] = Stock; + return $"{Command_Update} {TableName} {Command_Set} {Column_Name} = @Name, {Column_Description} = @Description, {Column_Stock} = @Stock {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_Goods(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Select_AllGoodsWithItemAndPrice(SQLHelper SQLHelper, long GoodsId = 0) + { + if (GoodsId != 0) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + } + + string sql = $"{Select_GoodsWithItemAndPrice}{(GoodsId != 0 ? $"\r\n{Command_Where} {TableName}.{Column_Id} = @GoodsId" : "")}"; + + return sql; + } + } +} diff --git a/Library/SQLScript/Entity/InventoriesQuery.cs b/Library/SQLScript/Entity/InventoriesQuery.cs new file mode 100644 index 0000000..61ae4f0 --- /dev/null +++ b/Library/SQLScript/Entity/InventoriesQuery.cs @@ -0,0 +1,78 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class InventoriesQuery : Constant + { + public const string TableName = "Inventories"; + public const string Column_UserId = "UserId"; + public const string Column_Name = "Name"; + public const string Column_Credits = "Credits"; + public const string Column_Materials = "Materials"; + public const string Column_MainCharacter = "MainCharacter"; + + public const string Select_Inventories = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + + public static string Select_InventoryByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Select_Inventories} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Select_MainCharacterByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Command_Select} {Column_MainCharacter} {Command_From} {TableName} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Insert_Inventory(SQLHelper SQLHelper, long UserId, string Name, double Credits, double Materials, long MainCharacter) + { + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Name"] = Name; + SQLHelper.Parameters["@Credits"] = Credits; + SQLHelper.Parameters["@Materials"] = Materials; + SQLHelper.Parameters["@MainCharacter"] = MainCharacter; + + return $"{Command_Insert} {Command_Into} {TableName} ({Column_UserId}, {Column_Name}, {Column_Credits}, {Column_Materials}, {Column_MainCharacter}) " + + $"{Command_Values} (@UserId, @Name, @Credits, @Materials, @MainCharacter)"; + } + + public static string Update_Inventory(SQLHelper SQLHelper, long UserId, string Name, double Credits, double Materials, long MainCharacter) + { + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Name"] = Name; + SQLHelper.Parameters["@Credits"] = Credits; + SQLHelper.Parameters["@Materials"] = Materials; + SQLHelper.Parameters["@MainCharacter"] = MainCharacter; + + return $"{Command_Update} {TableName} {Command_Set} {Column_Name} = @Name, {Column_Credits} = @Credits, {Column_Materials} = @Materials, {Column_MainCharacter} = @MainCharacter {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Update_InventoryCredits(SQLHelper SQLHelper, long UserId, double Credits) + { + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Credits"] = Credits; + return $"{Command_Update} {TableName} {Command_Set} {Column_Credits} = @Credits {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Update_InventoryMaterials(SQLHelper SQLHelper, long UserId, double Materials) + { + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Materials"] = Materials; + return $"{Command_Update} {TableName} {Command_Set} {Column_Materials} = @Materials {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Update_InventoryMainCharacter(SQLHelper SQLHelper, long UserId, long MainCharacter) + { + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@MainCharacter"] = MainCharacter; + return $"{Command_Update} {TableName} {Command_Set} {Column_MainCharacter} = @MainCharacter {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Delete_Inventory(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_UserId} = @UserId"; + } + } +} diff --git a/Library/SQLScript/Entity/MarketItemsQuery.cs b/Library/SQLScript/Entity/MarketItemsQuery.cs new file mode 100644 index 0000000..66e1cf5 --- /dev/null +++ b/Library/SQLScript/Entity/MarketItemsQuery.cs @@ -0,0 +1,120 @@ +using Milimoe.FunGame.Core.Api.Transmittal; +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class MarketItemsQuery : Constant + { + public const string TableName = "MarketItems"; + public const string Column_Id = "Id"; + public const string Column_ItemGuid = "ItemGuid"; + public const string Column_UserId = "UserId"; + public const string Column_Price = "Price"; + public const string Column_CreateTime = "CreateTime"; + public const string Column_FinishTime = "FinishTime"; + public const string Column_Status = "Status"; + public const string Column_Buyer = "Buyer"; + + public const string Select_MarketItems = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + + public static string Select_MarketItemById(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Select_MarketItems} {Command_Where} {Column_Id} = @Id"; + } + + public static string Select_MarketItemsByItemId(SQLHelper SQLHelper, Guid ItemGuid) + { + SQLHelper.Parameters["@ItemGuid"] = ItemGuid.ToString(); + return $"{Select_MarketItems} {Command_Where} {Column_ItemGuid} = @ItemGuid"; + } + + public static string Select_MarketItemsByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Select_MarketItems} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Select_MarketItemsByState(SQLHelper SQLHelper, MarketItemState state) + { + SQLHelper.Parameters["@Status"] = (int)state; + return $"{Select_MarketItems} {Command_Where} {Column_Status} = @Status"; + } + + public static string Insert_MarketItem(SQLHelper SQLHelper, Guid ItemGuid, long UserId, double Price, MarketItemState state = MarketItemState.Listed) + { + SQLHelper.Parameters["@ItemGuid"] = ItemGuid.ToString(); + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Price"] = Price; + SQLHelper.Parameters["@Status"] = (int)state; + + return $"{Command_Insert} {Command_Into} {TableName} ({Column_ItemGuid}, {Column_UserId}, {Column_Price}, {Column_Status}) {Command_Values} (@ItemId, @UserId, @Price, @Status)"; + } + + public static string Update_MarketItemPrice(SQLHelper SQLHelper, long Id, double Price) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@Price"] = Price; + return $"{Command_Update} {TableName} {Command_Set} {Column_Price} = @Price {Command_Where} {Column_Id} = @Id"; + } + + public static string Update_MarketItemState(SQLHelper SQLHelper, long Id, MarketItemState state) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@Status"] = (int)state; + return $"{Command_Update} {TableName} {Command_Set} {Column_Status} = @Status {Command_Where} {Column_Id} = @Id"; + } + + public static string Update_MarketItemBuyer(SQLHelper SQLHelper, long Id, long Buyer) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@Buyer"] = Buyer; + SQLHelper.Parameters["@Status"] = (int)MarketItemState.Purchased; + return $"{Command_Update} {TableName} {Command_Set} {Column_Buyer} = @Buyer, {Column_Status} = @Status {Command_Where} {Column_Id} = @Id"; + } + + public static string Update_MarketItemFinishTime(SQLHelper SQLHelper, long Id, DateTime FinishTime) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@FinishTime"] = FinishTime; + return $"{Command_Update} {TableName} {Command_Set} {Column_FinishTime} = @FinishTime {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_MarketItem(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_MarketItemByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @UserId"; + } + + public static string Select_AllMarketItems(SQLHelper SQLHelper, long UserId = 0, MarketItemState? state = null) + { + string sql = Select_MarketItems; + string whereClause = ""; + + if (UserId != 0) + { + SQLHelper.Parameters["@UserId"] = UserId; + whereClause += $"{Command_And} {Column_UserId} = @UserId\r\n"; + } + + if (state.HasValue) + { + SQLHelper.Parameters["@Status"] = (int)state.Value; + whereClause += $"{Command_And} {Column_Status} = @Status\r\n"; + } + + if (!string.IsNullOrEmpty(whereClause)) + { + sql += $" {Command_Where} {whereClause[Command_And.Length..]}"; + } + + return sql.Trim(); + } + } +} diff --git a/Library/SQLScript/Entity/OfferItemsQuery.cs b/Library/SQLScript/Entity/OfferItemsQuery.cs new file mode 100644 index 0000000..c155d62 --- /dev/null +++ b/Library/SQLScript/Entity/OfferItemsQuery.cs @@ -0,0 +1,69 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class OfferItemsQuery : Constant + { + public const string TableName = "OfferItems"; + public const string TableName_Backup = "OfferItemsBackup"; + public const string Column_Id = "Id"; + public const string Column_OfferId = "OfferId"; + public const string Column_UserId = "UserId"; + public const string Column_ItemGuid = "ItemGuid"; + + public const string Select_OfferItems = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + public const string Select_OfferItemsBackup = $"{Command_Select} {Command_All} {Command_From} {TableName_Backup}"; + + public static string Select_OfferItemsByOfferIdAndUserId(SQLHelper SQLHelper, long OfferId, long UserId) + { + SQLHelper.Parameters["@OfferId"] = OfferId; + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Select_OfferItems} {Command_Where} {Column_OfferId} = @OfferId {Command_And} {Column_UserId} = @UserId"; + } + + public static string Select_OfferItemsBackupByOfferIdAndUserId(SQLHelper SQLHelper, long OfferId, long UserId) + { + SQLHelper.Parameters["@OfferId"] = OfferId; + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Select_OfferItemsBackup} {Command_Where} {Column_OfferId} = @OfferId {Command_And} {Column_UserId} = @UserId"; + } + + public static string Insert_OfferItem(SQLHelper SQLHelper, long OfferId, long UserId, Guid ItemGuid) + { + SQLHelper.Parameters["@OfferId"] = OfferId; + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@ItemGuid"] = ItemGuid.ToString(); + + return $"{Command_Insert} {Command_Into} {TableName} ({Column_OfferId}, {Column_UserId}, {Column_ItemGuid}) " + + $"{Command_Values} (@OfferId, @UserId, @ItemGuid)"; + } + + public static string Insert_OfferItemBackup(SQLHelper SQLHelper, long OfferId, long UserId, Guid ItemGuid) + { + SQLHelper.Parameters["@OfferId"] = OfferId; + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@ItemGuid"] = ItemGuid.ToString(); + + return $"{Command_Insert} {Command_Into} {TableName_Backup} ({Column_OfferId}, {Column_UserId}, {Column_ItemGuid}) " + + $"{Command_Values} (@OfferId, @UserId, @ItemGuid)"; + } + + public static string Delete_OfferItem(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_OfferItemsByOfferId(SQLHelper SQLHelper, long OfferId) + { + SQLHelper.Parameters["@OfferId"] = OfferId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_OfferId} = @OfferId"; + } + + public static string Delete_OfferItemsBackupByOfferId(SQLHelper SQLHelper, long OfferId) + { + SQLHelper.Parameters["@OfferId"] = OfferId; + return $"{Command_Delete} {Command_From} {TableName_Backup} {Command_Where} {Column_OfferId} = @OfferId"; + } + } +} diff --git a/Library/SQLScript/Entity/OffersQuery.cs b/Library/SQLScript/Entity/OffersQuery.cs new file mode 100644 index 0000000..366186a --- /dev/null +++ b/Library/SQLScript/Entity/OffersQuery.cs @@ -0,0 +1,75 @@ +using Milimoe.FunGame.Core.Api.Transmittal; +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class OffersQuery : Constant + { + public const string TableName = "Offers"; + public const string Column_Id = "Id"; + public const string Column_Offeror = "Offeror"; + public const string Column_Offeree = "Offeree"; + public const string Column_CreateTime = "CreateTime"; + public const string Column_FinishTime = "FinishTime"; + public const string Column_Status = "Status"; + public const string Column_NegotiatedTimes = "NegotiatedTimes"; + + public const string Select_Offers = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + + public static string Select_OfferById(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Select_Offers} {Command_Where} {Column_Id} = @Id"; + } + + public static string Select_OffersByOfferor(SQLHelper SQLHelper, long Offeror) + { + SQLHelper.Parameters["@Offeror"] = Offeror; + return $"{Select_Offers} {Command_Where} {Column_Offeror} = @Offeror"; + } + + public static string Select_OffersByOfferee(SQLHelper SQLHelper, long Offeree) + { + SQLHelper.Parameters["@Offeree"] = Offeree; + return $"{Select_Offers} {Command_Where} {Column_Offeree} = @Offeree"; + } + + public static string Insert_Offer(SQLHelper SQLHelper, long Offeror, long Offeree, OfferState Status, int NegotiatedTimes) + { + SQLHelper.Parameters["@Offeror"] = Offeror; + SQLHelper.Parameters["@Offeree"] = Offeree; + SQLHelper.Parameters["@Status"] = (int)Status; + SQLHelper.Parameters["@NegotiatedTimes"] = NegotiatedTimes; + + return $"{Command_Insert} {Command_Into} {TableName} ({Column_Offeror}, {Column_Offeree}, {Column_Status}, {Column_NegotiatedTimes}) " + + $"{Command_Values} (@Offeror, @Offeree, @Status, @NegotiatedTimes)"; + } + + public static string Update_OfferStatus(SQLHelper SQLHelper, long Id, OfferState Status) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@Status"] = (int)Status; + return $"{Command_Update} {TableName} {Command_Set} {Column_Status} = @Status {Command_Where} {Column_Id} = @Id"; + } + + public static string Update_OfferNegotiatedTimes(SQLHelper SQLHelper, long Id, int NegotiatedTimes) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@NegotiatedTimes"] = NegotiatedTimes; + return $"{Command_Update} {TableName} {Command_Set} {Column_NegotiatedTimes} = @NegotiatedTimes {Command_Where} {Column_Id} = @Id"; + } + + public static string Update_OfferFinishTime(SQLHelper SQLHelper, long Id, DateTime FinishTime) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@FinishTime"] = FinishTime; + return $"{Command_Update} {TableName} {Command_Set} {Column_FinishTime} = @FinishTime {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_Offer(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + } +} diff --git a/Library/SQLScript/Entity/RoomQuery.cs b/Library/SQLScript/Entity/RoomQuery.cs index c813b1c..cef0b24 100644 --- a/Library/SQLScript/Entity/RoomQuery.cs +++ b/Library/SQLScript/Entity/RoomQuery.cs @@ -1,4 +1,6 @@ -using Milimoe.FunGame.Core.Api.Transmittal; +using System.Text; +using Milimoe.FunGame.Core.Api.Transmittal; +using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Library.SQLScript.Entity { @@ -19,60 +21,130 @@ namespace Milimoe.FunGame.Core.Library.SQLScript.Entity public const string Column_Password = "Password"; public const string Column_MaxUsers = "MaxUsers"; public const string Select_Rooms = $"{Command_Select} {TableName}.{Command_All}, {UserQuery.TableName}.{UserQuery.Column_Username} {Command_As} {Column_RoomMasterName} " + - $"{Command_From} {TableName} {Command_LeftJoin} {UserQuery.TableName} {Command_On} {UserQuery.TableName}.{UserQuery.Column_UID} = {TableName}.{Column_RoomMaster}"; + $"{Command_From} {TableName} {Command_LeftJoin} {UserQuery.TableName} {Command_On} {UserQuery.TableName}.{UserQuery.Column_Id} = {TableName}.{Column_RoomMaster}"; - public static string Insert_CreateRoom(SQLHelper SQLHelper, string roomid, long roomMaster, Library.Constant.RoomType roomType, string gameModule, string gameMap, bool isRank, string password, int maxUsers) + public static string Select_IsExistRoom(SQLHelper SQLHelper, string Roomid) + { + SQLHelper.Parameters["@Roomid"] = Roomid; + return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_RoomID} = @Roomid"; + } + + public static string Select_RoomsByRoomState(SQLHelper SQLHelper, params RoomState[] States) + { + RoomState[] states = [.. States.Distinct()]; + if (states.Length == 0) + { + return $"{Select_Rooms} {Command_Where} 1 = 0"; + } + StringBuilder builder = new(); + builder.Append($" {Command_Where} {Column_RoomState} {Command_In} ("); + for (int i = 0; i < states.Length; i++) + { + if (i > 0) builder.Append(", "); + builder.Append($"@s{i}"); + SQLHelper.Parameters[$"@s{i}"] = states[i]; + } + builder.Append(')'); + return $"{Select_Rooms} {Command_Where} {builder}"; + } + + public static string Select_RoomsByGameModuleAndRoomState(SQLHelper SQLHelper, string GameModule = "", params RoomState[] States) + { + string sql = Select_Rooms; + string whereClause = ""; + + if (!string.IsNullOrEmpty(GameModule)) + { + SQLHelper.Parameters["@GameModule"] = GameModule; + whereClause += $"{Command_And} {Column_GameModule} = @GameModule\r\n"; + } + + RoomState[] states = [.. States.Distinct()]; + if (states.Length > 0) + { + StringBuilder builder = new(); + builder.Append($"{Command_And} {Column_RoomState} {Command_In} ("); + for (int i = 0; i < states.Length; i++) + { + if (i > 0) builder.Append(", "); + builder.Append($"@s{i}"); + SQLHelper.Parameters[$"@s{i}"] = states[i]; + } + builder.AppendLine(")"); + } + + if (!string.IsNullOrEmpty(whereClause)) + { + sql += $" {Command_Where} {whereClause[Command_And.Length..]}"; + } + + return sql.Trim(); + } + + public static string Insert_CreateRoom(SQLHelper SQLHelper, string Roomid, long RoomMaster, RoomType RoomType, string GameModule, string GameMap, bool IsRank, string Password, int MaxUsers) { Library.Constant.RoomState RoomState = Library.Constant.RoomState.Created; DateTime NowTime = DateTime.Now; - bool HasPass = password.Trim() != ""; + bool HasPass = Password.Trim() != ""; - SQLHelper.Parameters["@roomid"] = roomid; + SQLHelper.Parameters["@Roomid"] = Roomid; SQLHelper.Parameters["@CreateTime"] = NowTime; - SQLHelper.Parameters["@roomMaster"] = roomMaster; - SQLHelper.Parameters["@roomType"] = (int)roomType; - SQLHelper.Parameters["@gameModule"] = gameModule; - SQLHelper.Parameters["@gameMap"] = gameMap; + SQLHelper.Parameters["@RoomMaster"] = RoomMaster; + SQLHelper.Parameters["@RoomType"] = (int)RoomType; + SQLHelper.Parameters["@GameModule"] = GameModule; + SQLHelper.Parameters["@GameMap"] = GameMap; SQLHelper.Parameters["@RoomState"] = (int)RoomState; - SQLHelper.Parameters["@isRank"] = isRank ? 1 : 0; + SQLHelper.Parameters["@IsRank"] = IsRank ? 1 : 0; SQLHelper.Parameters["@HasPass"] = HasPass ? 1 : 0; - SQLHelper.Parameters["@password"] = password; - SQLHelper.Parameters["@maxUsers"] = maxUsers; + SQLHelper.Parameters["@Password"] = Password; + SQLHelper.Parameters["@MaxUsers"] = MaxUsers; return $"{Command_Insert} {Command_Into} {TableName} ({Column_RoomID}, {Column_CreateTime}, {Column_RoomMaster}, {Column_RoomType}, {Column_GameModule}, {Column_GameMap}, {Column_RoomState}, {Column_IsRank}, {Column_HasPass}, {Column_Password}, {Column_MaxUsers})" + - $" {Command_Values} (@roomid, @CreateTime, @roomMaster, @roomType, @gameModule, @gameMap, @RoomState, @isRank, @HasPass, @password, @maxUsers)"; + $" {Command_Values} (@Roomid, @CreateTime, @RoomMaster, @RoomType, @GameModule, @GameMap, @RoomState, @IsRank, @HasPass, @Password, @MaxUsers)"; } - public static string Delete_Rooms(SQLHelper SQLHelper, params string[] roomids) + public static string Delete_Rooms(SQLHelper SQLHelper, params string[] RoomIDs) { - if (roomids.Length != 0) + if (RoomIDs.Length != 0) { - string where = string.Join("', '", roomids); - SQLHelper.Parameters["@roomids"] = where; - return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_RoomID} {Command_In} (@roomids)"; + string[] roomids = [.. RoomIDs.Distinct()]; + if (roomids.Length > 0) + { + StringBuilder builder = new(); + builder.Append($"{Command_Where} {Column_RoomState} {Command_In} ("); + for (int i = 0; i < roomids.Length; i++) + { + if (i > 0) builder.Append(", "); + builder.Append($"@room{i}"); + SQLHelper.Parameters[$"@room{i}"] = roomids[i]; + } + builder.AppendLine(")"); + return $"{Command_Delete} {Command_From} {TableName} {builder}"; + } } - return $"{Command_Delete} {Command_From} {TableName}"; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} 1 = 0"; } - public static string Delete_QuitRoom(SQLHelper SQLHelper, string roomID, long roomMaster) + public static string Delete_QuitRoom(SQLHelper SQLHelper, string RoomID, long RoomMaster) { - SQLHelper.Parameters["@roomID"] = roomID; - SQLHelper.Parameters["@roomMaster"] = roomMaster; - return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_RoomID} = @roomID {Command_And} {Column_RoomMaster} = @roomMaster"; + SQLHelper.Parameters["@RoomID"] = RoomID; + SQLHelper.Parameters["@RoomMaster"] = RoomMaster; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_RoomID} = @RoomID {Command_And} {Column_RoomMaster} = @RoomMaster"; } - public static string Update_QuitRoom(SQLHelper SQLHelper, string roomid, long oldRoomMaster, long newRoomMaster) + public static string Update_QuitRoom(SQLHelper SQLHelper, string RoomID, long OldRoomMaster, long NewRoomMaster) { - SQLHelper.Parameters["@roomid"] = roomid; - SQLHelper.Parameters["@oldRoomMaster"] = oldRoomMaster; - SQLHelper.Parameters["@newRoomMaster"] = newRoomMaster; - return $"{Command_Update} {TableName} {Command_Set} {Column_RoomMaster} = @newRoomMaster {Command_Where} {Column_RoomID} = @roomid {Command_And} {Column_RoomMaster} = @oldRoomMaster"; + SQLHelper.Parameters["@RoomID"] = RoomID; + SQLHelper.Parameters["@OldRoomMaster"] = OldRoomMaster; + SQLHelper.Parameters["@NewRoomMaster"] = NewRoomMaster; + return $"{Command_Update} {TableName} {Command_Set} {Column_RoomMaster} = @NewRoomMaster {Command_Where} {Column_RoomID} = @Roomid {Command_And} {Column_RoomMaster} = @OldRoomMaster"; } - - public static string Select_IsExistRoom(SQLHelper SQLHelper, string roomid) + + public static string Update_UpdateRoomMaster(SQLHelper SQLHelper, string RoomID, long NewRoomMaster) { - SQLHelper.Parameters["@roomid"] = roomid; - return $"{Command_Select} {Command_All} {Command_From} {TableName} {Command_Where} {Column_RoomID} = @roomid"; + SQLHelper.Parameters["@RoomID"] = RoomID; + SQLHelper.Parameters["@NewRoomMaster"] = NewRoomMaster; + return $"{Command_Update} {TableName} {Command_Set} {Column_RoomMaster} = @NewRoomMaster {Command_Where} {Column_RoomID} = @RoomID"; } } } diff --git a/Library/SQLScript/Entity/StoreGoodsQuery.cs b/Library/SQLScript/Entity/StoreGoodsQuery.cs new file mode 100644 index 0000000..694a412 --- /dev/null +++ b/Library/SQLScript/Entity/StoreGoodsQuery.cs @@ -0,0 +1,65 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class StoreGoodsQuery : Constant + { + public const string TableName = "StoreGoods"; + public const string Column_Id = "Id"; + public const string Column_StoreId = "StoreId"; + public const string Column_GoodsId = "GoodsId"; + + public const string Select_StoreGoods = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + + public static string Select_StoreGoodsByStoreId(SQLHelper SQLHelper, long StoreId) + { + SQLHelper.Parameters["@StoreId"] = StoreId; + return $"{Select_StoreGoods} {Command_Where} {Column_StoreId} = @StoreId"; + } + + public static string Select_StoreGoodsByGoodsId(SQLHelper SQLHelper, long GoodsId) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + return $"{Select_StoreGoods} {Command_Where} {Column_GoodsId} = @GoodsId"; + } + + public static string Select_StoreGoodsByStoreIdAndGoodsId(SQLHelper SQLHelper, long StoreId, long goodsId) + { + SQLHelper.Parameters["@StoreId"] = StoreId; + SQLHelper.Parameters["@GoodsId"] = goodsId; + return $"{Select_StoreGoods} {Command_Where} {Column_StoreId} = @StoreId {Command_And} {Column_GoodsId} = @GoodsId"; + } + + public static string Insert_StoreGoods(SQLHelper SQLHelper, long StoreId, long GoodsId) + { + SQLHelper.Parameters["@StoreId"] = StoreId; + SQLHelper.Parameters["@GoodsId"] = GoodsId; + return $"{Command_Insert} {Command_Into} {TableName} ({Column_StoreId}, {Column_GoodsId}) {Command_Values} (@StoreId, @GoodsId)"; + } + + public static string Delete_StoreGoods(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_StoreGoodsByStoreId(SQLHelper SQLHelper, long StoreId) + { + SQLHelper.Parameters["@StoreId"] = StoreId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_StoreId} = @StoreId"; + } + + public static string Delete_StoreGoodsByGoodsId(SQLHelper SQLHelper, long GoodsId) + { + SQLHelper.Parameters["@GoodsId"] = GoodsId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_GoodsId} = @GoodsId"; + } + + public static string Delete_StoreGoodsByStoreIdAndGoodsId(SQLHelper SQLHelper, long StoreId, long GoodsId) + { + SQLHelper.Parameters["@StoreId"] = StoreId; + SQLHelper.Parameters["@GoodsId"] = GoodsId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_StoreId} = @StoreId {Command_And} {Column_GoodsId} = @GoodsId"; + } + } +} diff --git a/Library/SQLScript/Entity/StoreQuery.cs b/Library/SQLScript/Entity/StoreQuery.cs new file mode 100644 index 0000000..547a332 --- /dev/null +++ b/Library/SQLScript/Entity/StoreQuery.cs @@ -0,0 +1,70 @@ +using Milimoe.FunGame.Core.Api.Transmittal; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class StoreQuery : Constant + { + public const string TableName = "Stores"; + public const string Column_Id = "Id"; + public const string Column_StoreName = "StoreName"; + public const string Column_StartTime = "StartTime"; + public const string Column_EndTime = "EndTime"; + public const string Column_StoreId = "StoreId"; + public const string Column_GoodsId = "GoodsId"; + public const string Column_GoodsName = "GoodsName"; + + public const string Select_Stores = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + public const string Select_StoresWithGoods = $"{Command_Select} {TableName}.{Column_Id} {Column_StoreId}, {TableName}.{Column_StoreName}, " + + $"{GoodsQuery.TableName}.{GoodsQuery.Column_Id} {Column_GoodsId}, {GoodsQuery.TableName}.{GoodsQuery.Column_Name} {Column_GoodsName}, " + + $"{GoodsQuery.TableName}.{GoodsQuery.Column_Description}, {GoodsQuery.TableName}.{GoodsQuery.Column_Stock}, " + + $"{GoodsItemsQuery.TableName}.{GoodsItemsQuery.Column_ItemId}, {GoodsPricesQuery.TableName}.{GoodsPricesQuery.Column_Currency}, {GoodsPricesQuery.TableName}.{GoodsPricesQuery.Column_Price} " + + $"{Command_From} {StoreGoodsQuery.TableName}\r\n" + + $"{Command_LeftJoin} {TableName} {Command_On} {TableName}.{Column_Id} = {StoreGoodsQuery.TableName}.{StoreGoodsQuery.Column_StoreId}\r\n" + + $"{Command_LeftJoin} {GoodsQuery.TableName} {Command_On} {GoodsQuery.TableName}.{GoodsQuery.Column_Id} = {StoreGoodsQuery.TableName}.{StoreGoodsQuery.Column_GoodsId}\r\n" + + $"{Command_LeftJoin} {GoodsItemsQuery.TableName} {Command_On} {GoodsItemsQuery.TableName}.{GoodsItemsQuery.Column_GoodsId} = {GoodsQuery.TableName}.{GoodsQuery.Column_Id}\r\n" + + $"{Command_LeftJoin} {GoodsPricesQuery.TableName} {Command_On} {GoodsPricesQuery.TableName}.{GoodsPricesQuery.Column_GoodsId} = {GoodsQuery.TableName}.{GoodsQuery.Column_Id}"; + + public static string Select_StoreById(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Select_Stores} {Command_Where} {Column_Id} = @Id"; + } + + public static string Insert_Store(SQLHelper SQLHelper, string StoreName, DateTime? StartTime, DateTime? EndTime) + { + SQLHelper.Parameters["@StoreName"] = StoreName; + if (StartTime.HasValue) SQLHelper.Parameters["@StartTime"] = StartTime; + if (EndTime.HasValue) SQLHelper.Parameters["@EndTime"] = EndTime; + + return $"{Command_Insert} {Command_Into} {TableName} ({Column_StoreName}{(StartTime.HasValue ? $", {Column_StartTime}" : "")}{(EndTime.HasValue ? $", {Column_EndTime}" : "")}) " + + $"{Command_Values} (@StoreName{(StartTime.HasValue ? ", @StartTime" : "")}{(EndTime.HasValue ? ", @EndTime" : "")})"; + } + + public static string Update_Store(SQLHelper SQLHelper, long Id, string StoreName, DateTime? StartTime, DateTime? EndTime) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@StoreName"] = StoreName; + if (StartTime.HasValue) SQLHelper.Parameters["@StartTime"] = StartTime; + if (EndTime.HasValue) SQLHelper.Parameters["@EndTime"] = EndTime; + return $"{Command_Update} {TableName} {Command_Set} {Column_StoreName} = @StoreName{(StartTime.HasValue ? $", {Column_StartTime} = @StartTime" : "")}{(EndTime.HasValue ? $", {Column_EndTime} = @EndTime" : "")} {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_Store(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Select_AllGoodsInStore(SQLHelper SQLHelper, long StoreId = 0) + { + if (StoreId != 0) + { + SQLHelper.Parameters["@StoreId"] = StoreId; + } + + string sql = $"{Select_StoresWithGoods}{(StoreId != 0 ? $"\r\n{Command_Where} {StoreGoodsQuery.TableName}.{StoreGoodsQuery.Column_StoreId} = @StoreId" : "")}"; + + return sql; + } + } +} diff --git a/Library/SQLScript/Entity/UserCharactersQuery.cs b/Library/SQLScript/Entity/UserCharactersQuery.cs new file mode 100644 index 0000000..182c3fd --- /dev/null +++ b/Library/SQLScript/Entity/UserCharactersQuery.cs @@ -0,0 +1,150 @@ +using Milimoe.FunGame.Core.Api.Transmittal; +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class UserCharactersQuery : Constant + { + public const string TableName = "UserCharacters"; + public const string Column_Id = "Id"; + public const string Column_CharacterId = "CharacterId"; + public const string Column_UserId = "UserId"; + public const string Column_Name = "Name"; + public const string Column_FirstName = "FirstName"; + public const string Column_NickName = "NickName"; + public const string Column_PrimaryAttribute = "PrimaryAttribute"; + public const string Column_InitialATK = "InitialATK"; + public const string Column_InitialDEF = "InitialDEF"; + public const string Column_InitialHP = "InitialHP"; + public const string Column_InitialMP = "InitialMP"; + public const string Column_InitialSTR = "InitialSTR"; + public const string Column_InitialAGI = "InitialAGI"; + public const string Column_InitialINT = "InitialINT"; + public const string Column_InitialSPD = "InitialSPD"; + public const string Column_InitialHR = "InitialHR"; + public const string Column_InitialMR = "InitialMR"; + public const string Column_Level = "Level"; + public const string Column_LevelBreak = "LevelBreak"; + public const string Column_InSquad = "InSquad"; + public const string Column_TrainingTime = "TrainingTime"; + + public const string Select_UserCharacters = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + + public static string Select_UserCharacterById(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Select_UserCharacters} {Command_Where} {Column_Id} = @Id"; + } + + public static string Select_UserCharactersByCharacterId(SQLHelper SQLHelper, long CharacterId) + { + SQLHelper.Parameters["@CharacterId"] = CharacterId; + return $"{Select_UserCharacters} {Command_Where} {Column_CharacterId} = @CharacterId"; + } + + public static string Select_UserCharactersByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Select_UserCharacters} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Insert_UserCharacter(SQLHelper SQLHelper, long CharacterId, long UserId, string Name, string FirstName, string NickName, + PrimaryAttribute PrimaryAttribute, double InitialATK, double InitialDEF, double InitialHP, double InitialMP, double InitialSTR, double InitialAGI, double InitialINT, + double InitialSPD, double InitialHR, double InitialMR, int Level, int LevelBreak, bool InSquad, DateTime? TrainingTime = null) + { + SQLHelper.Parameters["@CharacterId"] = CharacterId; + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Name"] = Name; + SQLHelper.Parameters["@FirstName"] = FirstName; + SQLHelper.Parameters["@NickName"] = NickName; + SQLHelper.Parameters["@PrimaryAttribute"] = (int)PrimaryAttribute; + SQLHelper.Parameters["@InitialATK"] = InitialATK; + SQLHelper.Parameters["@InitialDEF"] = InitialDEF; + SQLHelper.Parameters["@InitialHP"] = InitialHP; + SQLHelper.Parameters["@InitialMP"] = InitialMP; + SQLHelper.Parameters["@InitialAGI"] = InitialAGI; + SQLHelper.Parameters["@InitialINT"] = InitialINT; + SQLHelper.Parameters["@InitialSTR"] = InitialSTR; + SQLHelper.Parameters["@InitialSPD"] = InitialSPD; + SQLHelper.Parameters["@InitialHR"] = InitialHR; + SQLHelper.Parameters["@InitialMR"] = InitialMR; + SQLHelper.Parameters["@Level"] = Level; + SQLHelper.Parameters["@LevelBreak"] = LevelBreak; + SQLHelper.Parameters["@InSquad"] = InSquad ? 1 : 0; + if (TrainingTime.HasValue) SQLHelper.Parameters["@TrainingTime"] = TrainingTime; + + string sql = $"{Command_Insert} {Command_Into} {TableName} (" + + $"{Column_CharacterId}, {Column_UserId}, {Column_Name}, {Column_FirstName}, {Column_NickName}, {Column_PrimaryAttribute}, " + + $"{Column_InitialATK}, {Column_InitialDEF}, {Column_InitialHP}, {Column_InitialMP}, {Column_InitialSTR}, {Column_InitialAGI}, " + + $"{Column_InitialINT}, {Column_InitialSPD}, {Column_InitialHR}, {Column_InitialMR}, {Column_Level}, {Column_LevelBreak}, {Column_InSquad}" + + $"{(TrainingTime.HasValue ? $", {Column_TrainingTime}" : "")}) " + + $"{Command_Values} (" + + $"@CharacterId, @UserId, @Name, @FirstName, @NickName, @PrimaryAttribute, " + + $"@InitialATK, @InitialDEF, @InitialHP, @InitialMP, @InitialSTR, @InitialAGI, " + + $"@InitialINT, @InitialSPD, @InitialHR, @InitialMR, @Level, @LevelBreak, @InSquad" + + $"{(TrainingTime.HasValue ? ", @TrainingTime" : "")})"; + return sql; + } + + public static string Update_UserCharacter(SQLHelper SQLHelper, long Id, long CharacterId, long UserId, string Name, string FirstName, string NickName, + PrimaryAttribute PrimaryAttribute, double InitialATK, double InitialDEF, double InitialHP, double InitialMP, double InitialSTR, double InitialAGI, double InitialINT, + double InitialSPD, double InitialHR, double InitialMR, int Level, int LevelBreak, bool InSquad, DateTime? TrainingTime = null) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@CharacterId"] = CharacterId; + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@Name"] = Name; + SQLHelper.Parameters["@FirstName"] = FirstName; + SQLHelper.Parameters["@NickName"] = NickName; + SQLHelper.Parameters["@PrimaryAttribute"] = (int)PrimaryAttribute; + SQLHelper.Parameters["@InitialATK"] = InitialATK; + SQLHelper.Parameters["@InitialDEF"] = InitialDEF; + SQLHelper.Parameters["@InitialHP"] = InitialHP; + SQLHelper.Parameters["@InitialMP"] = InitialMP; + SQLHelper.Parameters["@InitialAGI"] = InitialAGI; + SQLHelper.Parameters["@InitialINT"] = InitialINT; + SQLHelper.Parameters["@InitialSTR"] = InitialSTR; + SQLHelper.Parameters["@InitialSPD"] = InitialSPD; + SQLHelper.Parameters["@InitialHR"] = InitialHR; + SQLHelper.Parameters["@InitialMR"] = InitialMR; + SQLHelper.Parameters["@Level"] = Level; + SQLHelper.Parameters["@LevelBreak"] = LevelBreak; + SQLHelper.Parameters["@InSquad"] = InSquad ? 1 : 0; + if (TrainingTime.HasValue) SQLHelper.Parameters["@TrainingTime"] = TrainingTime; + + string sql = $"{Command_Update} {TableName} {Command_Set} " + + $"{Column_CharacterId} = @CharacterId, {Column_UserId} = @UserId, {Column_Name} = @Name, {Column_FirstName} = @FirstName, {Column_NickName} = @NickName, " + + $"{Column_PrimaryAttribute} = @PrimaryAttribute, {Column_InitialATK} = @InitialATK, {Column_InitialDEF} = @InitialDEF, {Column_InitialHP} = @InitialHP, " + + $"{Column_InitialMP} = @InitialMP, {Column_InitialSTR} = @InitialSTR, {Column_InitialAGI} = @InitialAGI, {Column_InitialINT} = @InitialINT, {Column_InitialSPD} = @InitialSPD, " + + $"{Column_InitialHR} = @InitialHR, {Column_InitialMR} = @InitialMR, {Column_Level} = @Level, {Column_LevelBreak} = @LevelBreak, {Column_InSquad} = @InSquad" + + $"{(TrainingTime.HasValue ? $", {Column_TrainingTime} = @TrainingTime" : "")} " + + $"{Command_Where} {Column_Id} = @Id"; + return sql; + } + + public static string Update_UserCharacterSquadState(SQLHelper SQLHelper, long Id, int InSquad) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@InSquad"] = InSquad; + return $"{Command_Update} {TableName} {Command_Set} {Column_InSquad} = @InSquad {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_UserCharacter(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_UserCharactersByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Delete_UserCharacterByCharacterId(SQLHelper SQLHelper, long CharacterId) + { + SQLHelper.Parameters["@CharacterId"] = CharacterId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_CharacterId} = @CharacterId"; + } + } +} diff --git a/Library/SQLScript/Entity/UserItemsQuery.cs b/Library/SQLScript/Entity/UserItemsQuery.cs new file mode 100644 index 0000000..94f23fa --- /dev/null +++ b/Library/SQLScript/Entity/UserItemsQuery.cs @@ -0,0 +1,187 @@ +using Milimoe.FunGame.Core.Api.Transmittal; +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class UserItemsQuery : Constant + { + public const string TableName = "UserItems"; + public const string Column_Id = "Id"; + public const string Column_ItemId = "ItemId"; + public const string Column_Guid = "Guid"; + public const string Column_UserId = "UserId"; + public const string Column_CharacterId = "CharacterId"; + public const string Column_ItemName = "ItemName"; + public const string Column_IsLock = "IsLock"; + public const string Column_Equipable = "Equipable"; + public const string Column_Unequipable = "Unequipable"; + public const string Column_EquipSlotType = "EquipSlotType"; + public const string Column_Key = "Key"; + public const string Column_Enable = "Enable"; + public const string Column_Price = "Price"; + public const string Column_IsSellable = "IsSellable"; + public const string Column_IsTradable = "IsTradable"; + public const string Column_NextSellableTime = "NextSellableTime"; + public const string Column_NextTradableTime = "NextTradableTime"; + public const string Column_RemainUseTimes = "RemainUseTimes"; + + public const string Select_UserItems = $"{Command_Select} {Command_All} {Command_From} {TableName}"; + + public static string Select_UserItemById(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Select_UserItems} {Command_Where} {Column_Id} = @Id"; + } + + public static string Select_UserItemByGuid(SQLHelper SQLHelper, Guid Guid) + { + SQLHelper.Parameters["@Guid"] = Guid; + return $"{Select_UserItems} {Command_Where} {Column_Guid} = @Guid"; + } + + public static string Select_UserItemsByItemId(SQLHelper SQLHelper, long ItemId) + { + SQLHelper.Parameters["@ItemId"] = ItemId; + return $"{Select_UserItems} {Command_Where} {Column_ItemId} = @ItemId"; + } + + public static string Select_UserItemsByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Select_UserItems} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Select_UserItemsByCharacterId(SQLHelper SQLHelper, long CharacterId) + { + SQLHelper.Parameters["@CharacterId"] = CharacterId; + return $"{Select_UserItems} {Command_Where} {Column_CharacterId} = @CharacterId"; + } + + public static string Insert_UserItem(SQLHelper SQLHelper, long ItemId, Guid Guid, long UserId, long CharacterId, string ItemName, + bool IsLock, bool Equipable, bool Unequipable, EquipSlotType EquipSlotType, int Key, bool Enable, double Price, bool IsSellable, bool IsTradable, + DateTime? NextSellableTime, DateTime? NextTradableTime, int RemainUseTimes) + { + SQLHelper.Parameters["@ItemId"] = ItemId; + SQLHelper.Parameters["@Guid"] = Guid.ToString(); + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@CharacterId"] = CharacterId; + SQLHelper.Parameters["@ItemName"] = ItemName; + SQLHelper.Parameters["@IsLock"] = IsLock ? 1 : 0; + SQLHelper.Parameters["@Equipable"] = Equipable ? 1 : 0; + SQLHelper.Parameters["@Unequipable"] = Unequipable ? 1 : 0; + SQLHelper.Parameters["@EquipSlotType"] = (int)EquipSlotType; + SQLHelper.Parameters["@Key"] = Key; + SQLHelper.Parameters["@Enable"] = Enable ? 1 : 0; + SQLHelper.Parameters["@Price"] = Price; + SQLHelper.Parameters["@IsSellable"] = IsSellable ? 1 : 0; + SQLHelper.Parameters["@IsTradable"] = IsTradable ? 1 : 0; + if (NextSellableTime.HasValue) SQLHelper.Parameters["@NextSellableTime"] = NextSellableTime; + if (NextTradableTime.HasValue) SQLHelper.Parameters["@NextTradableTime"] = NextTradableTime; + SQLHelper.Parameters["@RemainUseTimes"] = RemainUseTimes; + + string sql = $"{Command_Insert} {Command_Into} {TableName} " + + $"({Column_ItemId}, {Column_Guid}, {Column_UserId}, {Column_CharacterId}, {Column_ItemName}, {Column_IsLock}, {Column_Equipable}, {Column_Unequipable}, {Column_EquipSlotType}, {Column_Key}, {Column_Enable}, {Column_Price}, {Column_IsSellable}, {Column_IsTradable}, {Column_RemainUseTimes}" + + $"{(NextSellableTime.HasValue ? $", {Column_NextSellableTime}" : "")}" + + $"{(NextTradableTime.HasValue ? $", {Column_NextTradableTime}" : "")}) " + + $"{Command_Values} (@ItemId, @Guid, @UserId, @CharacterId, @ItemName, @IsLock, @Equipable, @Unequipable, @EquipSlotType, @Key, @Enable, @Price, @IsSellable, @IsTradable, @RemainUseTimes" + + $"{(NextSellableTime.HasValue ? ", @NextSellableTime" : "")}" + + $"{(NextTradableTime.HasValue ? ", @NextTradableTime" : "")})"; + return sql; + } + + public static string Update_UserItem(SQLHelper SQLHelper, long Id, long ItemId, long UserId, long CharacterId, string ItemName, + bool IsLock, bool Equipable, bool Unequipable, EquipSlotType EquipSlotType, int Key, bool Enable, double Price, bool IsSellable, bool IsTradable, + DateTime? NextSellableTime, DateTime? NextTradableTime, int RemainUseTimes) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@ItemId"] = ItemId; + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@CharacterId"] = CharacterId; + SQLHelper.Parameters["@ItemName"] = ItemName; + SQLHelper.Parameters["@IsLock"] = IsLock ? 1 : 0; + SQLHelper.Parameters["@Equipable"] = Equipable ? 1 : 0; + SQLHelper.Parameters["@Unequipable"] = Unequipable ? 1 : 0; + SQLHelper.Parameters["@EquipSlotType"] = (int)EquipSlotType; + SQLHelper.Parameters["@Key"] = Key; + SQLHelper.Parameters["@Enable"] = Enable ? 1 : 0; + SQLHelper.Parameters["@Price"] = Price; + SQLHelper.Parameters["@IsSellable"] = IsSellable ? 1 : 0; + SQLHelper.Parameters["@IsTradable"] = IsTradable ? 1 : 0; + if (NextSellableTime.HasValue) SQLHelper.Parameters["@NextSellableTime"] = NextSellableTime; + if (NextTradableTime.HasValue) SQLHelper.Parameters["@NextTradableTime"] = NextTradableTime; + SQLHelper.Parameters["@RemainUseTimes"] = RemainUseTimes; + + string sql = $"{Command_Update} {TableName} {Command_Set} " + + $"{Column_ItemId} = @ItemId, {Column_UserId} = @UserId, {Column_CharacterId} = @CharacterId, {Column_ItemName} = @ItemName, " + + $"{Column_IsLock} = @IsLock, {Column_Equipable} = @Equipable, {Column_Unequipable} = @Unequipable, {Column_EquipSlotType} = @EquipSlotType, " + + $"{Column_Key} = @Key, {Column_Enable} = @Enable, {Column_Price} = @Price, {Column_IsSellable} = @IsSellable, {Column_IsTradable} = @IsTradable, {Column_RemainUseTimes} = @RemainUseTimes" + + $"{(NextSellableTime.HasValue ? $", {Column_NextSellableTime} = @NextSellableTime" : "")}" + + $"{(NextTradableTime.HasValue ? $", {Column_NextTradableTime} = @NextTradableTime" : "")} " + + $"{Command_Where} {Column_Id} = @Id"; + return sql; + } + + public static string Update_UserItem(SQLHelper SQLHelper, Guid Guid, long ItemId, long UserId, long CharacterId, string ItemName, + bool IsLock, bool Equipable, bool Unequipable, EquipSlotType EquipSlotType, int Key, bool Enable, double Price, bool IsSellable, bool IsTradable, + DateTime? NextSellableTime, DateTime? NextTradableTime, int RemainUseTimes) + { + SQLHelper.Parameters["@Guid"] = Guid.ToString(); + SQLHelper.Parameters["@ItemId"] = ItemId; + SQLHelper.Parameters["@UserId"] = UserId; + SQLHelper.Parameters["@CharacterId"] = CharacterId; + SQLHelper.Parameters["@ItemName"] = ItemName; + SQLHelper.Parameters["@IsLock"] = IsLock ? 1 : 0; + SQLHelper.Parameters["@Equipable"] = Equipable ? 1 : 0; + SQLHelper.Parameters["@Unequipable"] = Unequipable ? 1 : 0; + SQLHelper.Parameters["@EquipSlotType"] = (int)EquipSlotType; + SQLHelper.Parameters["@Key"] = Key; + SQLHelper.Parameters["@Enable"] = Enable ? 1 : 0; + SQLHelper.Parameters["@Price"] = Price; + SQLHelper.Parameters["@IsSellable"] = IsSellable ? 1 : 0; + SQLHelper.Parameters["@IsTradable"] = IsTradable ? 1 : 0; + if (NextSellableTime.HasValue) SQLHelper.Parameters["@NextSellableTime"] = NextSellableTime; + if (NextTradableTime.HasValue) SQLHelper.Parameters["@NextTradableTime"] = NextTradableTime; + SQLHelper.Parameters["@RemainUseTimes"] = RemainUseTimes; + + string sql = $"{Command_Update} {TableName} {Command_Set} " + + $"{Column_ItemId} = @ItemId, {Column_UserId} = @UserId, {Column_CharacterId} = @CharacterId, {Column_ItemName} = @ItemName, " + + $"{Column_IsLock} = @IsLock, {Column_Equipable} = @Equipable, {Column_Unequipable} = @Unequipable, {Column_EquipSlotType} = @EquipSlotType, " + + $"{Column_Key} = @Key, {Column_Enable} = @Enable, {Column_Price} = @Price, {Column_IsSellable} = @IsSellable, {Column_IsTradable} = @IsTradable, {Column_RemainUseTimes} = @RemainUseTimes" + + $"{(NextSellableTime.HasValue ? $", {Column_NextSellableTime} = @NextSellableTime" : "")}" + + $"{(NextTradableTime.HasValue ? $", {Column_NextTradableTime} = @NextTradableTime" : "")} " + + $"{Command_Where} {Column_Guid} = @Guid"; + return sql; + } + + public static string Update_UserItemLockState(SQLHelper SQLHelper, long Id, int IsLock) + { + SQLHelper.Parameters["@Id"] = Id; + SQLHelper.Parameters["@IsLock"] = IsLock; + return $"{Command_Update} {TableName} {Command_Set} {Column_IsLock} = @IsLock {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_UserItem(SQLHelper SQLHelper, long Id) + { + SQLHelper.Parameters["@Id"] = Id; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Id} = @Id"; + } + + public static string Delete_UserItem(SQLHelper SQLHelper, Guid Guid) + { + SQLHelper.Parameters["@Guid"] = Guid; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_Guid} = @Guid"; + } + + public static string Delete_UserItemsByUserId(SQLHelper SQLHelper, long UserId) + { + SQLHelper.Parameters["@UserId"] = UserId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_UserId} = @UserId"; + } + + public static string Delete_UserItemByCharacterId(SQLHelper SQLHelper, long CharacterId) + { + SQLHelper.Parameters["@CharacterId"] = CharacterId; + return $"{Command_Delete} {Command_From} {TableName} {Command_Where} {Column_CharacterId} = @CharacterId"; + } + } +} diff --git a/Library/SQLScript/Entity/UserQuery.cs b/Library/SQLScript/Entity/UserQuery.cs index bb4fc9f..42e72b9 100644 --- a/Library/SQLScript/Entity/UserQuery.cs +++ b/Library/SQLScript/Entity/UserQuery.cs @@ -5,7 +5,7 @@ namespace Milimoe.FunGame.Core.Library.SQLScript.Entity public class UserQuery : Constant { public const string TableName = "Users"; - public const string Column_UID = "UID"; + public const string Column_Id = "Id"; public const string Column_Username = "Username"; public const string Column_Password = "Password"; public const string Column_RegTime = "RegTime"; @@ -27,6 +27,12 @@ namespace Milimoe.FunGame.Core.Library.SQLScript.Entity return $"{Select_Users} {Command_Where} {Column_Username} = @Username and {Column_Password} = @Password"; } + public static string Select_UserById(SQLHelper SQLHelper, long id) + { + SQLHelper.Parameters["@Id"] = id; + return $"{Select_Users} {Command_Where} {Column_Id} = @Id"; + } + public static string Select_IsExistEmail(SQLHelper SQLHelper, string Email) { SQLHelper.Parameters["@Email"] = Email; diff --git a/Library/SQLScript/fungame.sql b/Library/SQLScript/fungame.sql index 90251ae..7175df9 100644 --- a/Library/SQLScript/fungame.sql +++ b/Library/SQLScript/fungame.sql @@ -1,14 +1,141 @@ SET FOREIGN_KEY_CHECKS=0; +-- ---------------------------- +-- Table structure for ApiTokens +-- ---------------------------- +DROP TABLE IF EXISTS `ApiTokens`; +CREATE TABLE `ApiTokens` ( + `TokenID` varchar(255) NOT NULL DEFAULT '', + `SecretKey` varchar(255) NOT NULL DEFAULT '', + `Reference1` varchar(255) NOT NULL DEFAULT '', + `Reference2` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY (`TokenID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for Configs +-- ---------------------------- +DROP TABLE IF EXISTS `Configs`; +CREATE TABLE `Configs` ( + `Id` varchar(255) NOT NULL DEFAULT '', + `Content` varchar(255) NOT NULL DEFAULT '', + `Description` varchar(255) NOT NULL DEFAULT '', + `UpdateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + -- ---------------------------- -- Table structure for ForgetVerifyCodes -- ---------------------------- DROP TABLE IF EXISTS `ForgetVerifyCodes`; CREATE TABLE `ForgetVerifyCodes` ( - `Username` varchar(255) NOT NULL DEFAULT '', - `Email` varchar(255) NOT NULL DEFAULT '', - `ForgetVerifyCode` varchar(255) NOT NULL DEFAULT '', - `SendTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP + `Username` varchar(255) NOT NULL DEFAULT '', + `Email` varchar(255) NOT NULL DEFAULT '', + `ForgetVerifyCode` varchar(255) NOT NULL DEFAULT '', + `SendTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for GoodsItems +-- ---------------------------- +DROP TABLE IF EXISTS `GoodsItems`; +CREATE TABLE `GoodsItems` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `GoodsId` bigint(20) NOT NULL DEFAULT '0', + `ItemId` bigint(20) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for GoodsPrices +-- ---------------------------- +DROP TABLE IF EXISTS `GoodsPrices`; +CREATE TABLE `GoodsPrices` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `GoodsId` bigint(20) NOT NULL DEFAULT '0', + `Currency` varchar(255) NOT NULL DEFAULT '', + `Price` double(20,0) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for Goods +-- ---------------------------- +DROP TABLE IF EXISTS `Goods`; +CREATE TABLE `Goods` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `Name` varchar(255) NOT NULL DEFAULT '', + `Description` varchar(255) NOT NULL DEFAULT '', + `Stock` int(10) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for Inventories +-- ---------------------------- +DROP TABLE IF EXISTS `Inventories`; +CREATE TABLE `Inventories` ( + `UserId` bigint(20) NOT NULL DEFAULT '0', + `Name` varchar(255) NOT NULL DEFAULT '', + `Credits` double(20,0) NOT NULL DEFAULT '0', + `Materials` double(20,0) NOT NULL DEFAULT '0', + `MainCharacter` bigint(20) NOT NULL DEFAULT '0', + PRIMARY KEY (`UserId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for MarketItems +-- ---------------------------- +DROP TABLE IF EXISTS `MarketItems`; +CREATE TABLE `MarketItems` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `ItemGuid` varchar(255) NOT NULL DEFAULT '', + `UserId` bigint(20) NOT NULL DEFAULT '0', + `Price` double(20,0) NOT NULL DEFAULT '0', + `CreateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `FinishTime` datetime DEFAULT NULL, + `Status` int(10) NOT NULL DEFAULT '0', + `Buyer` bigint(20) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`,`ItemId`,`UserId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for OfferItems +-- ---------------------------- +DROP TABLE IF EXISTS `OfferItems`; +CREATE TABLE `OfferItems` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `OfferId` bigint(20) NOT NULL DEFAULT '0', + `UserId` bigint(20) NOT NULL DEFAULT '0', + `ItemGuid` varchar(255) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for OfferItemsBackup +-- ---------------------------- +DROP TABLE IF EXISTS `OfferItemsBackup`; +CREATE TABLE `OfferItemsBackup` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `OfferId` bigint(20) NOT NULL DEFAULT '0', + `UserId` bigint(20) NOT NULL DEFAULT '0', + `ItemGuid` varchar(255) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for Offers +-- ---------------------------- +DROP TABLE IF EXISTS `Offers`; +CREATE TABLE `Offers` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `Offeror` bigint(20) NOT NULL DEFAULT '0', + `Offeree` bigint(20) NOT NULL DEFAULT '0', + `CreateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `FinishTime` datetime DEFAULT NULL, + `Status` int(10) NOT NULL DEFAULT '0', + `NegotiatedTimes` int(10) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- @@ -16,10 +143,10 @@ CREATE TABLE `ForgetVerifyCodes` ( -- ---------------------------- DROP TABLE IF EXISTS `RegVerifyCodes`; CREATE TABLE `RegVerifyCodes` ( - `Username` varchar(255) NOT NULL DEFAULT '', - `Email` varchar(255) NOT NULL DEFAULT '', - `RegVerifyCode` varchar(255) NOT NULL DEFAULT '', - `RegTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP + `Username` varchar(255) NOT NULL DEFAULT '', + `Email` varchar(255) NOT NULL DEFAULT '', + `RegVerifyCode` varchar(255) NOT NULL DEFAULT '', + `RegTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- @@ -27,19 +154,19 @@ CREATE TABLE `RegVerifyCodes` ( -- ---------------------------- DROP TABLE IF EXISTS `Rooms`; CREATE TABLE `Rooms` ( - `Id` bigint(20) NOT NULL AUTO_INCREMENT, - `Roomid` varchar(255) NOT NULL DEFAULT '-1', - `CreateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `RoomMaster` bigint(20) NOT NULL DEFAULT '0', - `RoomType` int(8) NOT NULL DEFAULT '0', - `GameModule` varchar(255) NOT NULL DEFAULT '', - `GameMap` varchar(255) NOT NULL DEFAULT '', - `RoomState` int(8) NOT NULL DEFAULT '0', - `IsRank` int(1) NOT NULL DEFAULT '0', - `HasPass` int(1) NOT NULL DEFAULT '0', - `Password` varchar(255) NOT NULL DEFAULT '', - `MaxUsers` int(8) NOT NULL DEFAULT '0', - PRIMARY KEY (`Id`,`Roomid`) + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `Roomid` varchar(255) NOT NULL DEFAULT '-1', + `CreateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `RoomMaster` bigint(20) NOT NULL DEFAULT '0', + `RoomType` int(8) NOT NULL DEFAULT '0', + `GameModule` varchar(255) NOT NULL DEFAULT '', + `GameMap` varchar(255) NOT NULL DEFAULT '', + `RoomState` int(8) NOT NULL DEFAULT '0', + `IsRank` int(1) NOT NULL DEFAULT '0', + `HasPass` int(1) NOT NULL DEFAULT '0', + `Password` varchar(255) NOT NULL DEFAULT '', + `MaxUsers` int(8) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`,`Roomid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- @@ -47,21 +174,101 @@ CREATE TABLE `Rooms` ( -- ---------------------------- DROP TABLE IF EXISTS `ServerLoginLogs`; CREATE TABLE `ServerLoginLogs` ( - `ServerName` varchar(255) NOT NULL DEFAULT '', - `ServerKey` varchar(255) NOT NULL DEFAULT '', - `LoginTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP + `ServerName` varchar(255) NOT NULL DEFAULT '', + `ServerKey` varchar(255) NOT NULL DEFAULT '', + `LoginTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- --- Table structure for ApiTokens +-- Table structure for StoreGoods -- ---------------------------- -DROP TABLE IF EXISTS `ApiTokens`; -CREATE TABLE `ApiTokens` ( - `TokenID` varchar(255) NOT NULL DEFAULT '', - `SecretKey` varchar(255) NOT NULL DEFAULT '', - `Reference1` varchar(255) NOT NULL DEFAULT '', - `Reference2` varchar(255) NOT NULL DEFAULT '', - PRIMARY KEY (`TokenID`) +DROP TABLE IF EXISTS `StoreGoods`; +CREATE TABLE `StoreGoods` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `StoreId` bigint(20) NOT NULL DEFAULT '0', + `GoodsId` bigint(20) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for Stores +-- ---------------------------- +DROP TABLE IF EXISTS `Stores`; +CREATE TABLE `Stores` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `StoreName` varchar(255) NOT NULL DEFAULT '', + `StartTime` datetime DEFAULT NULL, + `EndTime` datetime DEFAULT NULL, + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for UserCharacters +-- ---------------------------- +DROP TABLE IF EXISTS `UserCharacters`; +CREATE TABLE `UserCharacters` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `CharacterId` bigint(20) NOT NULL DEFAULT '0', + `UserId` bigint(20) NOT NULL DEFAULT '0', + `Name` varchar(255) NOT NULL DEFAULT '', + `FirstName` varchar(255) NOT NULL DEFAULT '', + `NickName` varchar(255) NOT NULL DEFAULT '', + `PrimaryAttribute` int(1) NOT NULL DEFAULT '0', + `InitialATK` double(20,0) NOT NULL DEFAULT '0', + `InitialDEF` double(20,0) NOT NULL DEFAULT '0', + `InitialHP` double(20,0) NOT NULL DEFAULT '0', + `InitialMP` double(20,0) NOT NULL DEFAULT '0', + `InitialAGI` double(20,0) NOT NULL DEFAULT '0', + `InitialINT` double(20,0) NOT NULL DEFAULT '0', + `InitialSTR` double(20,0) NOT NULL DEFAULT '0', + `InitialSPD` double(20,0) NOT NULL DEFAULT '0', + `InitialHR` double(20,0) NOT NULL DEFAULT '0', + `InitialMR` double(20,0) NOT NULL DEFAULT '0', + `Level` int(10) NOT NULL DEFAULT '0', + `LevelBreak` int(10) NOT NULL DEFAULT '0', + `InSquad` int(1) NOT NULL DEFAULT '0', + `TrainingTime` datetime DEFAULT NULL, + PRIMARY KEY (`Id`,`CharacterId`,`UserId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for UserItems +-- ---------------------------- +DROP TABLE IF EXISTS `UserItems`; +CREATE TABLE `UserItems` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `ItemId` bigint(20) NOT NULL DEFAULT '0', + `Guid` varchar(255) NOT NULL DEFAULT '', + `UserId` bigint(20) NOT NULL DEFAULT '0', + `CharacterId` bigint(20) NOT NULL DEFAULT '0', + `ItemName` varchar(255) NOT NULL DEFAULT '', + `IsLock` int(1) NOT NULL DEFAULT '0', + `Equipable` int(1) NOT NULL DEFAULT '0', + `Unequipable` int(1) NOT NULL DEFAULT '0', + `EquipSlotType` int(2) NOT NULL DEFAULT '0', + `Key` int(10) NOT NULL DEFAULT '0', + `Enable` int(1) NOT NULL DEFAULT '0', + `Price` double(20,0) NOT NULL DEFAULT '0', + `IsSellable` int(1) NOT NULL DEFAULT '0', + `IsTradable` int(1) NOT NULL DEFAULT '0', + `NextSellableTime` datetime DEFAULT NULL, + `NextTradableTime` datetime DEFAULT NULL, + `RemainUseTimes` int(10) NOT NULL DEFAULT '0', + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for UserLogs +-- ---------------------------- +DROP TABLE IF EXISTS `UserLogs`; +CREATE TABLE `UserLogs` ( + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `UserId` bigint(20) NOT NULL DEFAULT '0', + `Title` varchar(255) NOT NULL DEFAULT '', + `Description` varchar(255) NOT NULL DEFAULT '', + `Remark` varchar(255) NOT NULL DEFAULT '', + `CreateTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- @@ -69,20 +276,30 @@ CREATE TABLE `ApiTokens` ( -- ---------------------------- DROP TABLE IF EXISTS `Users`; CREATE TABLE `Users` ( - `UID` bigint(20) NOT NULL AUTO_INCREMENT, - `Username` varchar(255) NOT NULL DEFAULT '', - `Password` varchar(255) NOT NULL DEFAULT '', - `RegTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `LastTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `LastIP` varchar(255) NOT NULL DEFAULT '', - `Email` varchar(255) NOT NULL DEFAULT '', - `Nickname` varchar(255) NOT NULL DEFAULT '', - `IsAdmin` int(1) NOT NULL DEFAULT '0', - `IsOperator` int(1) NOT NULL DEFAULT '0', - `IsEnable` int(1) NOT NULL DEFAULT '1', - `Credits` decimal(20,0) NOT NULL DEFAULT '0', - `Materials` decimal(20,0) NOT NULL DEFAULT '0', - `GameTime` decimal(20,0) NOT NULL DEFAULT '0', - `AutoKey` varchar(255) NOT NULL DEFAULT '', - PRIMARY KEY (`UID`,`Username`,`Email`) -) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8mb4; + `Id` bigint(20) NOT NULL AUTO_INCREMENT, + `Username` varchar(255) NOT NULL DEFAULT '', + `Password` varchar(255) NOT NULL DEFAULT '', + `RegTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `LastTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `LastIP` varchar(255) NOT NULL DEFAULT '', + `Email` varchar(255) NOT NULL DEFAULT '', + `Nickname` varchar(255) NOT NULL DEFAULT '', + `IsAdmin` int(1) NOT NULL DEFAULT '0', + `IsOperator` int(1) NOT NULL DEFAULT '0', + `IsEnable` int(1) NOT NULL DEFAULT '1', + `GameTime` double(20,0) NOT NULL DEFAULT '0', + `AutoKey` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY (`Id`,`Username`,`Email`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- ---------------------------- +-- Table structure for UserSignIns +-- ---------------------------- +DROP TABLE IF EXISTS `UserSignIns`; +CREATE TABLE `UserSignIns` ( + `UserId` bigint(20) NOT NULL DEFAULT '0', + `LastTime` datetime DEFAULT NULL, + `Days` int(10) NOT NULL DEFAULT '0', + `IsSigned` int(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`UserId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/Library/SQLScript/fungame_sqlite.sql b/Library/SQLScript/fungame_sqlite.sql index a134b83..dcedd61 100644 --- a/Library/SQLScript/fungame_sqlite.sql +++ b/Library/SQLScript/fungame_sqlite.sql @@ -1,5 +1,29 @@ PRAGMA foreign_keys = OFF; +-- ---------------------------- +-- Table structure for ApiTokens +-- ---------------------------- +DROP TABLE IF EXISTS "main"."ApiTokens"; +CREATE TABLE ApiTokens ( + TokenID TEXT NOT NULL DEFAULT '', + SecretKey TEXT NOT NULL DEFAULT '', + Reference1 TEXT NOT NULL DEFAULT '', + Reference2 TEXT NOT NULL DEFAULT '', + PRIMARY KEY (TokenID) +); + +-- ---------------------------- +-- Table structure for Configs +-- ---------------------------- +DROP TABLE IF EXISTS "main"."Configs"; +CREATE TABLE Configs ( + Id TEXT NOT NULL DEFAULT '', + Content TEXT NOT NULL DEFAULT '', + Description TEXT NOT NULL DEFAULT '', + UpdateTime DATETIME NOT NULL DEFAULT (DATETIME('now')), + PRIMARY KEY (Id) +); + -- ---------------------------- -- Table structure for ForgetVerifyCodes -- ---------------------------- @@ -11,6 +35,102 @@ CREATE TABLE ForgetVerifyCodes ( SendTime DATETIME NOT NULL DEFAULT (DATETIME('now')) ); +-- ---------------------------- +-- Table structure for GoodsItems +-- ---------------------------- +DROP TABLE IF EXISTS "main"."GoodsItems"; +CREATE TABLE GoodsItems ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + GoodsId INTEGER NOT NULL DEFAULT 0, + ItemId INTEGER NOT NULL DEFAULT 0 +); + +-- ---------------------------- +-- Table structure for GoodsPrices +-- ---------------------------- +DROP TABLE IF EXISTS "main"."GoodsPrices"; +CREATE TABLE GoodsPrices ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + GoodsId INTEGER NOT NULL DEFAULT 0, + Currency TEXT NOT NULL DEFAULT '', + Price REAL NOT NULL DEFAULT 0 +); + +-- ---------------------------- +-- Table structure for Goods +-- ---------------------------- +DROP TABLE IF EXISTS "main"."Goods"; +CREATE TABLE Goods ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + Name TEXT NOT NULL DEFAULT '', + Description TEXT NOT NULL DEFAULT '', + Stock INTEGER NOT NULL DEFAULT 0 +); + +-- ---------------------------- +-- Table structure for Inventories +-- ---------------------------- +DROP TABLE IF EXISTS "main"."Inventories"; +CREATE TABLE Inventories ( + UserId INTEGER NOT NULL DEFAULT 0, + Name TEXT NOT NULL DEFAULT '', + Credits REAL NOT NULL DEFAULT 0, + Materials REAL NOT NULL DEFAULT 0, + MainCharacter INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY (UserId) +); + +-- ---------------------------- +-- Table structure for MarketItems +-- ---------------------------- +DROP TABLE IF EXISTS "main"."MarketItems"; +CREATE TABLE MarketItems ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + ItemGuid TEXT NOT NULL DEFAULT '', + UserId INTEGER NOT NULL DEFAULT 0, + Price REAL NOT NULL DEFAULT 0, + CreateTime DATETIME NOT NULL DEFAULT (DATETIME('now')), + FinishTime DATETIME DEFAULT NULL, + Status INTEGER NOT NULL DEFAULT 0, + Buyer INTEGER NOT NULL DEFAULT 0 +); + +-- ---------------------------- +-- Table structure for OfferItems +-- ---------------------------- +DROP TABLE IF EXISTS "main"."OfferItems"; +CREATE TABLE OfferItems ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + OfferId INTEGER NOT NULL DEFAULT 0, + UserId INTEGER NOT NULL DEFAULT 0, + ItemGuid TEXT NOT NULL DEFAULT '' +); + +-- ---------------------------- +-- Table structure for OfferItemsBackup +-- ---------------------------- +DROP TABLE IF EXISTS "main"."OfferItemsBackup"; +CREATE TABLE OfferItemsBackup ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + OfferId INTEGER NOT NULL DEFAULT 0, + UserId INTEGER NOT NULL DEFAULT 0, + ItemGuid TEXT NOT NULL DEFAULT '' +); + +-- ---------------------------- +-- Table structure for Offers +-- ---------------------------- +DROP TABLE IF EXISTS "main"."Offers"; +CREATE TABLE Offers ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + Offeror INTEGER NOT NULL DEFAULT 0, + Offeree INTEGER NOT NULL DEFAULT 0, + CreateTime DATETIME NOT NULL DEFAULT (DATETIME('now')), + FinishTime DATETIME DEFAULT NULL, + Status INTEGER NOT NULL DEFAULT 0, + NegotiatedTimes INTEGER NOT NULL DEFAULT 0 +); + -- ---------------------------- -- Table structure for RegVerifyCodes -- ---------------------------- @@ -26,19 +146,19 @@ CREATE TABLE RegVerifyCodes ( -- Table structure for Rooms -- ---------------------------- DROP TABLE IF EXISTS "main"."Rooms"; -CREATE TABLE "Rooms" ( -"Id" INTEGER PRIMARY KEY AUTOINCREMENT, -"Roomid" TEXT NOT NULL DEFAULT '-1', -"CreateTime" DATETIME NOT NULL DEFAULT (DATETIME('now')), -"RoomMaster" INTEGER NOT NULL DEFAULT 0, -"RoomType" INTEGER NOT NULL DEFAULT 0, -"GameModule" TEXT NOT NULL DEFAULT '', -"GameMap" TEXT NOT NULL DEFAULT '', -"RoomState" INTEGER NOT NULL DEFAULT 0, -"IsRank" INTEGER NOT NULL DEFAULT 0, -"HasPass" INTEGER NOT NULL DEFAULT 0, -"Password" TEXT NOT NULL DEFAULT '', -"MaxUsers" INTEGER NOT NULL DEFAULT 0 +CREATE TABLE Rooms ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + Roomid TEXT NOT NULL DEFAULT '-1', + CreateTime DATETIME NOT NULL DEFAULT (DATETIME('now')), + RoomMaster INTEGER NOT NULL DEFAULT 0, + RoomType INTEGER NOT NULL DEFAULT 0, + GameModule TEXT NOT NULL DEFAULT '', + GameMap TEXT NOT NULL DEFAULT '', + RoomState INTEGER NOT NULL DEFAULT 0, + IsRank INTEGER NOT NULL DEFAULT 0, + HasPass INTEGER NOT NULL DEFAULT 0, + Password TEXT NOT NULL DEFAULT '', + MaxUsers INTEGER NOT NULL DEFAULT 0 ); -- ---------------------------- @@ -52,15 +172,90 @@ CREATE TABLE ServerLoginLogs ( ); -- ---------------------------- --- Table structure for ApiTokens +-- Table structure for StoreGoods -- ---------------------------- -DROP TABLE IF EXISTS "main"."ApiTokens"; -CREATE TABLE ApiTokens ( - TokenID TEXT NOT NULL DEFAULT '', - SecretKey TEXT NOT NULL DEFAULT '', - Reference1 TEXT NOT NULL DEFAULT '', - Reference2 TEXT NOT NULL DEFAULT '', - PRIMARY KEY (TokenID) +DROP TABLE IF EXISTS "main"."StoreGoods"; +CREATE TABLE StoreGoods ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + StoreId INTEGER NOT NULL DEFAULT 0, + GoodsId INTEGER NOT NULL DEFAULT 0 +); + +-- ---------------------------- +-- Table structure for Stores +-- ---------------------------- +DROP TABLE IF EXISTS "main"."Stores"; +CREATE TABLE Stores ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + StoreName TEXT NOT NULL DEFAULT '', + StartTime DATETIME DEFAULT NULL, + EndTime DATETIME DEFAULT NULL +); + +-- ---------------------------- +-- Table structure for UserCharacters +-- ---------------------------- +DROP TABLE IF EXISTS "main"."UserCharacters"; +CREATE TABLE UserCharacters ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + CharacterId INTEGER NOT NULL DEFAULT 0, + UserId INTEGER NOT NULL DEFAULT 0, + Name TEXT NOT NULL DEFAULT '', + FirstName TEXT NOT NULL DEFAULT '', + NickName TEXT NOT NULL DEFAULT '', + PrimaryAttribute INTEGER NOT NULL DEFAULT 0, + InitialATK REAL NOT NULL DEFAULT 0, + InitialDEF REAL NOT NULL DEFAULT 0, + InitialHP REAL NOT NULL DEFAULT 0, + InitialMP REAL NOT NULL DEFAULT 0, + InitialAGI REAL NOT NULL DEFAULT 0, + InitialINT REAL NOT NULL DEFAULT 0, + InitialSTR REAL NOT NULL DEFAULT 0, + InitialSPD REAL NOT NULL DEFAULT 0, + InitialHR REAL NOT NULL DEFAULT 0, + InitialMR REAL NOT NULL DEFAULT 0, + Level INTEGER NOT NULL DEFAULT 0, + LevelBreak INTEGER NOT NULL DEFAULT 0, + InSquad INTEGER NOT NULL DEFAULT 0, + TrainingTime DATETIME DEFAULT NULL +); + +-- ---------------------------- +-- Table structure for UserItems +-- ---------------------------- +DROP TABLE IF EXISTS "main"."UserItems"; +CREATE TABLE UserItems ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + ItemId INTEGER NOT NULL DEFAULT 0, + Guid TEXT NOT NULL DEFAULT '', + UserId INTEGER NOT NULL DEFAULT 0, + CharacterId INTEGER NOT NULL DEFAULT 0, + ItemName TEXT NOT NULL DEFAULT '', + IsLock INTEGER NOT NULL DEFAULT 0, + Equipable INTEGER NOT NULL DEFAULT 0, + Unequipable INTEGER NOT NULL DEFAULT 0, + EquipSlotType INTEGER NOT NULL DEFAULT 0, + Key INTEGER NOT NULL DEFAULT 0, + Enable INTEGER NOT NULL DEFAULT 0, + Price REAL NOT NULL DEFAULT 0, + IsSellable INTEGER NOT NULL DEFAULT 0, + IsTradable INTEGER NOT NULL DEFAULT 0, + NextSellableTime DATETIME DEFAULT NULL, + NextTradableTime DATETIME DEFAULT NULL, + RemainUseTimes INTEGER NOT NULL DEFAULT 0 +); + +-- ---------------------------- +-- Table structure for UserLogs +-- ---------------------------- +DROP TABLE IF EXISTS "main"."UserLogs"; +CREATE TABLE UserLogs ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + UserId INTEGER NOT NULL DEFAULT 0, + Title TEXT NOT NULL DEFAULT '', + Description TEXT NOT NULL DEFAULT '', + Remark TEXT NOT NULL DEFAULT '', + CreateTime DATETIME NOT NULL DEFAULT (DATETIME('now')) ); -- ---------------------------- @@ -68,9 +263,9 @@ CREATE TABLE ApiTokens ( -- ---------------------------- DROP TABLE IF EXISTS "main"."Users"; CREATE TABLE Users ( - UID INTEGER PRIMARY KEY AUTOINCREMENT, - Username TEXT NOT NULL, - Password TEXT NOT NULL, + Id INTEGER PRIMARY KEY AUTOINCREMENT, + Username TEXT NOT NULL DEFAULT '', + Password TEXT NOT NULL DEFAULT '', RegTime DATETIME NOT NULL DEFAULT (DATETIME('now')), LastTime DATETIME NOT NULL DEFAULT (DATETIME('now')), LastIP TEXT NOT NULL DEFAULT '', @@ -79,8 +274,18 @@ CREATE TABLE Users ( IsAdmin INTEGER NOT NULL DEFAULT 0, IsOperator INTEGER NOT NULL DEFAULT 0, IsEnable INTEGER NOT NULL DEFAULT 1, - Credits REAL NOT NULL DEFAULT 0, - Materials REAL NOT NULL DEFAULT 0, GameTime REAL NOT NULL DEFAULT 0, AutoKey TEXT NOT NULL DEFAULT '' ); + +-- ---------------------------- +-- Table structure for UserSignIns +-- ---------------------------- +DROP TABLE IF EXISTS "main"."UserSignIns"; +CREATE TABLE UserSignIns ( + UserId INTEGER NOT NULL DEFAULT 0, + LastTime DATETIME DEFAULT NULL, + Days INTEGER NOT NULL DEFAULT 0, + IsSigned INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY (UserId) +); diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..3744b23 --- /dev/null +++ b/NOTICE @@ -0,0 +1,16 @@ +This project incorporates material from the following open source projects: + +* FunGame Core + Copyright (c) 2023-present Project Redbud and Contributors. + Copyright (c) 2022-2023 Milimoe. + Licensed under the LGPLv3 License. See LICENSE for details. + + Contributors: + - ChrisWynyard (Project Redbud Member) + - CoolinP (Project Redbud Member) + - Milimoe (Project Redbud Member) + - yeziuku (Project Redbud Member) + +* .NET Runtime + Copyright (c) .NET Foundation and Contributors + Licensed under the MIT License. See https://github.com/dotnet/runtime/blob/main/LICENSE.TXT for details.