FriendDataManager.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using ET;
  4. namespace GFGGame
  5. {
  6. public class FriendDataManager : SingletonBase<FriendDataManager>
  7. {
  8. public void Clear()
  9. {
  10. ClearAddFriend();
  11. ClearRecommendDatas();
  12. ClearSearchDatas();
  13. ClearApplyDatas();
  14. }
  15. public int Count//今日已领体力数
  16. {
  17. get
  18. {
  19. return GameGlobal.myNumericComponent.GetAsInt(NumericType.TakeFriendGiftCount);
  20. }
  21. }
  22. //可领取体力的上限值
  23. public int maxGetPowerCount
  24. {
  25. get
  26. {
  27. var t = GameGlobal.myNumericComponent.GetAsInt(ET.NumericType.MonthCardFriendPowerAdd);
  28. return GlobalCfgArray.globalCfg.maxGetPowerCount + t * GlobalCfgArray.globalCfg.onceGivePowerCount;
  29. }
  30. }
  31. private Dictionary<long, FriendInfoData> _friendDic = new Dictionary<long, FriendInfoData>();//好友列表
  32. private List<long> _list = new List<long>();
  33. public List<long> FriendDatas
  34. {
  35. get
  36. {
  37. return _list;
  38. }
  39. }
  40. public void ClearAddFriend()
  41. {
  42. _list.Clear();
  43. _friendDic.Clear();
  44. }
  45. public void AddFriend(FriendInfoData roleInfo)
  46. {
  47. long roleId = roleInfo.roleInfo.roleId;
  48. if (_list.IndexOf(roleId) >= 0) return;
  49. _list.Add(roleId);
  50. _friendDic.Add(roleInfo.roleInfo.roleId, roleInfo);
  51. UpdateFriendList(true);
  52. }
  53. public void RemoveFriend(long roleId)
  54. {
  55. if (_list.IndexOf(roleId) >= 0)
  56. {
  57. _list.Remove(roleId);
  58. _friendDic.Remove(roleId);
  59. UpdateFriendList(true);
  60. }
  61. }
  62. public FriendInfoData GetFriendDataById(long roleId)
  63. {
  64. if (_friendDic.ContainsKey(roleId))
  65. {
  66. return _friendDic[roleId];
  67. }
  68. return null;
  69. }
  70. public void ChangeFriendInfo(OtherRoleInfoData roleInfo)
  71. {
  72. if (_friendDic.ContainsKey(roleInfo.roleId))
  73. {
  74. _friendDic[roleInfo.roleId].roleInfo = roleInfo;
  75. }
  76. }
  77. public void ChangeGiveGiftStates(long roleId, int state)
  78. {
  79. if (_friendDic.ContainsKey(roleId))
  80. {
  81. _friendDic[roleId].giveGiftState = state;
  82. }
  83. }
  84. public void ChangeTakeGiftStates(long roleId, int state)
  85. {
  86. if (_friendDic.ContainsKey(roleId))
  87. {
  88. _friendDic[roleId].takeGiftState = state;
  89. }
  90. }
  91. public void ChangeGiveTakeGiftStates(long roleId, int state, int takeState)
  92. {
  93. if (_friendDic.ContainsKey(roleId))
  94. {
  95. _friendDic[roleId].giveGiftState = state;
  96. _friendDic[roleId].takeGiftState = takeState;
  97. }
  98. }
  99. public void UpdateFriendList(bool sort)
  100. {
  101. // _list = _friendDic.Values.ToList<FriendInfoData>();
  102. if (!sort) return;
  103. _list.Sort((long a, long b) =>
  104. {
  105. long count = _friendDic[b].roleInfo.offlineTimeSec - _friendDic[a].roleInfo.offlineTimeSec;
  106. if (count > 0)
  107. {
  108. return -1;
  109. }
  110. else
  111. {
  112. return 1;
  113. }
  114. });
  115. }
  116. private List<OtherRoleInfoData> _recommendDatas = new List<OtherRoleInfoData>();//推荐列表
  117. public List<OtherRoleInfoData> RecommendDatas
  118. {
  119. get
  120. {
  121. return _recommendDatas;
  122. }
  123. }
  124. public void AddRecommendData(OtherRoleInfoData recommendData)
  125. {
  126. _recommendDatas.Add(recommendData);
  127. }
  128. public void ClearRecommendDatas()
  129. {
  130. _recommendDatas.Clear();
  131. }
  132. private List<OtherRoleInfoData> _searchDatas = new List<OtherRoleInfoData>();//搜索列表
  133. public List<OtherRoleInfoData> SearchDatas
  134. {
  135. get
  136. {
  137. return _searchDatas;
  138. }
  139. }
  140. public void AddSearchData(OtherRoleInfoData searchData)
  141. {
  142. _searchDatas.Add(searchData);
  143. }
  144. public void ClearSearchDatas()
  145. {
  146. _searchDatas.Clear();
  147. }
  148. private List<FriendInfoData> _applyDatas = new List<FriendInfoData>();//申请添加好友列表
  149. public List<FriendInfoData> ApplyDatas
  150. {
  151. get
  152. {
  153. return _applyDatas;
  154. }
  155. }
  156. public void AddApplyData(FriendInfoData applyData)
  157. {
  158. _applyDatas.Add(applyData);
  159. }
  160. public bool CheckInApplyList(long roleId)
  161. {
  162. foreach (var friendInfo in _applyDatas)
  163. {
  164. if (friendInfo.roleInfo.roleId == roleId)
  165. {
  166. return true;
  167. }
  168. }
  169. return false;
  170. }
  171. public void RemoveApplyData(long roleId)
  172. {
  173. for (int i = _applyDatas.Count - 1; i >= 0; i--)
  174. {
  175. if (roleId == _applyDatas[i].roleInfo.roleId)
  176. {
  177. _applyDatas.RemoveAt(i);
  178. }
  179. }
  180. }
  181. public void ClearApplyDatas()
  182. {
  183. _applyDatas.Clear();
  184. }
  185. public int GetGiftState(long roleId)
  186. {
  187. FriendInfoData friendInfo = _friendDic[roleId];
  188. if (friendInfo.takeGiftState == ConstBonusStatus.CAN_GET)
  189. {
  190. return 0;
  191. }
  192. if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.CanGave)
  193. {
  194. return 1;
  195. }
  196. if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.Gave && friendInfo.takeGiftState != ConstBonusStatus.GOT)
  197. {
  198. return 2;
  199. }
  200. return 3;
  201. }
  202. }
  203. }