添加Room类

This commit is contained in:
Mili 2023-03-17 00:17:05 +08:00
parent 3d5aee0a45
commit 3c2e26d67e
10 changed files with 60 additions and 66 deletions

View File

@ -1,27 +1,13 @@
using Milimoe.FunGame.Core.Library.Constant;
using System.Data;
using Milimoe.FunGame.Core.Entity;
namespace Milimoe.FunGame.Core.Api.Factory
{
internal class RoomFactory
{
internal static Milimoe.FunGame.Core.Entity.Room GetInstanceByRandomID(RoomType type, Milimoe.FunGame.Core.Entity.User? user)
internal static Room GetInstance(DataSet? DataSet)
{
Milimoe.FunGame.Core.Entity.Room room = new(user)
{
RoomType = type,
RoomState = RoomState.Created
};
return room;
}
internal static Milimoe.FunGame.Core.Entity.Room GetInstanceByRoomID(RoomType type, string roomid, Milimoe.FunGame.Core.Entity.User? user)
{
Milimoe.FunGame.Core.Entity.Room room = new(roomid, user)
{
RoomType = type,
RoomState = RoomState.Created
};
return room;
return new Room(DataSet);
}
}
}

View File

@ -1,22 +1,18 @@
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(SkillType type, string Name)
internal static Skill GetInstance(DataSet? DataSet, SkillType type = SkillType.Passive)
{
Skill? skill = null;
switch (type)
Skill skill = type switch
{
case SkillType.Active:
skill = new Milimoe.FunGame.Core.Entity.ActiveSkill(Name);
break;
case SkillType.Passive:
skill = new Milimoe.FunGame.Core.Entity.PassiveSkill(Name);
break;
}
SkillType.Active => new ActiveSkill(DataSet),
_ => new PassiveSkill(DataSet)
};
return skill;
}
}

View File

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

View File

@ -1,4 +1,5 @@
using System.Data;
using Milimoe.FunGame.Core.Api.Factory;
using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Core.Library.Constant;
@ -7,7 +8,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
public class Factory
{
/// <summary>
/// 获取一个可能为NULL的实例
/// 获取一个为NULL的实例
/// <para>Item默认返回PassiveItem</para>
/// <para>Skill默认返回PassiveSkill</para>
/// <para>若无法找到T返回唯一的空对象</para>
@ -20,11 +21,15 @@ namespace Milimoe.FunGame.Core.Api.Utility
object instance = General.EntityInstance;
if (typeof(T) == typeof(User))
{
instance = Api.Factory.UserFactory.GetInstance(DataSet);
instance = UserFactory.GetInstance(DataSet);
}
else if (typeof(T) == typeof(Skill))
else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill))
{
instance = SkillFactory.GetInstance(DataSet);
}
else if (typeof(T) == typeof(ActiveSkill))
{
instance = SkillFactory.GetInstance(DataSet, SkillType.Active);
}
return (T)instance;
}

View File

@ -1,4 +1,6 @@
namespace Milimoe.FunGame.Core.Entity
using System.Data;
namespace Milimoe.FunGame.Core.Entity
{
public class ActiveSkill : Skill
{
@ -15,15 +17,9 @@
public decimal Reference9 { get; set; } = 0;
public decimal Reference10 { get; set; } = 0;
internal ActiveSkill()
internal ActiveSkill(DataSet? DataSet)
{
Active = true;
}
internal ActiveSkill(string Name)
{
Active = true;
this.Name = Name;
}
}
}

View File

@ -1,4 +1,6 @@
namespace Milimoe.FunGame.Core.Entity
using System.Data;
namespace Milimoe.FunGame.Core.Entity
{
public class PassiveSkill : Skill
{
@ -13,15 +15,9 @@
public decimal Reference9 { get; set; } = 0;
public decimal Reference10 { get; set; } = 0;
internal PassiveSkill()
internal PassiveSkill(DataSet? DataSet)
{
Active = false;
}
internal PassiveSkill(string Name)
{
Active = false;
this.Name = Name;
}
}
}

View File

@ -1,13 +1,14 @@
using Milimoe.FunGame.Core.Interface.Entity;
using Milimoe.FunGame.Core.Library.Constant;
using System.Collections;
using System.Data;
namespace Milimoe.FunGame.Core.Entity
{
public class Room : BaseEntity
{
public string Roomid { get; set; } = "";
public DateTime Time { get; set; } = DateTime.Now;
public DateTime CreateTime { get; set; } = DateTime.Now;
public Hashtable PlayerList { get; set; } = new Hashtable();
public User? RoomMaster { get; set; }
public RoomType RoomType { get; set; }
@ -24,15 +25,12 @@ namespace Milimoe.FunGame.Core.Entity
public string Password { get; set; } = "";
public GameStatistics? Statistics { get; set; } = null;
internal Room(User? master = null)
internal Room(DataSet? DataSet)
{
if (DataSet != null && DataSet.Tables.Count > 0 && DataSet.Tables[0].Rows.Count > 0)
{
if (master != null) RoomMaster = master;
}
internal Room(string roomid, User? master = null)
{
Roomid = roomid;
if (master != null) RoomMaster = master;
}
}
public bool Equals(Room other)

View File

@ -9,14 +9,19 @@
public const string Command_Update = "Update";
public const string Command_Delete = "Delete";
public const string Command_Insert = "Insert";
public const string Command_Set = "Set";
public const string Command_Where = "Where";
public const string Command_From = "From";
public const string Command_All = "*";
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_On = "On";
}
}

View File

@ -0,0 +1,17 @@
namespace Milimoe.FunGame.Core.Library.SQLScript.Entity
{
public class RoomQuery
{
public const string TableName = "Rooms";
public const string Column_RoomID = "Roomid";
public const string Column_CreateTime = "CreateTime";
public const string Column_RoomMaster = "RoomMaster";
public const string Column_RoomMasterName = "RoomMasterName";
public const string Column_RoomType = "RoomType";
public const string Column_RoomState = "RoomState";
public const string Column_HasPass = "HasPass";
public const string Column_Password = "Password";
public const string Select_Rooms = $"{Constant.Command_Select} {TableName}.{Constant.Command_All}, {UserQuery.TableName}.{UserQuery.Column_Username} {Constant.Command_As} {Column_RoomMasterName} " +
$"{Constant.Command_From} {TableName} {Constant.Command_LeftJoin} {UserQuery.TableName} {Constant.Command_On} {UserQuery.TableName}.{UserQuery.Column_UID} = {TableName}.{Column_RoomMaster}";
}
}