Exemplo n.º 1
0
        private void ImportBtn_Clicked(GUI.GUIItem item)
        {
            if (_GameStarted && _Manager != null)
            {
                MouseUI mouseUI = _Manager.GetComponent <MouseUI>();

                GameObject     tileMap        = mouseUI._ModGet_TileMap();
                Tiles          shipTiles      = tileMap.GetComponent <Tiles>();
                ManagerJobs    managerJobs    = _Manager.GetComponent <ManagerJobs>();
                ManagerMenu    managerMenu    = _Manager.GetComponent <ManagerMenu>();
                ManagerOptions managerOptions = _Manager.GetComponent <ManagerOptions>();

                if (shipTiles != null)
                {
                    String json = System.IO.File.ReadAllText(System.IO.Path.Combine(ModFolder, "Design.json"), Encoding.UTF8);

                    TileData[] tiles = Pathfinding.Serialization.JsonFx.JsonReader.Deserialize <TileData[]>(json);

                    List <TileData> hull     = new List <TileData>();
                    List <TileData> floor    = new List <TileData>();
                    TileData        shipCore = null;
                    List <TileData> other    = new List <TileData>();

                    foreach (TileData td in tiles)
                    {
                        List <TileData.Vec3> StructureParts = new List <TileData.Vec3>();
                        StructureParts.AddRange(td.StructureParts);
                        td.StructureParts = StructureParts;

                        if (td.TileType == "Hull" || td.TileType == "HullCorner")
                        {
                            hull.Add(td);
                        }
                        else if (td.TileType == "Floor")
                        {
                            floor.Add(td);
                        }
                        else if (td.TileType == "ShipCore")
                        {
                            shipCore = td;
                        }
                        else
                        {
                            other.Add(td);
                        }
                    }

                    if (shipCore == null)
                    {
                        throw new Exception("Ship Design is missing required tile ShipCore");
                    }

                    _IsImporting = true;
                    _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                    managerMenu.StartCoroutine(UpdateTiles(shipTiles, managerJobs, managerOptions, tileMap, hull, floor, shipCore, other));
                    managerMenu.StartCoroutine(OnImportFinished(tiles));
                }
            }
        }
Exemplo n.º 2
0
        public static void RemoveTiles(params Vector2[] positions)
        {
            GameObject  tileMap     = GameObject.Find("TileMap");
            Tiles       shipTiles   = tileMap.GetComponent <Tiles>();
            ManagerJobs managerJobs = GameObject.Find("Manager").GetComponent <ManagerJobs>();

            foreach (Vector2 pos in positions)
            {
                RemoveTile(pos, tileMap);
            }
        }
Exemplo n.º 3
0
        public static void BuildTiles(params TileData[] tiles)
        {
            GameObject  tileMap     = GameObject.Find("TileMap");
            Tiles       shipTiles   = tileMap.GetComponent <Tiles>();
            ManagerJobs managerJobs = GameObject.Find("Manager").GetComponent <ManagerJobs>();

            foreach (TileData td in tiles)
            {
                shipTiles.tiles[td.X, td.Y].toBecome = td.TileType;

                if (td.StructureParts.Count > 0)
                {
                    List <Vector3> partsList = new List <Vector3>();
                    List <Vector2> tilesList = new List <Vector2>();

                    foreach (TileData.Vec3 vec in td.StructureParts)
                    {
                        Vector2 tilePos = new Vector2(vec.X, vec.Y);
                        if (!tilesList.Contains(tilePos))
                        {
                            tilesList.Add(tilePos);
                        }

                        Vector3 partData = vec.GetVector();
                        if (!partsList.Contains(partData))
                        {
                            partsList.Add(partData);
                        }
                    }

                    if (partsList.Count > 0)
                    {
                        foreach (Vector2 tilePos in tilesList)
                        {
                            shipTiles.tiles[(int)tilePos.x, (int)tilePos.y].toBecome = td.TileType;

                            foreach (Vector3 part in partsList)
                            {
                                shipTiles.tiles[(int)tilePos.x, (int)tilePos.y].structureParts.Add(part);
                            }
                        }
                    }
                }

                managerJobs.completeJob((int)td.X, (int)td.Y, tileMap, false, false);
                shipTiles.tiles[td.X, td.Y].leakValue = 0;
            }
        }
Exemplo n.º 4
0
        private static System.Collections.IEnumerator _RemoveTilesCR(Vector2[] positions, Action <Exception> completed)
        {
            GameObject  tileMap     = GameObject.Find("TileMap");
            Tiles       shipTiles   = tileMap.GetComponent <Tiles>();
            ManagerJobs managerJobs = GameObject.Find("Manager").GetComponent <ManagerJobs>();

            foreach (Vector2 pos in positions)
            {
                try
                {
                    RemoveTile(pos, tileMap);
                }
                catch (Exception ex)
                {
                    completed?.Invoke(ex);
                    yield break;
                }
                yield return(new WaitForRealSeconds(0.01f));
            }

            completed?.Invoke(null);
        }
Exemplo n.º 5
0
        private System.Collections.IEnumerator UpdateTiles(Tiles shipTiles, ManagerJobs managerJobs, ManagerOptions managerOptions, GameObject tileMap, List <TileData> hull, List <TileData> floor, TileData shipCore, List <TileData> other)
        {
            bool deadCrewEndGame = true;

            try
            {
                if (managerOptions != null)
                {
                    deadCrewEndGame = managerOptions.deadCrewEndGame;
                    managerOptions.deadCrewEndGame = false;
                }
            }
            catch (Exception ex)
            {
                this.DisplayError(ex);
                _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                _IsImporting = false;
                yield break;
            }
            yield return(new WaitForSeconds(0.01f));

            Structures structures   = null;
            int        cargoGold    = 0;
            int        cargoMetal   = 0;
            int        cargoSilicon = 0;
            int        cargoWater   = 0;
            int        cargoFood    = 0;
            int        cargoCredits = 0;

            try
            {
                structures = tileMap.GetComponent <Structures>();

                cargoGold    = structures.structure[0].reservesGold;
                cargoMetal   = structures.structure[0].reservesMetal;
                cargoSilicon = structures.structure[0].reservesSilicon;
                cargoWater   = structures.structure[0].reservesWater;
                cargoFood    = structures.structure[0].reservesFood;
                cargoCredits = structures.structure[0].credits;

                List <Vector2> tilesToRemove = new List <Vector2>();

                for (int x = shipTiles.tiles.GetLowerBound(0); x <= shipTiles.tiles.GetUpperBound(0); x++)
                {
                    for (int y = shipTiles.tiles.GetLowerBound(1); y <= shipTiles.tiles.GetUpperBound(1); y++)
                    {
                        if (String.IsNullOrEmpty(shipTiles.tiles[x, y].toBecome) && String.IsNullOrEmpty(shipTiles.tiles[x, y].tileType) && String.IsNullOrEmpty(shipTiles.tiles[x, y].structureType))
                        {
                            continue;
                        }

                        tilesToRemove.Add(new Vector2(x, y));
                    }
                }

                TileHelper.RemoveTiles(tilesToRemove);
            }
            catch (Exception ex)
            {
                this.DisplayError(ex);
                _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                _IsImporting = false;
                yield break;
            }

            yield return(new WaitForSeconds(0.01f));


            if (hull.Count > 0)
            {
                try
                {
                    TileHelper.BuildTiles(hull);
                }
                catch (Exception ex)
                {
                    this.DisplayError(ex);
                    _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                    _IsImporting = false;
                    yield break;
                }
                yield return(new WaitForSeconds(0.01f));
            }

            if (floor.Count > 0)
            {
                try
                {
                    TileHelper.BuildTiles(floor);
                }
                catch (Exception ex)
                {
                    this.DisplayError(ex);
                    _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                    _IsImporting = false;
                    yield break;
                }
                yield return(new WaitForSeconds(0.01f));
            }

            if (shipCore != null)
            {
                try
                {
                    TileHelper.BuildTiles(shipCore);
                }
                catch (Exception ex)
                {
                    this.DisplayError(ex);
                    _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                    _IsImporting = false;
                    yield break;
                }
                yield return(new WaitForSeconds(0.01f));
            }

            if (other.Count > 0)
            {
                try
                {
                    TileHelper.BuildTiles(other);
                }
                catch (Exception ex)
                {
                    this.DisplayError(ex);
                    _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                    _IsImporting = false;
                    yield break;
                }
                yield return(new WaitForSeconds(0.01f));
            }

            try
            {
                shipTiles.updateTileColors();
                shipTiles.updateTileMesh("All");

                Crew crew = tileMap.GetComponent <Crew>();
                foreach (GameObject crewMember in crew.crewList)
                {
                    crewMember.transform.position = new Vector3(shipCore.X, crewMember.transform.position.y, shipCore.Y);
                }
            }
            catch (Exception ex)
            {
                this.DisplayError(ex);
                _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                _IsImporting = false;
                yield break;
            }
            yield return(new WaitForSeconds(0.01f));

            try
            {
                if (managerOptions != null)
                {
                    managerOptions.deadCrewEndGame = deadCrewEndGame;
                }

                ManagerResources managerResources = _Manager.GetComponent <ManagerResources>();

                structures.structure[0].reservesGold    = 0;
                structures.structure[0].reservesMetal   = 0;
                structures.structure[0].reservesSilicon = 0;
                structures.structure[0].reservesWater   = 0;
                structures.structure[0].reservesFood    = 0;
                structures.structure[0].credits         = 0;
                structures.structure[0].cargoCurrent    = 0;


                managerResources.updateResourceReserves("Gold", cargoGold, tileMap, "");
                managerResources.updateResourceReserves("Metal", cargoMetal, tileMap, "");
                managerResources.updateResourceReserves("Silicon", cargoSilicon, tileMap, "");
                managerResources.updateResourceReserves("Water", cargoWater, tileMap, "");
                managerResources.updateResourceReserves("Food", cargoFood, tileMap, "");
                managerResources.updateCredits(cargoCredits, false);
            }
            catch (Exception ex)
            {
                this.DisplayError(ex);
                _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
                _IsImporting = false;
                yield break;
            }
            yield return(new WaitForSeconds(0.01f));

            _Manager.GetComponent <ManagerMenu>().toggleMainMenu();
            _IsImporting = false;
        }