private static void HandleItemSocketScroll(GameSession session, Item item) { ItemSocketScrollMetadata metadata = ItemSocketScrollMetadataStorage.GetMetadata(item.Function.Id); if (metadata is null) { return; } byte socketCount = ItemSocketScrollHelper.GetSocketCount(metadata.Id); int successRate = (int)ItemSocketScrollHelper.GetSuccessRate(metadata.Id) * 10000; session.Send(ItemSocketScrollPacket.OpenWindow(item.Uid, successRate, socketCount)); }
private static void HandleUseScroll(GameSession session, PacketReader packet) { long equipUid = packet.ReadLong(); long scrollUid = packet.ReadLong(); if (!session.Player.Inventory.HasItem(equipUid) && !session.Player.Inventory.HasItem(scrollUid)) { session.Send(ItemSocketScrollPacket.Error((int)ItemSocketScrollError.SelectedItemsNoLongerValid)); return; } Item scroll = session.Player.Inventory.GetByUid(scrollUid); Item equip = session.Player.Inventory.GetByUid(equipUid); ItemSocketScrollMetadata metadata = ItemSocketScrollMetadataStorage.GetMetadata(scroll.Function.Id); if (metadata is null) { session.Send(ItemSocketScrollPacket.Error((int)ItemSocketScrollError.SelectedItemCannotUseScroll)); return; } if (metadata.Rarity != equip.Rarity) { session.Send(ItemSocketScrollPacket.Error((int)ItemSocketScrollError.ItemRarityNotValid)); return; } if (metadata.MinLevel > equip.Level || metadata.MaxLevel < equip.Level) { session.Send(ItemSocketScrollPacket.Error((int)ItemSocketScrollError.ItemLevelNotValid)); return; } if (!metadata.ItemTypes.Contains(equip.Type)) { session.Send(ItemSocketScrollPacket.Error((int)ItemSocketScrollError.NotEligibleItem)); return; } byte socketCount = ItemSocketScrollHelper.GetSocketCount(metadata.Id); int successRate = (int)ItemSocketScrollHelper.GetSuccessRate(metadata.Id) * 10000; if (equip.Stats.GemSockets.Count(x => x.IsUnlocked) >= socketCount) { session.Send(ItemSocketScrollPacket.Error((int)ItemSocketScrollError.SelectedItemCannotHaveMoreSockets)); return; } Random random = Random.Shared; int randomValue = random.Next(0, 10000 + 1); bool scrollSuccess = successRate >= randomValue; if (scrollSuccess) { for (int i = 0; i < socketCount; i++) { if (equip.Stats.GemSockets[i].IsUnlocked) { continue; } equip.Stats.GemSockets[i].IsUnlocked = true; } if (metadata.MakeUntradeable) { equip.RemainingTrades = 0; } } session.Player.Inventory.ConsumeItem(session, scrollUid, 1); session.Send(ItemSocketScrollPacket.UseScroll(equip, successRate, scrollSuccess)); }