private void RemoveMerchant(PlayerMerchant merchant) { PlayerMerchant dummy; _merchants.TryRemove(new IntPoint((int)merchant.X, (int)merchant.Y), out dummy); merchant.Owner?.LeaveWorld(merchant); }
public void Reload(PlayerMerchant merchant) { using (TimedLock.Lock(MarketLock)) { if (!ValidateShopItem(merchant.PlayerShopItem)) { RemoveMerchant(merchant); return; } var itemType = GetItemType(merchant.PlayerShopItem); var market = _shops[itemType]; var itemCount = market.ContainsKey(merchant.Item) ? market[merchant.Item].Count : 0; ushort nextItem; if (merchant.TimeLeft <= 0 || itemCount <= 0) { if (itemCount > 0) { _queues[itemType].Enqueue(merchant.Item); } else { _items[itemType].Remove(merchant.Item); } if (!_queues[itemType].TryDequeue(out nextItem)) { RemoveMerchant(merchant); return; } merchant.TimeLeft = 30000; } else { nextItem = merchant.Item; } PlayerShopItem nextShopItem; var shop = market[nextItem]; using (TimedLock.Lock(shop)) { nextShopItem = shop[0]; } merchant.PlayerShopItem = nextShopItem; merchant.Item = nextShopItem.ItemId; merchant.Price = nextShopItem.Price; merchant.Count = shop.Count; } }
private void AddMerchants() { foreach (var shopLocs in _shopTypeLocations) { foreach (var shopLoc in shopLocs.Value) { if (_merchants.ContainsKey(shopLoc.Key)) { continue; } ushort objectType; if (!_queues[shopLocs.Key].TryDequeue(out objectType)) { continue; } var itemList = _shops[shopLocs.Key][objectType]; PlayerShopItem item; using (TimedLock.Lock(itemList)) { item = itemList[0]; } var m = new PlayerMerchant(_manager, 0x01ca) { PlayerShopItem = item, Item = item.ItemId, Price = item.Price, Currency = CurrencyType.Fame, Count = itemList.Count, //TimeLeft = Rand.Next(30000, 90000), ReloadOffset = shopLoc.Value }; _merchants.TryAdd(shopLoc.Key, m); m.Move(shopLoc.Key.X + .5f, shopLoc.Key.Y + .5f); _marketplace.EnterWorld(m); } } }