using CommonAI.Zone; using CommonAI.Zone.Instance; using CommonLang.Vector; using System; using System.Collections.Generic; using System.Linq; using System.Text; using XmdsCommon.Message; namespace XmdsCommonServer.Plugin.Units { public class XmdsDropableInstanceItem : InstanceItem { public XmdsDropableInstanceItem(InstanceZone zone, ItemTemplate item, string name, int force, InstanceUnit creater, string disPlayName) : base(zone, item, name, force, creater, disPlayName,0) { //base.OnTryPickItem += OnTryPickXmdsItem; } public override bool IsPickable(InstanceUnit unit) { if (base.IsPickable(unit)) { // 捡取判定,检定成功需要通知游戏服创建道具 XmdsCommon.Message.DropItem di = GenSyncItemInfo(false, unit.PlayerUUID).ExtData as XmdsCommon.Message.DropItem; if (di == null)//非掉落道具. { return true; } //强制冻结时间(时间内无法拾取该物品). //原来没用,我先不加了万一加了反而坑了呢.Modify by Alex.Yu 2016.11.07 if (this.PassTimeMS < di.FreezeTime) { return false; } //XmdsCommon.Plugin.XmdsUnitProperties prop = unit.Info.Properties as XmdsCommon.Plugin.XmdsUnitProperties; if (unit is XmdsInstancePlayer)// 会没有吗?// { var player = unit as XmdsInstancePlayer; var playerVirtual = player.Virtual as XmdsVirtual; //Mode 1 自由拾取 只检查自己背包 //Mode 2, 队伍背包,只检查队伍背包 //Mode 3, Roll点,只判断所有权 if (di.Mode == 1 && !player.CanPickDropableItem) { return false; } if (di.Mode == 2 && playerVirtual.GetTeamInventorySize() < 1) { playerVirtual.SendMsgToClient("noSpace"); return false; } bool is_owner = false; if (di.PlayerUUID != null) { for (int i = 0; i < di.PlayerUUID.Count; i++) { if (player.PlayerUUID == di.PlayerUUID[i]) { is_owner = true; break; } } } //个人tc,助攻tc仅个人可见,个人可拾取 if(di.bindPlayerId != null && di.bindPlayerId == player.PlayerUUID) { is_owner = true; } if (is_owner) { return true; } else { if (this.PassTimeMS >= di.ProtectTime) { return true; } else { return false; } } } } return false; } public override string GetBindPlayerId() { if(base.mSyncInfo.ExtData != null) { var dropItem = base.mSyncInfo.ExtData as XmdsCommon.Message.DropItem; if(dropItem != null) { return dropItem.bindPlayerId; } } return null; } protected override void onUpdate(bool slowRefresh) { //竞技场魂魄的拾取,需要特殊判断是人物身上的pickupRange,特此硬编写998物品 //非物品998的走原来父类方法 if(this.Info.TemplateID != 998) { base.onUpdate(slowRefresh); return; } if (IsPaused) { return; } if (mRemovedExpire!= null && mRemovedExpire.Update(Parent.UpdateIntervalMS)) { Parent.RemoveObject(this); } if (mViewTriggerTimer != null && mViewTriggerTimer.Update(Parent.UpdateIntervalMS)) { //mViewTrigger.Enable = true; //mViewTrigger.onLookUpdate(X, Y); float min_len = float.MaxValue; InstanceUnit min = null; Parent.ForEachNearObjects(X, Y, this.mData.BodySize, (InstanceUnit u, ref bool cancel) => { if (u.IsPlayer && u is XmdsInstancePlayer &&!u.IsDead()) { var player = u as XmdsInstancePlayer; var playerVirtual = player.Virtual as XmdsVirtual; float len = MathVector.getDistance(u.X, u.Y, this.X, this.Y) - playerVirtual.MirrorProp.pickupRange; if (min_len > len && len < this.mData.BodySize) { min_len = len; min = u; } } //cancel = false; }); if (min != null) { this.DirectPickItem(min,() => { RemoveDropItemB2C rd = new RemoveDropItemB2C(this.ID, min.ID); min.queueEvent(rd); }); } } } } }