private static void DoWork() { var csInitial = Logic.Client.PlayerInfo.GetMyCatshop(); while (_state != State.Stopping) { while (_state == State.Suspending) { Thread.Sleep(100); } var cs = Logic.Client.PlayerInfo.GetMyCatshop(); var sellItem = cs.SellList.Any() ? cs.SellList.Random() : null; var buyItem = cs.BuyList.Any() ? cs.BuyList.Random() : null; if (sellItem == null && buyItem == null) { break; } bool adBuy = buyItem != null && (sellItem == null || RandomUtils.RandomBoolean()); if (adBuy) { Logic.Client.Chat.SendMessage(string.Format("C> {0} - máxima preço!{1}", PwDatabase.GetItemName(buyItem.ItemId, "br"), StringUtils.Repeat(" ", RandomUtils.RandomInt(0, 10)))); Thread.Sleep(1200); Logic.Client.Chat.SendMessage(string.Format("$C> {0} - máxima preço!{1}", PwDatabase.GetItemName(buyItem.ItemId, "br"), StringUtils.Repeat(" ", RandomUtils.RandomInt(0, 10)))); } else { Logic.Client.Chat.SendMessage(string.Format("V> {0} - mínimo preço!{1}", PwDatabase.GetItemName(sellItem.ItemId, "br"), StringUtils.Repeat(" ", RandomUtils.RandomInt(0, 10)))); Thread.Sleep(1200); Logic.Client.Chat.SendMessage(string.Format("$V> {0} - mínimo preço!{1}", PwDatabase.GetItemName(sellItem.ItemId, "br"), StringUtils.Repeat(" ", RandomUtils.RandomInt(0, 10)))); } Thread.Sleep(2000); } }
public static void DoWork() { var rect = new Rectangle(116, 861, 125, 857, true); _state = State.Working; for (; ;) { var visited = new List <Player>(); while (true) { if (_state == State.Suspending) { _state = State.Suspended; while (_state != State.Resuming) { Thread.Sleep(100); } _state = State.Working; } else if (_state == State.Stopping) { _state = State.Stopped; return; } Catshops.RemoveAll(cs => DateTime.Now - cs.LastUpdate > TimeSpan.FromMinutes(5)); var players = Logic.Client.Environment.GetPlayers().Where(p => rect.IsCoordIn(p.Coords)).Where(p => p.IsCatshop).ToList(); var player = players.FirstOrDefault(p => !visited.Any(vis => vis.Id == p.Id)); if (player == null) { break; } visited.Add(player); CatshopCnt = visited.Count; Logic.Client.Additional.DoSelect((uint)player.Id); Thread.Sleep(500); int cnt = 0; while (Logic.Client.PlayerInfo.CurrentDialogId != player.Id && cnt < 10) { cnt++; Logic.Client.ActionStructs.TalkNpc((uint)player.Id); Thread.Sleep(500); } if (Logic.Client.PlayerInfo.CurrentDialogId != player.Id) { continue; } cnt = 0; while (Logic.Client.PlayerInfo.GetOpenedCatshop().Empty&& cnt++ < 30) { Thread.Sleep(100); } if (Logic.Client.PlayerInfo.GetOpenedCatshop().Empty) { continue; } Catshops.RemoveAll(cs => cs.Id == player.Id); Catshops.Add(new Catshop { Id = player.Id, PlayerName = player.Name, ShopName = player.ShopName, BuyItems = Logic.Client.PlayerInfo.GetOpenedCatshop().BuyList. Select(ii => new Item { Id = ii.ItemId, Name = PwDatabase.GetItemName(ii.ItemId), Price = ii.SellPrice, Amount = ii.Amount }). ToArray(), SellItems = Logic.Client.PlayerInfo.GetOpenedCatshop().SellList. Select(ii => new Item { Id = ii.ItemId, Name = PwDatabase.GetItemName(ii.ItemId), Price = ii.SellPrice, Amount = ii.Amount }). ToArray(), LastUpdate = DateTime.Now, }); Thread.Sleep(500); } } }