forked from project-redbud/FunGame-Core
修改Factory构造函数
This commit is contained in:
parent
57417a33ac
commit
c3808f1290
@ -5,9 +5,9 @@ namespace Milimoe.FunGame.Core.Api.Factory
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using System.Data;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using System.Data;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Api.Factory
|
||||
{
|
||||
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
|
||||
{
|
||||
SkillType.Active => new ActiveSkill(DataSet),
|
||||
_ => new PassiveSkill(DataSet)
|
||||
SkillType.Active => new ActiveSkill(DataRow),
|
||||
_ => new PassiveSkill(DataRow)
|
||||
};
|
||||
return skill;
|
||||
}
|
||||
|
||||
@ -5,9 +5,9 @@ namespace Milimoe.FunGame.Core.Api.Factory
|
||||
{
|
||||
internal class UserFactory
|
||||
{
|
||||
internal static User GetInstance(DataSet? DataSet)
|
||||
internal static User GetInstance(DataRow? DataRow)
|
||||
{
|
||||
return new User(DataSet);
|
||||
return new User(DataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,38 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
{
|
||||
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>
|
||||
/// 获取一个不为NULL的实例
|
||||
/// <para>Item默认返回PassiveItem</para>
|
||||
@ -14,29 +46,100 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
/// <para>若无法找到T,返回唯一的空对象</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Entity类</typeparam>
|
||||
/// <param name="DataSets">使用DataSet构造对象(真香)</param>
|
||||
/// <returns></returns>
|
||||
public static T GetInstance<T>(params DataSet?[] DataSets)
|
||||
/// <param name="DataRows">使用DataRow构造对象</param>
|
||||
/// <returns>T</returns>
|
||||
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;
|
||||
if (typeof(T) == typeof(User))
|
||||
{
|
||||
instance = UserFactory.GetInstance(DataSets[0]);
|
||||
instance = GetUser(DataRows[0]);
|
||||
}
|
||||
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))
|
||||
{
|
||||
instance = SkillFactory.GetInstance(DataSets[0], SkillType.Active);
|
||||
instance = GetSkill(DataRows[0], SkillType.Active);
|
||||
}
|
||||
else if (typeof(T) == typeof(Room))
|
||||
{
|
||||
instance = RoomFactory.GetInstance(DataSets[0], DataSets[1]);
|
||||
instance = GetRoom(DataRows[0], DataRows[1]);
|
||||
}
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
public decimal Reference9 { get; set; } = 0;
|
||||
public decimal Reference10 { get; set; } = 0;
|
||||
|
||||
internal ActiveSkill(DataSet? DataSet)
|
||||
internal ActiveSkill(DataRow? DataRow)
|
||||
{
|
||||
Active = true;
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
public decimal Reference9 { get; set; } = 0;
|
||||
public decimal Reference10 { get; set; } = 0;
|
||||
|
||||
internal PassiveSkill(DataSet? DataSet)
|
||||
internal PassiveSkill(DataRow? DataRow)
|
||||
{
|
||||
Active = false;
|
||||
}
|
||||
|
||||
@ -27,18 +27,17 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
public string Password { get; set; } = "";
|
||||
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)row[RoomQuery.Column_ID];
|
||||
Roomid = (string)row[RoomQuery.Column_RoomID];
|
||||
CreateTime = (DateTime)row[RoomQuery.Column_CreateTime];
|
||||
RoomMaster = Api.Utility.Factory.GetInstance<User>(DsUser);
|
||||
RoomType = (RoomType)Convert.ToInt32(row[RoomQuery.Column_RoomType]);
|
||||
RoomState = (RoomState)Convert.ToInt32(row[RoomQuery.Column_RoomState]);
|
||||
Password = (string)row[RoomQuery.Column_Password];
|
||||
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);
|
||||
RoomType = (RoomType)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomType]);
|
||||
RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]);
|
||||
Password = (string)DrRoom[RoomQuery.Column_Password];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)row[UserQuery.Column_UID];
|
||||
Username = (string)row[UserQuery.Column_Username];
|
||||
Password = (string)row[UserQuery.Column_Password];
|
||||
RegTime = (DateTime)row[UserQuery.Column_RegTime];
|
||||
LastTime = (DateTime)row[UserQuery.Column_LastTime];
|
||||
Email = (string)row[UserQuery.Column_Email];
|
||||
NickName = (string)row[UserQuery.Column_Nickname];
|
||||
IsAdmin = Convert.ToInt32(row[UserQuery.Column_IsAdmin]) == 1;
|
||||
IsOperator = Convert.ToInt32(row[UserQuery.Column_IsOperator]) == 1;
|
||||
IsEnable = Convert.ToInt32(row[UserQuery.Column_IsEnable]) == 1;
|
||||
Credits = Convert.ToDecimal(row[UserQuery.Column_Credits]);
|
||||
Materials = Convert.ToDecimal(row[UserQuery.Column_Materials]);
|
||||
GameTime = Convert.ToDecimal(row[UserQuery.Column_GameTime]);
|
||||
AutoKey = (string)row[UserQuery.Column_AutoKey];
|
||||
Id = (long)DataRow[UserQuery.Column_UID];
|
||||
Username = (string)DataRow[UserQuery.Column_Username];
|
||||
Password = (string)DataRow[UserQuery.Column_Password];
|
||||
RegTime = (DateTime)DataRow[UserQuery.Column_RegTime];
|
||||
LastTime = (DateTime)DataRow[UserQuery.Column_LastTime];
|
||||
Email = (string)DataRow[UserQuery.Column_Email];
|
||||
NickName = (string)DataRow[UserQuery.Column_Nickname];
|
||||
IsAdmin = Convert.ToInt32(DataRow[UserQuery.Column_IsAdmin]) == 1;
|
||||
IsOperator = Convert.ToInt32(DataRow[UserQuery.Column_IsOperator]) == 1;
|
||||
IsEnable = Convert.ToInt32(DataRow[UserQuery.Column_IsEnable]) == 1;
|
||||
Credits = Convert.ToDecimal(DataRow[UserQuery.Column_Credits]);
|
||||
Materials = Convert.ToDecimal(DataRow[UserQuery.Column_Materials]);
|
||||
GameTime = Convert.ToDecimal(DataRow[UserQuery.Column_GameTime]);
|
||||
AutoKey = (string)DataRow[UserQuery.Column_AutoKey];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 = 2048;
|
||||
public const int SocketByteSize = 20480;
|
||||
public const int StreamByteSize = 2048;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,19 +17,37 @@ namespace Milimoe.FunGame.Core.Library.Server
|
||||
_Server = Server;
|
||||
}
|
||||
|
||||
public List<Room> GetList()
|
||||
public List<Room> GetRoomList()
|
||||
{
|
||||
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)
|
||||
{
|
||||
_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)
|
||||
{
|
||||
_List.Remove(Room.Name);
|
||||
_List.Remove(Room.Roomid);
|
||||
}
|
||||
|
||||
public Room? GetRoom(string RoomID)
|
||||
|
||||
@ -130,9 +130,9 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
object[] objs = SocketObject.Parameters;
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
DataSet? Set = SocketObject.GetParam<DataSet>(0);
|
||||
DataRow? row = SocketObject.GetParam<DataRow>(0);
|
||||
// 创建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?.OnAfterLoginEvent(Login.EventArgs);
|
||||
return;
|
||||
|
||||
@ -162,6 +162,10 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
case SocketMessageType.Chat:
|
||||
SocketHandler_Chat(SocketObject);
|
||||
break;
|
||||
|
||||
case SocketMessageType.UpdateRoom:
|
||||
SocketHandler_UpdateRoom(SocketObject);
|
||||
break;
|
||||
|
||||
case SocketMessageType.Unknown:
|
||||
default:
|
||||
@ -221,6 +225,11 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
Main.OnAfterIntoRoomEvent(args);
|
||||
}
|
||||
|
||||
private void SocketHandler_UpdateRoom(SocketObject SocketObject)
|
||||
{
|
||||
Main.UpdateUI(MainInvokeType.UpdateRoom, SocketObject.Parameters);
|
||||
}
|
||||
|
||||
private void SocketHandler_Chat(SocketObject SocketObject)
|
||||
{
|
||||
SendTalkEventArgs SendTalkEventArgs = new(LastSendTalkMessage);
|
||||
|
||||
26
FunGame.Desktop/UI/Main/Main.Designer.cs
generated
26
FunGame.Desktop/UI/Main/Main.Designer.cs
generated
@ -306,18 +306,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
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.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.Name = "PresetText";
|
||||
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.FormattingEnabled = true;
|
||||
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.Name = "RoomList";
|
||||
this.RoomList.Size = new System.Drawing.Size(186, 192);
|
||||
|
||||
@ -200,6 +200,14 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
NoticeText.Text = Config.FunGame_Notice;
|
||||
break;
|
||||
|
||||
case MainInvokeType.UpdateRoom:
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
List<string> list = (List<string>)objs[0];
|
||||
RoomList.Items.AddRange(list.ToArray());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user