public int GetItemAmount(int id) { InvEntry e = GetItemEntry(id); if (e == null) { return(0); } return(e.amount); }
private static IEnumerable <InvEntry> GetInvList(string html) { var invList = new List <InvEntry>(); const string patternStartInv = "</b></font></td></tr>"; var pos = html.IndexOf(patternStartInv, StringComparison.Ordinal); if (pos == -1) { return(invList); } pos += patternStartInv.Length; while (true) { const string parrernStartTr = "<tr><td bgcolor=#F5F5F5>"; if (!html.Substring(pos, parrernStartTr.Length).StartsWith(parrernStartTr, StringComparison.Ordinal)) { break; } const string parrernEndTr = "<td bgcolor=#FCFAF3><img src=http://image.neverlands.ru/1x1.gif width=5 height=1></td></tr></table></td></tr></table></td></tr>"; var posEnd = html.IndexOf(parrernEndTr, pos, StringComparison.Ordinal); if (posEnd == -1) { const string parrernEndTrShort = "<img src=http://image.neverlands.ru/1x1.gif width=1 height=5></td></tr></table></td></tr>"; posEnd = html.IndexOf(parrernEndTrShort, pos, StringComparison.Ordinal); if (posEnd == -1) { return(invList); } posEnd += parrernEndTrShort.Length; } else { posEnd += parrernEndTr.Length; } var htmlEntry = html.Substring(pos, posEnd - pos); var invEntry = new InvEntry(htmlEntry); invList.Add(invEntry); pos = posEnd; } return(invList); }
public void AddItem(int id, int amount) { InvEntry e = GetItemEntry(id); if (e == null) { if (amount < 0) { return; } e = new InvEntry(id, amount); state.inventory.Add(e); } else { e.amount += amount; if (e.amount <= 0) { state.inventory.Remove(e); } } }
private static string MainPhpInv(string html) { const string patternStartInv = "</b></font></td></tr>"; var pos = html.IndexOf(patternStartInv, StringComparison.Ordinal); if (pos == -1) { return(html); } pos += patternStartInv.Length; var posStartInv = pos; InvList.Clear(); while (true) { const string parrernStartTr = "<tr><td bgcolor=#F5F5F5>"; if (!html.Substring(pos, parrernStartTr.Length).StartsWith(parrernStartTr, StringComparison.Ordinal)) { break; } const string parrernEndTr = "<td bgcolor=#FCFAF3><img src=http://image.neverlands.ru/1x1.gif width=5 height=1></td></tr></table></td></tr></table></td></tr>"; var posEnd = html.IndexOf(parrernEndTr, pos, StringComparison.Ordinal); if (posEnd == -1) { const string parrernEndTrShort = "<img src=http://image.neverlands.ru/1x1.gif width=1 height=5></td></tr></table></td></tr>"; posEnd = html.IndexOf(parrernEndTrShort, pos, StringComparison.Ordinal); if (posEnd == -1) { return(html); } posEnd += parrernEndTrShort.Length; } else { posEnd += parrernEndTr.Length; } var htmlEntry = html.Substring(pos, posEnd - pos); var invEntry = new InvEntry(htmlEntry); if ( invEntry.IsExpired() || (!string.IsNullOrEmpty(AppVars.BulkDropThing) && !string.IsNullOrEmpty(AppVars.BulkDropPrice) && AppVars.BulkDropThing.Equals(invEntry.DropThing, StringComparison.CurrentCultureIgnoreCase) && AppVars.BulkDropPrice.Equals(invEntry.DropPrice, StringComparison.CurrentCultureIgnoreCase))) { html = BuildRedirect($"Выбрасывание предмета <b>«{invEntry.DropThing}»</b>...", invEntry.DropLink); return(html); } if ( !string.IsNullOrEmpty(invEntry.PssLink) && !string.IsNullOrEmpty(AppVars.BulkSellThing) && !string.IsNullOrEmpty(invEntry.PssThing) && (AppVars.BulkSellThing.Equals(invEntry.PssThing)) && (AppVars.BulkSellPrice == invEntry.PssPrice) ) { AppVars.BulkSellSum += AppVars.BulkSellPrice; var messageSell = $"Продажа предмета <b>«{invEntry.PssThing}»</b>. Выручка {AppVars.BulkSellSum} NV..."; html = BuildRedirect(messageSell, invEntry.PssLink); return(html); } InvList.Add(invEntry); pos = posEnd; } if (!string.IsNullOrEmpty(AppVars.BulkDropThing)) { var messageBulkDropFinished = $"Выбрасывание пачки <b>«{AppVars.BulkDropThing}»</b> завершено."; try { if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new UpdateChatDelegate(AppVars.MainForm.UpdateChat), messageBulkDropFinished); } } catch (InvalidOperationException) { } AppVars.BulkDropThing = string.Empty; } if ( !string.IsNullOrEmpty(AppVars.BulkSellThing) ) { var messageBulkSellFinished = $"Продажа пачки <b>«{AppVars.BulkSellThing}»</b> завершена. Выручка составила <b>{AppVars.BulkSellSum}</b> NV."; try { if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new UpdateChatDelegate(AppVars.MainForm.UpdateChat), messageBulkSellFinished); } } catch (InvalidOperationException) { } AppVars.BulkSellThing = string.Empty; } if (InvList.Count > 1) { // Удаляем дубли if (AppVars.Profile.DoInvPack) { for (var indexFirst = 0; indexFirst < (InvList.Count - 1); indexFirst++) { for (var indexSecond = indexFirst + 1; indexSecond < InvList.Count; indexSecond++) { if (InvList[indexFirst].CompareTo(InvList[indexSecond]) != 0) { continue; } if (InvList[indexFirst].CompareDolg(InvList[indexSecond]) > 0) { InvList[indexFirst] = (InvEntry)InvList[indexSecond].Clone(); } InvList[indexFirst].Inc(); InvList.RemoveAt(indexSecond); indexSecond--; } } } } // Вставка кнопки массовой продажи for (var index = 0; index < InvList.Count; index++) { InvList[index].AddBulkSell(); } // Вставка кнопки массового выброса for (var index = 0; index < InvList.Count; index++) { InvList[index].AddBulkDelete(); } // Сортировка if (AppVars.Profile.DoInvSort) { var invComparer = new InvComparer(); InvList.Sort(invComparer); } var sb = new StringBuilder(); for (var index = 0; index < InvList.Count; index++) { sb.Append(InvList[index].Build()); } var sbnew = new StringBuilder(html.Substring(0, posStartInv)); sbnew.Append(sb); sbnew.Append(html.Substring(pos)); return(sbnew.ToString()); }