Exemple #1
0
    public void GenerateMap()
    {
        MapData NewMapData = new MapData();

        NewMapData.GenerateIndexes.Columns = 20;
        NewMapData.GenerateIndexes.Row     = 20;

        StoreStack StoresStack = new StoreStack();

        int   TileID = 1;
        float Xcoord = -0.64f * (NewMapData.GenerateIndexes.Columns / 2) + 0.32f;
        float Ycoord = 0.64f * (NewMapData.GenerateIndexes.Row / 2) - 0.32f;

        for (int c = 1; c < NewMapData.GenerateIndexes.Columns + 1; c++)
        {
            for (int r = 1; r < NewMapData.GenerateIndexes.Row + 1; r++)
            {
                MapTileSample newTile = new MapTileSample();
                newTile.TileID = TileID;
                newTile.Skin   = Random.Range(0, 6);
                for (int a = 0; a < newTile.Smokes.Length; a++)
                {
                    newTile.Smokes[a] = true;
                }
                newTile.Coordinates = new Vector3(Xcoord, Ycoord, 0.0f);
                newTile.Empty       = true;
                NewMapData.Tiles.Add(newTile);
                Xcoord += 0.64f;
                TileID += 1;
            }
            Xcoord  = -0.64f * (NewMapData.GenerateIndexes.Columns / 2) + 0.32f;
            Ycoord -= 0.64f;
        }

        int StoresNum = 20;

        for (int s = 0; s < StoresNum; s++)
        {
            string Type = "";
            if (s == 0)
            {
                Type = "Slaves";
                Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                if (newstore != null)
                {
                    NewMapData.GenerateIndexes.Stores.Add(newstore);
                }
                else
                {
                    s -= 1;
                }
            }
            if (s == 1)
            {
                Type = "Stuff";
                Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, true);
                if (newstore != null)
                {
                    NewMapData.GenerateIndexes.Stores.Add(newstore);
                }
                else
                {
                    s -= 1;
                }
            }
            if (s == 2)
            {
                Type = "Bullets";
                Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, true);
                if (newstore != null)
                {
                    NewMapData.GenerateIndexes.Stores.Add(newstore);
                }
                else
                {
                    s -= 1;
                }
            }
            if (s == 3)
            {
                Type = "Guns";
                Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, true);
                if (newstore != null)
                {
                    NewMapData.GenerateIndexes.Stores.Add(newstore);
                }
                else
                {
                    s -= 1;
                }
            }
            if (s == 4)
            {
                Type = "Recycling";
                Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                if (newstore != null)
                {
                    NewMapData.GenerateIndexes.Stores.Add(newstore);
                }
                else
                {
                    s -= 1;
                }
            }
            if (s >= 5 && s < 10)
            {
                Type = "Stuff";
                Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                if (newstore != null)
                {
                    NewMapData.GenerateIndexes.Stores.Add(newstore);
                }
                else
                {
                    s -= 1;
                }
            }
            if (s >= 10 && s < 15)
            {
                Type = "Bullets";
                Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                if (newstore != null)
                {
                    NewMapData.GenerateIndexes.Stores.Add(newstore);
                }
                else
                {
                    s -= 1;
                }
            }
            if (s >= 15)
            {
                int randNum = Random.Range(1, 6);
                if (randNum == 1)
                {
                    Type = "Slaves";
                    Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                    if (newstore != null)
                    {
                        NewMapData.GenerateIndexes.Stores.Add(newstore);
                    }
                    else
                    {
                        s -= 1;
                    }
                }
                if (randNum == 2)
                {
                    Type = "Guns";
                    Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                    if (newstore != null)
                    {
                        NewMapData.GenerateIndexes.Stores.Add(newstore);
                    }
                    else
                    {
                        s -= 1;
                    }
                }
                if (randNum == 3)
                {
                    Type = "Bullets";
                    Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                    if (newstore != null)
                    {
                        NewMapData.GenerateIndexes.Stores.Add(newstore);
                    }
                    else
                    {
                        s -= 1;
                    }
                }
                if (randNum == 4)
                {
                    Type = "Stuff";
                    Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                    if (newstore != null)
                    {
                        NewMapData.GenerateIndexes.Stores.Add(newstore);
                    }
                    else
                    {
                        s -= 1;
                    }
                }
                if (randNum == 5)
                {
                    Type = "Recycling";
                    Store newstore = CreateNewStore(NewMapData, StoresStack, Type, s, false);
                    if (newstore != null)
                    {
                        NewMapData.GenerateIndexes.Stores.Add(newstore);
                    }
                    else
                    {
                        s -= 1;
                    }
                }
            }
        }

        for (int a = 0; a < 10; a++)
        {
            BanditArea NewBand = CreateNewBand(NewMapData, a);
            if (NewBand != null)
            {
                NewMapData.GenerateIndexes.Bandits.Add(NewBand);
            }
            else
            {
                a -= 1;
            }
        }

        for (int o = 0; o < 10; o++)
        {
            int randPlace = Random.Range(0, NewMapData.Tiles.Count);
            if (NewMapData.Tiles[randPlace].Empty == true)
            {
                Obstacle newObst = new Obstacle();
                newObst.Skin  = Random.Range(1, 4);
                newObst.Place = randPlace;
                NewMapData.GenerateIndexes.Obstacles.Add(newObst);
            }
            else
            {
                o -= 1;
            }
        }

        string       SaveData  = JsonUtility.ToJson(NewMapData);
        StreamWriter WriteData = new StreamWriter(Application.persistentDataPath + "/MapData.json");

        WriteData.Write(SaveData);
        WriteData.Close();

        string       SaveStores  = JsonUtility.ToJson(StoresStack);
        StreamWriter WriteStores = new StreamWriter(Application.persistentDataPath + "/StoresStack.json");

        WriteStores.Write(SaveStores);
        WriteStores.Close();
    }
Exemple #2
0
    public Store CreateNewStore(MapData NewMapData, StoreStack StoresStack, string Type, int StoreID, bool In_Radius)
    {
        if (Type == "Slaves")
        {
            int RandomCell = NewMapData.Tiles[Random.Range(0, NewMapData.GenerateIndexes.Columns * NewMapData.GenerateIndexes.Row - 1)].TileID;

            if (NewMapData.Tiles[RandomCell].Empty == true)
            {
                MapTileSample Tile = NewMapData.Tiles[RandomCell];

                Store      newStore = new Store();
                StorePoint AddStore = new StorePoint();
                newStore.TileID  = Tile.TileID;
                newStore.StoreID = StoreID;
                newStore.Type    = Type;

                AddStore.TypeOfStore = newStore.Type;
                AddStore.StoreID     = newStore.StoreID;
                AddStore.CountOfItem = Random.Range(10, 15);
                for (int Slv = 0; Slv < AddStore.CountOfItem; Slv++)
                {
                    AddStore.SlaveRandomize();
                }
                StoresStack.storePoint.Add(AddStore);

                if (StoreID == 0)
                {
                    NewMapData.GenerateIndexes.PlayerCoords = Tile.Coordinates + new Vector3(0, 0, -5);
                }

                Tile.Empty = false;
                return(newStore);
            }
            else
            {
                return(null);
            }
        }
        if (Type == "Guns")
        {
            CreateInCircle newCirc = new CreateInCircle();
            if (In_Radius == true)
            {
                newCirc.TakeCell  = NewMapData.GenerateIndexes.Stores[StoreID - 1].TileID;
                newCirc.MapColumn = NewMapData.GenerateIndexes.Columns;
                newCirc.MapRow    = NewMapData.GenerateIndexes.Row;
                newCirc.Radius    = 2;
                newCirc.GenerateCell();
                //Debug.Log(newCirc.TargetCell);
                if (NewMapData.Tiles[newCirc.TargetCell - 1].Empty == true)
                {
                    MapTileSample Tile     = NewMapData.Tiles[newCirc.TargetCell - 1];
                    Store         newStore = new Store();
                    StorePoint    AddStore = new StorePoint();
                    newStore.TileID  = Tile.TileID;
                    newStore.StoreID = StoreID;
                    newStore.Type    = Type;

                    AddStore.TypeOfStore = newStore.Type;
                    AddStore.StoreID     = newStore.StoreID;
                    AddStore.CountOfItem = Random.Range(10, 15);
                    for (int Wpn = 0; Wpn < AddStore.CountOfItem; Wpn++)
                    {
                        AddStore.WeaponRandomize();
                    }
                    StoresStack.storePoint.Add(AddStore);

                    Tile.Empty = false;
                    return(newStore);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                int RandCell = Random.Range(0, NewMapData.Tiles.Count);
                if (NewMapData.Tiles[RandCell].Empty == true)
                {
                    MapTileSample Tile     = NewMapData.Tiles[RandCell];
                    Store         newStore = new Store();
                    StorePoint    AddStore = new StorePoint();
                    newStore.TileID  = Tile.TileID;
                    newStore.StoreID = StoreID;
                    newStore.Type    = Type;

                    AddStore.TypeOfStore = newStore.Type;
                    AddStore.StoreID     = newStore.StoreID;
                    AddStore.CountOfItem = Random.Range(10, 15);
                    for (int Wpn = 0; Wpn < AddStore.CountOfItem; Wpn++)
                    {
                        AddStore.WeaponRandomize();
                    }
                    StoresStack.storePoint.Add(AddStore);

                    Tile.Empty = false;
                    return(newStore);
                }
                else
                {
                    return(null);
                }
            }
        }
        if (Type == "Bullets")
        {
            if (In_Radius == true)
            {
                CreateInCircle newCirc = new CreateInCircle();
                newCirc.TakeCell  = NewMapData.GenerateIndexes.Stores[StoreID - 1].TileID;
                newCirc.MapColumn = NewMapData.GenerateIndexes.Columns;
                newCirc.MapRow    = NewMapData.GenerateIndexes.Row;
                newCirc.Radius    = 2;
                newCirc.GenerateCell();
                //Debug.Log(newCirc.TargetCell);
                if (NewMapData.Tiles[newCirc.TargetCell - 1].Empty == true)
                {
                    MapTileSample Tile     = NewMapData.Tiles[newCirc.TargetCell - 1];
                    Store         newStore = new Store();
                    StorePoint    AddStore = new StorePoint();
                    newStore.TileID  = Tile.TileID;
                    newStore.StoreID = StoreID;
                    newStore.Type    = Type;

                    AddStore.TypeOfStore = newStore.Type;
                    AddStore.StoreID     = newStore.StoreID;
                    AddStore.CountOfItem = Random.Range(10, 15);
                    for (int Bul = 0; Bul < AddStore.CountOfItem; Bul++)
                    {
                        AddStore.BulletRandomize();
                    }
                    StoresStack.storePoint.Add(AddStore);

                    Tile.Empty = false;
                    return(newStore);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                int RandCell = Random.Range(0, NewMapData.Tiles.Count);
                if (NewMapData.Tiles[RandCell].Empty == true)
                {
                    MapTileSample Tile     = NewMapData.Tiles[RandCell];
                    Store         newStore = new Store();
                    StorePoint    AddStore = new StorePoint();
                    newStore.TileID  = Tile.TileID;
                    newStore.StoreID = StoreID;
                    newStore.Type    = Type;

                    AddStore.TypeOfStore = newStore.Type;
                    AddStore.StoreID     = newStore.StoreID;
                    AddStore.CountOfItem = Random.Range(10, 15);
                    for (int Bul = 0; Bul < AddStore.CountOfItem; Bul++)
                    {
                        AddStore.BulletRandomize();
                    }
                    StoresStack.storePoint.Add(AddStore);

                    Tile.Empty = false;
                    return(newStore);
                }
                else
                {
                    return(null);
                }
            }
        }
        if (Type == "Stuff")
        {
            if (In_Radius == true)
            {
                CreateInCircle newCirc = new CreateInCircle();
                newCirc.TakeCell  = NewMapData.GenerateIndexes.Stores[StoreID - 1].TileID;
                newCirc.MapColumn = NewMapData.GenerateIndexes.Columns;
                newCirc.MapRow    = NewMapData.GenerateIndexes.Row;
                newCirc.Radius    = 2;
                newCirc.GenerateCell();
                if (NewMapData.Tiles[newCirc.TargetCell - 1].Empty == true)
                {
                    MapTileSample Tile     = NewMapData.Tiles[newCirc.TargetCell - 1];
                    Store         newStore = new Store();
                    StorePoint    AddStore = new StorePoint();
                    newStore.TileID  = Tile.TileID;
                    newStore.StoreID = StoreID;
                    newStore.Type    = Type;

                    AddStore.TypeOfStore = newStore.Type;
                    AddStore.StoreID     = newStore.StoreID;
                    AddStore.CountOfItem = Random.Range(10, 15);
                    for (int Stf = 0; Stf < AddStore.CountOfItem; Stf++)
                    {
                        AddStore.StuffRandomize(Stf);
                    }
                    StoresStack.storePoint.Add(AddStore);

                    Tile.Empty = false;
                    return(newStore);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                int RandCell = Random.Range(0, NewMapData.Tiles.Count);
                if (NewMapData.Tiles[RandCell].Empty == true)
                {
                    MapTileSample Tile     = NewMapData.Tiles[RandCell];
                    Store         newStore = new Store();
                    StorePoint    AddStore = new StorePoint();
                    newStore.TileID  = Tile.TileID;
                    newStore.StoreID = StoreID;
                    newStore.Type    = Type;

                    AddStore.TypeOfStore = newStore.Type;
                    AddStore.StoreID     = newStore.StoreID;
                    AddStore.CountOfItem = Random.Range(10, 15);
                    for (int Stf = 0; Stf < AddStore.CountOfItem; Stf++)
                    {
                        AddStore.StuffRandomize(Stf);
                    }
                    StoresStack.storePoint.Add(AddStore);

                    Tile.Empty = false;
                    return(newStore);
                }
                else
                {
                    return(null);
                }
            }
        }
        if (Type == "Recycling")
        {
            //CreateInCircle newCirc = new CreateInCircle();
            //newCirc.TakeCell = NewMapData.GenerateIndexes.Stores[StoreID - 1].TileID;
            //newCirc.MapColumn = NewMapData.GenerateIndexes.Columns;
            //newCirc.MapRow = NewMapData.GenerateIndexes.Row;
            //newCirc.Radius = 3;
            //newCirc.GenerateCell();
            int RandomCell = NewMapData.Tiles[Random.Range(0, NewMapData.Tiles.Count)].TileID;

            Debug.Log(RandomCell);
            if (NewMapData.Tiles[RandomCell].Empty == true)
            {
                MapTileSample Tile     = NewMapData.Tiles[RandomCell];
                Store         newStore = new Store();
                StorePoint    AddStore = new StorePoint();
                newStore.TileID  = Tile.TileID;
                newStore.StoreID = StoreID;
                newStore.Type    = Type;

                AddStore.TypeOfStore = newStore.Type;
                AddStore.StoreID     = newStore.StoreID;
                StoresStack.storePoint.Add(AddStore);

                Tile.Empty = false;
                return(newStore);
            }
            else
            {
                return(null);
            }
        }
        else
        {
            return(null);
        }
    }