private D2StatList FindStatListNode(D2Unit unit, uint state) { if (unit.StatListNode.IsNull) { return(null); } var statNodeEx = reader.Read <D2StatListEx>(unit.StatListNode); // Get the appropriate stat node. DataPointer statsPointer = statNodeEx.pMyStats; if (statNodeEx.ListFlags.HasFlag(StatListFlag.HasCompleteStats)) { statsPointer = statNodeEx.pMyLastList; } if (statsPointer.IsNull) { return(null); } // Get previous node in the linked list (belonging to this list). D2StatList getPreviousNode(D2StatList x) { if (x.PreviousList.IsNull) { return(null); } return(reader.Read <D2StatList>(x.PreviousList)); } // Iterate stat nodes until we find the node we're looking for. D2StatList statNode = reader.Read <D2StatList>(statsPointer); for (; statNode != null; statNode = getPreviousNode(statNode)) { if (statNode.State != state) { continue; } if (statNode.Flags.HasFlag(StatListFlag.HasProperties)) { break; } } return(statNode); }
private void CombineNodeStats(List <D2Stat> stats, D2StatList node) { if (node == null || node.Stats.Address.IsNull) { return; } D2Stat[] nodeStats = reader.ReadArray <D2Stat>(node.Stats.Address, node.Stats.Length); foreach (D2Stat nodeStat in nodeStats) { int index = stats.FindIndex(x => x.HiStatID == nodeStat.HiStatID && x.LoStatID == nodeStat.LoStatID); if (index >= 0) { // Already have the stat, increase value. stats[index].Value += nodeStat.Value; } else { // Stat not found, add to list. stats.Add(nodeStat); } } }