public void ItemSlotAction(List <BodyLocation> slots, Action <ItemReader, D2Unit> action) { if (reader == null) { return; } // Add all items found in the slots. bool FilterSlots(D2ItemData data) => slots.FindIndex(x => x == data.BodyLoc && data.InvPage == InventoryPage.Equipped) >= 0; foreach (var item in inventoryReader.EnumerateInventory(FilterSlots)) { action?.Invoke(inventoryReader.ItemReader, item); } }
public void ItemSlotAction(List <BodyLocation> slots, Action <ItemReader, D2Unit> action) { if (reader == null) { return; } var inventoryReader = new InventoryReader(reader, memory); // Add all items found in the slots. Func <D2ItemData, bool> filterSlots = data => slots.FindIndex(x => x == data.BodyLoc && data.InvPage == InventoryPage.Equipped) >= 0; foreach (var item in inventoryReader.EnumerateInventory(filterSlots)) { if (action != null) { action(inventoryReader.ItemReader, item); } } }
private void UpdateAutoSplits(GameInfo gameInfo, Character character) { foreach (AutoSplit autosplit in main.Settings.Autosplits) { if (autosplit.IsReached) { continue; } if (autosplit.Type != AutoSplit.SplitType.Special) { continue; } if (autosplit.Value == (int)AutoSplit.Special.GameStart) { CompleteAutoSplit(autosplit, character); } if (autosplit.Value == (int)AutoSplit.Special.Clear100Percent && character.CompletedQuestCounts[gameInfo.Game.Difficulty] == D2QuestHelper.Quests.Count && autosplit.MatchesDifficulty(gameInfo.Game.Difficulty)) { CompleteAutoSplit(autosplit, character); } if (autosplit.Value == (int)AutoSplit.Special.Clear100PercentAllDifficulties && character.CompletedQuestCounts[0] == D2QuestHelper.Quests.Count && character.CompletedQuestCounts[1] == D2QuestHelper.Quests.Count && character.CompletedQuestCounts[2] == D2QuestHelper.Quests.Count) { CompleteAutoSplit(autosplit, character); } } bool haveUnreachedCharLevelSplits = false; bool haveUnreachedAreaSplits = false; bool haveUnreachedItemSplits = false; bool haveUnreachedQuestSplits = false; foreach (AutoSplit autosplit in main.Settings.Autosplits) { if (autosplit.IsReached || !autosplit.MatchesDifficulty(gameInfo.Game.Difficulty)) { continue; } switch (autosplit.Type) { case AutoSplit.SplitType.CharLevel: haveUnreachedCharLevelSplits = true; break; case AutoSplit.SplitType.Area: haveUnreachedAreaSplits = true; break; case AutoSplit.SplitType.Item: haveUnreachedItemSplits = true; break; case AutoSplit.SplitType.Quest: haveUnreachedQuestSplits = true; break; } } // if no unreached splits, return if (!(haveUnreachedCharLevelSplits || haveUnreachedAreaSplits || haveUnreachedItemSplits || haveUnreachedQuestSplits)) { return; } List <int> itemsIds = new List <int>(); int area = -1; if (haveUnreachedItemSplits) { // Get all item IDs. var inventoryReader = new InventoryReader(reader, memory); itemsIds = (from item in inventoryReader.EnumerateInventory() select item.eClass).ToList(); } if (haveUnreachedAreaSplits) { area = reader.ReadByte(memory.Address.Area, AddressingMode.Relative); } ushort[] questBuffer = null; if (haveUnreachedQuestSplits) { questBuffer = GetQuestBuffer(gameInfo.PlayerData, gameInfo.Game.Difficulty); } foreach (AutoSplit autosplit in main.Settings.Autosplits) { if (autosplit.IsReached || !autosplit.MatchesDifficulty(gameInfo.Game.Difficulty)) { continue; } switch (autosplit.Type) { case AutoSplit.SplitType.CharLevel: if (autosplit.Value <= character.Level) { CompleteAutoSplit(autosplit, character); } break; case AutoSplit.SplitType.Area: if (autosplit.Value == area) { CompleteAutoSplit(autosplit, character); } break; case AutoSplit.SplitType.Item: if (itemsIds.Contains(autosplit.Value)) { CompleteAutoSplit(autosplit, character); } break; case AutoSplit.SplitType.Quest: if (D2QuestHelper.IsQuestComplete((D2QuestHelper.Quest)autosplit.Value, questBuffer)) { CompleteAutoSplit(autosplit, character); } break; } } }
public void UpdateItemStats(ProcessMemoryReader r, D2MemoryTable memory, D2Unit pl) { InventoryReader inventoryReader = new InventoryReader(r, memory); UnitReader unitReader = new UnitReader(r, memory); // Build filter to get only equipped items. Func <D2ItemData, bool> filter = data => data.BodyLoc != BodyLocation.None; foreach (D2Unit item in inventoryReader.EnumerateInventory(filter)) { List <D2Stat> itemStats = unitReader.GetStats(item); if (itemStats == null) { continue; } StringBuilder statBuilder = new StringBuilder(); statBuilder.Append(inventoryReader.ItemReader.GetFullItemName(item)); statBuilder.Append("\n"); List <string> magicalStrings = inventoryReader.ItemReader.GetMagicalStrings(item); foreach (string str in magicalStrings) { statBuilder.Append(" "); statBuilder.Append(str); statBuilder.Append("\n"); } Control c = null; D2ItemData itemData = r.Read <D2ItemData>(item.UnitData); switch (itemData.BodyLoc) { case BodyLocation.Head: c = tabPageHead; break; case BodyLocation.Amulet: c = tabPageAmulet; break; case BodyLocation.BodyArmor: c = tabPageBody; break; case BodyLocation.PrimaryRight: c = tabPageWeaponRight; break; case BodyLocation.PrimaryLeft: c = tabPageWeaponLeft; break; case BodyLocation.RingRight: c = tabPageRingRight; break; case BodyLocation.RingLeft: c = tabPageRingLeft; break; //case BodyLocation.SecondaryLeft: c = tabPageRingRight; break; //case BodyLocation.SecondaryRight: c = tabPageRingLeft; break; case BodyLocation.Belt: c = tabPageBelt; break; case BodyLocation.Boots: c = tabPageFeet; break; case BodyLocation.Gloves: c = tabPageHand; break; } if (c != null) { if (c.Controls.Count == 0) { c.Invoke(new Action(delegate() { c.Controls.Add(new RichTextBox()); c.Controls[0].Dock = DockStyle.Fill; })); } c.Controls[0].Invoke(new Action(() => c.Controls[0].Text = statBuilder.ToString())); } } }