public virtual void Bind(ITradable tradable, Empire empire, TradablesListPanel parent) { this.guiPanelHelper = Services.GetService <global::IGuiService>().GuiPanelHelper; Diagnostics.Assert(this.guiPanelHelper != null, "Unable to access GuiPanelHelper"); this.empire = empire; this.parent = parent; }
//아이템 구매 public static void Buy(ref int money, SlotItem item, InventoryTab targetTab, Action buyFailEvent = null, Action tabFullEvent = null) { if (item is ITradable) { ITradable tradableItem = item as ITradable; //아이템이 추가될 탭이 꽉 찼을 경우 이벤트 발생 및 종료 if (targetTab.IsFull) { tabFullEvent?.Invoke(); return; } //아이템 구매 if (money >= tradableItem.BuyPrice) { money -= tradableItem.BuyPrice; targetTab.Add(item, true); } else { buyFailEvent?.Invoke(); //돈이 부족할 경우 이벤트 실행및 종료 } } }
private void BuyTradable(ITradable tradable, Garrison destination = null) { if (base.PlayerController == null) { Diagnostics.LogError("No PlayerController on BuyablePanel."); return; } if (this.SelectedTradableLine == null || this.SelectedTradableLine.Tradable == null) { Diagnostics.LogError("Trying to buy a tradable while there is no tradable selected."); return; } if (this.SelectedTradableLine.Tradable is TradableUnit && !(this.SelectedTradableLine.Tradable is TradableHero) && destination != null) { OrderBuyoutTradableUnit order = new OrderBuyoutTradableUnit(base.Empire.Index, this.SelectedTradableLine.Tradable.UID, (float)this.CurrentQuantity, destination.GUID); base.PlayerController.PostOrder(order); } else { OrderBuyoutTradable order2 = new OrderBuyoutTradable(base.Empire.Index, this.SelectedTradableLine.Tradable.UID, (float)this.CurrentQuantity); base.PlayerController.PostOrder(order2); } this.SelectedTradableLine = null; this.RefreshButtons(); }
//아이템 모두 판매 public static void Sell(ref int money, SlotItem item) { if (item is ITradable) { ITradable tradableItem = item as ITradable; int total = tradableItem.SellPrice * item.Count; item.Tab.Remove(item); money += total; } }
public Double GetTradeCoefficient(ITradable hero) { if (!_tradeCoefficients.ContainsKey(hero)) { //TODO: Move to constants var defaultTradeCoefficient = 0.8; _tradeCoefficients.Add(hero, defaultTradeCoefficient); } return(_tradeCoefficients[hero]); }
public void Show(InventorySlot slot, Widget widget) { ActiveToggle(true); SlotItem item = slot.Item; SelectWidget = widget; //받아온값 넘겨받기 //슬롯의 아이템 탭 이름에 따라 가격 표시 설정 if (item is ITradable) { ITradable tradable = item as ITradable; if (SelectWidget == Widget.Shop) { priceText.text = "구매 가격 : " + tradable.BuyPrice.ToString(); } else if (SelectWidget == Widget.QuickSlot) { priceText.text = "판매 가격 : " + tradable.SellPrice * item.Count; } else if (SelectWidget == Widget.Inventory) { priceText.text = "판매 가격 : " + tradable.SellPrice * item.Count; } } //아이템 갯수에 따라 이름 및 갯수 표시 if (item.Count == 1) { nameText.text = item.DisplayName; } else { nameText.text = $"{item.DisplayName} ({item.Count})"; } //아이템 타입에 따라 색상 변경 switch (item.Type) { case "weapon": typeText.color = new Color32(50, 160, 160, 255); break; case "material": typeText.color = new Color32(160, 50, 160, 255); break; case "potion": typeText.color = new Color32(160, 160, 50, 255); break; default: typeText.color = new Color32(50, 50, 50, 255); break; } //아이템 타입 및 설명 표시 typeText.text = slot.Item.Type; descText.text = slot.Item.Description; }
protected override void DrawContent(InventorySlot slot) { this.slot = slot; //슬롯 등록 SlotItem item = slot.Item; //아이템 가져오기 // Tab에 따라서 MenuViewer 위치 변경 및 버튼 변경 if (SelectWidget == Widget.Shop) { anchor = ViewerAnchor.BottomRight; ITradable _tradable = item as ITradable; useText.text = $"구매\n ( 가격 : {_tradable.BuyPrice} )"; removeText.text = "버리기"; removeButton.interactable = false; sellButton.interactable = false; } else if (SelectWidget == Widget.QuickSlot) { anchor = ViewerAnchor.TopRight; if (item is Equipment) { removeText.text = "착용 해제"; } else { removeText.text = "등록 해제"; } removeButton.interactable = true; sellButton.interactable = false; } else if (SelectWidget == Widget.Inventory) { anchor = ViewerAnchor.BottomLeft; removeText.text = "버리기"; if (item is Equipment) { useText.text = "착용"; } else { useText.text = "사용"; } removeButton.interactable = true; sellButton.interactable = true; } }
public Boolean SellItem(ITradable buyer, IInventoryItem itemToTrade) { //TODO: Calculate gold Double tradeCoefficient = GetTradeCoefficient(buyer); Int32 finalCost = itemToTrade.Cost + (Int32)(itemToTrade.Cost * (1 - tradeCoefficient)); if (buyer.Gold >= finalCost) { _inventory.Remove(itemToTrade); Gold += finalCost; buyer.Gold -= finalCost; buyer.Inventory.Add(itemToTrade); return(true); } return(false); }
public Boolean BuyItem(ITradable seller, IInventoryItem itemToTrade) { Double tradeCoefficient = GetTradeCoefficient(seller); var finalCost = (Int32)(itemToTrade.Cost * tradeCoefficient); if (Gold >= finalCost) { _inventory.Add(itemToTrade); Gold -= finalCost; seller.Gold += finalCost; seller.Inventory.Remove(itemToTrade); return(true); } return(false); }
private void AddForeignItem() { if (this.tvwForeign.SelectedNode.Tag == null) { return; } ITradable item = this.tvwForeign.SelectedNode.Tag as ITradable; if (item != null && !this.takenItems.Contains(item)) { if (item.GetType() == typeof(GoldLumpSum)) { GoldLumpSum sum = (GoldLumpSum)item; GoldAmountDialog dlg = new GoldAmountDialog(); if (dlg.ShowDialog(this) == DialogResult.OK) { sum.LumpSum = dlg.GoldAmount; } else { return; } } else if (item.GetType() == typeof(GoldPerTurn)) { GoldPerTurn turn = (GoldPerTurn)item; GoldAmountDialog dlg = new GoldAmountDialog(); if (dlg.ShowDialog(this) == DialogResult.OK) { turn.AmountPerTurn = dlg.GoldAmount; } else { return; } } this.takenItems.Add(item); Rebind(); } }
//아이템 특정 갯수 판매 public static void Sell(ref int money, SlotItem item, int count) { if (item is ITradable) { if (item.Count >= count) { ITradable tradableItem = item as ITradable; int total = tradableItem.SellPrice * count; item.Count -= count; if (item.Count <= 0) { item.Tab.Remove(item); } money += total; } else { Sell(ref money, item); } } }