private static void HandleExtractGem(GameSession session, PacketReader packet)
    {
        long equipItemUid = packet.ReadLong();
        byte slot         = packet.ReadByte();

        if (!session.Player.Inventory.HasItem(equipItemUid) && !session.Player.Inventory.ItemIsEquipped(equipItemUid))
        {
            session.Send(ItemSocketSystemPacket.Notice((int)ItemSocketSystemNotice.ItemIsNotInYourInventory));
            return;
        }

        Item equipItem = session.Player.Inventory.GetByUid(equipItemUid);

        if (equipItem.Stats.GemSockets[slot].Gemstone == null)
        {
            return;
        }

        Gemstone gemstone = equipItem.Stats.GemSockets[slot].Gemstone;

        int gemLevel = ItemGemstoneUpgradeMetadataStorage.GetGemLevel(gemstone.Id);

        Script   script       = ScriptLoader.GetScript("Functions/calcGetGemStonePutOffPrice");
        DynValue scriptResult = script.RunFunction("calcGetGemStonePutOffPrice", gemLevel, (int)equipItem.InventoryTab);

        string itemTag        = scriptResult.Tuple[0].String;
        int    ingredientCost = (int)scriptResult.Tuple[1].Number;

        if (!ConsumeIngredients(session, session.Player.Inventory, ingredientCost, itemTag))
        {
            return;
        }

        Item gemstoneItem = new(gemstone.Id, rarity : 4)
        {
            IsLocked   = gemstone.IsLocked,
            UnlockTime = gemstone.UnlockTime,
        };

        if (gemstone.OwnerId != 0)
        {
            Player owner = GameServer.PlayerManager.GetPlayerById(gemstone.OwnerId);
            if (owner != null)
            {
                gemstoneItem.OwnerCharacterId   = owner.CharacterId;
                gemstoneItem.OwnerCharacterName = owner.Name;
            }
        }

        // remove gemstone from item
        equipItem.Stats.GemSockets[slot].Gemstone = null;

        session.Player.Inventory.AddItem(session, gemstoneItem, true);
        session.Send(ItemSocketSystemPacket.ExtractGem(equipItemUid, gemstoneItem.Uid, slot));
    }
Exemple #2
0
    private static void HandleExtractGem(GameSession session, PacketReader packet)
    {
        long equipItemUid = packet.ReadLong();
        byte slot         = packet.ReadByte();

        if (!session.Player.Inventory.Items.ContainsKey(equipItemUid))
        {
            session.Send(ItemSocketSystemPacket.Notice((int)ItemSocketSystemNotice.ItemIsNotInYourInventory));
            return;
        }

        Item equipItem = session.Player.Inventory.Items[equipItemUid];

        if (equipItem.Stats.GemSockets[slot].Gemstone == null)
        {
            return;
        }

        Gemstone gemstone = equipItem.Stats.GemSockets[slot].Gemstone;

        // crystal fragment cost
        Item gemstoneItem = new(gemstone.Id)
        {
            IsLocked   = gemstone.IsLocked,
            UnlockTime = gemstone.UnlockTime,
            Rarity     = 4
        };

        if (gemstone.OwnerId != 0)
        {
            Player owner = GameServer.PlayerManager.GetPlayerById(gemstone.OwnerId);
            if (owner != null)
            {
                gemstoneItem.OwnerCharacterId   = owner.CharacterId;
                gemstoneItem.OwnerCharacterName = owner.Name;
            }
        }

        // remove gemstone from item
        equipItem.Stats.GemSockets[slot].Gemstone = null;

        session.Player.Inventory.AddItem(session, gemstoneItem, true);
        session.Send(ItemSocketSystemPacket.ExtractGem(equipItemUid, gemstoneItem.Uid, slot));
    }
}