Exemple #1
0
    bool DoAttack()
    {
        eye.aimList.RemoveAll((g) => g == null || TerrainUnit.IsStaticType(g.type));
        if (eye.aimList.Count > 0)
        {
            eye.aimList.OrderBy((g) => (g.transform.position - transform.position).magnitude);
            int i = 0; bool validTarget = true;
            while (!TerrainUnit.IsManualType(eye.aimList[i].GetComponent <TerrainUnit>().type))
            {
                i++;
                if (i >= eye.aimList.Count)
                {
                    validTarget = false;
                    break;
                }
            }
            if (validTarget)
            {
                GameObject instance = Instantiate(bulletPrefab, this.transform.position, Quaternion.identity);
                instance.GetComponent <BulletMotivation>().target = eye.aimList[i].gameObject;
                return(true);
            }
        }
        return(false);

        // return false;
    }
    /// <summary>
    /// 查找四周有无符合条件的邻居
    ///
    /// t: 留空则搜索 IsManualType
    /// </summary>
    public bool HasNeibour(int x, int y, Func <UnitType, bool> t = null
                           )
    {
        // x += poolCur;
        x %= size.x;
        for (int i = 0; i < 4; i++)
        {
            if (_4direction[i, 0] + x < 0 || _4direction[i, 0] + x >= size.x ||
                _4direction[i, 1] + y < 0 || _4direction[i, 1] + y >= size.y)
            {
                continue;
            }
            if (t == null)
            {
                if (!TerrainUnit.IsManualType(map[_4direction[i, 0] + x, _4direction[i, 1] + y].type))// type
                {
                    continue;
                }
            }
            else
            {
                if (!t(map[_4direction[i, 0] + x, _4direction[i, 1] + y].type))// type
                {
                    continue;
                }
            }

            if (1 >= Mathf.Abs(map[_4direction[i, 0] + x, _4direction[i, 1] + y].position.y - map[x, y].position.y))// 0<= dy <= 1
            {
                return(true);
            }
        }
        return(false);
    }
Exemple #3
0
    /// <summary>
    /// cd count if has target in field
    /// </summary>
    /// <returns></returns>
    bool HaveTarget()
    {
        previteHaveTargetCount++;
        if (previteHaveTargetCount > 5)
        {
            foreach (var item in eye.aimList)
            {
                if (TerrainUnit.IsManualType(item.GetComponent <TerrainUnit>().type))
                {
                    previteHaveTarget      = true;
                    previteHaveTargetCount = 0;
                    return(true);
                }
            }

            previteHaveTargetCount = 0;
            previteHaveTarget      = false;
            return(false);
        }
        return(previteHaveTarget);
    }