void LoadPlayerData()
    {
        if (File.Exists(Application.persistentDataPath + "/PlayerData.json"))
        {
            Loader.LoadAll();
            int SlvNum = 0;
            foreach (GameObject slv in PlayInv.SlavePlace)
            {
                if (slv != null)
                {
                    slv.transform.SetParent(SlavesContainer.transform);
                    slv.transform.position = SlavesFields.transform.GetChild(SlvNum).gameObject.transform.position + new Vector3(0, 0, -0.1f);
                    slv.GetComponent <SlaveProperties>().Goal = EnemiesFields.transform.GetChild(5).gameObject;
                    this.GetComponent <WORK_Battle>().Slaves.Add(slv);
                }
                SlvNum++;
            }
        }

        if (File.Exists(Application.persistentDataPath + "/BanditTroop.json"))
        {
            string    GetEnemyData = File.ReadAllText(Application.persistentDataPath + "/BanditTroop.json");
            TroopData GetTroop     = new TroopData();
            GetTroop     = JsonUtility.FromJson <TroopData>(GetEnemyData);
            NumberOfArea = GetTroop.NumberOfArea;
            Count        = GetTroop.TroopCount;
            Battle.Clan  = GetTroop.Band;

            for (int e = 0; e < GetTroop.TroopCount; e++)
            {
                GameObject E = Instantiate(Resources.Load("EnemyDoll")) as GameObject;
                E.name = "Enm" + e;
                E.GetComponent <EnemyProperties>().FullHealth = GetTroop.Enemies[e].FullHealth;
                E.GetComponent <EnemyProperties>().Health     = GetTroop.Enemies[e].Health;
                E.GetComponent <EnemyProperties>().Damage     = GetTroop.Enemies[e].Damage;
                E.GetComponent <EnemyProperties>().Accuracy   = GetTroop.Enemies[e].Accuracy;
                E.GetComponent <EnemyProperties>().Level      = GetTroop.Enemies[e].Level;
                E.GetComponent <EnemyProperties>().Skin       = GetTroop.Enemies[e].Skin;
                E.transform.SetParent(EnemiesContainer.transform);
                this.GetComponent <WORK_Battle>().Enemies.Add(E);
            }

            int GetEnemy = 0;
            PanoramaCoef = -0.1f;
            for (int i = 0; i < GetTroop.Places.Length; i++)
            {
                if (GetTroop.Places[i] == true)
                {
                    EnemiesContainer.transform.GetChild(GetEnemy).transform.position = EnemiesFields.transform.GetChild(i).transform.position + new Vector3(0, 0, PanoramaCoef);
                    GetEnemy     += 1;
                    PanoramaCoef -= 0.1f;
                }
            }
        }
    }
Beispiel #2
0
    //=========================== Загрузка карты и ресурсов игрока =============================
    void LoadMap()
    {
        if (File.Exists(Application.persistentDataPath + "/PlayerData.json"))
        {
            Loader.LoadAll();
            foreach (GameObject Slv in PlayInv.SlavePlace)
            {
                if (Slv != null)
                {
                    Slv.transform.localPosition = new Vector3(0, 0, 0);
                    GameObject GetPack = Slv.GetComponent <SlaveProperties>().InventoryPack.gameObject;
                    foreach (Transform place in GetPack.transform)
                    {
                        if (place.transform.childCount != 0)
                        {
                            GameObject getItem = place.transform.GetChild(0).gameObject;
                            if (getItem.GetComponent <OtherStuff>() != null)
                            {
                                if (getItem.GetComponent <OtherStuff>().Skin == 2)
                                {
                                    WaterContainer.Add(getItem);
                                }
                            }
                        }
                    }
                }
            }
        }
        if (File.Exists(Application.persistentDataPath + "/MapData.json"))
        {
            string MapData = File.ReadAllText(Application.persistentDataPath + "/MapData.json").ToString();

            MapData GetMap = new MapData();
            GetMap = JsonUtility.FromJson <MapData>(MapData);

            int GetMapTileNum = 0;
            foreach (MapTileSample TileMap in GetMap.Tiles)
            {
                GameObject Tile = Instantiate(Resources.Load("TileMapDoll")) as GameObject;
                Tile.GetComponent <MapTile>().TileID = GetMap.Tiles[GetMapTileNum].TileID;
                Tile.GetComponent <MapTile>().Skin   = GetMap.Tiles[GetMapTileNum].Skin;
                for (int s = 0; s < GetMap.Tiles[GetMapTileNum].Smokes.Length; s++)
                {
                    if (GetMap.Tiles[GetMapTileNum].Smokes[s] == false)
                    {
                        Tile.GetComponent <MapTile>().SmokeOfWar[s].gameObject.active = false;
                    }
                }

                Tile.name = "Tile_" + Tile.GetComponent <MapTile>().TileID;
                Tile.transform.SetParent(MapContainer.transform);
                Tile.transform.localPosition = GetMap.Tiles[GetMapTileNum].Coordinates;
                //if (TileMap.Empty == false) {
                //    Tile.GetComponent<SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f, 1);
                //}
                GetMapTileNum += 1;
            }


            int GetBanditNum = 0;
            foreach (BanditArea Band in GetMap.GenerateIndexes.Bandits)
            {
                GameObject newBand = Instantiate(Resources.Load("BanditsAreaDoll")) as GameObject;
                newBand.transform.SetParent(MapContainer.transform);
                newBand.transform.localPosition                 = MapContainer.transform.GetChild(GetMap.GenerateIndexes.Bandits[GetBanditNum].Coordinates - 1).transform.localPosition + new Vector3(0, 0, -0.1f);
                newBand.GetComponent <BanditsDoll>().Clan       = GetMap.GenerateIndexes.Bandits[GetBanditNum].Clan;
                newBand.GetComponent <BanditsDoll>().Coverage   = GetMap.GenerateIndexes.Bandits[GetBanditNum].Coverage;
                newBand.GetComponent <BanditsDoll>().Population = GetMap.GenerateIndexes.Bandits[GetBanditNum].Population;
                newBand.GetComponent <BanditsDoll>().Number     = GetMap.GenerateIndexes.Bandits[GetBanditNum].NumberOfArea;
                newBand.GetComponent <BanditsDoll>().Attacks    = GetMap.GenerateIndexes.Bandits[GetBanditNum].Attacks;
                if (PlayInv.If_Tutorial == true)
                {
                    foreach (Collider2D col in newBand.GetComponent <BanditsDoll>().Colliders)
                    {
                        col.enabled = false;
                    }
                }
                else
                {
                    if (newBand.GetComponent <BanditsDoll>().Clan != "")
                    {
                        newBand.GetComponent <BanditsDoll>().Colliders[newBand.GetComponent <BanditsDoll>().Coverage - 1].enabled = true;
                    }
                }
                GetBanditNum += 1;
            }

            int GetStoreNum = 0;
            foreach (Store store in GetMap.GenerateIndexes.Stores)
            {
                GameObject newStore = Instantiate(Resources.Load("StoresDoll")) as GameObject;
                newStore.transform.SetParent(MapContainer.transform);
                newStore.GetComponent <StoreChip>().TypeOfStore = GetMap.GenerateIndexes.Stores[GetStoreNum].Type;
                newStore.GetComponent <StoreChip>().StoreID     = GetMap.GenerateIndexes.Stores[GetStoreNum].StoreID;
                Vector3 GetCoords = GetMap.Tiles[GetMap.GenerateIndexes.Stores[GetStoreNum].TileID - 1].Coordinates;
                newStore.transform.localPosition = GetCoords + new Vector3(0, 0, -0.1f);
                GetStoreNum += 1;
            }
            int GetObstNum = 0;
            foreach (Obstacle Obst in GetMap.GenerateIndexes.Obstacles)
            {
                GameObject newObst = Instantiate(Resources.Load("Obstacles")) as GameObject;
                newObst.transform.SetParent(MapContainer.transform);
                newObst.GetComponent <Obstacles>().Skin = Obst.Skin;
                Vector3 GetCoords = GetMap.Tiles[Obst.Place].Coordinates;
                newObst.transform.localPosition = GetCoords + new Vector3(0, 0, -0.1f);
                GetObstNum += 1;
            }

            Player.transform.localPosition = new Vector3(GetMap.GenerateIndexes.PlayerCoords.x, GetMap.GenerateIndexes.PlayerCoords.y, InfoText.transform.position.z + 0.5f);

            CamBorderTop    = MapContainer.transform.GetChild(0).transform.position.y - 0.32f * 2;
            CamBorderLeft   = MapContainer.transform.GetChild(0).transform.position.x + 0.32f * 5;
            CamBorderBottom = MapContainer.transform.GetChild(GetMap.Tiles.Count - 1).transform.position.y + 0.32f * 2;
            CamBorderRight  = MapContainer.transform.GetChild(GetMap.Tiles.Count - 1).transform.position.x - 0.32f * 2;

            foreach (BanditArea band in GetMap.GenerateIndexes.Bandits)
            {
                if (band.Clan == "")
                {
                    GoToWaterTower.active = true;
                }
                else
                {
                    GoToWaterTower.active = false;
                    break;
                }
            }
        }
        MapContainer.transform.localPosition -= new Vector3(0, 0, Player.transform.localPosition.z);
        Goal.transform.localPosition          = Player.transform.localPosition;
        MainCamera.transform.position         = new Vector3(Player.transform.position.x, Player.transform.position.y, MainCamera.transform.position.z);
    }
Beispiel #3
0
    public void Start()
    {
        Application.targetFrameRate = 60;

        Loader.LoadAll();
        Loader.LoadStoreInfo(PlayInv.StoreID);

        int FillItems = 0;

        foreach (GameObject Item in PlayInv.Items)
        {
            Item.transform.SetParent(ItemsInStore.transform);
            Item.transform.localPosition = ItemsInStore.transform.GetChild(FillItems).transform.localPosition + new Vector3(0, 0, -0.1f);
            FillItems += 1;
        }
        if (SLAVES != null)
        {
            SLAVES.GetComponent <SlaveEngine>().LengthOfSlaves = PlayInv.Items.Count;
            Greeting1();
        }

        if (ITEMS != null)
        {
            if (ITEMS.GetComponent <ItemEngine>() != null)
            {
                ITEMS.GetComponent <ItemEngine>().LenghtOfItems = PlayInv.Items.Count;
                ShowYourItems();
            }
            else if (ITEMS.GetComponent <BulletsEngine>() != null)
            {
                ITEMS.GetComponent <BulletsEngine>().LenghtOfItems = PlayInv.Items.Count;
                ShowYourItems();
            }
        }

        foreach (GameObject Slave in PlayInv.SlavePlace)
        {
            if (Slave != null)
            {
                if (SLAVES != null)
                {
                    Slave.transform.position = BoughtItems.transform.GetChild(Slave.transform.GetSiblingIndex()).transform.position;
                    BoughtItems.transform.GetChild(Slave.transform.GetSiblingIndex()).gameObject.active = false;
                    Slave.GetComponent <SlaveProperties>().Bought = true;
                }
                else
                {
                    Slave.transform.localPosition = new Vector3(0, 0, 0);
                }
            }
        }

        if (PlayInv.TypeOfStore == "Bullets")
        {
            Loader.FindWeapons(BulletsEngine);
            BulletsEngine.LoadWeapons();
            BulletsEngine.Deselect();
        }
        if (PlayInv.TypeOfStore == "Guns")
        {
            int Plc = 0;
            foreach (GameObject Item in PlayInv.Package)
            {
                if (Item == null)
                {
                    BoughtItems.transform.GetChild(Plc).gameObject.active = true;
                }
                else
                {
                    if (Item.GetComponent <WeaponProperties>() != null)
                    {
                        Item.GetComponent <WeaponProperties>().Bought = true;
                    }
                    if (Item.GetComponent <OtherStuff>() != null)
                    {
                        Item.GetComponent <OtherStuff>().Bought = true;
                    }
                    Item.transform.position = BoughtItems.transform.GetChild(Plc).gameObject.transform.position;
                    BoughtItems.transform.GetChild(Plc).gameObject.active = false;
                }
                Plc++;
            }
            ShowYourItems();
        }
        if (PlayInv.TypeOfStore == "Stuff")
        {
            int Plc = 0;
            foreach (GameObject Item in PlayInv.Package)
            {
                if (Item == null)
                {
                    BoughtItems.transform.GetChild(Plc).gameObject.active = true;
                }
                else
                {
                    if (Item.GetComponent <WeaponProperties>() != null)
                    {
                        Item.GetComponent <WeaponProperties>().Bought = true;
                    }
                    if (Item.GetComponent <OtherStuff>() != null)
                    {
                        Item.GetComponent <OtherStuff>().Bought = true;
                    }
                    Item.transform.position = BoughtItems.transform.GetChild(Plc).gameObject.transform.position;
                    BoughtItems.transform.GetChild(Plc).gameObject.active = false;
                }
                Plc++;
            }
            ShowYourItems();
        }

        if (GetTutor != null)
        {
            if (PlayInv.If_Tutorial == true)
            {
                GetTutor.Steps = PlayInv.Step_Of_Tutorial;
                if (GetTutor.Steps == 1)
                {
                    GetTutor.enabled      = true;
                    GetTutor.First_Launch = true;
                }
            }
        }
    }