public async Task UseItemHandler(GameSession session, ItemUseItemReqMessage message)
        {
            // This is a weird thing since newer seasons
            // The client sends a request with itemid 0 on login
            // and requires an answer to it for equipment to work properly


            if (message.Action == UseItemAction.UnEquip && message.ItemId == 0)
            {
                await session.SendAsync(new ItemUseItemAckMessage(message.Action, message.CharacterSlot, message.EquipSlot, message.ItemId));

                return;
            }
            if (message.ItemId > 5115000)
            {
                await session.SendAsync(new ItemUseItemAckMessage(message.Action, message.CharacterSlot, message.EquipSlot, message.ItemId));

                await session.SendAsync(new ServerResultAckMessage(ServerResult.TaskCompensationError));

                return;
            }
            else
            {
                var plr   = session.Player;
                var @char = plr.CharacterManager[message.CharacterSlot];
                var item  = plr.Inventory[message.ItemId];

                if (@char == null || item == null || (plr.Room != null && plr.RoomInfo.State != PlayerState.Lobby))
                {
                    await session.SendAsync(new ServerResultAckMessage(ServerResult.DBError));

                    return;
                }

                try
                {
                    switch (message.Action)
                    {
                    case UseItemAction.Equip:
                        @char.Equip(item, message.EquipSlot);
                        break;

                    case UseItemAction.UnEquip:
                        @char.UnEquip(item.ItemNumber.Category, message.EquipSlot);
                        break;
                    }
                }
                catch (CharacterException ex)
                {
                    Logger.ForAccount(session)
                    .Error(ex, "Unable to use item");
                    await session.SendAsync(new ServerResultAckMessage(ServerResult.DBError));

                    return;
                }
            }
            return;
        }
Exemplo n.º 2
0
        public void UseItemHandler(GameSession session, ItemUseItemReqMessage message)
        {
            if (message.Action == UseItemAction.UnEquip && message.ItemId == 0)
            {
                session.SendAsync(new ItemUseItemAckMessage(message.Action, message.CharacterSlot, message.EquipSlot,
                                                            message.ItemId));
                return;
            }

            var plr   = session.Player;
            var @char = plr.CharacterManager[message.CharacterSlot];
            var item  = plr.Inventory[message.ItemId];

            if (@char == null || item == null || plr.Room != null && plr.RoomInfo.State != PlayerState.Lobby)
            {
                session.SendAsync(new ItemUseItemAckMessage(UseItemAction.NoAction, message.CharacterSlot,
                                                            message.EquipSlot,
                                                            message.ItemId));
                return;
            }

            try
            {
                switch (message.Action)
                {
                case UseItemAction.Equip:
                    @char.Equip(item, message.EquipSlot);
                    break;

                case UseItemAction.UnEquip:
                    @char.UnEquip(item.ItemNumber.Category, message.EquipSlot);
                    break;
                }
            }
            catch (CharacterException ex)
            {
                Logger.ForAccount(session)
                .Error(ex.Message, "Unable to use item");
                session.SendAsync(new ItemUseItemAckMessage(UseItemAction.NoAction, message.CharacterSlot,
                                                            message.EquipSlot,
                                                            message.ItemId));
                session.SendAsync(new ServerResultAckMessage(ServerResult.FailedToRequestTask));
            }
        }