/// <summary> /// Resets the trade component. /// </summary> public void Reset() { TargetId = 0; ItemCount = 0; Gold = 0; State = TradeState.Item; Items = new ItemContainerComponent(_maxTradeItemsCapacity); }
/// <inheritdoc /> public void BuyItem(IPlayerEntity player, NpcShopItemInfo shopItemInfo, int quantity) { var npc = player.FindEntity <INpcEntity>(x => x.Object.Name == player.PlayerData.CurrentShopName); if (npc == null) { _logger.LogError($"ShopSystem: Cannot find NPC: {player.PlayerData.CurrentShopName}"); return; } if (!npc.NpcData.HasShop) { _logger.LogError($"ShopSystem: NPC {npc.Object.Name} doesn't have a shop."); return; } if (shopItemInfo.Tab < 0 || shopItemInfo.Tab >= ShopData.DefaultTabCount) { _logger.LogError($"Attempt to buy an item from {npc.Object.Name} shop tab that is out of range."); return; } ItemContainerComponent shopTab = npc.Shop.ElementAt(shopItemInfo.Tab); if (shopItemInfo.Slot < 0 || shopItemInfo.Slot > shopTab.MaxCapacity - 1) { _logger.LogError($"ShopSystem: Item slot index was out of tab bounds. Slot: {shopItemInfo.Slot}"); return; } Item shopItem = shopTab.GetItemAtSlot(shopItemInfo.Slot); if (shopItem.Id != shopItemInfo.ItemId) { _logger.LogError($"ShopSystem: Shop item id doens't match the item id that {player.Object.Name} is trying to buy."); return; } if (player.PlayerData.Gold < shopItem.Data.Cost) { _logger.LogTrace($"ShopSystem: {player.Object.Name} doens't have enough gold to buy item {shopItem.Data.Name} at {shopItem.Data.Cost}."); _textPacketFactory.SendDefinedText(player, DefineText.TID_GAME_LACKMONEY); return; } int itemsCreatedCount = _inventorySystem.CreateItem(player, shopItem, quantity); if (itemsCreatedCount > 0) { _playerDataSystem.DecreaseGold(player, shopItem.Data.Cost * itemsCreatedCount); } }
public InventoryWindow(InventoryWindowTemplate template) : base(null, template) { Contract.Requires <ArgumentNullException>(template != null, "template"); Contract.Requires <ArgumentNullException>(template.Items != null, "template.Items"); Contract.Requires <ArgumentNullException>(template.World != null, "player"); _inventory = template.World.Player.Get <ItemContainerComponent>(); _equipment = template.World.Player.Get <EquipmentComponent>(); _player = template.World.Player; _bodyPartWidth = _equipment.Slots.Max(s => s.Length) + 5; // todo replace to code _sizeList = new Rectangle(new Point(1, 1), new Size(Size.Width - 2, Size.Height)); }
void Container_ItemChanged(ItemContainerComponent sender, DEngine.Core.EventArgs <Entity> e) { }