XmdsInstanceItem.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.Instance;
  3. using CommonLang.Vector;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using XmdsCommon.Message;
  9. namespace XmdsCommonServer.Plugin.Units
  10. {
  11. public class XmdsDropableInstanceItem : InstanceItem
  12. {
  13. public XmdsDropableInstanceItem(InstanceZone zone,
  14. ItemTemplate item,
  15. string name,
  16. int force,
  17. InstanceUnit creater,
  18. string disPlayName)
  19. : base(zone, item, name, force, creater, disPlayName,0)
  20. {
  21. //base.OnTryPickItem += OnTryPickXmdsItem;
  22. }
  23. public override bool IsPickable(InstanceUnit unit)
  24. {
  25. if (base.IsPickable(unit))
  26. {
  27. // 捡取判定,检定成功需要通知游戏服创建道具
  28. XmdsCommon.Message.DropItem di = GenSyncItemInfo(false, unit.PlayerUUID).ExtData as XmdsCommon.Message.DropItem;
  29. if (di == null)//非掉落道具.
  30. {
  31. return true;
  32. }
  33. //强制冻结时间(时间内无法拾取该物品).
  34. //原来没用,我先不加了万一加了反而坑了呢.Modify by Alex.Yu 2016.11.07
  35. if (this.PassTimeMS < di.FreezeTime)
  36. {
  37. return false;
  38. }
  39. //XmdsCommon.Plugin.XmdsUnitProperties prop = unit.Info.Properties as XmdsCommon.Plugin.XmdsUnitProperties;
  40. if (unit is XmdsInstancePlayer)// 会没有吗?//
  41. {
  42. var player = unit as XmdsInstancePlayer;
  43. var playerVirtual = player.Virtual as XmdsVirtual;
  44. //Mode 1 自由拾取 只检查自己背包
  45. //Mode 2, 队伍背包,只检查队伍背包
  46. //Mode 3, Roll点,只判断所有权
  47. if (di.Mode == 1 && !player.CanPickDropableItem)
  48. {
  49. return false;
  50. }
  51. if (di.Mode == 2 && playerVirtual.GetTeamInventorySize() < 1)
  52. {
  53. playerVirtual.SendMsgToClient("noSpace");
  54. return false;
  55. }
  56. bool is_owner = false;
  57. if (di.PlayerUUID != null)
  58. {
  59. for (int i = 0; i < di.PlayerUUID.Count; i++)
  60. {
  61. if (player.PlayerUUID == di.PlayerUUID[i])
  62. {
  63. is_owner = true;
  64. break;
  65. }
  66. }
  67. }
  68. //个人tc,助攻tc仅个人可见,个人可拾取
  69. if(di.bindPlayerId != null && di.bindPlayerId == player.PlayerUUID)
  70. {
  71. is_owner = true;
  72. }
  73. if (is_owner)
  74. {
  75. return true;
  76. }
  77. else
  78. {
  79. if (this.PassTimeMS >= di.ProtectTime)
  80. {
  81. return true;
  82. }
  83. else
  84. {
  85. return false;
  86. }
  87. }
  88. }
  89. }
  90. return false;
  91. }
  92. public override string GetBindPlayerId()
  93. {
  94. if(base.mSyncInfo.ExtData != null)
  95. {
  96. var dropItem = base.mSyncInfo.ExtData as XmdsCommon.Message.DropItem;
  97. if(dropItem != null)
  98. {
  99. return dropItem.bindPlayerId;
  100. }
  101. }
  102. return null;
  103. }
  104. protected override void onUpdate(bool slowRefresh)
  105. {
  106. //竞技场魂魄的拾取,需要特殊判断是人物身上的pickupRange,特此硬编写998物品
  107. //非物品998的走原来父类方法
  108. if(this.Info.TemplateID != 998)
  109. {
  110. base.onUpdate(slowRefresh);
  111. return;
  112. }
  113. if (IsPaused) { return; }
  114. if (mRemovedExpire!= null && mRemovedExpire.Update(Parent.UpdateIntervalMS))
  115. {
  116. Parent.RemoveObject(this);
  117. }
  118. if (mViewTriggerTimer != null && mViewTriggerTimer.Update(Parent.UpdateIntervalMS))
  119. {
  120. //mViewTrigger.Enable = true;
  121. //mViewTrigger.onLookUpdate(X, Y);
  122. float min_len = float.MaxValue;
  123. InstanceUnit min = null;
  124. Parent.ForEachNearObjects(X, Y, this.mData.BodySize, (InstanceUnit u, ref bool cancel) =>
  125. {
  126. if (u.IsPlayer && u is XmdsInstancePlayer &&!u.IsDead())
  127. {
  128. var player = u as XmdsInstancePlayer;
  129. var playerVirtual = player.Virtual as XmdsVirtual;
  130. float len = MathVector.getDistance(u.X, u.Y, this.X, this.Y) - playerVirtual.MirrorProp.pickupRange;
  131. if (min_len > len && len < this.mData.BodySize)
  132. {
  133. min_len = len;
  134. min = u;
  135. }
  136. }
  137. //cancel = false;
  138. });
  139. if (min != null)
  140. {
  141. this.DirectPickItem(min,() => {
  142. RemoveDropItemB2C rd = new RemoveDropItemB2C(this.ID, min.ID);
  143. min.queueEvent(rd);
  144. });
  145. }
  146. }
  147. }
  148. }
  149. }