FriendDataManager.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. return GlobalCfgArray.globalCfg.maxGetPowerCount + GameGlobal.myNumericComponent.GetAsInt(ET.NumericType.MonthCardFriendPowerAdd);
  28. }
  29. }
  30. private Dictionary<long, FriendInfoData> _friendDic = new Dictionary<long, FriendInfoData>();//好友列表
  31. private List<FriendInfoData> _list = new List<FriendInfoData>();
  32. public List<FriendInfoData> FriendDatas
  33. {
  34. get
  35. {
  36. return _list;
  37. }
  38. }
  39. public void ClearAddFriend()
  40. {
  41. _list.Clear();
  42. _friendDic.Clear();
  43. }
  44. public void AddFriend(FriendInfoData roleInfo)
  45. {
  46. if (_friendDic.ContainsKey(roleInfo.roleInfo.roleId)) return;
  47. _friendDic.Add(roleInfo.roleInfo.roleId, roleInfo);
  48. UpdateFriendList(true);
  49. }
  50. public void RemoveFriend(long roleId)
  51. {
  52. if (_friendDic.ContainsKey(roleId))
  53. {
  54. _friendDic.Remove(roleId);
  55. UpdateFriendList(true);
  56. }
  57. }
  58. public FriendInfoData GetFriendDataById(long roleId)
  59. {
  60. if (_friendDic.ContainsKey(roleId))
  61. {
  62. return _friendDic[roleId];
  63. }
  64. return null;
  65. }
  66. public void ChangeFriendInfo(OtherRoleInfoData roleInfo)
  67. {
  68. if (_friendDic.ContainsKey(roleInfo.roleId))
  69. {
  70. _friendDic[roleInfo.roleId].roleInfo = roleInfo;
  71. }
  72. }
  73. public void ChangeGiveGiftStates(long roleId, int state)
  74. {
  75. if (_friendDic.ContainsKey(roleId))
  76. {
  77. _friendDic[roleId].giveGiftState = state;
  78. }
  79. }
  80. public void ChangeTakeGiftStates(long roleId, int state)
  81. {
  82. if (_friendDic.ContainsKey(roleId))
  83. {
  84. _friendDic[roleId].takeGiftState = state;
  85. }
  86. }
  87. public void ChangeGiveTakeGiftStates(long roleId, int state, int takeState)
  88. {
  89. if (_friendDic.ContainsKey(roleId))
  90. {
  91. _friendDic[roleId].giveGiftState = state;
  92. _friendDic[roleId].takeGiftState = takeState;
  93. }
  94. }
  95. public void UpdateFriendList(bool sort)
  96. {
  97. _list = _friendDic.Values.ToList<FriendInfoData>();
  98. if (!sort) return;
  99. _list.Sort((FriendInfoData a, FriendInfoData b) =>
  100. {
  101. long count = b.roleInfo.offlineTimeSec - a.roleInfo.offlineTimeSec;
  102. if (count > 0)
  103. {
  104. return -1;
  105. }
  106. else
  107. {
  108. return 1;
  109. }
  110. });
  111. }
  112. private List<OtherRoleInfoData> _recommendDatas = new List<OtherRoleInfoData>();//推荐列表
  113. public List<OtherRoleInfoData> RecommendDatas
  114. {
  115. get
  116. {
  117. return _recommendDatas;
  118. }
  119. }
  120. public void AddRecommendData(OtherRoleInfoData recommendData)
  121. {
  122. _recommendDatas.Add(recommendData);
  123. }
  124. public void ClearRecommendDatas()
  125. {
  126. _recommendDatas.Clear();
  127. }
  128. private List<OtherRoleInfoData> _searchDatas = new List<OtherRoleInfoData>();//搜索列表
  129. public List<OtherRoleInfoData> SearchDatas
  130. {
  131. get
  132. {
  133. return _searchDatas;
  134. }
  135. }
  136. public void AddSearchData(OtherRoleInfoData searchData)
  137. {
  138. _searchDatas.Add(searchData);
  139. }
  140. public void ClearSearchDatas()
  141. {
  142. _searchDatas.Clear();
  143. }
  144. private List<FriendInfoData> _applyDatas = new List<FriendInfoData>();//申请添加好友列表
  145. public List<FriendInfoData> ApplyDatas
  146. {
  147. get
  148. {
  149. return _applyDatas;
  150. }
  151. }
  152. public void AddApplyData(FriendInfoData applyData)
  153. {
  154. _applyDatas.Add(applyData);
  155. }
  156. public void RemoveApplyData(long roleId)
  157. {
  158. for (int i = _applyDatas.Count - 1; i >= 0; i--)
  159. {
  160. if (roleId == _applyDatas[i].roleInfo.roleId)
  161. {
  162. _applyDatas.RemoveAt(i);
  163. }
  164. }
  165. }
  166. public void ClearApplyDatas()
  167. {
  168. _applyDatas.Clear();
  169. }
  170. public int GetGiftState(long roleId)
  171. {
  172. FriendInfoData friendInfo = _friendDic[roleId];
  173. if (friendInfo.takeGiftState == ConstBonusStatus.CAN_GET)
  174. {
  175. return 0;
  176. }
  177. if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.CanGave)
  178. {
  179. return 1;
  180. }
  181. if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.Gave && friendInfo.takeGiftState != ConstBonusStatus.GOT)
  182. {
  183. return 2;
  184. }
  185. return 3;
  186. }
  187. }
  188. }