예제 #1
0
    /// <summary>
    /// 获取指定范围内的对象列表(攻击范围、溅射范围、治疗范围等)
    /// </summary>
    /// <param name="attacker">过滤掉的对象</param>
    /// <param name="ownerType">阵营</param>
    /// <param name="x">范围的中心点X</param>
    /// <param name="y">范围的中心点Y</param>
    /// <param name="range">范围</param>
    /// <param name="blindrange">盲区范围</param>
    /// <param name="filter">过滤器,如果过滤器返回true,则指定的对象被过滤掉。</param>
    /// <returns></returns>
    public List <TileEntity> GetEntitiesByRange(TileEntity attacker, OwnerType ownerType, float x, float y, float range, float blindrange, Func <TileEntity, bool> filter = null)
    {
        List <TileEntity> ret         = new List <TileEntity>();
        float             blindrange2 = blindrange * blindrange;

        foreach (TileEntity targeter in m_entities[(int)ownerType])
        {
            if (attacker == targeter)
            {
                continue;
            }

            if (targeter.IsDead())
            {
                continue;
            }

            if (!EntityTypeUtil.IsAnyTargeter(targeter.entityType))
            {
                continue;
            }

            //  不是限定类型的目标则过滤掉
            if (attacker != null && EntityTypeUtil.IsAnyActor(targeter.entityType) && attacker.model.onlyAttackTargetType != EntityType.None && attacker.model.onlyAttackTargetType != targeter.entityType)
            {
                continue;
            }

            if (filter != null && filter(targeter))
            {
                continue;
            }

            if (targeter.IsInAttackRange(x, y, range, blindrange2))
            {
                ret.Add(targeter);
            }
        }
        return(ret);
    }