public void TryAddDetails(object o, int name, int value, Category cat) { SearchDetail d = Details.FirstOrDefault(det => det.Attribute == o); if (o is Layer) { SearchDetail layer = Details.FirstOrDefault(det => det.Attribute is Layer && (Layer)det.Attribute != (Layer)o); if (layer != null) { Details.Remove(layer); } Details.Add(new SearchDetail(o, name, value, cat)); SearchType = (Layer)o; } else if (d == null) { Details.Add(new SearchDetail(o, name, value, cat)); } else if (d.Value != value) { d.Value = value; } }
public void TryAddDetails(object o, int name, int propname, int value, Category cat) { SearchDetail d = Details.FirstOrDefault(det => det.Attribute == o); if (o is Layer) { SearchDetail layer = Details.FirstOrDefault(det => det.Attribute is Layer && (Layer)det.Attribute != (Layer)o); if (layer != null) { Details.Remove(layer); } Details.Add(new SearchDetail(o, name, propname, value, cat)); SearchType = (Layer)o; } else if (d == null) { d = new SearchDetail(o, name, propname, value, cat); Details.Add(d); } else if (d.Value != value) { d.Value = value; } /*if (d.Attribute is TalismanSlayerName && (TalismanSlayerName)d.Attribute == TalismanSlayerName.Undead) * { * TryAddDetails(SlayerName.Silver, name, value, cat); * }*/ }
public static List <SearchItem> DoSearchAuction(SearchCriteria criteria) { if (criteria == null || Auction.Auction.Auctions == null || Auction.Auction.Auctions.Count == 0) { return(null); } List <SearchItem> list = new List <SearchItem>(); SearchDetail first = null; for (var index = 0; index < criteria.Details.Count; index++) { var d = criteria.Details[index]; if (d.Attribute is Misc misc && misc == Misc.ExcludeFel) { first = d; break; } } bool excludefel = first != null; for (var index = 0; index < Auction.Auction.Auctions.Count; index++) { Auction.Auction pv = Auction.Auction.Auctions[index]; if (pv.AuctionItem != null && pv.AuctionItem.Map != Map.Internal && pv.AuctionItem.Map != null && pv.OnGoing && (!excludefel || pv.AuctionItem.Map != Map.Felucca)) { list.Add(new SearchItem(pv.Safe, pv.AuctionItem, (int)pv.Buyout, false)); } } switch (criteria.SortBy) { case SortBy.LowToHigh: list = list.OrderBy(vi => vi.Price).ToList(); break; case SortBy.HighToLow: list = list.OrderBy(vi => - vi.Price).ToList(); break; } return(list); }
public override void OnResponse(RelayInfo info) { if (info.ButtonID != 0) { if (!VendorSearch.CanSearch(User)) { User.SendLocalizedMessage(1154680); //Before using vendor search, you must be in a justice region or a safe log-out location (such as an inn or a house which has you on its Owner, Co-owner, or Friends list). return; } TextRelay searchname = info.GetTextEntry(1); if (searchname != null && !string.IsNullOrEmpty(searchname.Text)) { string text = searchname.Text.Trim(); if (Criteria.SearchName == null || text.ToLower() != Criteria.SearchName.ToLower()) { Criteria.SearchName = searchname.Text; } } } switch (info.ButtonID) { case 0: break; case 1: // Search { User.CloseGump(typeof(SearchResultsGump)); if (Criteria.IsEmpty) { SendGump(new VendorSearchGump(User, 1154586)); // Please select some criteria to search for. } else { var resultsTask = FindVendorItemsAsync(User, Criteria); var pollingTimer = new TaskPollingTimer <List <SearchItem> >(resultsTask, (results) => { User.CloseGump(typeof(SearchWaitGump)); if (results == null || results.Count == 0) { SendGump(new VendorSearchGump(User, 1154587)); // No items matched your search. } else { Refresh(true); SendGump(new SearchResultsGump(User, results)); } }); resultsTask.Start(); pollingTimer.Start(); SendGump(new SearchWaitGump(User, pollingTimer)); } break; } case 2: // Clear Criteria { Criteria.Reset(); Refresh(true); break; } case 4: // Nothing, resend gump Refresh(true); break; case 7: // remove item name Criteria.SearchName = null; Refresh(true); break; case 8: // remove price entry Criteria.EntryPrice = false; Refresh(true); break; case 9: // remove auction entry Refresh(true); break; case 236: // Low to High Criteria.SortBy = SortBy.LowToHigh; Refresh(true); break; case 237: // High to Low Criteria.SortBy = SortBy.HighToLow; Refresh(true); break; case 238: // Non Auction Item Criteria.Auction = false; Refresh(true); break; case 239: // Auction Item Criteria.Auction = true; Refresh(true); break; case 1154512: // Set Min/Max price TextRelay tr1 = info.GetTextEntry(7); TextRelay tr2 = info.GetTextEntry(8); if (tr1 != null && tr1.Text != null) { string text = tr1.Text.Trim(); if (int.TryParse(text, out int min)) { Criteria.MinPrice = min; } } if (tr2 != null && tr2.Text != null) { string text = tr2.Text.Trim(); if (int.TryParse(text, out int max)) { Criteria.MaxPrice = max; } } Criteria.EntryPrice = true; Refresh(true); break; default: if (info.ButtonID > 1000) { SearchDetail toRemove = Criteria.Details[info.ButtonID - 1001]; if (toRemove.Category == Category.Equipment) { Criteria.SearchType = Layer.Invalid; } Criteria.Details.Remove(toRemove); Refresh(true); } else { if (Criteria.Details.Count >= 20) { SendGump(new VendorSearchGump(User, 1154681)); // You may not add any more search criteria items. } var criteria = SearchCriteriaCategory.AllCategories.SelectMany(x => x.Criteria, (x, c) => new { x.Category, c.Object, c.Cliloc, c.PropCliloc }).ToList()[info.ButtonID - 50]; object o = criteria.Object; int value = 0; TextRelay valuetext = info.GetTextEntry(info.ButtonID - 40); if (valuetext != null) { value = Math.Max(o is AosAttribute && (AosAttribute)o == AosAttribute.CastSpeed ? -1 : 0, Utility.ToInt32(valuetext.Text)); } Criteria.TryAddDetails(o, criteria.Cliloc, criteria.PropCliloc, value, criteria.Category); Refresh(true); } break; } }
public int GetValueForDetails(object o) { SearchDetail detail = Details.FirstOrDefault(d => d.Attribute == o); return(detail != null ? detail.Value : 0); }
public override void OnResponse(NetState state, RelayInfo info) { if (info.ButtonID != 0) { TextRelay searchname = info.GetTextEntry(0); if (searchname != null && !String.IsNullOrEmpty(searchname.Text)) { string text = searchname.Text.Trim(); if (Criteria.SearchName == null || text.ToLower() != Criteria.SearchName.ToLower()) { Criteria.SearchName = searchname.Text; } } } switch (info.ButtonID) { case 0: break; case 1: // Set Min/Max price TextRelay tr1 = info.GetTextEntry(1); TextRelay tr2 = info.GetTextEntry(2); if (tr1 != null && tr1.Text != null) { string text = tr1.Text.Trim(); int min = 0; if (int.TryParse(text, out min)) { Criteria.MinPrice = min; } } if (tr2 != null && tr2.Text != null) { string text = tr2.Text.Trim(); int max = 0; if (int.TryParse(text, out max)) { Criteria.MaxPrice = max; } } Refresh(); break; case 2: // Low to High Criteria.SortBy = SortBy.LowToHigh; Refresh(); break; case 3: // High to Low Criteria.SortBy = SortBy.HighToLow; Refresh(); break; case 4: // Nothing, resend gump Criteria.SortBy = SortBy.None; Refresh(); break; case 5: // Clear Criteria Criteria.Reset(); Refresh(); break; case 6: // Search User.CloseGump(typeof(SearchResultsGump)); if (Criteria.IsEmpty) { Refresh(false, true); } else { List <VendorItem> list = VendorSearch.DoSearch(User, Criteria); if (list == null || list.Count == 0) { Refresh(true); } else { Refresh(); User.SendGump(new SearchResultsGump(User, list)); } } break; case 7: // remove item name Criteria.SearchName = null; Refresh(); break; default: if (info.ButtonID >= 100 && info.ButtonID < 200) { ChosenCategory = info.ButtonID - 100; Refresh(); } else if (info.ButtonID >= 200 && info.ButtonID < 300 && ChosenCategory >= 0 && ChosenCategory < VendorSearch.Categories.Count) { int index = info.ButtonID - 200; SearchCategory category = VendorSearch.Categories[ChosenCategory]; Tuple <object, int> data = category.Objects[index]; object o = data.Item1; int value = 0; TextRelay valuetext = info.GetTextEntry(index + 400); if (valuetext != null) { value = Math.Max(o is AosAttribute && (AosAttribute)o == AosAttribute.CastSpeed ? -1 : 0, Utility.ToInt32(valuetext.Text)); } Criteria.TryAddDetails(o, data.Item2, value, category.Category); Refresh(); } else if (info.ButtonID >= 300 && info.ButtonID - 300 >= 0 && info.ButtonID - 300 < Criteria.Details.Count) { SearchDetail toRemove = Criteria.Details[info.ButtonID - 300]; if (toRemove.Category == Category.Equipment) { Criteria.SearchType = Layer.Invalid; } Criteria.Details.Remove(toRemove); Refresh(); } break; } }
public static List <SearchItem> DoSearch(SearchCriteria criteria) { if (criteria == null || PlayerVendor.PlayerVendors == null || PlayerVendor.PlayerVendors.Count == 0) { return(null); } List <SearchItem> list = new List <SearchItem>(); SearchDetail first = null; for (var index = 0; index < criteria.Details.Count; index++) { var d = criteria.Details[index]; if (d.Attribute is Misc misc && misc == Misc.ExcludeFel) { first = d; break; } } bool excludefel = first != null; for (var i = 0; i < PlayerVendor.PlayerVendors.Count; i++) { PlayerVendor pv = PlayerVendor.PlayerVendors[i]; if (pv.Map != Map.Internal && pv.Map != null && pv.Backpack != null && pv.VendorSearch && pv.Backpack.Items.Count > 0 && (!excludefel || pv.Map != Map.Felucca)) { List <Item> items = GetItems(pv); for (var index = 0; index < items.Count; index++) { Item item = items[index]; VendorItem vendorItem = pv.GetVendorItem(item); int price = 0; bool isChild = false; if (vendorItem != null) { price = vendorItem.Price; } else if (item.Parent is Container parent) { vendorItem = GetParentVendorItem(pv, parent); if (vendorItem != null) { isChild = true; price = vendorItem.Price; } } if (price > 0 && CheckMatch(item, price, criteria)) { list.Add(new SearchItem(pv, item, price, isChild)); } } ColUtility.Free(items); } } switch (criteria.SortBy) { case SortBy.LowToHigh: list = list.OrderBy(vi => vi.Price).ToList(); break; case SortBy.HighToLow: list = list.OrderBy(vi => - vi.Price).ToList(); break; } return(list); }
public override void OnResponse(RelayInfo info) { NoCrit = false; NoFind = false; if (info.ButtonID != 0) { if (!VendorSearch.CanSearch(User)) { User.SendLocalizedMessage(1154680); //Before using vendor search, you must be in a justice region or a safe log-out location (such as an inn or a house which has you on its Owner, Co-owner, or Friends list). return; } TextRelay searchname = info.GetTextEntry(0); if (searchname != null && !String.IsNullOrEmpty(searchname.Text)) { string text = searchname.Text.Trim(); if (Criteria.SearchName == null || text.ToLower() != Criteria.SearchName.ToLower()) { Criteria.SearchName = searchname.Text; } } } switch (info.ButtonID) { case 0: break; case 1: // Set Min/Max price TextRelay tr1 = info.GetTextEntry(1); TextRelay tr2 = info.GetTextEntry(2); if (tr1 != null && tr1.Text != null) { string text = tr1.Text.Trim(); int min = 0; if (int.TryParse(text, out min)) { Criteria.MinPrice = min; } } if (tr2 != null && tr2.Text != null) { string text = tr2.Text.Trim(); int max = 0; if (int.TryParse(text, out max)) { Criteria.MaxPrice = max; } } Criteria.EntryPrice = true; Refresh(); break; case 2: // Low to High Criteria.SortBy = SortBy.LowToHigh; Refresh(); break; case 3: // High to Low Criteria.SortBy = SortBy.HighToLow; Refresh(); break; case 4: // Nothing, resend gump Refresh(); break; case 5: // Clear Criteria Criteria.Reset(); Refresh(); break; case 6: // Search User.CloseGump(typeof(SearchResultsGump)); if (Criteria.IsEmpty) { NoCrit = true; Refresh(); } else { List <VendorItem> list = VendorSearch.DoSearch(User, Criteria); if (list == null || list.Count == 0) { NoFind = true; Refresh(); } else { Refresh(); BaseGump.SendGump(new SearchResultsGump(User, list)); } } break; case 7: // remove item name Criteria.SearchName = null; Refresh(); break; case 8: // remove price entry Criteria.EntryPrice = false; Refresh(); break; default: if (info.ButtonID >= 100 && info.ButtonID < 200) { ChosenCategory = info.ButtonID - 100; Refresh(); } else if (info.ButtonID >= 200 && info.ButtonID < 300 && ChosenCategory >= 0 && ChosenCategory < VendorSearch.Categories.Count) { int index = info.ButtonID - 200; SearchCategory category = VendorSearch.Categories[ChosenCategory]; Tuple <object, int> data = category.Objects[index]; object o = data.Item1; int value = 0; TextRelay valuetext = info.GetTextEntry(index + 400); if (valuetext != null) { value = Math.Max(o is AosAttribute && (AosAttribute)o == AosAttribute.CastSpeed ? -1 : 0, Utility.ToInt32(valuetext.Text)); } Criteria.TryAddDetails(o, data.Item2, value, category.Category); Refresh(); } else if (info.ButtonID >= 300 && info.ButtonID - 300 >= 0 && info.ButtonID - 300 < Criteria.Details.Count) { SearchDetail toRemove = Criteria.Details[info.ButtonID - 300]; if (toRemove.Category == Category.Equipment) { Criteria.SearchType = Layer.Invalid; } Criteria.Details.Remove(toRemove); Refresh(); } break; } }