Example #1
0
    public void PopulateShop(bool restoreFromSave)
    {
        List <template_item> unOwnedItems = new List <template_item>();
        PlayerState          player       = SaveManager.instance.GetCurrentPlayerState();

        if (restoreFromSave)
        {
            bool toySlotUsed = false;
            for (int i = 0; i < player.GetCurrentDayItems().Count; ++i)
            {
                template_item item = ArticyDatabase.GetObject(player.GetCurrentDayItems()[i]) as template_item;

                if (toySlotUsed && item.Template.item_data.item_slot_number == 2)
                {
                    GameObject marker = Shop.instance.GetShopItemSpawnMarkerForPosition(1);
                    SpawnItem(item, marker.transform.position);
                }
                else
                {
                    GameObject marker = Shop.instance.GetShopItemSpawnMarkerForPosition(item.Template.item_data.item_slot_number);
                    SpawnItem(item, marker.transform.position);
                    if (item.Template.item_data.item_slot_number == 2)
                    {
                        toySlotUsed = true;
                    }
                }

                //if (i >= shopItemSpawnMarkers.Count)
                //{
                //    Debug.LogError("Invalid number of items in savegame! Contact Ott!");
                //}
                //else
                //{

                //}
            }
        }
        else
        {
            bool          isInfoToolSlotEmpty = true;
            template_item substituteItem      = null;
            for (int j = 0; j < 3; ++j)
            {
                unOwnedItems.Clear();
                for (int i = 0; i < ItemDictionary[j].Count; ++i)
                {
                    //if (!SaveManager.instance.GetCurrentCarryoverPlayerState().IsItemOwnedByID(ItemDictionary[j][i].Id))
                    //{
                    //    unOwnedItems.Add(ItemDictionary[j][i]);
                    //}

                    if (!ItemDictionary[j][i].Template.item_data.item_variable.CallScript() && substituteItem != ItemDictionary[j][i])
                    {
                        if (j == 1)
                        {
                            isInfoToolSlotEmpty = false;
                        }
                        if (ItemDictionary[j][i] != GetStarterBody() && ItemDictionary[j][i] != GetStarterHead())
                        {
                            unOwnedItems.Add(ItemDictionary[j][i]);
                        }
                    }
                }

                if (isInfoToolSlotEmpty && j == 1)
                {
                    for (int i = 0; i < ItemDictionary[2].Count; ++i)
                    {
                        if (!ItemDictionary[2][i].Template.item_data.item_variable.CallScript())
                        {
                            if (ItemDictionary[2][i] != GetStarterBody() && ItemDictionary[2][i] != GetStarterHead())
                            {
                                unOwnedItems.Add(ItemDictionary[2][i]);
                            }
                        }
                    }
                }

                if (unOwnedItems.Count > 0)
                {
                    if (isInfoToolSlotEmpty && j == 1)
                    {
                        GameObject marker = Shop.instance.GetShopItemSpawnMarkerForPosition(1);

                        template_item rolledItem = unOwnedItems[Random.Range(0, unOwnedItems.Count)];
                        substituteItem = rolledItem;
                        unOwnedItems.Remove(rolledItem);
                        SpawnItem(rolledItem, marker.transform.position);
                        player.AddCurrentDayItem(rolledItem.Id);
                    }
                    else
                    {
                        GameObject marker = Shop.instance.GetShopItemSpawnMarkerForPosition(j);

                        template_item rolledItem = unOwnedItems[Random.Range(0, unOwnedItems.Count)];
                        unOwnedItems.Remove(rolledItem);
                        SpawnItem(rolledItem, marker.transform.position);
                        player.AddCurrentDayItem(rolledItem.Id);
                    }
                }
            }
        }
    }