예제 #1
0
    /// <summary>Loads inventory data for items and money</summary>
    /// <param name="saveData_">The PartySaveData reference that holds the item and money data we need to store</param>
    public void LoadPartyFromSave(PartySaveData saveData_)
    {
        //Saving the money
        this.money = saveData_.money;

        //Looping through all of the inventory slot objects in the save data
        this.itemSlots = new List <Item>();
        for (int i = 0; i < saveData_.inventorySlots.Count; ++i)
        {
            //If the current item is emtpy, we add an empty slot
            if (saveData_.inventorySlots[i] == "")
            {
                this.itemSlots.Add(null);
            }
            //If the current item isn't empty, we add it's item component to our inventory
            else
            {
                PrefabIDTagData prefabID = JsonUtility.FromJson(saveData_.inventorySlots[i], typeof(PrefabIDTagData)) as PrefabIDTagData;
                GameObject      itemObj  = GameObject.Instantiate(IDManager.globalReference.GetPrefabFromID(prefabID.iDNumber));

                itemObj.transform.SetParent(this.transform);
                this.itemSlots.Add(itemObj.GetComponent <Item>());
            }
        }
        for (int s = 0; s < saveData_.stackedItems.Count; ++s)
        {
            //Making sure the item in this item stack matches the same item in the
            //Getting the stack data
            InventoryItemStackData stackData  = JsonUtility.FromJson(saveData_.stackedItems[s], typeof(InventoryItemStackData)) as InventoryItemStackData;
            GameObject             stackedObj = GameObject.Instantiate(IDManager.globalReference.GetPrefabFromID(stackData.iDNumber));

            //Making sure the stacked object is actually an item
            if (stackedObj.GetComponent <Item>())
            {
                //Making sure the item in this stack matches the item in the designated inventory index
                if (stackData.itemStackIndex < this.itemSlots.Count &&
                    this.itemSlots[stackData.itemStackIndex].GetComponent <IDTag>().numberID == stackData.iDNumber)
                {
                    //Looping through every item that's in this stack
                    for (int si = 0; si < stackData.numberOfItemsInStack; ++si)
                    {
                        //Creating a new instance of the stacked item
                        GameObject stackedItem = GameObject.Instantiate(IDManager.globalReference.GetPrefabFromID(stackData.iDNumber));
                        //Parenting the stacked item to the one that's in the inventory slot
                        stackedItem.transform.SetParent(this.itemSlots[stackData.itemStackIndex].transform);
                        //Increasing the stack size count in the inventory slot
                        this.itemSlots[stackData.itemStackIndex].currentStackSize += 1;

                        //If the inventory slot has reached the max stack size, we stop
                        if (this.itemSlots[stackData.itemStackIndex].currentStackSize >= this.itemSlots[stackData.itemStackIndex].maxStackSize)
                        {
                            break;
                        }
                    }
                }
            }
        }
    }
예제 #2
0
    //Constructor function for this class
    public PlayerProgress(GameData gameData_, TileMapManager tileGrid_, LevelUpManager levelUpManager_, CharacterManager charManager_, QuestTracker questTracker_)
    {
        //Setting the GameData.cs variables
        this.difficulty          = gameData_.currentDifficulty;
        this.allowNewUnlockables = gameData_.allowNewUnlockables;
        this.folderName          = gameData_.saveFolder;
        this.randState           = Random.state;

        //Setting the CreateTileGrid.cs variables
        this.gridCols = tileGrid_.cols;
        this.gridRows = tileGrid_.rows;

        //Setting the HUDChallengeRampUpTimer.cs variables
        this.currentDifficulty      = HUDChallengeRampUpTimer.globalReference.currentDifficulty;
        this.currentDifficultyTimer = HUDChallengeRampUpTimer.globalReference.currentTimer;

        //Setting the LevelUpManager variable
        this.characterLevel = levelUpManager_.characterLevel;

        //Setting the PartyGroup.cs variables
        this.partyGroup1 = new PartySaveData(PartyGroup.globalReference);

        //Looping through all of the dead character info in CharacterManager.cs
        this.deadCharacters = new List <DeadCharacterInfo>();
        for (int d = 0; d < charManager_.deadCharacters.Count; ++d)
        {
            this.deadCharacters.Add(charManager_.deadCharacters[d]);
        }

        //Looping through all of the enemy tile encounters in CharacterManager.cs
        this.enemyTileEncounters = new List <EnemyTileEncounterInfo>();
        for (int e = 0; e < CharacterManager.globalReference.tileEnemyEncounters.Count; ++e)
        {
            //Making sure the encounter isn't null first
            if (CharacterManager.globalReference.tileEnemyEncounters[e] != null)
            {
                //Creating a new tile encounter info for the enemy
                EnemyTileEncounterInfo enemyInfo = new EnemyTileEncounterInfo(CharacterManager.globalReference.tileEnemyEncounters[e]);
                //Adding the enemy encounter info to our list to serialize
                this.enemyTileEncounters.Add(enemyInfo);
            }
        }

        //Looping through all of the quests in our quest log
        this.questLog = new List <string>();
        foreach (Quest q in questTracker_.questLog)
        {
            this.questLog.Add(JsonUtility.ToJson(new QuestSaveData(q), true));
        }

        //Saving all of the finished quest names
        this.finishedQuests = questTracker_.completedQuestNames;
    }