using System.Data; using Milimoe.FunGame.Core.Api.Factory; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Api.Utility { public class Factory { /// /// 获取Room实例 /// /// Room /// User(RoomMaster) /// 取指定行 /// public static Room GetRoom(DataSet? DsRoom, DataSet? DsUser, int Index = 0) { return RoomFactory.GetInstance(DsRoom, DsUser, Index); } /// /// 获取大厅(-1号房) /// /// internal static Room GetHall() { return GetRoom(null, null); } /// /// 获取Skill实例,默认返回PassiveSkill /// /// SkillRow /// Skill类型 /// 取指定行 /// public static Skill GetSkill(DataSet? DataSet, SkillType SkillType = SkillType.Passive, int Index = 0) { return SkillFactory.GetInstance(DataSet, SkillType, Index); } /// /// 获取User实例 /// awaa /// UserRow /// 取指定行 /// public static User GetUser(DataSet? DataSet, int Index = 0) { return UserFactory.GetInstance(DataSet, Index); } /// /// 获取一个不为NULL的实例 /// Item默认返回PassiveItem /// Skill默认返回PassiveSkill /// 若无法找到T,返回唯一的空对象 /// /// Entity类 /// 使用DataSets构造对象 /// T public static T GetInstance(params DataSet?[] DataSets) { if (DataSets is null || DataSets.Length == 0) throw new GetInstanceException(); object instance = General.EntityInstance; if (typeof(T) == typeof(User)) { instance = GetUser(DataSets[0]); } else if (typeof(T) == typeof(Skill) || typeof(T) == typeof(PassiveSkill)) { instance = GetSkill(DataSets[0]); } else if (typeof(T) == typeof(ActiveSkill)) { instance = GetSkill(DataSets[0], SkillType.Active); } else if (typeof(T) == typeof(Room)) { instance = GetRoom(DataSets[0], DataSets[1]); } return (T)instance; } /// /// 获取T的数组 /// Item默认返回PassiveItem数组 /// Skill默认返回PassiveSkill数组 /// 若无法找到T,返回空数组 /// /// Entity类 /// 使用DataSet构造对象数组 /// List T public static List GetList(params DataSet?[] DataSets) { List 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) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { object entity = GetUser(ds, i); 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) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { object entity = GetSkill(ds, SkillType.Passive, i); list.Add((T)entity); } } } else if (typeof(T) == typeof(ActiveSkill)) { DataSet? ds = DataSets[0]; if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { object entity = GetSkill(ds, SkillType.Active, i); list.Add((T)entity); } } } else if (typeof(T) == typeof(Room)) { DataSet? DsRoom = DataSets[0]; DataSet? DsUser = DataSets[1]; object entity = General.HallInstance; list.Add((T)entity); if (DsRoom != null && DsRoom.Tables[0].Rows.Count > 0) { for (int i = 0; i < DsRoom.Tables[0].Rows.Count; i++) { entity = GetRoom(DsRoom, DsUser, i); list.Add((T)entity); } } } return list; } } }