Beispiel #1
0
    public static void Load( )
    {
        PlayerModel   playerModel = ModelManager.Get("PlayerModel") as PlayerModel;
        RoleShopModel shopModel   = ModelManager.Get <RoleShopModel>("RoleShopModel");

        playerModel.talents    = new List <MyTalent.Talent>();
        playerModel.fightRoles = new RoleBase[9];
        playerModel.preRoles   = new RoleBase[PlayerModel.Max_Pre_Role_Count];
        playerModel.playerData = new PlayerData(0);

        if (PlayerPrefs.HasKey("shopRoles"))
        {
            string[] roleStrings = PlayerPrefs.GetString("shopRoles").Split(',');

            for (int i = 0; i < roleStrings.Length; i++)
            {
                shopModel.roles[i] = int.Parse(roleStrings[i]);
            }
        }

        if (PlayerPrefs.HasKey("money"))
        {
            playerModel.SetMoney(PlayerPrefs.GetInt("money") - playerModel.GetMoney());
        }
//         else
//         {
//             playerModel.SetMoney(100 - playerModel.GetMoney());
//         }

        if (PlayerPrefs.HasKey("gameLevel"))
        {
            (ModelManager.Get("GameLevelModel") as GameLevelModel).SetLevel(PlayerPrefs.GetInt("gameLevel"));
        }
//         else
//         {
//             (ModelManager.Get("GameLevelModel") as GameLevelModel).SetLevel(0);
//         }

        if (PlayerPrefs.HasKey("peopleLevel"))
        {
            playerModel.peopleLevel = PlayerPrefs.GetInt("peopleLevel");
        }
        //         else
        //         {
        //             playerModel.peopleLevel = 2;
        //         }

        if (PlayerPrefs.HasKey("talents"))
        {
            string   tStrings = PlayerPrefs.GetString("talents");
            string[] talents  = tStrings.Split(',');

            foreach (string s in talents)
            {
                int id = int.Parse(s);
                playerModel.AddTalent(id);
            }
        }



        if (PlayerPrefs.HasKey("hp"))
        {
            playerModel.SetHp(PlayerPrefs.GetInt("hp") - playerModel.GetHp());
        }
        else
        {
            playerModel.SetHp(30 - playerModel.GetHp());
        }

        if (PlayerPrefs.HasKey("fightRoles"))
        {
            string   rolesString = PlayerPrefs.GetString("fightRoles");
            string[] roles       = rolesString.Split('|');

            for (int i = 0; i < roles.Length; i++)
            {
                string[] roleString = roles[i].Split(',');

                int index = int.Parse(roleString[0]);

                int roleId = int.Parse(roleString[1]);

                int level = int.Parse(roleString[2]);

                int equipId1 = int.Parse(roleString[3]);

                int equipId2 = int.Parse(roleString[4]);

                RoleBase role = new RoleBase();
                role.SetId(roleId, level);
                if (equipId1 != -1)
                {
                    role.AddEquip(new Equip(equipId1));
                }
                if (equipId2 != -1)
                {
                    role.AddEquip(new Equip(equipId2));
                }

                playerModel.AddFightRole(role, index);
            }
        }

        if (PlayerPrefs.HasKey("preRoles"))
        {
            string   rolesString = PlayerPrefs.GetString("preRoles");
            string[] roles       = rolesString.Split('|');

            for (int i = 0; i < roles.Length; i++)
            {
                string[] roleString = roles[i].Split(',');

                int index = int.Parse(roleString[0]);

                int roleId = int.Parse(roleString[1]);

                int level = int.Parse(roleString[2]);

                int equipId1 = int.Parse(roleString[3]);

                int equipId2 = int.Parse(roleString[4]);

                RoleBase role = new RoleBase();
                role.SetId(roleId, level);
                if (equipId1 != -1)
                {
                    role.AddEquip(new Equip(equipId1));
                }
                if (equipId2 != -1)
                {
                    role.AddEquip(new Equip(equipId2));
                }

                playerModel.SetPreRole(role, index);
            }
        }

        if (PlayerPrefs.HasKey("equips"))
        {
            var equipModel = ModelManager.Get <EquipModel>("EquipModel");

            string equipsString = PlayerPrefs.GetString("equips");

            string[] equips = equipsString.Split(',');
            foreach (string equipString in equips)
            {
                int id = int.Parse(equipString);
                equipModel.AddEquip(id);
            }
        }
    }