public void OnQuantityValueChanged() { if (SelectedItem == null) { return; } var itemModel = SelectedItem.ItemModel; int itemQuantity = Convert.ToInt32(QuantityInputField.text); //clamp values if (itemQuantity <= 0 || itemQuantity > SelectedItem.Quantity) { itemQuantity = MathUtils.Clamp <int>(itemQuantity, 1, SelectedItem.Quantity); QuantityInputField.text = itemQuantity.ToString(); } if (IsShop && Selected == SelectedState.Container) { int adjValue = RpgValues.AdjustedBuyPrice(GameState.Instance.PlayerRpgState, itemModel.Value); TransferText.text = string.Format("Value: {0}({1}) | Weight: {2}({3})", adjValue, adjValue * itemQuantity, itemModel.Weight, itemModel.Weight * itemQuantity); } else if (IsShop && Selected == SelectedState.Inventory) { int adjValue = RpgValues.AdjustedSellPrice(GameState.Instance.PlayerRpgState, itemModel.Value); TransferText.text = string.Format("Value: {0}({1}) | Weight: {2}({3})", adjValue, adjValue * itemQuantity, itemModel.Weight, itemModel.Weight * itemQuantity); } else { TransferText.text = string.Format("Value: {0}({1}) | Weight: {2}({3})", itemModel.Value, itemModel.Value * itemQuantity, itemModel.Weight, itemModel.Weight * itemQuantity); } }
private void PaintSelectedItem() { var itemModel = SelectedItem.ItemModel; SelectedItemText.text = itemModel.Name; var itemDef = InventoryModel.GetDef(itemModel.Name); if (itemDef == null) { SelectedItemDescription.text = "{missing def}"; } else { SelectedItemText.text = itemDef.NiceName; SelectedItemDescription.text = itemDef.Description; Texture2D tex = CoreUtils.LoadResource <Texture2D>("UI/Icons/" + itemDef.Image); if (tex != null) { SelectedItemImage.texture = tex; } } SelectedItemStats.text = itemModel.GetStatsString(); TransferButton.gameObject.SetActive(true); var transferButtonText = TransferButton.GetComponentInChildren <Text>(); if (Selected == SelectedState.Container && !IsShop) { transferButtonText.text = "< Transfer"; } else if (Selected == SelectedState.Inventory && !IsShop) { transferButtonText.text = "Transfer >"; } else if (Selected == SelectedState.Container && IsShop) { transferButtonText.text = "< Buy"; } else if (Selected == SelectedState.Inventory && IsShop) { transferButtonText.text = "Sell >"; } if (IsShop && Selected == SelectedState.Container) { int adjValue = RpgValues.AdjustedBuyPrice(GameState.Instance.PlayerRpgState, itemModel.Value); TransferText.text = string.Format("Value: {0}({1}) | Weight: {2}({3})", adjValue, adjValue * 1, itemModel.Weight, itemModel.Weight * 1); } else if (IsShop && Selected == SelectedState.Inventory) { int adjValue = RpgValues.AdjustedSellPrice(GameState.Instance.PlayerRpgState, itemModel.Value); TransferText.text = string.Format("Value: {0}({1}) | Weight: {2}({3})", adjValue, adjValue * 1, itemModel.Weight, itemModel.Weight * 1); } else { TransferText.text = string.Format("Value: {0}({1}) | Weight: {2}({3})", itemModel.Value, itemModel.Value * 1, itemModel.Weight, itemModel.Weight * 1); } }
public void OnClickTransfer() { //immediate fail conditions if (Selected == SelectedState.None || SelectedItem == null) { return; } int quantity = MathUtils.Clamp <int>(Convert.ToInt32(QuantityInputField.text), 1, Mathf.Abs(SelectedItem.Quantity)); //if it's a shop and we don't have money, check and possibly fail //(we would also handle carry weight here if that was actually implemented ?) if (IsShop) { string moneyTypeName = Enum.GetNames(typeof(MoneyType))[0]; if (Selected == SelectedState.Inventory) { //we are SELLING, check CONTAINER money int neededMoney = Mathf.RoundToInt(quantity * RpgValues.AdjustedSellPrice(GameState.Instance.PlayerRpgState, SelectedItem.ItemModel.Value)); int haveMoney = Container.CountItem(moneyTypeName); if (neededMoney > haveMoney) { Modal.PushMessageModal(string.Format("This shop doesn't have enough currency to pay for that (have {0}, need {1})", haveMoney, neededMoney), "Insufficient Currency", null, null); return; } else { //var iMoneyItem = Inventory.FindItem(moneyTypeName)[0]; //it's weirdly asymmetrical and I don't know why Inventory.AddItem(moneyTypeName, neededMoney); var cMoneyItem = Container.FindItem(moneyTypeName)[0]; Container.TakeItem(cMoneyItem, neededMoney); } } else if (Selected == SelectedState.Container) { //we are BUYING, check PLAYER money int neededMoney = Mathf.RoundToInt(quantity * RpgValues.AdjustedBuyPrice(GameState.Instance.PlayerRpgState, SelectedItem.ItemModel.Value)); int haveMoney = Inventory.CountItem(moneyTypeName); if (neededMoney > haveMoney) { Modal.PushMessageModal(string.Format("You don't have enough currency to pay for that (have {0}, need {1})", haveMoney, neededMoney), "Insufficient Currency", null, null); return; } else { var iMoneyItem = Inventory.FindItem(moneyTypeName)[0]; Inventory.RemoveItem(iMoneyItem, neededMoney); var cMoneyItem = Container.FindItem(moneyTypeName)[0]; Container.PutItem(cMoneyItem, neededMoney); } } } //simpler cases: transferring inventory to container or vice versa if (Selected == SelectedState.Inventory) { //transfer item to container if (!SelectedItem.ItemModel.Stackable) { Inventory.RemoveItem(SelectedItem); Container.PutItem(SelectedItem); } else { Inventory.RemoveItem(SelectedItem, quantity); Container.PutItem(SelectedItem, quantity); } } else if (Selected == SelectedState.Container) { //transfer item to inventory if (!SelectedItem.ItemModel.Stackable) { Inventory.AddItem(SelectedItem); Container.TakeItem(SelectedItem); } else { Inventory.AddItem(SelectedItem.ItemModel.Name, quantity); Container.TakeItem(SelectedItem, quantity); } } //don't forget to fix the stacks! Container.FixStacks(); //clear and repaint ClearState(); PaintAll(); }