IClassSystem.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using MaidStatus.CsvData;
  5. using wf;
  6. namespace MaidStatus
  7. {
  8. public abstract class IClassSystem<T> where T : AbstractClassData
  9. {
  10. public abstract ReadOnlySortedDictionary<int, ClassData<T>> datas { get; protected set; }
  11. public abstract ReadOnlySortedDictionary<int, ClassData<T>> oldDatas { get; protected set; }
  12. public abstract Status status { get; protected set; }
  13. public abstract ClassData<T> Add(T data, bool setOpenFlag, bool updateBonusStatus = true);
  14. public abstract void Remove(T data, bool updateBonusStatus = true);
  15. public abstract T IdToClass(int id);
  16. public abstract void Serialize(BinaryWriter binary);
  17. public abstract void Deserialize(BinaryReader binary, int version);
  18. protected abstract List<T> GetAllBaseClassData();
  19. public virtual SortedDictionary<int, ClassData<T>> GetAllDatas()
  20. {
  21. SortedDictionary<int, ClassData<T>> sortedDictionary = new SortedDictionary<int, ClassData<T>>();
  22. foreach (ClassData<T> classData in this.datas.GetValueArray())
  23. {
  24. if (!sortedDictionary.ContainsKey(classData.data.id))
  25. {
  26. sortedDictionary.Add(classData.data.id, classData);
  27. }
  28. }
  29. if (this.oldDatas != null)
  30. {
  31. foreach (ClassData<T> classData2 in this.oldDatas.GetValueArray())
  32. {
  33. if (!sortedDictionary.ContainsKey(classData2.data.id))
  34. {
  35. sortedDictionary.Add(classData2.data.id, classData2);
  36. }
  37. }
  38. }
  39. return sortedDictionary;
  40. }
  41. public virtual ClassData<T> Add(int id, bool setOpenFlag, bool updateBonusStatus = true)
  42. {
  43. return this.Add(this.IdToClass(id), setOpenFlag, updateBonusStatus);
  44. }
  45. public virtual void Remove(int id, bool updateBonusStatus = true)
  46. {
  47. this.Remove(this.IdToClass(id), updateBonusStatus);
  48. }
  49. public virtual bool Contains(int id)
  50. {
  51. return this.Contains(this.IdToClass(id));
  52. }
  53. public virtual bool Contains(T data)
  54. {
  55. return data != null && (this.datas.ContainsKey(data.id) || (this.oldDatas != null && this.oldDatas.ContainsKey(data.id)));
  56. }
  57. public virtual ClassData<T> Get(T data)
  58. {
  59. return this.Contains(data) ? ((!this.datas.ContainsKey(data.id)) ? this.oldDatas[data.id] : this.datas[data.id]) : null;
  60. }
  61. public virtual ClassData<T> Get(int id)
  62. {
  63. return this.Get(this.IdToClass(id));
  64. }
  65. public virtual List<T> GetLearnPossibleClassDatas(bool unlearnedOnly, AbstractClassData.ClassType classTypeFlags)
  66. {
  67. List<T> list = new List<T>();
  68. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  69. List<T> allBaseClassData = this.GetAllBaseClassData();
  70. foreach (T t in allBaseClassData)
  71. {
  72. if (!unlearnedOnly || !this.Contains(t.id))
  73. {
  74. if ((classTypeFlags & t.classType) != (AbstractClassData.ClassType)0 && t.learnConditions.isLearnPossibleStatus(this.status))
  75. {
  76. list.Add(t);
  77. }
  78. }
  79. }
  80. return list;
  81. }
  82. protected SortedDictionary<int, ClassData<T>> classDatas_;
  83. protected SortedDictionary<int, ClassData<T>> oldClassDatas_;
  84. }
  85. }