//------------------------------------------------------ public void Setup(Item currentItem, ShopScrollList currentScrollList, GameObject tempPainel, int slotIdTemp, ItemOnShop shopTemp) { slotId = slotIdTemp; item = currentItem; nameLabel.text = item.itemName; iconImage.sprite = item.artwork; tempShopPrices = shopTemp; season = currentScrollList.tempData.season; switch (season) { case 0: buyValue = shopTemp.SpringBuy; sellValue = shopTemp.SpringSell; break; case 1: buyValue = shopTemp.SummerBuy; sellValue = shopTemp.SummerSell; break; case 2: buyValue = shopTemp.AutumBuy; sellValue = shopTemp.AutumSell; break; case 3: buyValue = shopTemp.WinterBuy; sellValue = shopTemp.WinterSell; break; default: break; } if (tempPainel.name == "PlayerContentPainel" || tempPainel.name == "SellContent") { priceText.text = "<color=green>" + sellValue.ToString() + "G</color>"; } else { priceText.text = "<color=red>-" + buyValue.ToString() + "G</color>"; } if (tempPainel.name == "ShopContent") { amount.text = ""; } if (tempPainel.name == "CartContent") { nameLabel.text = "x1"; } scrollList = currentScrollList; tempPainelGameObject = tempPainel; }
//-------------------------------------------------------------------- public void PlayerSellCartPlayerToCart(ItemOnShop itemToAdd, int buyValue, int id) { balance += buyValue; UpdateBalance(); playerSellList.Add(itemToAdd); for (int i = 0; i < playerButtonList.Count; i++) { if (playerButtonList[i].slotId == id) { playerList.RemoveAt(i); } } RefreshPlayerContent(); RefreshSellCart(); }
//-------------------------------------------------------------------- public void PlayerSellCartRemoveFromSellCart(int slotIdTemp) { for (int i = 0; i < playerSellList.Count; i++) { if (playerSellButtonList[i].slotId == slotIdTemp) { itmTemp = playerSellList[i]; playerSellList.RemoveAt(i); playerList.Add(itmTemp); balance -= playerSellButtonList[i].sellValue; } } UpdateBalance(); RefreshPlayerContent(); RefreshSellCart(); }
//------------------------------------------------------ public ItemOnShop CreateNewitemOnShop() { ItemOnShop itmShopTemp = new ItemOnShop(); itmShopTemp.itemShop = this.tempShopPrices.itemShop; itmShopTemp.amount = this.tempShopPrices.amount; itmShopTemp.showInShop = this.tempShopPrices.showInShop; itmShopTemp.AutumBuy = this.tempShopPrices.AutumBuy; itmShopTemp.SpringBuy = this.tempShopPrices.SpringBuy; itmShopTemp.WinterBuy = this.tempShopPrices.WinterBuy; itmShopTemp.AutumSell = this.tempShopPrices.AutumSell; itmShopTemp.SpringSell = this.tempShopPrices.SpringSell; itmShopTemp.SummerBuy = this.tempShopPrices.SummerBuy; itmShopTemp.SummerSell = this.tempShopPrices.SummerSell; itmShopTemp.WinterSell = this.tempShopPrices.WinterSell; return(itmShopTemp); }
//------------------------------------------------------ public void Setup(Item currentItem, ShopScrollList currentScrollList, GameObject tempPainel, int slotIdTemp) { slotId = slotIdTemp; item = currentItem; nameLabel.text = item.itemName; iconImage.sprite = item.artwork; tempShopPrices = null; shopHaveItem = false; if (tempPainel.name == "PlayerContentPainel") { priceText.text = "<color=green>" + item.sellValue.ToString() + "G</color>"; } else { priceText.text = "<color=red>-" + item.buyValue.ToString() + "G</color>"; } scrollList = currentScrollList; tempPainelGameObject = tempPainel; }
//-------------------------------------------------------------------- //-Player to sell cart code ------------------------------------------ //-------------------------------------------------------------------- private void PlayerSellCartAddButton() { for (int i = 0; i < playerSellList.Count; i++) { Item item = playerSellList[i].itemShop; GameObject newButton = playerSellObjectPool.GetObject(); newButton.transform.SetParent(playerSellContentPainel.transform); SampleButton sampleButton = newButton.GetComponent <SampleButton>(); for (int j = 0; j < shopItemList.Count; j++) { if (item.itemName == shopItemList[j].itemShop.itemName) { findItemOnShopToCopyValue = true; shopPositonItemPriceTemp = j; } } if (!findItemOnShopToCopyValue) { ItemOnShop itm = new ItemOnShop(); itm.SpringBuy = item.buyValue; itm.AutumBuy = item.buyValue; itm.WinterBuy = item.buyValue; itm.SummerBuy = item.buyValue; itm.SpringSell = item.sellValue; itm.AutumSell = item.sellValue; itm.WinterSell = item.sellValue; itm.SummerSell = item.sellValue; sampleButton.Setup(item, this, playerSellContentPainel, i, itm); playerSellButtonList.Add(sampleButton); } else { sampleButton.Setup(item, this, playerSellContentPainel, i, shopItemList[shopPositonItemPriceTemp]); playerSellButtonList.Add(sampleButton); } findItemOnShopToCopyValue = false; } }
//-------------------------------------------------------------------- //add to Cart \/ code ------------------------------------------------ //-------------------------------------------------------------------- public void AddToCart(ItemOnShop itemToAdd, int buyValue) { balance -= buyValue; UpdateBalance(); encounterAStack = false; stackPosition = 0; if (cartList.Count > 0) { for (int i = 0; i < cartList.Count; i++) { if (cartList[i].itemShop.itemName == itemToAdd.itemShop.itemName && cartList[i].itemShop.maxStack > cartList[i].amount) { encounterAStack = true; stackPosition = i; } } if (encounterAStack) { if ((cartList[stackPosition].amount + quantity) < cartList[stackPosition].itemShop.maxStack) { cartList[stackPosition].amount += quantity; } else { leftOver = quantity - (cartList[stackPosition].itemShop.maxStack - cartList[stackPosition].amount); cartList[stackPosition].amount = cartList[stackPosition].itemShop.maxStack; while (leftOver > 0) { if (leftOver > itemToAdd.itemShop.maxStack) { leftOver -= itemToAdd.itemShop.maxStack; cartList.Add(itemToAdd); cartList[cartList.Count - 1].amount = cartList[cartList.Count - 1].itemShop.maxStack; } else { cartList.Add(itemToAdd); cartList[cartList.Count - 1].amount = leftOver; leftOver = 0; } } } } else { if (quantity > itemToAdd.itemShop.maxStack) { leftOver = quantity - (cartList[stackPosition].itemShop.maxStack - cartList[stackPosition].amount); cartList[stackPosition].amount = cartList[stackPosition].itemShop.maxStack; while (leftOver > 0) { if (leftOver > itemToAdd.itemShop.maxStack) { leftOver -= itemToAdd.itemShop.maxStack; cartList.Add(itemToAdd); cartList[cartList.Count - 1].amount = cartList[cartList.Count - 1].itemShop.maxStack; } else { cartList.Add(itemToAdd); cartList[cartList.Count - 1].amount = leftOver; leftOver = 0; } } } else { cartList.Add(itemToAdd); cartList[cartList.Count - 1].amount = quantity; leftOver = 0; } } } else { cartList.Add(itemToAdd); cartList[cartList.Count - 1].amount = 1; } encounterAStack = false; //cartList.Add(itemToAdd); RemoveButtonsCart(); AddButtonsToCart(); }