private static bool AssignMagic_Gem_New(WorldObject wo, TreasureDeath profile, TreasureRoll roll)
        {
            // TODO: move to standard AssignMagic() pipeline

            var spell = SpellSelectionTable.Roll(1);

            var spellLevel = SpellLevelChance.Roll(profile.Tier);

            var spellLevels = SpellLevelProgression.GetSpellLevels(spell);

            if (spellLevels == null || spellLevels.Count != 8)
            {
                log.Error($"AssignMagic_Gem_New({wo.Name}, {profile.TreasureType}, {roll.ItemType}) - unknown spell {spell}");
                return(false);
            }

            var finalSpellId = spellLevels[spellLevel - 1];

            wo.SpellDID = (uint)finalSpellId;

            var _spell = new Server.Entity.Spell(finalSpellId);

            // retail spellcraft was capped at 370
            wo.ItemSpellcraft = Math.Min((int)_spell.Power, 370);

            var castableMana = (int)_spell.BaseMana * 5;

            wo.ItemMaxMana = RollItemMaxMana_New(wo, roll, castableMana);
            wo.ItemCurMana = wo.ItemMaxMana;

            // verified
            wo.ItemManaCost = castableMana;

            return(true);
        }
        private static List <SpellId> RollEnchantments(WorldObject wo, TreasureDeath profile, TreasureRoll roll)
        {
            /*if (wo.SpellSelectionCode == null)
             * {
             *  log.Warn($"RollEnchantments({wo.Name}) - missing spell selection code / PropertyInt.TsysMutationData");
             *  return null;
             * }*/

            // test method: determine spell selection code dynamically
            var spellSelectionCode = GetSpellSelectionCode_Dynamic(wo, roll);

            if (spellSelectionCode == 0)
            {
                return(null);
            }

            //Console.WriteLine($"Using spell selection code {spellSelectionCode} for {wo.Name}");

            var numEnchantments = RollNumEnchantments(wo, profile, roll);

            if (numEnchantments <= 0)
            {
                return(null);
            }

            var numAttempts = numEnchantments * 3;

            var spells = new HashSet <SpellId>();

            for (var i = 0; i < numAttempts && spells.Count < numEnchantments; i++)
            {
                var spell = SpellSelectionTable.Roll(spellSelectionCode);

                if (spell != SpellId.Undef)
                {
                    spells.Add(spell);
                }
            }

            return(RollSpellLevels(wo, profile, spells));
        }