XmdsVirtual_Pet.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. using CommonAI.Data;
  2. using CommonAI.Zone.Instance;
  3. using System.Collections.Generic;
  4. using XmdsCommon.Message;
  5. using XmdsCommon.Plugin;
  6. using XmdsCommonServer.Message;
  7. using XmdsCommonServer.Plugin.Units;
  8. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  9. namespace XmdsCommonServer.Plugin
  10. {
  11. public class XmdsVirtual_Pet : XmdsVirtual
  12. {
  13. /// <summary>
  14. /// 药剂HP恢复.
  15. /// </summary>
  16. private XmdsVirtual_Player.ItemRecoveryTask mHPRecoveryTask = new XmdsVirtual_Player.ItemRecoveryTask();
  17. /// <summary>
  18. /// 药剂MP恢复.
  19. /// </summary>
  20. private XmdsVirtual_Player.ItemRecoveryTask mMPRecoveryTask = new XmdsVirtual_Player.ItemRecoveryTask();
  21. /// <summary>
  22. /// 药剂HPMP同时恢复.
  23. /// </summary>
  24. private XmdsVirtual_Player.ItemRecoveryTask mHPMPRecoveryTask = new XmdsVirtual_Player.ItemRecoveryTask();
  25. private XmdsVirtual mMaster = null;
  26. public XmdsVirtual_Pet(XmdsInstancePet unit) : base(unit)
  27. {
  28. }
  29. public void InitVisibleData(PetBaseInfo info)
  30. {
  31. PetVisibleDataB2C data = new PetVisibleDataB2C();
  32. data.BaseInfo = info;
  33. mUnit.Level = info.level;
  34. mUnit.SetVisibleInfo(data);
  35. }
  36. public void SetMaster(XmdsVirtual master)
  37. {
  38. mMaster = master;
  39. if (this.mUnit != null)
  40. {
  41. (this.mUnit as XmdsInstancePet).SummonerUnit = mMaster.mUnit;
  42. }
  43. master.OnHandleCombatChangeEvent += Master_OnHandleCombatChangeEvent;
  44. //首次需要同步战斗状态.
  45. Master_OnHandleCombatChangeEvent(master.CombatState);
  46. }
  47. private void Master_OnHandleCombatChangeEvent(BattleStatus status)
  48. {
  49. (this.mUnit as XmdsInstancePet).OnMasterChangeCombatStatus(status);
  50. }
  51. public override string GetPlayerUUID()
  52. {
  53. InstanceUnit u = (mUnit as InstancePet).Master;
  54. if (u != null)
  55. {
  56. return ((u.Virtual) as XmdsVirtual).GetPlayerUUID();
  57. }
  58. return base.GetPlayerUUID();
  59. }
  60. public override int GetForceID()
  61. {
  62. InstanceUnit u = (mUnit as InstancePet).Master;
  63. if (u != null)
  64. {
  65. return ((u.Virtual) as XmdsVirtual).GetForceID();
  66. }
  67. return base.GetForceID();
  68. }
  69. public override string GetGuildID()
  70. {
  71. InstanceUnit u = (mUnit as InstancePet).Master;
  72. if (u != null)
  73. {
  74. return ((u.Virtual) as XmdsVirtual).GetGuildID();
  75. }
  76. return base.GetGuildID();
  77. }
  78. public override int GetServerID()
  79. {
  80. InstanceUnit u = (mUnit as InstancePet).Master;
  81. if (u != null)
  82. {
  83. return ((u.Virtual) as XmdsVirtual).GetServerID();
  84. }
  85. return base.GetServerID();
  86. }
  87. public override PKLevel GetCurPKLevel()
  88. {
  89. InstanceUnit u = (mUnit as InstancePet).Master;
  90. if (u != null)
  91. {
  92. return ((u.Virtual) as XmdsVirtual).GetCurPKLevel();
  93. }
  94. return base.GetCurPKLevel();
  95. }
  96. public override PKMode GetCurPKMode()
  97. {
  98. InstanceUnit u = (mUnit as InstancePet).Master;
  99. if (u != null)
  100. {
  101. return ((u.Virtual) as XmdsVirtual).GetCurPKMode();
  102. }
  103. return base.GetCurPKMode();
  104. }
  105. public override bool IsMember(XmdsVirtual target, PKMode mode, bool includeSelf, bool onlyForTeam)
  106. {
  107. if (includeSelf == true && this.mUnit == target.mUnit)
  108. {
  109. return true;
  110. }
  111. InstanceUnit u = (this.mUnit as InstancePet).SummonerUnit;
  112. if (u != null)
  113. {
  114. XmdsVirtual zv = u.Virtual as XmdsVirtual;
  115. return zv.IsMember(target, mode, includeSelf, onlyForTeam);
  116. }
  117. return base.IsMember(target, mode, includeSelf, onlyForTeam);
  118. }
  119. public bool IsMaster(XmdsVirtual target)
  120. {
  121. bool ret = false;
  122. if ((this.mUnit as InstancePet).Master == target.mUnit)
  123. {
  124. ret = true;
  125. }
  126. return ret;
  127. }
  128. public XmdsVirtual GetMaster()
  129. {
  130. return mMaster;
  131. }
  132. public override uint GetMasterID()
  133. {
  134. if(this.mMaster != null)
  135. {
  136. return this.mMaster.mUnit.ID;
  137. }
  138. return 0;
  139. }
  140. public override InstanceUnit GetMasterUnit()
  141. {
  142. if (this.mMaster != null)
  143. {
  144. return this.mMaster.mUnit;
  145. }
  146. return null;
  147. }
  148. public override void OnKillUnit(XmdsVirtual dead)
  149. {
  150. if (CalPKValue(dead) == true)
  151. {
  152. if (dead.IsPlayerUnit() &&
  153. dead.GetCurPKLevel() == PKLevel.White)
  154. {
  155. XmdsInstancePlayer zip = (mUnit as InstancePet).Master as XmdsInstancePlayer;
  156. if (zip != null)
  157. {
  158. (zip.Virtual as XmdsVirtual).OnKillUnit(dead);
  159. }
  160. }
  161. }
  162. }
  163. public override void OnHitOthter(XmdsVirtual target)
  164. {
  165. if (mHateSystem.ContainsID(target.mUnit.ID) == false)
  166. {
  167. mHateSystem.AddTarget(target);
  168. }
  169. var zv = GetMaster();
  170. if (zv != null)
  171. {
  172. zv.OnHitOthter(target);
  173. }
  174. }
  175. public override bool IsPlayerUnit()
  176. {
  177. bool ret = false;
  178. InstanceUnit u = (mUnit as InstancePet).Master;
  179. if (u is XmdsInstancePlayer)
  180. {
  181. ret = true;
  182. }
  183. return ret;
  184. }
  185. public override XmdsVirtual_Player GetPlayerUnit()
  186. {
  187. XmdsVirtual_Player ret = null;
  188. InstanceUnit u = (mUnit as InstancePet).Master;
  189. if (u != null && u is XmdsInstancePlayer)
  190. {
  191. ret = u.Virtual as XmdsVirtual_Player;
  192. }
  193. return ret;
  194. }
  195. public void UpdateBaseInfo(PetBaseInfo info)
  196. {
  197. mUnit.Level = info.level;
  198. mProp.ServerData.BaseInfo.UnitLv = info.level;
  199. var p = GetMaster();
  200. if (p != null)
  201. {
  202. //宿主ID.
  203. info.MasterID = p.mUnit.ID;
  204. }
  205. if (this.mUnit.VisibleInfo is PetVisibleDataB2C)
  206. {
  207. //服务端数据保存更新.
  208. PetVisibleDataB2C pvd = this.mUnit.VisibleInfo as PetVisibleDataB2C;
  209. pvd.BaseInfo = info;
  210. //推送变更协议.
  211. PetBaseInfoChangeEventB2C evt = new PetBaseInfoChangeEventB2C();
  212. evt.BaseInfo = info;
  213. this.mUnit.queueEvent(evt);
  214. }
  215. }
  216. public void UpdatePetProps(XmdsUnitProp prop)
  217. {
  218. XmdsUnitPropEventB2C evt = new XmdsUnitPropEventB2C();
  219. evt.Props = prop;
  220. OnPlayerPropertiesChanged(evt);
  221. }
  222. public void OnReceivePetSkillChangeEventR2B(PetSkillChangeEventR2B evt)
  223. {
  224. if (evt != null)
  225. {
  226. switch (evt.OperateID)
  227. {
  228. case PlayerSkillChangeEventR2B.SkillOperate.Replace:
  229. this.mSkillHelper.ReplaceSkill(evt.SkillList);
  230. break;
  231. case PlayerSkillChangeEventR2B.SkillOperate.Add:
  232. this.mSkillHelper.AddSkill(evt.SkillList);
  233. break;
  234. case PlayerSkillChangeEventR2B.SkillOperate.Remove:
  235. this.mSkillHelper.RemoveSkill(evt.SkillList);
  236. break;
  237. case PlayerSkillChangeEventR2B.SkillOperate.Reset:
  238. //this.mSkillHelper.ResetSkill(evt.SkillList);
  239. this.ResetSkill(evt.SkillList);
  240. break;
  241. default: break;
  242. }
  243. }
  244. }
  245. public override void OnUpdateTriggerSkill(int intervalMS, bool slowRefresh)
  246. {
  247. UpdateItemRecoveryTask(intervalMS);
  248. base.OnUpdateTriggerSkill(intervalMS, slowRefresh);
  249. }
  250. private void UpdateItemRecoveryTask(int intervalMS)
  251. {
  252. mHPRecoveryTask.Update(intervalMS);
  253. mMPRecoveryTask.Update(intervalMS);
  254. mHPMPRecoveryTask.Update(intervalMS);
  255. }
  256. public void OnRceivePropertyChangeEventR2B(PropertyChangeEventR2B evt)
  257. {
  258. FormatLog("OnRceivePropertyChangeOrder", null);
  259. bool success = false;
  260. switch (evt.ChangeType)
  261. {
  262. case PropertyChangeEventR2B.PropertyChangeType.HP:
  263. if (evt.Duration > 0)
  264. {
  265. mHPMPRecoveryTask.Init(this, evt, true);
  266. }
  267. else
  268. {
  269. success = AddHP(evt.ChangeValueType, evt.ChangeValue, false);
  270. }
  271. break;
  272. case PropertyChangeEventR2B.PropertyChangeType.NPC:
  273. if (this.mUnit.CurrentHP != this.mUnit.MaxHP ||
  274. this.mUnit.CurrentMP != this.mUnit.MaxMP)
  275. {
  276. this.AddHP(this.mUnit.MaxHP, null, false);
  277. this.AddMP(this.mUnit.MaxMP, null, false, true);
  278. }
  279. break;
  280. default: break;
  281. }
  282. }
  283. public void OnReceivePetFollowModeChangeEventR2B(PetFollowModeChangeEventR2B evt)
  284. {
  285. SetFollowMode(evt.mode);
  286. }
  287. public void SetFollowMode(XmdsCommon.Plugin.XmdsPetConifg.XmdsPetFollowMode mode)
  288. {
  289. (this.mUnit as XmdsInstancePet).SetFollowMode(mode);
  290. }
  291. //protected override void CombatStateConnect(CombatStateChangeEvent.BattleStatus status, byte reason)
  292. //{
  293. // var v = GetMaster();
  294. // if (v != null)
  295. // {
  296. // v.SetCombatState(status, reason);
  297. // }
  298. //}
  299. protected override void Dispose()
  300. {
  301. if (mMaster != null)
  302. {
  303. mMaster.OnHandleCombatChangeEvent -= Master_OnHandleCombatChangeEvent;
  304. mMaster = null;
  305. }
  306. base.Dispose();
  307. }
  308. public override bool IsAttackable(XmdsVirtual attacker)
  309. {
  310. var v = GetMaster();
  311. if (v != null)
  312. {
  313. return v.IsAttackable(attacker);
  314. }
  315. return base.IsAttackable(attacker);
  316. }
  317. public override bool TeamMemberVisible
  318. {
  319. get
  320. {
  321. if (mMaster != null)
  322. {
  323. return (!mMaster.mUnit.IsDead());
  324. }
  325. return base.TeamMemberVisible;
  326. }
  327. set
  328. {
  329. base.TeamMemberVisible = value;
  330. }
  331. }
  332. }
  333. }