コード例 #1
0
    private static void HandleUnlockSocket(GameSession session, PacketReader packet)
    {
        long        itemUid      = packet.ReadLong();
        byte        fodderAmount = packet.ReadByte();
        List <long> fodderUids   = new();

        for (int i = 0; i < fodderAmount; i++)
        {
            long fodderUid = packet.ReadLong();
            fodderUids.Add(fodderUid);
        }

        Inventory inventory = session.Player.Inventory;

        if (!inventory.Items.ContainsKey(itemUid))
        {
            session.Send(ItemSocketSystemPacket.Notice((int)ItemSocketSystemNotice.ItemIsNotInYourInventory));
            return;
        }
        Item equip = inventory.Items[itemUid];
        int  equipUnlockedSlotCount = equip.Stats.GemSockets.Count(x => x.IsUnlocked);

        foreach (long uid in fodderUids)
        {
            if (!inventory.Items.ContainsKey(uid))
            {
                session.Send(ItemSocketSystemPacket.Notice((int)ItemSocketSystemNotice.ItemIsNotInYourInventory));
                return;
            }

            Item fodder = inventory.Items[uid];
            int  fodderUnlockedSlotCount = fodder.Stats.GemSockets.Count(x => x.IsUnlocked);
            if (equipUnlockedSlotCount == fodderUnlockedSlotCount)
            {
                continue;
            }

            session.Send(ItemSocketSystemPacket.Notice((int)ItemSocketSystemNotice.CannotBeUsedAsMaterial));
            return;
        }

        // get socket slot to unlock
        int slot = equip.Stats.GemSockets.FindIndex(0, equip.Stats.GemSockets.Count, x => !x.IsUnlocked);

        if (slot < 0)
        {
            return;
        }

        // fragmment cost. hard coded into the client?
        int crystalFragmentCost = 0;

        if (slot == 0)
        {
            crystalFragmentCost = 400;
        }
        else if (slot is 1 or 2)
        {
            crystalFragmentCost = 600;
        }

        int crystalFragmentsTotalAmount = 0;
        List <KeyValuePair <long, Item> > crystalFragments = inventory.Items.Where(x => x.Value.Tag == "CrystalPiece").ToList();

        crystalFragments.ForEach(x => crystalFragmentsTotalAmount += x.Value.Amount);

        if (crystalFragmentsTotalAmount < crystalFragmentCost)
        {
            return;
        }

        foreach ((long uid, Item item) in crystalFragments)
        {
            if (item.Amount >= crystalFragmentCost)
            {
                inventory.ConsumeItem(session, uid, crystalFragmentCost);
                break;
            }

            crystalFragmentCost -= item.Amount;
            inventory.ConsumeItem(session, uid, item.Amount);
        }
        foreach (long uid in fodderUids)
        {
            inventory.ConsumeItem(session, uid, 1);
        }

        equip.Stats.GemSockets[slot].IsUnlocked = true;
        List <GemSocket> unlockedSockets = equip.Stats.GemSockets.Where(x => x.IsUnlocked).ToList();

        session.Send(ItemSocketSystemPacket.UnlockSocket(equip, (byte)slot, unlockedSockets));
    }
コード例 #2
0
    private static void HandleUnlockSocket(GameSession session, PacketReader packet)
    {
        long        itemUid      = packet.ReadLong();
        byte        fodderAmount = packet.ReadByte();
        List <long> fodderUids   = new();

        for (int i = 0; i < fodderAmount; i++)
        {
            long fodderUid = packet.ReadLong();
            fodderUids.Add(fodderUid);
        }

        IInventory inventory = session.Player.Inventory;

        if (!inventory.HasItem(itemUid))
        {
            session.Send(ItemSocketSystemPacket.Notice((int)ItemSocketSystemNotice.ItemIsNotInYourInventory));
            return;
        }
        Item equip = inventory.GetByUid(itemUid);
        int  equipUnlockedSlotCount = equip.Stats.GemSockets.Count(x => x.IsUnlocked);

        foreach (long uid in fodderUids)
        {
            if (!inventory.HasItem(uid))
            {
                session.Send(ItemSocketSystemPacket.Notice((int)ItemSocketSystemNotice.ItemIsNotInYourInventory));
                return;
            }

            Item fodder = inventory.GetByUid(uid);
            int  fodderUnlockedSlotCount = fodder.Stats.GemSockets.Count(x => x.IsUnlocked);
            if (equipUnlockedSlotCount == fodderUnlockedSlotCount)
            {
                continue;
            }

            session.Send(ItemSocketSystemPacket.Notice((int)ItemSocketSystemNotice.CannotBeUsedAsMaterial));
            return;
        }

        // get socket slot to unlock
        int slot = equip.Stats.GemSockets.FindIndex(0, equip.Stats.GemSockets.Count, x => !x.IsUnlocked);

        if (slot < 0)
        {
            return;
        }

        Script   script       = ScriptLoader.GetScript("Functions/calcItemSocketUnlockIngredient");
        DynValue scriptResult = script.RunFunction("calcItemSocketUnlockIngredient", equip.Rarity, slot, (int)equip.InventoryTab);

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

        if (!ConsumeIngredients(session, inventory, ingredientCost, ingredientTag))
        {
            return;
        }

        foreach (long uid in fodderUids)
        {
            inventory.ConsumeItem(session, uid, 1);
        }

        equip.Stats.GemSockets[slot].IsUnlocked = true;
        List <GemSocket> unlockedSockets = equip.Stats.GemSockets.Where(x => x.IsUnlocked).ToList();

        session.Send(ItemSocketSystemPacket.UnlockSocket(equip, (byte)slot, unlockedSockets));
    }