XmdsPlayerAOI.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using CommonAI.Zone.Helper;
  3. using CommonAI.Zone.Instance;
  4. using CommonLang;
  5. using XmdsCommon.Plugin;
  6. namespace XmdsCommonServer.Plugin.Scene
  7. {
  8. /// <summary>
  9. /// 由玩家创建的私有位面
  10. /// </summary>
  11. public class XmdsPlayerAOI : ObjectAoiStatus
  12. {
  13. private readonly InstancePlayer m_owner;
  14. private readonly InstanceZone m_zone;
  15. /// <summary>
  16. /// 玩家自己
  17. /// </summary>
  18. public InstancePlayer Owner { get { return m_owner; } }
  19. bool _canSeeMe = false;
  20. public override bool CanSeeMe
  21. {
  22. get
  23. {
  24. return _canSeeMe;
  25. }
  26. }
  27. bool _canSeeOther = false;
  28. public override bool CanSeeOther
  29. {
  30. get
  31. {
  32. return _canSeeOther;
  33. }
  34. }
  35. public override bool IsNeedNotifyClient
  36. {
  37. get
  38. {
  39. return true;
  40. }
  41. }
  42. /// <summary>
  43. /// 是否在死亡后退出位面
  44. /// </summary>
  45. public bool DeadExit { get; set; }
  46. /// <summary>
  47. /// 此次aoi名称
  48. /// </summary>
  49. public string AoiName { get; set; }
  50. /// <summary>
  51. /// 没有怪物则销毁位面
  52. /// </summary>
  53. public bool isDestoryedOnMonsterDead
  54. {
  55. get;
  56. private set;
  57. }
  58. /// <summary>
  59. /// 任务完成则自动退出位面
  60. /// </summary>
  61. public string QuestId
  62. {
  63. get;
  64. private set;
  65. }
  66. private void onOwnerDead(InstanceUnit unit, InstanceUnit attacker)
  67. {
  68. if (DeadExit)
  69. {
  70. unit.setAoiStatus(null);
  71. }
  72. }
  73. private void onQuestStatusChanged(InstancePlayer player, string quest, string key, string value)
  74. {
  75. if(player == m_owner && quest == QuestId && key == XmdsQuestData.Attribute_SubState && value == "1")
  76. {
  77. player.setAoiStatus(null);
  78. }
  79. }
  80. public XmdsPlayerAOI(InstancePlayer player,
  81. bool can_see_me = false,
  82. bool can_see_other = false ,
  83. bool isDestoryedOnMonsterDead = false,
  84. bool DeadExit = false,
  85. string QuestId = null)
  86. {
  87. this.m_owner = player;
  88. this.m_zone = player.Parent;
  89. this._canSeeMe = can_see_me;
  90. this._canSeeOther = can_see_other;
  91. this.isDestoryedOnMonsterDead = isDestoryedOnMonsterDead;
  92. this.DeadExit = DeadExit;
  93. this.QuestId = QuestId;
  94. if(!string.IsNullOrEmpty(this.QuestId))
  95. {
  96. this.m_zone.OnQuestStatusChanged += onQuestStatusChanged;
  97. }
  98. player.OnDead += onOwnerDead;
  99. }
  100. protected override void onObjectEnter(InstanceZoneObject o)
  101. {
  102. base.onObjectEnter(o);
  103. }
  104. protected override void onObjectLeave(InstanceZoneObject o)
  105. {
  106. base.onObjectLeave(o);
  107. if (o == m_owner)
  108. {
  109. (o as InstancePlayer).OnDead -= onOwnerDead;
  110. this.Cleanup();
  111. }
  112. if (isDestoryedOnMonsterDead && GetUnitCountByForce(1) == 0)
  113. {
  114. m_owner.setAoiStatus(null);
  115. }
  116. }
  117. /// <summary>
  118. /// 玩家掉线后,干掉所有私有AOI单位
  119. /// </summary>
  120. public void Cleanup()
  121. {
  122. using(var list = ListObjectPool<InstanceZoneObject>.AllocAutoRelease(base.Objects))
  123. {
  124. foreach (var obj in list)
  125. {
  126. if (obj != m_owner)
  127. {
  128. if(obj is InstancePlayer)
  129. {
  130. (obj as InstancePlayer).setAoiStatus(null);
  131. }
  132. else
  133. {
  134. m_zone.RemoveObjectByID(obj.ID);
  135. }
  136. }
  137. }
  138. }
  139. if (!string.IsNullOrEmpty(this.QuestId))
  140. {
  141. this.m_zone.OnQuestStatusChanged -= onQuestStatusChanged;
  142. }
  143. }
  144. }
  145. }