MainAccount.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System;
  5. using System.Text;
  6. using System.IO;
  7. using LuaInterface;
  8. //屏蔽不使用声明变量的警告
  9. #pragma warning disable 0414
  10. public class MainCharacter
  11. {
  12. private int mCurMapId = 0; //当前所在的地图ID
  13. public int CurMapId
  14. {
  15. get { return mCurMapId; }
  16. set { mCurMapId = value; }
  17. }
  18. private int mCurLevelId = 1; //当前通关的关卡id
  19. public int CurLevelId
  20. {
  21. get { return mCurLevelId; }
  22. set { mCurLevelId = value; }
  23. }
  24. private bool mbDisposed = false;
  25. private HeroActorData mActorData = null;
  26. public HeroActorData Actor
  27. {
  28. get { return mActorData; }
  29. }
  30. private List<ActorData> mTeamActors = null;
  31. public List<ActorData> TeamActors
  32. {
  33. get { return mTeamActors; }
  34. }
  35. //战斗数据
  36. private HeroActorData mBattleActorData = null;
  37. public HeroActorData mBattleActor
  38. {
  39. get { return mBattleActorData; }
  40. }
  41. private List<ActorData> mBattleTeamActors = null;
  42. public List<ActorData> NormleBattleTeamActors
  43. {
  44. get {
  45. if (null == mBattleTeamActors)
  46. mBattleTeamActors = new List<ActorData>(TeamActors.Count);
  47. else
  48. mBattleTeamActors.Clear();
  49. for (int idx = 0; idx < TeamActors.Count; idx++)
  50. {
  51. JSONObject JsonActorData = TeamActors[idx].ToJson();
  52. ActorData actor = ActorData.CreateActorFromJson(JsonActorData);
  53. if (null != TeamActors[idx].PetData)
  54. {
  55. JsonActorData = TeamActors[idx].PetData.ToJson();
  56. ActorData pPetData = ActorData.CreateActorFromJson(JsonActorData);
  57. actor.SetPet(pPetData);
  58. }
  59. if (TeamActors[idx].IsHero)
  60. {
  61. actor.Name = TeamActors[idx].Name;
  62. }
  63. if (idx == 0)
  64. mBattleActorData = actor as HeroActorData;
  65. mBattleTeamActors.Add(actor);
  66. }
  67. return mBattleTeamActors;
  68. }
  69. }
  70. bool offline = false;
  71. public MainCharacter()
  72. {
  73. }
  74. public void Clear()
  75. {
  76. if (null != mActorData)
  77. {
  78. mActorData = null;
  79. }
  80. if (mTeamActors != null)
  81. {
  82. mTeamActors.Clear();
  83. mTeamActors = null;
  84. }
  85. }
  86. public void SetTeamActors(LuaTable teamParam)
  87. {
  88. if (offline) return;
  89. if (mTeamActors == null)
  90. mTeamActors = new List<ActorData>();
  91. else
  92. mTeamActors.Clear();
  93. if (teamParam == null) return;
  94. for (int i = 1; i <= teamParam.Length; ++i)
  95. {
  96. long uid = 0;
  97. long usedPetId = 0;
  98. int baseId = 0,level = 0;
  99. int petBaseId = 0,petLevel = 1;
  100. int headFrameId = 0;
  101. string strName = string.Empty;
  102. LuaTable ltt = (LuaTable)teamParam[i];
  103. if(ltt["uid"] != null)
  104. long.TryParse(ltt["uid"].ToString(), out uid);
  105. if (ltt["id"] != null)
  106. int.TryParse(ltt["id"].ToString(), out baseId);
  107. if (ltt["lv"] != null)
  108. int.TryParse(ltt["lv"].ToString(), out level);
  109. if (ltt["petId"] != null)
  110. long.TryParse(ltt["petId"].ToString(), out usedPetId);
  111. if (ltt["petBaseId"] != null)
  112. int.TryParse(ltt["petBaseId"].ToString(), out petBaseId);
  113. if (ltt["petLv"] != null)
  114. int.TryParse(ltt["petLv"].ToString(), out petLevel);
  115. if (ltt["Name"] != null)
  116. strName = ltt["Name"].ToString();
  117. if (ltt["headFrameId"] != null)
  118. int.TryParse(ltt["headFrameId"].ToString(), out headFrameId);
  119. if (uid == 0 || baseId == 0) continue;
  120. SkillParam[] skillParams = null;
  121. List<SkillParam> pSkillList = null;
  122. if (ltt["skills"] != null)
  123. {
  124. LuaTable skills = (LuaTable)ltt["skills"];
  125. pSkillList = ActorData.ParseSkillParam(skills);
  126. skillParams = pSkillList != null ? pSkillList.ToArray() : null;
  127. for(int t=0;t< pSkillList.Count;t++)
  128. {
  129. Debug.Log(pSkillList[t].skillId.ToString());
  130. }
  131. }
  132. SkillParam[] petSkillParams = null;
  133. if(ltt["petSkills"] != null)
  134. {
  135. LuaTable petSkills = (LuaTable)ltt["petSkills"];
  136. List<SkillParam> temp = ActorData.ParseSkillParam(petSkills);
  137. petSkillParams = temp != null ? temp.ToArray() : null;
  138. }
  139. ActorData ad = null;
  140. if (i == 1)
  141. {
  142. int jobId = 0;
  143. int.TryParse(ltt["jobId"].ToString(), out jobId);
  144. if (mActorData == null)
  145. {
  146. mActorData = ActorDataMgr.Instance.CreateMainRole(ltt);
  147. }
  148. else
  149. {
  150. bool dirtyProfession = (jobId != mActorData.ProfessionId);
  151. if(dirtyProfession)
  152. {
  153. mActorData.Initialize(baseId, level, skillParams);
  154. if (null == BattleMgr.Instance.Battle)//不在战斗中 直接设置
  155. {
  156. mActorData.SetProfessionId(jobId);
  157. }
  158. else
  159. {
  160. BattleMgr.Instance.SetProfessionDirty(dirtyProfession, jobId);//标记后 设置
  161. }
  162. }
  163. else
  164. {
  165. BattleMgr.Instance.UpdateTeamSkills((int)mActorData.ID, pSkillList);
  166. }
  167. }
  168. if(strName != string.Empty)
  169. {
  170. mActorData.Name = strName;
  171. }
  172. mActorData.Level = level;
  173. mActorData.HeadFrameId = headFrameId;
  174. ad = mActorData;
  175. }
  176. else
  177. {
  178. if(ActorDataMgr.Instance.HasFellowActorData(baseId))
  179. {
  180. FellowActorData fellowAD = ActorDataMgr.Instance.GetActorsByBaseId(baseId) as FellowActorData;
  181. //fellowAD.Initialize(baseId, level, skillParams);
  182. fellowAD.ID = uid > 0 ? uid : baseId;
  183. ad = fellowAD;
  184. BattleMgr.Instance.UpdateTeamSkills((int)ad.ID, pSkillList);
  185. }
  186. else
  187. {
  188. ad = ActorDataMgr.Instance.CreateFellow(uid, baseId, level, skillParams);
  189. }
  190. bool isTransferred = false;
  191. if (ltt["isTransferred"] != null)
  192. bool.TryParse(ltt["isTransferred"].ToString(), out isTransferred);
  193. ad.IsTransferred = isTransferred;
  194. }
  195. if (ltt["buffs"] != null)
  196. {
  197. List<BuffParam> buffs = ActorData.ParseBuffParam((LuaTable)ltt["buffs"]);
  198. ad.SetBuffs(buffs!=null?buffs.ToArray():null);
  199. }
  200. if(usedPetId > 0)
  201. {
  202. PetActorData petData = ActorDataMgr.Instance.GetPetDataById(usedPetId);
  203. if(petData != null)
  204. {
  205. ad.SetPet(petData);
  206. }
  207. else
  208. {
  209. petData = ActorDataMgr.Instance.CreatePet(usedPetId, petBaseId, petLevel, null);
  210. ad.SetPet(petData);
  211. }
  212. }
  213. else
  214. {
  215. ad.SetPet(null);
  216. }
  217. mTeamActors.Add(ad);
  218. }
  219. }
  220. public void Dispose()
  221. {
  222. if (mbDisposed)
  223. return;
  224. ActorDataMgr.Instance.Clear();
  225. Clear();
  226. mbDisposed = true;
  227. }
  228. }