Пример #1
0
    //========================== Create New Player Data =============================

    public void CreateNewPlayerData()
    {
        PlayerSource NewPlayer = new PlayerSource();

        NewPlayer.CurrentStore     = 0;
        NewPlayer.Money            = Random.Range(600, 800) * 5;
        NewPlayer.If_Tutorial      = true;
        NewPlayer.Step_Of_Tutorial = 1;

        SlaveDoll AddSlv = new SlaveDoll();

        AddSlv.Skin       = Random.Range(1, 6);
        AddSlv.Health     = Random.Range(50, 90) * 5;
        AddSlv.FullHealth = AddSlv.Health;
        AddSlv.Damage     = Random.Range(4, 12) * 5;
        AddSlv.Accuracy   = Random.Range(3, 10);
        AddSlv.Start_Fhp  = AddSlv.FullHealth;
        AddSlv.Start_Dmg  = AddSlv.Damage;
        AddSlv.Start_Acc  = AddSlv.Accuracy;
        AddSlv.Heal_Units = 3;
        AddSlv.Shot_Units = 5;
        AddSlv.Rush_Units = 3;
        AddSlv.Level      = 1;
        NewPlayer.Slaves.Add(AddSlv);

        for (int a = 0; a < 2; a++)
        {
            ItemDoll Item = new ItemDoll();
            Item.TypeOfItem    = "Stuff";
            Item.Name          = "Water";
            Item.Skin          = 2;
            Item.Liters        = 100;
            Item.Price         = 100;
            NewPlayer.Items[a] = Item;
        }

        ItemDoll wpn = new ItemDoll();

        wpn.TypeOfItem     = "Weapon";
        wpn.Skin           = Random.Range(1, 11);
        wpn.Condition      = Random.Range(1, 5);
        wpn.Price          = 30;
        NewPlayer.Items[2] = wpn;

        string       PlayerToStr = JsonUtility.ToJson(NewPlayer);
        StreamWriter WriteData   = new StreamWriter(Application.persistentDataPath + "/PlayerData.json");

        WriteData.Write(PlayerToStr);
        WriteData.Close();
    }
Пример #2
0
    //======================================================= SAVE INVENTORY ===========================================================

    public void SaveAll()
    {
        PlayerSource newInventory = new PlayerSource();

        newInventory.Money            = PlayInv.Money;
        newInventory.CurrentStore     = PlayInv.StoreID;
        newInventory.If_Tutorial      = PlayInv.If_Tutorial;
        newInventory.Step_Of_Tutorial = Tutor.Steps;

        foreach (GameObject Slave in PlayInv.SlavePlace)
        {
            SlaveDoll newSlave = new SlaveDoll();
            if (Slave != null)
            {
                SlaveProperties GetSlv = Slave.GetComponent <SlaveProperties>();
                newSlave.StatusEmpty = false;
                newSlave.Number      = GetSlv.Number;
                newSlave.Health      = GetSlv.Health;
                newSlave.FullHealth  = GetSlv.FullHealth;
                newSlave.Damage      = GetSlv.Damage;
                newSlave.Accuracy    = GetSlv.Accuracy;
                newSlave.Battles     = GetSlv.Battles;
                newSlave.Level       = GetSlv.Level;
                newSlave.Skin        = GetSlv.Skin;
                newSlave.Price       = GetSlv.Price;
                newSlave.Efficiency  = GetSlv.Efficiency;
                newSlave.WeaponSkin  = GetSlv.WeaponSkin;
                newSlave.HaveGun     = GetSlv.HaveGun;
                newSlave.FullPackage = GetSlv.FullPackage;
                newSlave.Start_Fhp   = GetSlv.Start_Fhp;
                newSlave.Start_Dmg   = GetSlv.Start_Dmg;
                newSlave.Start_Acc   = GetSlv.Start_Acc;
                newSlave.Heal_Units  = GetSlv.Heal_Units;
                newSlave.Shot_Units  = GetSlv.Shot_Units;
                newSlave.Rush_Units  = GetSlv.Rush_Units;
                int GetStuffPlace = 0;
                GetSlv.InventoryPack.gameObject.active = true;
                foreach (Transform Place in GetSlv.InventoryPack.transform)
                {
                    if (Place.transform.childCount != 0)
                    {
                        GameObject GetItem = Place.transform.GetChild(0).gameObject;
                        if (GetItem.GetComponent <WeaponProperties>() != null)
                        {
                            ItemDoll         GetPlace = new ItemDoll();
                            WeaponProperties GetWpn   = GetItem.GetComponent <WeaponProperties>();
                            GetPlace.TypeOfItem = "Weapon";
                            GetPlace.Skin       = GetWpn.Skin;
                            GetPlace.Name       = GetWpn.WeapName;
                            GetPlace.Damage     = GetWpn.Damage;
                            GetPlace.Condition  = GetWpn.Condition;
                            GetPlace.Efficiency = GetWpn.Efficiency;
                            GetPlace.Price      = GetWpn.Price;
                            GetPlace.Bullets    = GetWpn.Bullets;
                            newSlave.Package[Place.transform.GetSiblingIndex()] = GetPlace;
                        }
                        if (GetItem.GetComponent <OtherStuff>() != null)
                        {
                            ItemDoll   GetPlace = new ItemDoll();
                            OtherStuff GetStf   = GetItem.GetComponent <OtherStuff>();
                            GetPlace.TypeOfItem = "Stuff";
                            GetPlace.Skin       = GetStf.Skin;
                            GetPlace.Price      = GetStf.Price;
                            GetPlace.Liters     = GetStf.Liters;
                            GetPlace.Name       = GetStf.Name;
                            newSlave.Package[Place.transform.GetSiblingIndex()] = GetPlace;
                        }
                    }
                }
            }
            else
            {
                newSlave.StatusEmpty = true;
            }
            newInventory.Slaves.Add(newSlave);
        }

        int NumPlace = 0;

        foreach (GameObject Item in PlayInv.Package)
        {
            if (Item != null)
            {
                if (Item.GetComponent <WeaponProperties>() != null)
                {
                    ItemDoll         GetPlace = new ItemDoll();
                    WeaponProperties GetWpn   = Item.GetComponent <WeaponProperties>();
                    GetPlace.TypeOfItem          = "Weapon";
                    GetPlace.Skin                = GetWpn.Skin;
                    GetPlace.Name                = GetWpn.WeapName;
                    GetPlace.Damage              = GetWpn.Damage;
                    GetPlace.Condition           = GetWpn.Condition;
                    GetPlace.Efficiency          = GetWpn.Efficiency;
                    GetPlace.Price               = GetWpn.Price;
                    GetPlace.Bullets             = GetWpn.Bullets;
                    newInventory.Items[NumPlace] = GetPlace;
                }
                if (Item.GetComponent <OtherStuff>() != null)
                {
                    ItemDoll   GetPlace = new ItemDoll();
                    OtherStuff GetStf   = Item.GetComponent <OtherStuff>();
                    GetPlace.TypeOfItem          = "Stuff";
                    GetPlace.Skin                = GetStf.Skin;
                    GetPlace.Price               = GetStf.Price;
                    GetPlace.Liters              = GetStf.Liters;
                    GetPlace.Name                = GetStf.Name;
                    newInventory.Items[NumPlace] = GetPlace;
                }
            }
            NumPlace += 1;
        }

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

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