Ejemplo n.º 1
0
        public void Show(Storage storage, ShopStructure shopStructure = null)
        {
            if (!targetStorage)
            {
                this.shopStructure = shopStructure;
                moneyText.gameObject.SetActive(shopStructure);
                costText.gameObject.SetActive(shopStructure);
                targetStorage = storage;

                Player.instance.controlsEnabled = false;

                UpdateList();

                detailsNameText.text        = "";
                detailsImage.sprite         = null;
                detailsDescriptionText.text = "";

                UpdatePickButton();

                targetStorage.onItemsUpdate += UpdateList;

                controlsUnlocked = false;

                canvas.enabled = true;
                targetStorageScrollList.enabled = true;
            }
        }
Ejemplo n.º 2
0
    public static bool ItemInShopStructures(ItemType itemType, Vector3 position, out Item item, out Storage storage, ShopStructure exclude = null)
    {
        ShopStructure shop = ShopStructure.list
                             .FindAll(s => s != exclude && s.storage.Count(itemType) > 0)
                             .OrderBy(s => /*s.storage.items.Find(i => i.type == missing[0].type).value + */ (s.transform.position - position).magnitude)
                             .FirstOrDefault();

        if (shop)
        {
            item    = shop.storage.items.Find(i => i.type == itemType);
            storage = shop.storage;
            return(true);
        }

        item    = null;
        storage = null;
        return(false);
    }
Ejemplo n.º 3
0
    public static bool FuelInShopStructures(Vector3 position, out Item item, out Storage storage)
    {
        ShopStructure shop = ShopStructure.list
                             .FindAll(s => s.storage.items.Find(i => i.type.fuelValue > 0))
                             .OrderBy(s => (s.transform.position - position).magnitude)
                             .FirstOrDefault();

        if (shop)
        {
            item    = shop.storage.items.OrderByDescending(i => i.type.fuelValue).FirstOrDefault();
            storage = shop.storage;
            return(true);
        }

        item    = null;
        storage = null;
        return(false);
    }
Ejemplo n.º 4
0
    public static void LoadShop(ShopItemPopulator populator)
    {
        if (shopCache == null || !shopCache.updated)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                //Não tem internet, pega do arquivo de cache;
                if (SaveGameSystem.DoesSaveGameExist("shop"))
                {
                    shopCache         = (ShopStructure)SaveGameSystem.LoadGame("shop");
                    shopCache.updated = false;
                }
            }
            else
            {
                //Tem internet
                FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://pimba-ball.firebaseio.com/");
                DatabaseReference reference = FirebaseDatabase.DefaultInstance.GetReference("flamelink");

                //LÊ O SHOP DO FIREBASE
                Task tkk = reference.GetValueAsync().ContinueWith((Task <DataSnapshot> task) =>
                {
                    if (task.IsFaulted)
                    {
                        Debug.LogError(task.Exception);
                    }
                    else if (task.IsCompleted)
                    {
                        DataSnapshot snap = task.Result;
                        Dictionary <string, object> myDict = (Dictionary <string, object>)snap.Value;

                        shopCache = new ShopStructure(myDict, false, true);

                        populator.QueueToExecute(() => {
                            bool res = SaveGameSystem.SaveGame(shopCache, "shop");
                            Debug.Log("Loja carregada, tentei salvar no cache, funcionou? " + res);
                        });
                    }
                });
            }
        }
    }