Esempio n. 1
0
    private static void HandleRepackage(GameSession session, PacketReader packet)
    {
        long ribbonUid        = packet.ReadLong();
        long repackingItemUid = packet.ReadLong();

        Item ribbon        = session.Player.Inventory.GetByUid(ribbonUid);
        Item repackingItem = session.Player.Inventory.GetByUid(repackingItemUid);

        if (repackingItem == null || ribbon == null)
        {
            session.Send(ItemRepackagePacket.Notice((int)ItemRepackageNotice.ItemInvalid));
            return;
        }

        if (repackingItem.RemainingTrades != 0 || repackingItem.IsBound())
        {
            session.Send(ItemRepackagePacket.Notice((int)ItemRepackageNotice.CannotBePackaged));
        }

        int ribbonRequirementAmount = ItemMetadataStorage.GetPropertyMetadata(ribbon.Id).RepackageItemConsumeCount;

        if (ribbonRequirementAmount > ribbon.Amount)
        {
            session.Send(ItemRepackagePacket.Notice((int)ItemRepackageNotice.CannotBePackaged));
            return;
        }

        if (!ItemRepackageMetadataStorage.ItemCanRepackage(ribbon.Function.Id, repackingItem.Level, repackingItem.Rarity))
        {
            session.Send(ItemRepackagePacket.Notice((int)ItemRepackageNotice.ItemInvalid));
            return;
        }

        repackingItem.RemainingRepackageCount -= 1;
        repackingItem.RemainingTrades++;

        session.Player.Inventory.ConsumeItem(session, ribbon.Uid, ribbonRequirementAmount);

        session.Send(ItemRepackagePacket.Repackage(repackingItem));
    }
Esempio n. 2
0
        private static void HandleRepackage(GameSession session, PacketReader packet)
        {
            long ribbonUid        = packet.ReadLong();
            long repackingItemUid = packet.ReadLong();

            Item ribbon        = session.Player.Inventory.Items.Values.FirstOrDefault(x => x.Uid == ribbonUid);
            Item repackingItem = session.Player.Inventory.Items.Values.FirstOrDefault(x => x.Uid == repackingItemUid);

            if (repackingItem == null || ribbon == null)
            {
                session.Send(ItemRepackagePacket.Notice((int)ItemRepackageNotice.ItemInvalid));
                return;
            }

            if (repackingItem.RemainingTrades != 0)
            {
                session.Send(ItemRepackagePacket.Notice((int)ItemRepackageNotice.CannotBePackaged));
            }

            int ribbonRequirementAmount = ItemMetadataStorage.GetRepackageConsumeCount(ribbon.Id);

            if (ribbonRequirementAmount > ribbon.Amount)
            {
                session.Send(ItemRepackagePacket.Notice((int)ItemRepackageNotice.CannotBePackaged));
                return;
            }

            if (!ItemRepackageMetadataStorage.ItemCanRepackage(ribbon.Function.Id, repackingItem.Level, repackingItem.Rarity))
            {
                session.Send(ItemRepackagePacket.Notice((int)ItemRepackageNotice.ItemInvalid));
                return;
            }

            repackingItem.RepackageCount -= 1;
            repackingItem.RemainingTrades++;

            InventoryController.Consume(session, ribbon.Uid, ribbonRequirementAmount);

            session.Send(ItemRepackagePacket.Repackage(repackingItem));
        }