修改Factory构造函数

This commit is contained in:
Mili 2023-03-20 23:30:52 +08:00
parent 57417a33ac
commit c3808f1290
14 changed files with 189 additions and 77 deletions

View File

@ -5,9 +5,9 @@ namespace Milimoe.FunGame.Core.Api.Factory
{ {
internal class RoomFactory internal class RoomFactory
{ {
internal static Room GetInstance(DataSet? DsRoom, DataSet? DsUser) internal static Room GetInstance(DataRow? DrRoom, DataRow? DrUser)
{ {
return new Room(DsRoom, DsUser); return new Room(DrRoom, DrUser);
} }
} }
} }

View File

@ -1,17 +1,17 @@
using Milimoe.FunGame.Core.Entity; using System.Data;
using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
using System.Data;
namespace Milimoe.FunGame.Core.Api.Factory namespace Milimoe.FunGame.Core.Api.Factory
{ {
internal class SkillFactory internal class SkillFactory
{ {
internal static Skill GetInstance(DataSet? DataSet, SkillType type = SkillType.Passive) internal static Skill GetInstance(DataRow? DataRow, SkillType type = SkillType.Passive)
{ {
Skill skill = type switch Skill skill = type switch
{ {
SkillType.Active => new ActiveSkill(DataSet), SkillType.Active => new ActiveSkill(DataRow),
_ => new PassiveSkill(DataSet) _ => new PassiveSkill(DataRow)
}; };
return skill; return skill;
} }

View File

@ -5,9 +5,9 @@ namespace Milimoe.FunGame.Core.Api.Factory
{ {
internal class UserFactory internal class UserFactory
{ {
internal static User GetInstance(DataSet? DataSet) internal static User GetInstance(DataRow? DataRow)
{ {
return new User(DataSet); return new User(DataRow);
} }
} }
} }

View File

@ -7,6 +7,38 @@ namespace Milimoe.FunGame.Core.Api.Utility
{ {
public class Factory public class Factory
{ {
/// <summary>
/// 获取Room实例
/// </summary>
/// <param name="DrRoom">RoomRow</param>
/// <param name="DrUser">UserRow(RoomMaster)</param>
/// <returns></returns>
public static Room GetRoom(DataRow? DrRoom, DataRow? DrUser)
{
return RoomFactory.GetInstance(DrRoom, DrUser);
}
/// <summary>
/// 获取Skill实例默认返回PassiveSkill
/// </summary>
/// <param name="DataRow">SkillRow</param>
/// <param name="SkillType">Skill类型</param>
/// <returns></returns>
public static Skill GetSkill(DataRow? DataRow, SkillType SkillType = SkillType.Passive)
{
return SkillFactory.GetInstance(DataRow, SkillType);
}
/// <summary>
/// 获取User实例
/// </summary>
/// <param name="DataRow">UserRow</param>
/// <returns></returns>
public static User GetUser(DataRow? DataRow)
{
return UserFactory.GetInstance(DataRow);
}
/// <summary> /// <summary>
/// 获取一个不为NULL的实例 /// 获取一个不为NULL的实例
/// <para>Item默认返回PassiveItem</para> /// <para>Item默认返回PassiveItem</para>
@ -14,29 +46,100 @@ namespace Milimoe.FunGame.Core.Api.Utility
/// <para>若无法找到T返回唯一的空对象</para> /// <para>若无法找到T返回唯一的空对象</para>
/// </summary> /// </summary>
/// <typeparam name="T">Entity类</typeparam> /// <typeparam name="T">Entity类</typeparam>
/// <param name="DataSets">使用DataSet构造对象真香</param> /// <param name="DataRows">使用DataRow构造对象</param>
/// <returns></returns> /// <returns>T</returns>
public static T GetInstance<T>(params DataSet?[] DataSets) public static T GetInstance<T>(params DataRow?[] DataRows)
{ {
if (DataSets is null || DataSets.Length == 0) throw new GetInstanceException(); if (DataRows is null || DataRows.Length == 0) throw new GetInstanceException();
object instance = General.EntityInstance; object instance = General.EntityInstance;
if (typeof(T) == typeof(User)) if (typeof(T) == typeof(User))
{ {
instance = UserFactory.GetInstance(DataSets[0]); instance = GetUser(DataRows[0]);
} }
else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill)) else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill))
{ {
instance = SkillFactory.GetInstance(DataSets[0]); instance = GetSkill(DataRows[0]);
} }
else if (typeof(T) == typeof(ActiveSkill)) else if (typeof(T) == typeof(ActiveSkill))
{ {
instance = SkillFactory.GetInstance(DataSets[0], SkillType.Active); instance = GetSkill(DataRows[0], SkillType.Active);
} }
else if (typeof(T) == typeof(Room)) else if (typeof(T) == typeof(Room))
{ {
instance = RoomFactory.GetInstance(DataSets[0], DataSets[1]); instance = GetRoom(DataRows[0], DataRows[1]);
} }
return (T)instance; return (T)instance;
} }
/// <summary>
/// 获取T的数组
/// <para>Item默认返回PassiveItem数组</para>
/// <para>Skill默认返回PassiveSkill数组</para>
/// <para>若无法找到T返回空数组</para>
/// </summary>
/// <typeparam name="T">Entity类</typeparam>
/// <param name="DataSets">使用DataSet构造对象数组</param>
/// <returns>List T</returns>
public static List<T> GetList<T>(params DataSet?[] DataSets)
{
List<T> list = new();
if (DataSets is null || DataSets.Length == 0) throw new GetInstanceException();
if (typeof(T) == typeof(User))
{
DataSet? ds = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow? row in ds.Tables[0].Rows)
{
object entity = GetUser(row);
list.Add((T)entity);
}
}
}
else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill))
{
DataSet? ds = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow? row in ds.Tables[0].Rows)
{
object entity = GetSkill(row);
list.Add((T)entity);
}
}
}
else if (typeof(T) == typeof(ActiveSkill))
{
DataSet? ds = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow? row in ds.Tables[0].Rows)
{
object entity = GetSkill(row, SkillType.Active);
list.Add((T)entity);
}
}
}
else if (typeof(T) == typeof(Room))
{
DataSet? ds = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow? row in ds.Tables[0].Rows)
{
if (row != null)
{
DataRow[] rows = ds.Tables[1].Select($"{Library.SQLScript.Entity.UserQuery.Column_Username} = '{row[Library.SQLScript.Entity.RoomQuery.Column_RoomMasterName]}'");
if (rows != null && rows.Length > 0)
{
object entity = GetRoom(row, rows[0]);
list.Add((T)entity);
}
}
}
}
}
return new List<T>();
}
} }
} }

View File

@ -17,7 +17,7 @@ namespace Milimoe.FunGame.Core.Entity
public decimal Reference9 { get; set; } = 0; public decimal Reference9 { get; set; } = 0;
public decimal Reference10 { get; set; } = 0; public decimal Reference10 { get; set; } = 0;
internal ActiveSkill(DataSet? DataSet) internal ActiveSkill(DataRow? DataRow)
{ {
Active = true; Active = true;
} }

View File

@ -15,7 +15,7 @@ namespace Milimoe.FunGame.Core.Entity
public decimal Reference9 { get; set; } = 0; public decimal Reference9 { get; set; } = 0;
public decimal Reference10 { get; set; } = 0; public decimal Reference10 { get; set; } = 0;
internal PassiveSkill(DataSet? DataSet) internal PassiveSkill(DataRow? DataRow)
{ {
Active = false; Active = false;
} }

View File

@ -27,18 +27,17 @@ namespace Milimoe.FunGame.Core.Entity
public string Password { get; set; } = ""; public string Password { get; set; } = "";
public GameStatistics? Statistics { get; set; } = null; public GameStatistics? Statistics { get; set; } = null;
internal Room(DataSet? DsRoom, DataSet? DsUser) internal Room(DataRow? DrRoom, DataRow? DrUser)
{ {
if (DsRoom != null && DsRoom.Tables.Count > 0 && DsRoom.Tables[0].Rows.Count > 0) if (DrRoom != null)
{ {
DataRow row = DsRoom.Tables[0].Rows[0]; Id = (long)DrRoom[RoomQuery.Column_ID];
Id = (long)row[RoomQuery.Column_ID]; Roomid = (string)DrRoom[RoomQuery.Column_RoomID];
Roomid = (string)row[RoomQuery.Column_RoomID]; CreateTime = (DateTime)DrRoom[RoomQuery.Column_CreateTime];
CreateTime = (DateTime)row[RoomQuery.Column_CreateTime]; RoomMaster = Api.Utility.Factory.GetInstance<User>(DrUser);
RoomMaster = Api.Utility.Factory.GetInstance<User>(DsUser); RoomType = (RoomType)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomType]);
RoomType = (RoomType)Convert.ToInt32(row[RoomQuery.Column_RoomType]); RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]);
RoomState = (RoomState)Convert.ToInt32(row[RoomQuery.Column_RoomState]); Password = (string)DrRoom[RoomQuery.Column_Password];
Password = (string)row[RoomQuery.Column_Password];
} }
} }

View File

@ -28,25 +28,24 @@ namespace Milimoe.FunGame.Core.Entity
} }
internal User(DataSet? DataSet) internal User(DataRow? DataRow)
{ {
if (DataSet != null && DataSet.Tables.Count > 0 && DataSet.Tables[0].Rows.Count > 0) if (DataRow != null)
{ {
DataRow row = DataSet.Tables[0].Rows[0]; Id = (long)DataRow[UserQuery.Column_UID];
Id = (long)row[UserQuery.Column_UID]; Username = (string)DataRow[UserQuery.Column_Username];
Username = (string)row[UserQuery.Column_Username]; Password = (string)DataRow[UserQuery.Column_Password];
Password = (string)row[UserQuery.Column_Password]; RegTime = (DateTime)DataRow[UserQuery.Column_RegTime];
RegTime = (DateTime)row[UserQuery.Column_RegTime]; LastTime = (DateTime)DataRow[UserQuery.Column_LastTime];
LastTime = (DateTime)row[UserQuery.Column_LastTime]; Email = (string)DataRow[UserQuery.Column_Email];
Email = (string)row[UserQuery.Column_Email]; NickName = (string)DataRow[UserQuery.Column_Nickname];
NickName = (string)row[UserQuery.Column_Nickname]; IsAdmin = Convert.ToInt32(DataRow[UserQuery.Column_IsAdmin]) == 1;
IsAdmin = Convert.ToInt32(row[UserQuery.Column_IsAdmin]) == 1; IsOperator = Convert.ToInt32(DataRow[UserQuery.Column_IsOperator]) == 1;
IsOperator = Convert.ToInt32(row[UserQuery.Column_IsOperator]) == 1; IsEnable = Convert.ToInt32(DataRow[UserQuery.Column_IsEnable]) == 1;
IsEnable = Convert.ToInt32(row[UserQuery.Column_IsEnable]) == 1; Credits = Convert.ToDecimal(DataRow[UserQuery.Column_Credits]);
Credits = Convert.ToDecimal(row[UserQuery.Column_Credits]); Materials = Convert.ToDecimal(DataRow[UserQuery.Column_Materials]);
Materials = Convert.ToDecimal(row[UserQuery.Column_Materials]); GameTime = Convert.ToDecimal(DataRow[UserQuery.Column_GameTime]);
GameTime = Convert.ToDecimal(row[UserQuery.Column_GameTime]); AutoKey = (string)DataRow[UserQuery.Column_AutoKey];
AutoKey = (string)row[UserQuery.Column_AutoKey];
} }
} }

View File

@ -15,7 +15,7 @@ namespace Milimoe.FunGame.Core.Library.Constant
public const int MaxThread_General = 20; public const int MaxThread_General = 20;
public const int MaxTask_4C4G = 40; public const int MaxTask_4C4G = 40;
public const int SocketByteSize = 2048; public const int SocketByteSize = 20480;
public const int StreamByteSize = 2048; public const int StreamByteSize = 2048;
} }
} }

View File

@ -17,19 +17,37 @@ namespace Milimoe.FunGame.Core.Library.Server
_Server = Server; _Server = Server;
} }
public List<Room> GetList() public List<Room> GetRoomList()
{ {
return _List.Values.Cast<Room>().ToList(); return _List.Values.Cast<Room>().ToList();
} }
public List<string> GetRoomIDList()
{
return _List.Keys.Cast<string>().ToList();
}
public void Clear()
{
_List.Clear();
}
public void AddRoom(Room Room) public void AddRoom(Room Room)
{ {
_List.Add(Room.Name, Room); _List.Add(Room.Roomid, Room);
}
public void AddRooms(List<Room> Rooms)
{
foreach (Room Room in Rooms)
{
_List.Add(Room.Roomid, Room);
}
} }
public void RemoveRoom(Room Room) public void RemoveRoom(Room Room)
{ {
_List.Remove(Room.Name); _List.Remove(Room.Roomid);
} }
public Room? GetRoom(string RoomID) public Room? GetRoom(string RoomID)

View File

@ -130,9 +130,9 @@ namespace Milimoe.FunGame.Desktop.Model
object[] objs = SocketObject.Parameters; object[] objs = SocketObject.Parameters;
if (objs != null && objs.Length > 0) if (objs != null && objs.Length > 0)
{ {
DataSet? Set = SocketObject.GetParam<DataSet>(0); DataRow? row = SocketObject.GetParam<DataRow>(0);
// 创建User对象并返回到Main // 创建User对象并返回到Main
RunTime.Main?.UpdateUI(MainInvokeType.SetUser, new object[] { Factory.GetInstance<User>(Set) }); RunTime.Main?.UpdateUI(MainInvokeType.SetUser, new object[] { Factory.GetInstance<User>(row) });
RunTime.Login?.OnSucceedLoginEvent(Login.EventArgs); RunTime.Login?.OnSucceedLoginEvent(Login.EventArgs);
RunTime.Login?.OnAfterLoginEvent(Login.EventArgs); RunTime.Login?.OnAfterLoginEvent(Login.EventArgs);
return; return;

View File

@ -163,6 +163,10 @@ namespace Milimoe.FunGame.Desktop.Model
SocketHandler_Chat(SocketObject); SocketHandler_Chat(SocketObject);
break; break;
case SocketMessageType.UpdateRoom:
SocketHandler_UpdateRoom(SocketObject);
break;
case SocketMessageType.Unknown: case SocketMessageType.Unknown:
default: default:
break; break;
@ -221,6 +225,11 @@ namespace Milimoe.FunGame.Desktop.Model
Main.OnAfterIntoRoomEvent(args); Main.OnAfterIntoRoomEvent(args);
} }
private void SocketHandler_UpdateRoom(SocketObject SocketObject)
{
Main.UpdateUI(MainInvokeType.UpdateRoom, SocketObject.Parameters);
}
private void SocketHandler_Chat(SocketObject SocketObject) private void SocketHandler_Chat(SocketObject SocketObject)
{ {
SendTalkEventArgs SendTalkEventArgs = new(LastSendTalkMessage); SendTalkEventArgs SendTalkEventArgs = new(LastSendTalkMessage);

View File

@ -306,18 +306,7 @@ namespace Milimoe.FunGame.Desktop.UI
this.PresetText.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.PresetText.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.PresetText.Font = new System.Drawing.Font("LanaPixel", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.PresetText.Font = new System.Drawing.Font("LanaPixel", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.PresetText.FormattingEnabled = true; this.PresetText.FormattingEnabled = true;
this.PresetText.Items.AddRange(new object[] { this.PresetText.Items.AddRange(new object[] { "- 快捷消息 -" });
"- 快捷消息 -",
"签到",
"积分",
"查看库存",
"游戏商店",
"创建游戏 混战",
"创建游戏 团队",
"开始游戏",
"重新连接",
"开启自动重连",
"关闭自动重连"});
this.PresetText.Location = new System.Drawing.Point(195, 422); this.PresetText.Location = new System.Drawing.Point(195, 422);
this.PresetText.Name = "PresetText"; this.PresetText.Name = "PresetText";
this.PresetText.Size = new System.Drawing.Size(121, 26); this.PresetText.Size = new System.Drawing.Size(121, 26);
@ -360,19 +349,6 @@ namespace Milimoe.FunGame.Desktop.UI
this.RoomList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.RoomList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.RoomList.FormattingEnabled = true; this.RoomList.FormattingEnabled = true;
this.RoomList.ItemHeight = 19; this.RoomList.ItemHeight = 19;
this.RoomList.Items.AddRange(new object[] {
"114514",
"1919810",
"12900",
"12600",
"12100",
"3329500",
"111111",
"123456",
"123698745",
"667678970",
"3305106902",
"987654"});
this.RoomList.Location = new System.Drawing.Point(0, 26); this.RoomList.Location = new System.Drawing.Point(0, 26);
this.RoomList.Name = "RoomList"; this.RoomList.Name = "RoomList";
this.RoomList.Size = new System.Drawing.Size(186, 192); this.RoomList.Size = new System.Drawing.Size(186, 192);

View File

@ -200,6 +200,14 @@ namespace Milimoe.FunGame.Desktop.UI
NoticeText.Text = Config.FunGame_Notice; NoticeText.Text = Config.FunGame_Notice;
break; break;
case MainInvokeType.UpdateRoom:
if (objs != null && objs.Length > 0)
{
List<string> list = (List<string>)objs[0];
RoomList.Items.AddRange(list.ToArray());
}
break;
default: default:
break; break;
} }