Example #1
0
    public void OnUpdate(IEntity entity, object param = null)
    {
        Client.IEntity mainPlayer = Client.ClientGlobal.Instance().MainPlayer;
        if (mainPlayer == null || mainPlayer.IsDead() || entity == null)
        {
            return;
        }

        UnityEngine.Vector3 dis = mainPlayer.GetPos() - entity.GetPos();

        uint npcid = (uint)entity.GetProp((int)Client.EntityProp.BaseID);

        if (npcid != m_nNpcID || SQRMagnitude <= 0f)
        {
            m_nNpcID = npcid;
            table.NpcDataBase npcdb = GameTableManager.Instance.GetTableItem <table.NpcDataBase>(m_nNpcID);
            if (npcdb != null)
            {
                SQRMagnitude = npcdb.dwCallDis * npcdb.dwCallDis * 0.01f * 0.01f;
            }
        }

        if (dis.sqrMagnitude < SQRMagnitude)
        {
            if (IsTrigger)
            {
                return;
            }
            IsTrigger = true;
            Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.CAMP_ADDCOLLECTNPC,
                                                                new stCampCollectNpc()
            {
                npcid = entity.GetUID(), enter = true
            });
        }
        else
        {
            if (IsTrigger)
            {
                Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.CAMP_ADDCOLLECTNPC,
                                                                    new stCampCollectNpc()
                {
                    npcid = entity.GetUID(), enter = false
                });
            }
            IsTrigger = false;
        }
    }
Example #2
0
    public void OnUpdate(IEntity entity, object param = null)
    {
        if (IsTrigger)
        {
            //如果过了2秒还存在 说明没有捡起
            if (UnityEngine.Time.realtimeSinceStartup - m_fTriggerTime > 2.5f)
            {
                IsTrigger = false;
            }
            return;
        }

        Client.IEntity mainPlayer = Client.ClientGlobal.Instance().MainPlayer;
        if (mainPlayer == null || mainPlayer.IsDead() || entity == null)
        {
            return;
        }


        IBox box = entity as IBox;

        if (box == null)
        {
            return;
        }

        UnityEngine.Vector3 dis = mainPlayer.GetPos() - entity.GetPos();
        if (dis.sqrMagnitude < SQRMagnitude)
        {
            IsTrigger = true;
            if (box.CanPick())
            {
                m_fTriggerTime = UnityEngine.Time.realtimeSinceStartup;
                NetService.Instance.Send(new GameCmd.stPickUpItemPropertyUserCmd_C()
                {
                    qwThisID = entity.GetID()
                });
//                 if (box.CanAutoPick())
//                 {
//                     Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.ROBOTCOMBAT_PICKUPITEM,
//                         new Client.stPickUpItem() { itemid = entity.GetID(), state = 1 });
//                 }
                // UnityEngine.Debug.Log("捡起道具 " + entity.GetID());
            }
        }
    }