还原实体类构造函数,并修复一些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 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 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
{
SkillType.Active => new ActiveSkill(DataRow),
_ => new PassiveSkill(DataRow)
SkillType.Active => new ActiveSkill(DataSet, Index),
_ => new PassiveSkill(DataSet, Index)
};
return skill;
}

View File

@ -5,9 +5,9 @@ namespace Milimoe.FunGame.Core.Api.Factory
{
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="DrUser">UserRow(RoomMaster)</param>
/// <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>
/// 获取Skill实例默认返回PassiveSkill
/// </summary>
/// <param name="DataRow">SkillRow</param>
/// <param name="DataSet">SkillRow</param>
/// <param name="SkillType">Skill类型</param>
/// <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>
/// 获取User实例
/// </summary>
/// <param name="DataRow">UserRow</param>
/// </summary>awaa
/// <param name="DataSet">UserRow</param>
/// <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>
@ -46,27 +46,27 @@ namespace Milimoe.FunGame.Core.Api.Utility
/// <para>若无法找到T返回唯一的空对象</para>
/// </summary>
/// <typeparam name="T">Entity类</typeparam>
/// <param name="DataRows">使用DataRow构造对象</param>
/// <param name="DataSets">使用DataSets构造对象</param>
/// <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;
if (typeof(T) == typeof(User))
{
instance = GetUser(DataRows[0]);
instance = GetUser(DataSets[0]);
}
else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill))
{
instance = GetSkill(DataRows[0]);
instance = GetSkill(DataSets[0]);
}
else if (typeof(T) == typeof(ActiveSkill))
{
instance = GetSkill(DataRows[0], SkillType.Active);
instance = GetSkill(DataSets[0], SkillType.Active);
}
else if (typeof(T) == typeof(Room))
{
instance = GetRoom(DataRows[0], DataRows[1]);
instance = GetRoom(DataSets[0], DataSets[1]);
}
return (T)instance;
}
@ -89,9 +89,9 @@ namespace Milimoe.FunGame.Core.Api.Utility
DataSet? ds = DataSets[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);
}
}
@ -101,9 +101,9 @@ namespace Milimoe.FunGame.Core.Api.Utility
DataSet? ds = DataSets[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);
}
}
@ -113,33 +113,27 @@ namespace Milimoe.FunGame.Core.Api.Utility
DataSet? ds = DataSets[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);
}
}
}
else if (typeof(T) == typeof(Room))
{
DataSet? ds = DataSets[0];
if (ds != null && ds.Tables[0].Rows.Count > 0)
DataSet? DsRoom = DataSets[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)
{
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]);
object entity = GetRoom(DsRoom, DsUser, i);
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 Reference10 { get; set; } = 0;
internal ActiveSkill(DataRow? DataRow)
internal ActiveSkill(DataSet? DataSet, int Index = 0)
{
Active = true;
}

View File

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

View File

@ -3,6 +3,7 @@ using System.Collections;
using Milimoe.FunGame.Core.Interface.Entity;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
using System.Linq;
namespace Milimoe.FunGame.Core.Entity
{
@ -27,14 +28,15 @@ namespace Milimoe.FunGame.Core.Entity
public string Password { get; set; } = "";
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];
Roomid = (string)DrRoom[RoomQuery.Column_RoomID];
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]);
RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]);
Password = (string)DrRoom[RoomQuery.Column_Password];
@ -55,5 +57,20 @@ namespace Milimoe.FunGame.Core.Entity
{
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];
Username = (string)DataRow[UserQuery.Column_Username];
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 MaxTask_4C4G = 40;
public const int SocketByteSize = 20480;
public const int SocketByteSize = 512 * 1024;
public const int StreamByteSize = 2048;
}
}

View File

@ -130,9 +130,9 @@ namespace Milimoe.FunGame.Desktop.Model
object[] objs = SocketObject.Parameters;
if (objs != null && objs.Length > 0)
{
DataRow? row = SocketObject.GetParam<DataRow>(0);
DataSet? DataSet = SocketObject.GetParam<DataSet>(0);
// 创建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?.OnAfterLoginEvent(Login.EventArgs);
return;

View File

@ -227,7 +227,9 @@ namespace Milimoe.FunGame.Desktop.Model
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)

View File

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