ActorDataMgr.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using LuaInterface;
  5. public class ActorDataMgr : Singleton<ActorDataMgr>
  6. {
  7. private List<ActorData> mActors = null;
  8. private List<PetActorData> mPetActors = null;
  9. public override void Init()
  10. {
  11. base.Init();
  12. mActors = new List<ActorData>();
  13. }
  14. public override void UnInit()
  15. {
  16. base.UnInit();
  17. Clear();
  18. }
  19. public void Clear()
  20. {
  21. if (mActors != null)
  22. {
  23. mActors.Clear();
  24. }
  25. if (mPetActors != null)
  26. {
  27. mPetActors.Clear();
  28. }
  29. }
  30. public void ResetData()
  31. {
  32. if(mActors != null)
  33. {
  34. for(int idx =0; idx < mActors.Count;idx++)
  35. {
  36. mActors[idx].SetDropBuffs(null);
  37. }
  38. }
  39. if(mPetActors != null)
  40. {
  41. for(int idx =0; idx < mPetActors.Count;idx++)
  42. {
  43. mPetActors[idx].SetDropBuffs(null);
  44. }
  45. }
  46. }
  47. public Dictionary<int, float> GetIncreaseSecondAttrVal(int id, int strVal, int agiVal, int intVal, int vitVal, int dexVal, int lukVal)
  48. {
  49. ActorData actorData = GetActorsById(id);
  50. if (actorData != null)
  51. {
  52. int[] vals = new int[] { strVal, agiVal, intVal, vitVal, dexVal, lukVal };
  53. return actorData.GetPreviewAttr(vals);
  54. }
  55. return null;
  56. }
  57. public Dictionary<int, float> GetRoleIncreaseSecondAttrVal(int id, int strVal, int agiVal, int intVal, int vitVal, int dexVal, int lukVal)
  58. {
  59. int[] vals = new int[] { strVal, agiVal, intVal, vitVal, dexVal, lukVal };
  60. ActorData actorData = GetActorsById(id);
  61. if (actorData != null)
  62. {
  63. return actorData.GetPreviewAttr(vals);
  64. }
  65. return null;
  66. }
  67. public Dictionary<int, float> GetLvUpLocalPreviewSecondAttrVal(int id, int lv)
  68. {
  69. ActorData actorData = GetActorsById(id);
  70. if (actorData != null)
  71. {
  72. return actorData.GetPreviewLvUpLocalAttr(lv);
  73. }
  74. return null;
  75. }
  76. public Dictionary<int, float> GetLvUpPreviewSecondAttrVal(int id, int lv)
  77. {
  78. ActorData actorData = GetActorsById(id);
  79. if (actorData != null)
  80. {
  81. return actorData.GetPreviewLvUpAttr(lv);
  82. }
  83. return null;
  84. }
  85. public HeroActorData GetHeroActorData(int baseId)
  86. {
  87. return GameMgr.Instance.CharacterInfo.Actor;
  88. }
  89. public FellowActorData GetFellowActorData(int uid,int baseId)
  90. {
  91. FellowActorData fellow = null;
  92. ActorData actor = GetActorsByBaseId(baseId);
  93. if(actor == null)
  94. {
  95. fellow = CreateFellow(uid, baseId, 1, null);
  96. }
  97. else
  98. {
  99. fellow = actor as FellowActorData;
  100. }
  101. return fellow;
  102. }
  103. public PetActorData GetPetActorData(long uid,int baseId)
  104. {
  105. PetActorData pet = GetPetDataById(uid);
  106. if(pet == null)
  107. {
  108. pet = CreatePet(uid, baseId, 1, null);
  109. }
  110. return pet;
  111. }
  112. public ActorData GetActorData(bool role,int baseId)
  113. {
  114. if(role)
  115. {
  116. return GetHeroActorData(baseId);
  117. }
  118. else
  119. {
  120. return GetActorsByBaseId(baseId);
  121. }
  122. }
  123. public bool HasFellowActorData(int baseId)
  124. {
  125. return GetActorsByBaseId(baseId) != null;
  126. }
  127. public int GetFellowActorDataCountByUid(int uid)
  128. {
  129. int count = 0;
  130. for (int idx = mActors.Count - 1; idx >= 0; idx--)
  131. {
  132. if (mActors[idx].ID == uid)
  133. {
  134. count += 1;
  135. }
  136. }
  137. return count;
  138. }
  139. public void DeleteFellowActorData(int baseId)
  140. {
  141. for(int idx = mActors.Count - 1; idx >= 0;idx--)
  142. {
  143. if(mActors[idx].BaseId == baseId)
  144. {
  145. mActors[idx].Dispose();
  146. mActors.RemoveAt(idx);
  147. return;
  148. }
  149. }
  150. }
  151. public void DeleteActorDataById(long uid)
  152. {
  153. for (int idx = mActors.Count - 1; idx >= 0; idx--)
  154. {
  155. if (mActors[idx].ID == uid)
  156. {
  157. mActors[idx].Dispose();
  158. mActors.RemoveAt(idx);
  159. }
  160. }
  161. }
  162. public void RefreshFellowActorData(long uid,int baseId)
  163. {
  164. if (mActors == null) return;
  165. for (int idx = mActors.Count - 1; idx >=0; idx--)
  166. {
  167. if (mActors[idx].ID == uid && mActors[idx].BaseId != baseId)
  168. {
  169. mActors[idx].Dispose();
  170. mActors.RemoveAt(idx);
  171. }
  172. }
  173. }
  174. public bool HasPetActorData(long uid)
  175. {
  176. return GetPetDataById(uid) != null;
  177. }
  178. public HeroActorData CreateMainRole(LuaTable roleParam)
  179. {
  180. HeroActorData hero = ActorData.CreatePlayerActor(roleParam) as HeroActorData;
  181. mActors.Add(hero);
  182. return hero;
  183. }
  184. public FellowActorData CreateFellow(long uid,int baseId,int level, SkillParam[] skillParams)
  185. {
  186. FellowActorData fellow = ActorData.CreateFellowActor(uid, baseId, level, skillParams) as FellowActorData;
  187. mActors.Add(fellow);
  188. return fellow;
  189. }
  190. public PetActorData CreatePet(long uid,int baseId,int level,SkillParam[] skillParams)
  191. {
  192. PetActorData pet = ActorData.CreatePetActor(uid, baseId, level, skillParams) as PetActorData;
  193. if (mPetActors == null)
  194. mPetActors = new List<PetActorData>();
  195. mPetActors.Add(pet);
  196. return pet;
  197. }
  198. //boss战变身宠物
  199. public PetActorData CreatePetBossActor(long uid, int baseId, int level)
  200. {
  201. PetActorData pet = ActorData.CreatePetBossActor(uid, baseId, level) as PetActorData;
  202. if (mPetActors == null)
  203. mPetActors = new List<PetActorData>();
  204. mPetActors.Add(pet);
  205. return pet;
  206. }
  207. public ActorData CreateNpc(int uid,int baseId,int pos,int level)
  208. {
  209. ActorData npc = ActorData.CreateNpcPlayerActor(uid, baseId, level);
  210. npc.PositionValue = pos;
  211. return npc;
  212. }
  213. public ActorData GetActorsById(long uid)
  214. {
  215. if (mActors == null) return null;
  216. for(int idx = mActors.Count -1; idx >= 0; idx --)
  217. {
  218. if (mActors[idx].ID == uid) return mActors[idx];
  219. }
  220. return null;
  221. }
  222. public ActorData GetActorsById(long uid,int baseId)
  223. {
  224. if (mActors == null) return null;
  225. for (int idx = 0; idx < mActors.Count; idx++)
  226. {
  227. if (mActors[idx].ID == uid && mActors[idx].BaseId == baseId) return mActors[idx];
  228. }
  229. return null;
  230. }
  231. public ActorData GetActorsByBaseId(int baseId)
  232. {
  233. if (mActors == null) return null;
  234. for (int idx = 0; idx < mActors.Count; idx++)
  235. {
  236. if (mActors[idx].BaseId == baseId) return mActors[idx];
  237. }
  238. return null;
  239. }
  240. public PetActorData GetPetDataById(long uid)
  241. {
  242. if (mPetActors == null) return null;
  243. for(int idx =0; idx < mPetActors.Count;idx++)
  244. {
  245. if (mPetActors[idx].ID == uid)
  246. return mPetActors[idx];
  247. }
  248. return null;
  249. }
  250. public void DeletePetActorData(int uid)
  251. {
  252. if (mPetActors == null) return;
  253. for (int idx = mPetActors.Count - 1; idx >= 0; idx--)
  254. {
  255. if (mPetActors[idx].ID == uid)
  256. {
  257. mPetActors[idx].Dispose();
  258. mPetActors.RemoveAt(idx);
  259. return;
  260. }
  261. }
  262. }
  263. }