// 讀檔.
    public bool Load()
    {
        if (PlayerPrefs.HasKey(GameDefine.szSavePlayer) == false)
        {
            return(false);
        }

        SavePlayer Temp = Json.ToObject <SavePlayer>(PlayerPrefs.GetString(GameDefine.szSavePlayer));

        if (Temp == null)
        {
            return(false);
        }

        iStage      = Temp.iStage;
        iStyle      = Temp.iStyle;
        iCurrency   = Temp.iCurrency;
        iBattery    = Temp.iBattery;
        iLightAmmo  = Temp.iLightAmmo;
        iHeavyAmmo  = Temp.iHeavyAmmo;
        iBomb       = Temp.iBomb;
        iStamina    = Temp.iStamina;
        iDamageLv   = Temp.iDamageLv;
        iPlayTime   = Temp.iPlayTime;
        iEnemyKill  = Temp.iEnemyKill;
        iPlayerLost = Temp.iPlayerLost;
        iAdsWatch   = Temp.iAdsWatch;
        MemberParty = MemberLoad(Temp.Party);
        MemberDepot = MemberLoad(Temp.Depot);

        return(true);
    }
Exemple #2
0
    public static void firstOpening()
    {
        string path = Application.persistentDataPath + "/saved.json";

        string path2 = Application.persistentDataPath + "/whatPlayerHas.json";

        if (!System.IO.File.Exists(path))
        {
            SavePlayer newSave = new SavePlayer();
            newSave.hat   = null;
            newSave.color = "whitePlayer";
            newSave.glass = null;
            string jsonVersion1 = JsonUtility.ToJson(newSave);
            System.IO.File.WriteAllText(path, jsonVersion1);
        }
        if (!System.IO.File.Exists(path2))
        {
            whatPlayerHas newFile = new whatPlayerHas();
            newFile.listPlayer = new List <string>();
            newFile.listPlayer.Add("whitePlayer");
            newFile.listHat   = new List <string>();
            newFile.listGlass = new List <string>();
            string jsonVersion = JsonUtility.ToJson(newFile);
            System.IO.File.WriteAllText(path2, jsonVersion);
        }
    }
Exemple #3
0
 private void Awake()
 {
     if (PlayerPrefs.HasKey("SaveP"))
     {
         SaveP = JsonUtility.FromJson <SavePlayer>(PlayerPrefs.GetString("SaveP"));
         GoldMiner.goldStack = SaveP.goldStack;
     }
 }
Exemple #4
0
        public static string WriteSave(NetCharacter ch, string description, int ids, DateTime?timeStamp)
        {
            var builder = new StringBuilder();

            builder.AppendLine("[Player]");
            if (timeStamp != null)
            {
                var fileTime = timeStamp?.ToFileTime();
                builder.Append("tstamp = ");
                builder.Append((fileTime >> 32).ToString());
                builder.Append(", ");
                builder.AppendLine((fileTime & 0xFFFFFFFF).ToString());
            }
            if (description != null)
            {
                builder.Append("description = ").AppendLine(SavePlayer.EncodeName(description));
            }
            else
            {
                builder.Append("descrip_strid = ").AppendLine(ids.ToString());
            }
            if (!string.IsNullOrWhiteSpace(ch.Name))
            {
                builder.Append("name = ").AppendLine(SavePlayer.EncodeName(ch.Name));
            }
            if (!string.IsNullOrWhiteSpace(ch.Base))
            {
                builder.Append("base = ").AppendLine(ch.Base);
            }
            if (!string.IsNullOrWhiteSpace(ch.System))
            {
                builder.Append("system = ").AppendLine(ch.System);
            }
            builder.Append("pos = ").AppendLine(Vector3(ch.Position));
            builder.Append("money = ").AppendLine(ch.Credits.ToString());
            if (ch.Ship != null)
            {
                builder.Append("ship_archetype = ").AppendLine(ch.Ship.Nickname);
            }
            foreach (var item in ch.Items)
            {
                if (!string.IsNullOrEmpty(item.Hardpoint))
                {
                    var hp = item.Hardpoint.Equals("internal", StringComparison.OrdinalIgnoreCase)
                        ? ""
                        : item.Hardpoint;
                    builder.Append("equip = ").Append(item.Equipment.Nickname).Append(",")
                    .Append(hp).Append(",").AppendLine("1");
                }
                else
                {
                    builder.Append("cargo = ");
                    builder.AppendLine($"{item.Equipment.Nickname}, {item.Count}, , , 0");
                }
            }
            return(builder.ToString());
        }
 /// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 public void CallSave(SavePlayer player)
 {
     this.player = player;
     // Set the request flag
     if ((!Guide.IsVisible) && (GameSaveRequested == false))
     {
         GameSaveRequested = true;
         result = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
     }
 }
Exemple #6
0
 /// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 public void CallSave(SavePlayer player)
 {
     this.player = player;
     // Set the request flag
     if ((!Guide.IsVisible) && (GameSaveRequested == false))
     {
         GameSaveRequested = true;
         result            = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
     }
 }
        public void Load(SavePlayer savePlayer)
        {
            SavePlayer         = savePlayer;
            savePlayer.OnSave += SavePlayer_OnSave;
            Inventory.InitItem(savePlayer.Inventory);

            InvokeOnHealthChange();
            InvokeOnManaChange();
            InvokeOnExperienceChange();
            InvokeOnLevelChange();
        }
Exemple #8
0
        public SaveGame NewCharacter(string name, int factionIndex)
        {
            var fac   = GameData.Ini.NewCharDB.Factions[factionIndex];
            var pilot = GameData.Ini.NewCharDB.Pilots.First(x =>
                                                            x.Nickname.Equals(fac.Pilot, StringComparison.OrdinalIgnoreCase));
            var package = GameData.Ini.NewCharDB.Packages.First(x =>
                                                                x.Nickname.Equals(fac.Package, StringComparison.OrdinalIgnoreCase));
            //TODO: initial_rep = %%FACTION%%
            //does this have any effect in FL?

            var src = new StringBuilder(Encoding.UTF8.GetString(FlCodec.ReadFile(GameData.VFS.Resolve("EXE\\mpnewcharacter.fl"))));

            src.Replace("%%NAME%%", SavePlayer.EncodeName(name));
            src.Replace("%%BASE_COSTUME%%", pilot.Body);
            src.Replace("%%COMM_COSTUME%%", pilot.Comm);
            //Changing voice breaks in vanilla (commented out in mpnewcharacter)
            src.Replace("%%VOICE%%", pilot.Voice);
            //TODO: pilot comm_anim (not in vanilla mpnewcharacter)
            //TODO: pilot body_anim (not in vanilla mpnewcharacter)
            src.Replace("%%MONEY%%", package.Money.ToString());
            src.Replace("%%HOME_SYSTEM%%", GameData.GetBase(fac.Base).System);
            src.Replace("%%HOME_BASE%%", fac.Base);

            var pkgStr = new StringBuilder();

            pkgStr.Append("ship_archetype = ").AppendLine(package.Ship);
            var loadout = GameData.Ini.Loadouts.Loadouts.First(x =>
                                                               x.Nickname.Equals(package.Loadout, StringComparison.OrdinalIgnoreCase));

            //do loadout
            foreach (var x in loadout.Equip)
            {
                pkgStr.AppendLine(new PlayerEquipment()
                {
                    EquipName = x.Nickname,
                    Hardpoint = x.Hardpoint ?? ""
                }.ToString());
            }

            foreach (var x in loadout.Cargo)
            {
                pkgStr.AppendLine(new PlayerCargo()
                {
                    CargoName = x.Nickname,
                    Count     = x.Count
                }.ToString());
            }
            //append
            src.Replace("%%PACKAGE%%", pkgStr.ToString());
            var initext = src.ToString();

            return(SaveGame.FromString($"mpnewcharacter: {fac.Nickname}", initext));
        }
Exemple #9
0
    void Start()
    {
        ballShow            = GameObject.Find("BallShow");
        x                   = readDataFromFile();
        has                 = readItemsFromFile();
        playerColorMaterial = Resources.Load <Material>("PlayerMaterials/" + x.color);
        ballShow.GetComponent <SpriteRenderer>().sharedMaterial = playerColorMaterial;
        savePrices();
        setTextsOnMarket();

        updateStocks();
        setEquipped();
        doTick();
    }
Exemple #10
0
    void SavePosition()
    {
        float      x    = transform.position.x;
        float      y    = transform.position.y;
        SavePlayer save = new SavePlayer {
            X = x, Y = y
        };
        XmlSerializer formatter = new XmlSerializer(typeof(SavePlayer));

        using (FileStream fs = new FileStream("Assets/Saves/save.xml", FileMode.Open))
        {
            formatter.Serialize(fs, save);
            fs.Close();
        }
    }
Exemple #11
0
    private void Awake()
    {
        MarketEvents.firstOpening();

        Time.timeScale = 1;

        SavePlayer x = MarketEvents.readDataFromFile();

        playerColorMaterial = Resources.Load <Material>("PlayerMaterials/" + x.color);

        if (playerColorMaterial == null)
        {
            playerColorMaterial = Resources.Load <Material>("PlayerMaterials/whitePlayer");
        }
        GetComponent <SpriteRenderer>().sharedMaterial = playerColorMaterial;
    }
Exemple #12
0
 public void doTick()
 {
     x = readDataFromFile();
     foreach (Transform t in contentSlider.transform)
     {
         Debug.Log(clicked);
         bool res = x.color.Equals(findChildTechnique(t.gameObject, "mat").GetComponent <SpriteRenderer>().sharedMaterial.name);
         if (res)
         {
             findChildTechnique(t.gameObject, "ticked").SetActive(true);
         }
         else
         {
             findChildTechnique(t.gameObject, "ticked").SetActive(false);
         }
     }
 }
Exemple #13
0
    public void equipThem()
    {
        SavePlayer saved = new SavePlayer();

        if (ballShow.GetComponent <SpriteRenderer>().sharedMaterial != null)
        {
            string x = ballShow.GetComponent <SpriteRenderer>().sharedMaterial.name;
            saved.color = x;
        }
        else
        {
            saved.color = "whitePlayer";
        }
        string jsonVersion = JsonUtility.ToJson(saved);

        writeDataToFile(jsonVersion);
        doTick();
    }
Exemple #14
0
        /// <summary>
        /// This method loads a serialized data object
        /// from the StorageContainer for this game.
        /// </summary>
        /// <param name="device"></param>
        private void DoLoadGame(StorageDevice device)
        {
            // Open a storage container.
            IAsyncResult result =
                device.BeginOpenContainer("StorageDemo", null, null);

            // Wait for the WaitHandle to become signaled.
            result.AsyncWaitHandle.WaitOne();

            StorageContainer container = device.EndOpenContainer(result);

            // Close the wait handle.
            result.AsyncWaitHandle.Close();

            string filename = "savegame.sav";

            // Check to see whether the save exists.
            if (!container.FileExists(filename))
            {
                // If not, dispose of the container and return.
                container.Dispose();
                return;
            }

            // Open the file.
            Stream stream = container.OpenFile(filename, FileMode.Open);

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(SavePlayer));

            player = (SavePlayer)serializer.Deserialize(stream);

            // Close the file.
            stream.Close();

            // Dispose the container.
            container.Dispose();

            //// Report the data to the console.
            //Debug.WriteLine("Name:     " + data.PlayerName);
            //Debug.WriteLine("Level:    " + data.Level.ToString());
            //Debug.WriteLine("Score:    " + data.Score.ToString());
            //Debug.WriteLine("Position: " + data.AvatarPosition.ToString());
        }
Exemple #15
0
    public void SaveGame(int level)
    {
        SavePlayer savePlayer = new SavePlayer(player);
        SaveMap    saveMap    = MapGen.mapinstance.Save();

        if (!Directory.Exists(Application.persistentDataPath + saveslot))
        {
            Directory.CreateDirectory(Application.persistentDataPath + saveslot);
        }

        // Write playersave
        string json = JsonUtility.ToJson(savePlayer);

        Debug.Log(Application.persistentDataPath + saveslot + playerfilename);
        File.WriteAllText(Application.persistentDataPath + saveslot + playerfilename, json);

        // Write mapsave
        json = JsonUtility.ToJson(saveMap);
        Debug.Log(Application.persistentDataPath + saveslot + level.ToString() + mapfilename);
        File.WriteAllText(Application.persistentDataPath + saveslot + level.ToString() + mapfilename, json);
    }
Exemple #16
0
    public void SetState(ISerialDataStore state)
    {
        SavePlayer past = (SavePlayer)state;

        isExitingRewind = true;
        rb.isKinematic  = true;

        rb.velocity   = Vector2.zero; // Needed to cancel velocity applied during rewind
        acceleration  = past.acceleration;
        velocityX     = past.velocityX;
        velocityY     = past.velocityY;
        IsMovingRight = past.IsMovingRight;

        lastX = past.lastX;

        isEitherDown = past.isEitherDown;
        isLeftDown   = past.isLeftDown;
        isRightDown  = past.isRightDown;
        isLeftDown   = past.isLeftUp;
        isRightUp    = past.isRightUp;

        isGrounded = past.grounded;
        jumps      = past.jumps;

        wallJumps    = past.wallJumps;
        canWallJump  = past.canWallJump;
        coolDownJump = past.coolDownJump;

        jumpBuffer = maxJumpBuffer;

        transform.position = new Vector3(past.positionX, past.positionY, transform.position.z);

        rightHorizontalAxisDown = past.rightHorizontalAxisDown;
        leftHorizontalAxisDown  = past.leftHorizontalAxisDown;

        rb.freezeRotation = past.freezeRotation;
        rb.rotation       = past.rotation;

        transform.localScale = new Vector3(past.localXScale, 1, 1);
    }
Exemple #17
0
    // 存檔.
    public void Save()
    {
        SavePlayer Temp = new SavePlayer();

        Temp.iStage      = iStage;
        Temp.iStyle      = iStyle;
        Temp.iCurrency   = iCurrency;
        Temp.iBattery    = iBattery;
        Temp.iLightAmmo  = iLightAmmo;
        Temp.iHeavyAmmo  = iHeavyAmmo;
        Temp.iBomb       = iBomb;
        Temp.iStamina    = iStamina;
        Temp.iDamageLv   = iDamageLv;
        Temp.iPlayTime   = iPlayTime;
        Temp.iEnemyKill  = iEnemyKill;
        Temp.iPlayerLost = iPlayerLost;
        Temp.iAdsWatch   = iAdsWatch;
        Temp.Party       = MemberSave(MemberParty);
        Temp.Depot       = MemberSave(MemberDepot);

        PlayerPrefs.SetString(GameDefine.szSavePlayer, Json.ToString(Temp));
    }
Exemple #18
0
    public bool LoadGame(int level)
    {
        if (File.Exists(Application.persistentDataPath + saveslot + playerfilename))
        {
            string json;
            if (File.Exists(Application.persistentDataPath + saveslot + level.ToString() + mapfilename))
            {
                // Load mapsave
                json = File.ReadAllText(Application.persistentDataPath + saveslot + level.ToString() + mapfilename);
                SaveMap saveMap = JsonUtility.FromJson <SaveMap>(json);
                MapGen.mapinstance.Load(saveMap);
            }

            // Load playersave
            json = File.ReadAllText(Application.persistentDataPath + saveslot + playerfilename);
            SavePlayer savePlayer = JsonUtility.FromJson <SavePlayer>(json);
            savePlayer.LoadData(player);


            return(true);
        }
        return(false);
    }
 public IPlayer SavePlayer(IPlayer player)
 {
     var command = new SavePlayer(PlayerFactory.MakePlayer(player));
     _executer.Execute(command);
     return command.Result;
 }
Exemple #20
0
 private void Awake()
 {
     savedata = FindObjectOfType <SavePlayer>();
     savedata.PlayerPauseLoad();
     animator = GetComponent <Animator>();
 }
Exemple #21
0
 private void Start()
 {
     saveddata = FindObjectOfType <SavePlayer>();
 }
        /// <summary>
        /// This method loads a serialized data object
        /// from the StorageContainer for this game.
        /// </summary>
        /// <param name="device"></param>
        private void DoLoadGame(StorageDevice device)
        {
            // Open a storage container.
            IAsyncResult result =
                device.BeginOpenContainer("StorageDemo", null, null);

            // Wait for the WaitHandle to become signaled.
            result.AsyncWaitHandle.WaitOne();

            StorageContainer container = device.EndOpenContainer(result);

            // Close the wait handle.
            result.AsyncWaitHandle.Close();

            string filename = "savegame.sav";

            // Check to see whether the save exists.
            if (!container.FileExists(filename))
            {
                // If not, dispose of the container and return.
                container.Dispose();
                return;
            }

            // Open the file.
            Stream stream = container.OpenFile(filename, FileMode.Open);

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(SavePlayer));
            player = (SavePlayer)serializer.Deserialize(stream);

            // Close the file.
            stream.Close();

            // Dispose the container.
            container.Dispose();

            //// Report the data to the console.
            //Debug.WriteLine("Name:     " + data.PlayerName);
            //Debug.WriteLine("Level:    " + data.Level.ToString());
            //Debug.WriteLine("Score:    " + data.Score.ToString());
            //Debug.WriteLine("Position: " + data.AvatarPosition.ToString());
        }