FriendDataManager.cs 6.4 KB

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