FriendDataManager.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. // 按照时间戳大->小排序,时间戳为0的(在线)置顶
  104. _list.Sort((long a, long b) =>
  105. {
  106. if(_friendDic[a].roleInfo.offlineTimeSec == 0
  107. && _friendDic[b].roleInfo.offlineTimeSec == 0)
  108. {
  109. return 0;
  110. }
  111. if(_friendDic[a].roleInfo.offlineTimeSec == 0)
  112. {
  113. return -1;
  114. }
  115. if (_friendDic[b].roleInfo.offlineTimeSec == 0)
  116. {
  117. return 1;
  118. }
  119. long count = _friendDic[a].roleInfo.offlineTimeSec - _friendDic[b].roleInfo.offlineTimeSec;
  120. if (count > 0)
  121. {
  122. return -1;
  123. }
  124. else if(count < 0)
  125. {
  126. return 1;
  127. }
  128. else
  129. {
  130. return 0;
  131. }
  132. });
  133. }
  134. private List<OtherRoleInfoData> _recommendDatas = new List<OtherRoleInfoData>();//推荐列表
  135. public List<OtherRoleInfoData> RecommendDatas
  136. {
  137. get
  138. {
  139. return _recommendDatas;
  140. }
  141. }
  142. public void AddRecommendData(OtherRoleInfoData recommendData)
  143. {
  144. _recommendDatas.Add(recommendData);
  145. }
  146. public void ClearRecommendDatas()
  147. {
  148. _recommendDatas.Clear();
  149. }
  150. private List<OtherRoleInfoData> _searchDatas = new List<OtherRoleInfoData>();//搜索列表
  151. public List<OtherRoleInfoData> SearchDatas
  152. {
  153. get
  154. {
  155. return _searchDatas;
  156. }
  157. }
  158. public void AddSearchData(OtherRoleInfoData searchData)
  159. {
  160. _searchDatas.Add(searchData);
  161. }
  162. public void ClearSearchDatas()
  163. {
  164. _searchDatas.Clear();
  165. }
  166. private List<FriendInfoData> _applyDatas = new List<FriendInfoData>();//申请添加好友列表
  167. public List<FriendInfoData> ApplyDatas
  168. {
  169. get
  170. {
  171. return _applyDatas;
  172. }
  173. }
  174. public void AddApplyData(FriendInfoData applyData)
  175. {
  176. _applyDatas.Add(applyData);
  177. }
  178. public bool CheckInApplyList(long roleId)
  179. {
  180. foreach (var friendInfo in _applyDatas)
  181. {
  182. if (friendInfo.roleInfo.roleId == roleId)
  183. {
  184. return true;
  185. }
  186. }
  187. return false;
  188. }
  189. public void RemoveApplyData(long roleId)
  190. {
  191. for (int i = _applyDatas.Count - 1; i >= 0; i--)
  192. {
  193. if (roleId == _applyDatas[i].roleInfo.roleId)
  194. {
  195. _applyDatas.RemoveAt(i);
  196. }
  197. }
  198. }
  199. public void ClearApplyDatas()
  200. {
  201. _applyDatas.Clear();
  202. }
  203. public int GetGiftState(long roleId)
  204. {
  205. FriendInfoData friendInfo = _friendDic[roleId];
  206. if (friendInfo.takeGiftState == ConstBonusStatus.CAN_GET)
  207. {
  208. return 0;
  209. }
  210. if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.CanGave)
  211. {
  212. return 1;
  213. }
  214. if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.Gave && friendInfo.takeGiftState != ConstBonusStatus.GOT)
  215. {
  216. return 2;
  217. }
  218. return 3;
  219. }
  220. }
  221. }