public MonsterRole FindNearestFakeMonster(Vector3 pos)
    {
        float dis = 9999999f;

        MonsterRole role = null;

        foreach (MonsterRole m in m_mapFakeMonster.Values)
        {
            if (m.isDead || m is CollectRole || (m is MS0000 && ((MS0000)m).owner_cid == PlayerModel.getInstance().cid) ||
                (m is MDC000 && ((MDC000)m).escort_name == A3_LegionModel.getInstance().myLegion.clname))
            {
                continue;
            }
            if (m is MDC000 && (int)(((float)((MDC000)m).curhp / (float)((MDC000)m).maxHp) * 100) <= 20)
            {
                continue;
            }
            Vector3 off_pos = m.m_curPhy.position - pos;
            float   off_dis = off_pos.magnitude;
            if (off_dis < SelfRole._inst.m_LockDis && off_dis < dis)
            {
                //debug.Log("遍历怪物位置");
                dis  = off_dis;
                role = m;
            }
        }

        return(role);
    }
    public MonsterRole FindNearestMonster(Vector3 pos, Func <MonsterRole, bool> handle = null, bool useMark = false, PK_TYPE pkState = PK_TYPE.PK_PEACE, bool onTask = false)
    {
        float dis = 9999999f;

        MonsterRole role = null, t_role = null;
        float       t_dis;

        RoleMgr.ClearMark(!useMark, pkState,
                          filterHandle: (m) => (m.m_curPhy.position - pos).magnitude < (SelfRole.fsm.Autofighting ? StateInit.Instance.Distance : SelfRole._inst.m_LockDis));
        foreach (MonsterRole m in m_mapMonster.Values)
        {
            if (m.isDead || m is CollectRole || (m is MS0000 && ((MS0000)m).owner_cid == PlayerModel.getInstance().cid))
            {
                continue;
            }
            if (m.issummon)
            {
                continue;
            }
            if (SelfRole.fsm.Autofighting && (m.m_curPhy.position - StateInit.Instance.Origin).magnitude > StateInit.Instance.Distance)
            {
                continue;
            }
            else
            {
                float _off_dis = (m.m_curPhy.position - pos).magnitude;
                if (_off_dis < (SelfRole.fsm.Autofighting ? Mathf.Min(SelfRole._inst.m_LockDis, StateInit.Instance.Distance) : SelfRole._inst.m_LockDis) &&
                    _off_dis < dis)
                {
                    t_dis  = _off_dis;
                    t_role = m;
                }
            }
            if (m is MDC000 && ((MDC000)m).escort_name == A3_LegionModel.getInstance().myLegion.clname)
            {
                continue;
            }
            if (m is MDC000 && (int)(((float)((MDC000)m).curhp / (float)((MDC000)m).maxHp) * 100) <= 20)
            {
                continue;
            }
            if ((taskMonId?.applied ?? false) && taskMonId.value != m.monsterid)
            {
                continue;
            }
            if (handle?.Invoke(m) ?? false)
            {
                continue;
            }
            if (onTask &&
                PlayerModel.getInstance().task_monsterIdOnAttack.ContainsKey(A3_TaskModel.getInstance().main_task_id) &&
                m.monsterid != PlayerModel.getInstance().task_monsterIdOnAttack[A3_TaskModel.getInstance().main_task_id])
            {
                continue;
            }
            if (TeamProxy.getInstance().MyTeamData != null)
            {
                if (A3_ActiveModel.getInstance().mwlr_on)
                {
                    if (A3_ActiveModel.getInstance().mwlr_target_monId != m.monsterid)
                    {
                        continue;
                    }
                }
                if (m.ownerName != null && !TeamProxy.getInstance().MyTeamData.IsInMyTeam(m.ownerName))
                {
                    continue;
                }
            }
            else if (m.ownerName != null && m.ownerName != PlayerModel.getInstance().name)
            {
                continue;
            }
            if (pkState != PK_TYPE.PK_PKALL && m is MS0000 && ((MS0000)m).owner_cid != 0)
            {
                continue;
            }
            float off_dis = (m.m_curPhy.position - pos).magnitude;
            if (off_dis < (SelfRole.fsm.Autofighting ? Mathf.Min(SelfRole._inst.m_LockDis, StateInit.Instance.Distance) : SelfRole._inst.m_LockDis) &&
                off_dis < dis)
            {
                dis  = off_dis;
                role = m;
            }
        }
        if (role != null && useMark)
        {
            role.m_isMarked = true;
        }
        else if (role == null)
        {
            role = t_role;
        }
        return(role);
    }
    public MonsterRole AddDartCar(Variant d)//镖车
    {
        init();
        if (GRMap.grmap_loading)
        {
            cacheProxy.Add(d);
            return(null);
        }
        Vector3 born_pt  = new Vector3(d["x"] / GameConstant.PIXEL_TRANS_UNITYPOS, 0f, d["y"] / GameConstant.PIXEL_TRANS_UNITYPOS);
        int     id       = d["mid"];
        uint    serverid = d["iid"];

        if (m_mapMonster.ContainsKey(serverid))
        {
            return(m_mapMonster[serverid]);
        }

        SXML   xml    = dMon[id];
        int    tempid = xml.getInt("obj");
        float  scale  = xml.getFloat("scale");
        string name   = string.Empty;

        if (serverid <= 0)
        {
            if (Globle.m_nTestMonsterID > 0)
            {
                tempid = Globle.m_nTestMonsterID;
            }
        }
        MDC000 mon = new MDC000();

        mon.tempXMl  = xml;
        mon.isBoos   = xml.getInt("boss") == 1;
        mon.isBoss_c = xml.getInt("boss_c") == 1;
        if (scale > 0f)
        {
            mon.scale = scale;
        }
        if (mon != null)
        {
            if (serverid > 0)
            {
                mon.m_unIID = serverid;
                m_mapMonster.Add(serverid, mon);//这个地图上的所有的monster
            }
            else
            {
                mon.isfake  = true;
                mon.m_unIID = idIdx;
                m_mapFakeMonster.Add(idIdx, mon);
                idIdx++;
            }

            mon.Init("monster_" + tempid, EnumLayer.LM_MONSTER, born_pt, 0);
            mon.curhp       = d["hp"];
            mon.maxHp       = d["battleAttrs"]["max_hp"];
            mon.escort_name = d["escort_name"];
            PlayerNameUIMgr.getInstance().show(mon);
            PlayerNameUIMgr.getInstance().setDartName(mon, d["escort_name"] + ContMgr.getCont("MonsterMgr1"));
            mon.roleName  = d["escort_name"] + ContMgr.getCont("MonsterMgr1");
            mon.monsterid = id;
            if (mon.roleName == A3_LegionModel.getInstance().myLegion.name)
            {
                mon.m_isMarked = false;
            }

            //if (GRMap.grmap_loading == false)
            //    mon.refreshViewType(2);

            mon.dartid = id;
            mon.isDart = true;
        }
        m_listMonster.Add(mon);
        if (mon != null)
        {
            dispatchEvent(GameEvent.Create(MonsterMgr.EVENT_MONSTER_ADD, this, mon));
        }


        if (d.ContainsKey("moving"))
        {
            uint  iid  = d["iid"]._uint;
            var   vv   = MonsterMgr._inst.getMonster(iid);
            float to_x = d["moving"]["to_x"]._float;
            float to_y = d["moving"]["to_y"]._float;

            NavMeshHit hit;
            Vector3    vec = new Vector3(to_x * 32 / GameConstant.PIXEL_TRANS_UNITYPOS, 0f, to_y * 32 / GameConstant.PIXEL_TRANS_UNITYPOS);
            NavMesh.SamplePosition(vec, out hit, 100f, vv.m_layer);
            vv.SetDestPos(hit.position);
        }
        return(mon);
    }