public void UseMagnifyingGlass(short nMagnifyingPOS, short nEquipPOS) { if (Parent.Stats.nHP <= 0) { return; } var pTemplate = InventoryManipulator.GetItem(Parent, InventoryType.Consume, nMagnifyingPOS).Template as ConsumeItemTemplate; var pEquip = InventoryManipulator.GetItem(Parent, InventoryType.Equip, nEquipPOS) as GW_ItemSlotEquip; if (pEquip is null || pTemplate is null) { return; } if (pEquip.HasVisiblePotential) { return; } if (pEquip.nGrade == PotentialGradeCode.Normal) { return; } if (pEquip.CashItem) { return; } if (!ItemLogic.MagnifyingGlass(pTemplate.TemplateId)) { return; } if (pEquip.EquipTemplate.ReqLevel > ItemConstants.GlassRevealLevel(pTemplate.TemplateId)) { return; } if (pEquip.nOption1 == 0) { pEquip.nGrade = PotentialGradeCode.Visible_Rare; // cant get epic on first reveal } else { switch (pEquip.nGrade) { case PotentialGradeCode.Hidden_Rare: if (Constants.Rand.NextDouble() < RateConstants.ItemPotential_EpicOdds) { pEquip.nGrade = PotentialGradeCode.Visible_Epic; } else { pEquip.nGrade = PotentialGradeCode.Visible_Rare; } break; case PotentialGradeCode.Hidden_Epic: if (Constants.Rand.NextDouble() < RateConstants.ItemPotential_UniqueOdds) { pEquip.nGrade = PotentialGradeCode.Visible_Unique; } else { pEquip.nGrade = PotentialGradeCode.Visible_Epic; } break; case PotentialGradeCode.Hidden_Unique: pEquip.nGrade = PotentialGradeCode.Visible_Unique; break; } } var potentialCollection = MasterManager.ItemOptionTemplates .GetAll() .Where(p => p.ReqLevel <= pEquip.EquipTemplate.ReqLevel && // throw out incorrect level range ItemConstants.OptionTypeFitsEquipType(pEquip.nItemID, p.OptionType) && // throw out incorrect equip types ItemConstants.OptionGradeFitsEquipGrade(p.TemplateId, pEquip.nGrade) && // throw out incorrect grade codes p.OptionType != 90 // these show "Hidden" for some reason o___o ); var itemOptionTemplates = potentialCollection as ItemOptionTemplate[] ?? potentialCollection.ToArray(); if (itemOptionTemplates.Length <= 3) { throw new IndexOutOfRangeException($"unable to put potential on item. CID: {Parent.dwId} | EPOS: {nEquipPOS} | Grade: {nameof(pEquip.nGrade)} | Level: {pEquip.EquipTemplate.ReqLevel}"); } var lines = new List <int> { itemOptionTemplates.Random().TemplateId, itemOptionTemplates.Random().TemplateId }; lines.Sort(); // so the potential grades are in order if (pEquip.nOption3 == 0 || pEquip.nOption1 == 0) { var odds = pEquip.nOption1 == 0 ? RateConstants.ItemPotential_ThirdLineFirstReveal : RateConstants.ItemPotential_ThirdLineOdds; // lower odds for third line on first reveal if (Constants.Rand.NextDouble() < odds) { pEquip.nOption3 = (short)lines[0]; } } else // option1 > 0 && option3 != 0 { pEquip.nOption3 = (short)lines[0]; } pEquip.nOption2 = (short)lines[1]; // recalculate to ensure the first option is always the same grade as the equip pEquip.nOption1 = (short)itemOptionTemplates .Where(p => ItemConstants.GradeCodeByID(p.TemplateId) == pEquip.nGrade && p.TemplateId >= lines[1]).Random() .TemplateId; pEquip.sTitle = $"{pEquip.nOption1}|{pEquip.nOption2}"; Parent.Modify.Inventory(ctx => { ctx.UpdateEquipInformation(pEquip, nEquipPOS); }); InventoryManipulator.RemoveFrom(Parent, InventoryType.Consume, nMagnifyingPOS); Parent.SendPacket(pEquip.ShowItemReleaseEffect(Parent.dwId, nEquipPOS)); }