FriendDataManager.cs 6.2 KB

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