/// <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); } }
/// <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); }
/// <summary> /// Fija el objetivo /// Actualmente desactivado todo lo que no sea la herramienta "SELECCIONAR" /// </summary> void FijarObjetivo() { int maxY = Mathf.Max(posInicial.y, posFinal.y) + 1; int maxX = Mathf.Max(posInicial.x, posFinal.x) + 1; if (manager.herramientaSeleccionada != HERRAMIENTA.Seleccionar) { //CREA UNA ACCION for (int y = (int)Mathf.Min(posInicial.y, posFinal.y); y < maxY; y++) { for (int x = (int)Mathf.Min(posInicial.x, posFinal.x); x < maxX; x++) { //TODO: Arreglar manager.actions.CreateAction(new IntVector2(x, y), manager.herramientaSeleccionada, TIPOACCION.Almacenar, null, false); } } } else { //MUESTRA LA INFORMACIÓN List <Estructura> estructuras = new List <Estructura>(); List <GameObject> selecciones = new List <GameObject>(); for (int y = Mathf.Min(posInicial.y, posFinal.y); y < maxY; y++) { for (int x = Mathf.Min(posInicial.x, posFinal.x); x < maxX; x++) { Estructura build = manager.GetNode(x, y).GetBuild(); if (primeraEstructura == null && build != null) { primeraEstructura = build; } if (build != null && build.GetBuildType() == primeraEstructura.GetBuildType()) { estructuras.Add(build); GameObject _obj = manager.info.GetSeleccion(); _obj.transform.position = new Vector3(x, y); selecciones.Add(_obj); } } } //Si ha encontrado alguna estructura mostrará su información //Si no mostrará la información del suelo. if (selecciones.Count > 0) { manager.info.SeleccionarUnidades(primeraEstructura, estructuras.ToArray(), selecciones.ToArray()); } else { for (int y = Mathf.Min(posInicial.y, posFinal.y); y < maxY; y++) { for (int x = Mathf.Min(posInicial.x, posFinal.x); x < maxX; x++) { GameObject _obj = manager.info.GetSeleccion(); _obj.transform.position = new Vector3(x, y); selecciones.Add(_obj); } } manager.info.SeleccionarTerreno(selecciones.ToArray()); } } CancelarObjetivo(); }