Example #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();
    }
Example #2
0
    //======================================================= SAVE STORE ITEMS ===========================================================

    public void SaveStoresInfo()
    {
        if (File.Exists(Application.persistentDataPath + "/StoresStack.json"))
        {
            string     GetInfo    = File.ReadAllText(Application.persistentDataPath + "/StoresStack.json");
            StoreStack StoresInfo = JsonUtility.FromJson <StoreStack>(GetInfo);
            int        StoreID    = PlayInv.StoreID;

            foreach (StorePoint Store in StoresInfo.storePoint)
            {
                if (Store.StoreID == StoreID)
                {
                    Store.Lot1.Clear();
                    Store.Lot2.Clear();
                    Store.Lot3.Clear();
                    Store.Lot4.Clear();
                    foreach (GameObject GetItem in PlayInv.Items)
                    {
                        if (GetItem.GetComponent <SlaveProperties>() != null)
                        {
                            SlaveProperties CheckProp = GetItem.GetComponent <SlaveProperties>();
                            SlvLot          NewSlv    = new SlvLot();

                            NewSlv.Skin        = CheckProp.Skin;
                            NewSlv.Health      = CheckProp.Health;
                            NewSlv.FullHealth  = CheckProp.FullHealth;
                            NewSlv.Damage      = CheckProp.Damage;
                            NewSlv.Accuracy    = CheckProp.Accuracy;
                            NewSlv.Level       = CheckProp.Level;
                            NewSlv.Price       = CheckProp.Price;
                            NewSlv.St_Health   = CheckProp.Start_Fhp;
                            NewSlv.St_Damage   = CheckProp.Start_Dmg;
                            NewSlv.St_Accuracy = CheckProp.Start_Acc;
                            NewSlv.Shot_Units  = CheckProp.Shot_Units;
                            NewSlv.Heal_Units  = CheckProp.Heal_Units;
                            NewSlv.Rush_Units  = CheckProp.Rush_Units;

                            Store.Lot1.Add(NewSlv);
                        }
                        if (GetItem.GetComponent <WeaponProperties>() != null)
                        {
                            WeaponProperties CheckProp = GetItem.GetComponent <WeaponProperties>();
                            WpnLot           NewWpn    = new WpnLot();

                            NewWpn.Name      = CheckProp.name;
                            NewWpn.Skin      = CheckProp.Skin;
                            NewWpn.Price     = CheckProp.Price;
                            NewWpn.Damage    = CheckProp.Damage;
                            NewWpn.Condition = CheckProp.Condition;
                            NewWpn.Bullets   = CheckProp.Bullets;

                            Store.Lot2.Add(NewWpn);
                        }
                        if (GetItem.GetComponent <BulletsProperties>() != null)
                        {
                            BulletsProperties CheckProp = GetItem.GetComponent <BulletsProperties>();
                            BulLot            NewBul    = new BulLot();

                            NewBul.Skin  = CheckProp.Skin;
                            NewBul.Name  = CheckProp.Name;
                            NewBul.Count = CheckProp.Count;
                            NewBul.Price = CheckProp.Price;

                            Store.Lot3.Add(NewBul);
                        }
                        if (GetItem.GetComponent <OtherStuff>() != null)
                        {
                            OtherStuff CheckProp = GetItem.GetComponent <OtherStuff>();
                            StffLot    NewStff   = new StffLot();

                            NewStff.Skin   = CheckProp.Skin;
                            NewStff.Price  = CheckProp.Price;
                            NewStff.Liters = CheckProp.Liters;

                            Store.Lot4.Add(NewStff);
                        }
                    }
                }
            }

            string       NewStoreData = JsonUtility.ToJson(StoresInfo);
            StreamWriter WriteNewData = new StreamWriter(Application.persistentDataPath + "/StoresStack.json");
            WriteNewData.Write(NewStoreData);
            WriteNewData.Close();
        }
    }
Example #3
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);
        }
    }
Example #4
0
    //======================================================= LOAD STORE ITEMS ===========================================================

    public void LoadStoreInfo(int StoreID)
    {
        if (File.Exists(Application.persistentDataPath + "/StoresStack.json"))
        {
            if (File.Exists(Application.persistentDataPath + "/PlayerData.json"))
            {
                string       GetPlayInfo   = File.ReadAllText(Application.persistentDataPath + "/PlayerData.json");
                PlayerSource GetPlaySource = JsonUtility.FromJson <PlayerSource>(GetPlayInfo);

                string     GetStoresInfo = File.ReadAllText(Application.persistentDataPath + "/StoresStack.json");
                StoreStack GetStore      = JsonUtility.FromJson <StoreStack>(GetStoresInfo);

                PlayInv.StoreID = GetPlaySource.CurrentStore;
                PlayInv.Money   = GetPlaySource.Money;

                int SlaveNum  = 0;
                int WeaponNum = 0;
                int BulletNum = 0;
                int StuffNum  = 0;
                foreach (StorePoint Store in GetStore.storePoint)
                {
                    if (Store.StoreID == PlayInv.StoreID)
                    {
                        PlayInv.TypeOfStore = Store.TypeOfStore;
                        foreach (SlvLot Slave in Store.Lot1)
                        {
                            GameObject Slv = Instantiate(Resources.Load("HeroPrefab")) as GameObject;
                            Slv.name = "Slv_" + SlaveNum;
                            SlaveProperties SlvProp = Slv.GetComponent <SlaveProperties>();
                            SlvProp.Skin       = Slave.Skin;
                            SlvProp.FullHealth = Slave.FullHealth;
                            SlvProp.Health     = Slave.Health;
                            SlvProp.Damage     = Slave.Damage;
                            SlvProp.Accuracy   = Slave.Accuracy;
                            SlvProp.Price      = Slave.Price;
                            SlvProp.Level      = Slave.Level;
                            SlvProp.Start_Fhp  = Slave.St_Health;
                            SlvProp.Start_Dmg  = Slave.St_Damage;
                            SlvProp.Start_Acc  = Slave.St_Accuracy;
                            SlvProp.Shot_Units = Slave.Shot_Units;
                            SlvProp.Heal_Units = Slave.Heal_Units;
                            SlvProp.Rush_Units = Slave.Rush_Units;
                            PlayInv.Items.Add(Slv);
                            SlaveNum += 1;
                        }
                        foreach (WpnLot Weapon in Store.Lot2)
                        {
                            GameObject Wpn = Instantiate(Resources.Load("WeaponDoll")) as GameObject;
                            Wpn.name = "Wpn_" + WeaponNum;
                            WeaponProperties WpnProp = Wpn.GetComponent <WeaponProperties>();
                            WpnProp.WeapName  = Weapon.Name;
                            WpnProp.Skin      = Weapon.Skin;
                            WpnProp.Price     = Weapon.Price;
                            WpnProp.Damage    = Weapon.Damage;
                            WpnProp.Condition = Weapon.Condition;
                            WpnProp.Bullets   = Weapon.Bullets;
                            PlayInv.Items.Add(Wpn);
                            WeaponNum += 1;
                        }
                        foreach (BulLot Bullets in Store.Lot3)
                        {
                            GameObject Bul = Instantiate(Resources.Load("BulletsDoll")) as GameObject;
                            Bul.name = "Bul_" + BulletNum;
                            BulletsProperties BulProp = Bul.GetComponent <BulletsProperties>();
                            BulProp.Name  = Bullets.Name;
                            BulProp.Skin  = Bullets.Skin;
                            BulProp.Count = Bullets.Count;
                            BulProp.Price = Bullets.Price;
                            PlayInv.Items.Add(Bul);
                            BulletNum += 1;
                        }
                        foreach (StffLot Stuff in Store.Lot4)
                        {
                            GameObject Stf = Instantiate(Resources.Load("OtherStuff")) as GameObject;
                            Stf.name = "Stf_" + StuffNum;
                            OtherStuff StfProp = Stf.GetComponent <OtherStuff>();
                            StfProp.Skin   = Stuff.Skin;
                            StfProp.Price  = Stuff.Price;
                            StfProp.Liters = Stuff.Liters;
                            PlayInv.Items.Add(Stf);
                            StuffNum += 1;
                        }
                    }
                }
            }
        }
    }