还原实体类构造函数,并修复一些BUG

This commit is contained in:
Mili 2023-03-22 00:40:37 +08:00
parent c3808f1290
commit cf811e9225
12 changed files with 71 additions and 55 deletions

View File

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

View File

@ -6,12 +6,12 @@ namespace Milimoe.FunGame.Core.Api.Factory
{ {
internal class SkillFactory internal class SkillFactory
{ {
internal static Skill GetInstance(DataRow? DataRow, SkillType type = SkillType.Passive) internal static Skill GetInstance(DataSet? DataSet, SkillType type = SkillType.Passive, int Index = 0)
{ {
Skill skill = type switch Skill skill = type switch
{ {
SkillType.Active => new ActiveSkill(DataRow), SkillType.Active => new ActiveSkill(DataSet, Index),
_ => new PassiveSkill(DataRow) _ => new PassiveSkill(DataSet, Index)
}; };
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(DataRow? DataRow) internal static User GetInstance(DataSet? DataSet, int Index = 0)
{ {
return new User(DataRow); return new User(DataSet, Index);
} }
} }
} }

View File

@ -13,30 +13,30 @@ namespace Milimoe.FunGame.Core.Api.Utility
/// <param name="DrRoom">RoomRow</param> /// <param name="DrRoom">RoomRow</param>
/// <param name="DrUser">UserRow(RoomMaster)</param> /// <param name="DrUser">UserRow(RoomMaster)</param>
/// <returns></returns> /// <returns></returns>
public static Room GetRoom(DataRow? DrRoom, DataRow? DrUser) public static Room GetRoom(DataSet? DsRoom, DataSet? DsUser, int Index = 0)
{ {
return RoomFactory.GetInstance(DrRoom, DrUser); return RoomFactory.GetInstance(DsRoom, DsUser, Index);
} }
/// <summary> /// <summary>
/// 获取Skill实例默认返回PassiveSkill /// 获取Skill实例默认返回PassiveSkill
/// </summary> /// </summary>
/// <param name="DataRow">SkillRow</param> /// <param name="DataSet">SkillRow</param>
/// <param name="SkillType">Skill类型</param> /// <param name="SkillType">Skill类型</param>
/// <returns></returns> /// <returns></returns>
public static Skill GetSkill(DataRow? DataRow, SkillType SkillType = SkillType.Passive) public static Skill GetSkill(DataSet? DataSet, SkillType SkillType = SkillType.Passive, int Index = 0)
{ {
return SkillFactory.GetInstance(DataRow, SkillType); return SkillFactory.GetInstance(DataSet, SkillType, Index);
} }
/// <summary> /// <summary>
/// 获取User实例 /// 获取User实例
/// </summary> /// </summary>awaa
/// <param name="DataRow">UserRow</param> /// <param name="DataSet">UserRow</param>
/// <returns></returns> /// <returns></returns>
public static User GetUser(DataRow? DataRow) public static User GetUser(DataSet? DataSet, int Index = 0)
{ {
return UserFactory.GetInstance(DataRow); return UserFactory.GetInstance(DataSet, Index);
} }
/// <summary> /// <summary>
@ -46,27 +46,27 @@ 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="DataRows">使用DataRow构造对象</param> /// <param name="DataSets">使用DataSets构造对象</param>
/// <returns>T</returns> /// <returns>T</returns>
public static T GetInstance<T>(params DataRow?[] DataRows) public static T GetInstance<T>(params DataSet?[] DataSets)
{ {
if (DataRows is null || DataRows.Length == 0) throw new GetInstanceException(); if (DataSets is null || DataSets.Length == 0) throw new GetInstanceException();
object instance = General.EntityInstance; object instance = General.EntityInstance;
if (typeof(T) == typeof(User)) if (typeof(T) == typeof(User))
{ {
instance = GetUser(DataRows[0]); instance = GetUser(DataSets[0]);
} }
else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill)) else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill))
{ {
instance = GetSkill(DataRows[0]); instance = GetSkill(DataSets[0]);
} }
else if (typeof(T) == typeof(ActiveSkill)) else if (typeof(T) == typeof(ActiveSkill))
{ {
instance = GetSkill(DataRows[0], SkillType.Active); instance = GetSkill(DataSets[0], SkillType.Active);
} }
else if (typeof(T) == typeof(Room)) else if (typeof(T) == typeof(Room))
{ {
instance = GetRoom(DataRows[0], DataRows[1]); instance = GetRoom(DataSets[0], DataSets[1]);
} }
return (T)instance; return (T)instance;
} }
@ -89,9 +89,9 @@ namespace Milimoe.FunGame.Core.Api.Utility
DataSet? ds = DataSets[0]; DataSet? ds = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0) if (ds != null && ds.Tables[0].Rows.Count > 0)
{ {
foreach (DataRow? row in ds.Tables[0].Rows) for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{ {
object entity = GetUser(row); object entity = GetUser(ds, i);
list.Add((T)entity); list.Add((T)entity);
} }
} }
@ -101,9 +101,9 @@ namespace Milimoe.FunGame.Core.Api.Utility
DataSet? ds = DataSets[0]; DataSet? ds = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0) if (ds != null && ds.Tables[0].Rows.Count > 0)
{ {
foreach (DataRow? row in ds.Tables[0].Rows) for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{ {
object entity = GetSkill(row); object entity = GetSkill(ds, SkillType.Passive, i);
list.Add((T)entity); list.Add((T)entity);
} }
} }
@ -113,33 +113,27 @@ namespace Milimoe.FunGame.Core.Api.Utility
DataSet? ds = DataSets[0]; DataSet? ds = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0) if (ds != null && ds.Tables[0].Rows.Count > 0)
{ {
foreach (DataRow? row in ds.Tables[0].Rows) for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{ {
object entity = GetSkill(row, SkillType.Active); object entity = GetSkill(ds, SkillType.Active, i);
list.Add((T)entity); list.Add((T)entity);
} }
} }
} }
else if (typeof(T) == typeof(Room)) else if (typeof(T) == typeof(Room))
{ {
DataSet? ds = DataSets[0]; DataSet? DsRoom = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0) DataSet? DsUser = DataSets[1];
if (DsRoom != null && DsRoom.Tables[0].Rows.Count > 0)
{ {
foreach (DataRow? row in ds.Tables[0].Rows) for (int i = 0; i < DsRoom.Tables[0].Rows.Count; i++)
{ {
if (row != null) object entity = GetRoom(DsRoom, DsUser, i);
{ list.Add((T)entity);
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>(); return list;
} }
} }
} }

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(DataRow? DataRow) internal ActiveSkill(DataSet? DataSet, int Index = 0)
{ {
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(DataRow? DataRow) internal PassiveSkill(DataSet? DataSet, int Index = 0)
{ {
Active = false; Active = false;
} }

View File

@ -3,6 +3,7 @@ using System.Collections;
using Milimoe.FunGame.Core.Interface.Entity; using Milimoe.FunGame.Core.Interface.Entity;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.SQLScript.Entity; using Milimoe.FunGame.Core.Library.SQLScript.Entity;
using System.Linq;
namespace Milimoe.FunGame.Core.Entity namespace Milimoe.FunGame.Core.Entity
{ {
@ -27,14 +28,15 @@ 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(DataRow? DrRoom, DataRow? DrUser) internal Room(DataSet? DsRoom, DataSet? DsUser, int Index)
{ {
if (DrRoom != null) if (DsRoom != null && DsRoom.Tables[0].Rows.Count > 0)
{ {
DataRow DrRoom = DsRoom.Tables[0].Rows[Index];
Id = (long)DrRoom[RoomQuery.Column_ID]; Id = (long)DrRoom[RoomQuery.Column_ID];
Roomid = (string)DrRoom[RoomQuery.Column_RoomID]; Roomid = (string)DrRoom[RoomQuery.Column_RoomID];
CreateTime = (DateTime)DrRoom[RoomQuery.Column_CreateTime]; CreateTime = (DateTime)DrRoom[RoomQuery.Column_CreateTime];
RoomMaster = Api.Utility.Factory.GetInstance<User>(DrUser); RoomMaster = Api.Utility.Factory.GetUser(DsUser, GetUserRowIndex(DsUser, (long)DrRoom[RoomQuery.Column_RoomMaster]));
RoomType = (RoomType)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomType]); RoomType = (RoomType)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomType]);
RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]); RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]);
Password = (string)DrRoom[RoomQuery.Column_Password]; Password = (string)DrRoom[RoomQuery.Column_Password];
@ -55,5 +57,20 @@ namespace Milimoe.FunGame.Core.Entity
{ {
return Equals(other); return Equals(other);
} }
private static int GetUserRowIndex(DataSet? DsUser, long UID)
{
if (DsUser != null)
{
for (int i = 0; i < DsUser.Tables[0].Rows.Count; i++)
{
if (DsUser.Tables[0].Rows[i][UserQuery.Column_UID].Equals(UID))
{
return i;
}
}
}
return 0;
}
} }
} }

View File

@ -28,10 +28,11 @@ namespace Milimoe.FunGame.Core.Entity
} }
internal User(DataRow? DataRow) internal User(DataSet? DataSet, int Index = 0)
{ {
if (DataRow != null) if (DataSet != null && DataSet.Tables[0].Rows.Count > 0)
{ {
DataRow DataRow = DataSet.Tables[0].Rows[Index];
Id = (long)DataRow[UserQuery.Column_UID]; Id = (long)DataRow[UserQuery.Column_UID];
Username = (string)DataRow[UserQuery.Column_Username]; Username = (string)DataRow[UserQuery.Column_Username];
Password = (string)DataRow[UserQuery.Column_Password]; Password = (string)DataRow[UserQuery.Column_Password];

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 = 20480; public const int SocketByteSize = 512 * 1024;
public const int StreamByteSize = 2048; public const int StreamByteSize = 2048;
} }
} }

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)
{ {
DataRow? row = SocketObject.GetParam<DataRow>(0); DataSet? DataSet = SocketObject.GetParam<DataSet>(0);
// 创建User对象并返回到Main // 创建User对象并返回到Main
RunTime.Main?.UpdateUI(MainInvokeType.SetUser, new object[] { Factory.GetInstance<User>(row) }); RunTime.Main?.UpdateUI(MainInvokeType.SetUser, new object[] { Factory.GetInstance<User>(DataSet) });
RunTime.Login?.OnSucceedLoginEvent(Login.EventArgs); RunTime.Login?.OnSucceedLoginEvent(Login.EventArgs);
RunTime.Login?.OnAfterLoginEvent(Login.EventArgs); RunTime.Login?.OnAfterLoginEvent(Login.EventArgs);
return; return;

View File

@ -227,7 +227,9 @@ namespace Milimoe.FunGame.Desktop.Model
private void SocketHandler_UpdateRoom(SocketObject SocketObject) private void SocketHandler_UpdateRoom(SocketObject SocketObject)
{ {
Main.UpdateUI(MainInvokeType.UpdateRoom, SocketObject.Parameters); List<string>? list = SocketObject.GetParam<List<string>>(0);
list ??= new List<string>();
Main.UpdateUI(MainInvokeType.UpdateRoom, list);
} }
private void SocketHandler_Chat(SocketObject SocketObject) private void SocketHandler_Chat(SocketObject SocketObject)

View File

@ -1216,8 +1216,10 @@ namespace Milimoe.FunGame.Desktop.UI
private EventResult SucceedLoginEvent(object sender, GeneralEventArgs e) private EventResult SucceedLoginEvent(object sender, GeneralEventArgs e)
{ {
// 接入-1号房间聊天室 // 接入-1号房间聊天室
if (MainController?.IntoRoom("-1") ?? false) return EventResult.Success; MainController?.IntoRoom("-1");
else return EventResult.Fail; // 获取在线的房间列表
MainController?.UpdateRoom();
return EventResult.Success;
} }
#endregion #endregion