Example #1
0
        public TreasureWieldedTable(List <TreasureWielded> items)
        {
            Sets = new List <TreasureWieldedSet>();

            TreasureWieldedSet currentSet = null;

            for (var idx = 0; idx < items.Count; idx++)
            {
                var item = items[idx];
                if (item.SetStart)
                {
                    currentSet = new TreasureWieldedSet(items, idx);
                    Sets.Add(currentSet);
                    var totalNestedItems = currentSet.TotalNestedItems;
                    idx += totalNestedItems - 1;
                }
                else
                {
                    Console.WriteLine($"Warning: started parsing set with no SetStart on line {idx}");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Parses 1 TreasureWielded set from a TreasuredWielded table
        /// </summary>
        /// <param name="items">The list of items in the complete TreasureWielded table</param>
        /// <param name="startIdx">The start index of the set to parse</param>
        public TreasureWieldedSet(List <TreasureWielded> items, int startIdx, int depth = 0)
        {
            Items = new List <TreasureWieldedNode>();

            // add set start item
            var item = items[startIdx];

            if (!item.SetStart)
            {
                Console.WriteLine($"Warning: TreasureWieldedSet constructor called with startIdx {startIdx}, and SetStart=0");
            }

            var node = new TreasureWieldedNode(items, startIdx);

            Items.Add(node);
            //Console.WriteLine($"Parsing startSet item {item.WeenieClassId} @ idx {startIdx}, depth {depth}");

            // continue parsing
            for (var idx = startIdx + 1; idx < items.Count; idx++)
            {
                var prevItem = items[idx - 1];
                item = items[idx];

                // handle subsets
                if (prevItem.HasSubSet)
                {
                    if (item.SetStart)
                    {
                        var subset = new TreasureWieldedSet(items, idx, depth + 1);
                        node.Subset = subset;
                        var totalItems = subset.TotalNestedItems;
                        idx += totalItems - 1;
                    }
                    else
                    {
                        Console.WriteLine($"Warning: Subset detected on line {idx - 1}, but next idx is not a set start");
                    }
                }
                else
                {
                    // handle regular items
                    if (item.SetStart)
                    {
                        if (item.ContinuesPreviousSet)
                        {
                            // ensure subset parsed
                            if (node.Subset != null)
                            {
                                node = new TreasureWieldedNode(items, idx);
                                Items.Add(node);
                            }
                            else
                            {
                                if (depth == 0)
                                {
                                    Console.WriteLine($"Warning: continuing a previous set on line {idx}, but no subset found!");
                                }
                                else
                                {
                                    break;  // back to parent
                                }
                            }
                        }
                        else
                        {
                            // set completed
                            break;
                        }
                    }
                    else
                    {
                        // normal set continues...
                        node = new TreasureWieldedNode(items, idx);
                        Items.Add(node);
                    }
                }
            }
        }