Ejemplo n.º 1
0
    /// <summary>
    /// Crea una estructura en el mapa.
    /// </summary>
    public void AddBuildInMap(int x, int y, Estructura estructura)
    {
        if (x < 0 || y < 0 || x >= totalSize.x || y >= totalSize.y)
        {
            return;
        }

        if (!map[x, y].CreateBuild(estructura))
        {
            Debug.LogWarning("No se ha podido crear la estructura.");
            return;
        }

        //Busca si existe el tipo a crear
        //Si no existe, lo crea
        ESTRUCTURA _tipo = estructura.GetBuildType();

        if (builds.ContainsKey(_tipo))
        {
            if (!builds[_tipo].Contains(estructura))
            {
                builds[_tipo].Add(estructura);
            }
        }
        else
        {
            builds.Add(_tipo, new List <Estructura>());
        }

        IUpdatable[] _update = estructura.GetComponents <IUpdatable>();
        if (_update != null)
        {
            time.AddUpdatable(_update);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Elimina una estructura, devolviendo un porcentaje de lo que costaba su creación
    /// El valor va del 0 al 1.
    /// </summary>
    public void RemoveBuildInMap(int x, int y, float devolver = 0)
    {
        Estructura _build = map[x, y].GetBuild();

        if (_build == null)
        {
            return;
        }

        ResourceInfo[] items = build.getObjetoConstrucción(_build.nombre);

        ESTRUCTURA _tipo = _build.GetBuildType();

        if (ExistBuild(_tipo) && builds[_tipo] != null && builds[_tipo].Contains(_build))
        {
            builds[_tipo].Remove(_build);
        }

        IUpdatable[] update = _build.GetComponents <IUpdatable>();

        if (update != null)
        {
            time.RemoveUpdatable(update);
        }

        map[x, y].RemoveBuild();

        if (devolver > 0 && items != null && items.Length > 0)
        {
            int total = 0;
            for (int i = 0; i < items.Length; i++)
            {
                items[i].quantity = Mathf.RoundToInt(items[i].quantity * devolver);
                total            += items[i].quantity;
            }

            if (total > 0)
            {
                CrearSaco(new IntVector2(x, y), items);
            }
        }

        Destroy(_build.gameObject);
    }