public static void ExpandPetBoxRequest(IRealmClient client, RealmPacketIn packet)
        {
            ++packet.Position;
            short num = packet.ReadInt16();

            if (client.ActiveCharacter.Record.PetBoxEnchants > (byte)14)
            {
                FunctionalItemsHandler.SendPetBoxExpandedResponse(client,
                                                                  FunctionalItemsHandler.ExpandPetBoxStatus.Fail, num);
                client.ActiveCharacter.SendInfoMsg("Pet box expand for maximum 90 slots.");
            }
            else
            {
                Asda2Item shopShopItem = client.ActiveCharacter.Asda2Inventory.GetShopShopItem(num);
                if (shopShopItem == null)
                {
                    FunctionalItemsHandler.SendPetBoxExpandedResponse(client,
                                                                      FunctionalItemsHandler.ExpandPetBoxStatus.Fail, num);
                    client.ActiveCharacter.SendInfoMsg("Item not found restart client.");
                }
                else if (shopShopItem.Category != Asda2ItemCategory.ExpandPetBoxBy6)
                {
                    client.ActiveCharacter.YouAreFuckingCheater("Tryes to expand pet box with wrong item.", 50);
                }
                else
                {
                    --shopShopItem.Amount;
                    ++client.ActiveCharacter.Record.PetBoxEnchants;
                    FunctionalItemsHandler.SendPetBoxExpandedResponse(client,
                                                                      FunctionalItemsHandler.ExpandPetBoxStatus.Ok, num);
                }
            }
        }
        public static void UseShopItemRequest(IRealmClient client, RealmPacketIn packet)
        {
            packet.Position += 6;
            short slot = packet.ReadInt16();

            packet.Position += 4;
            ++packet.Position;
            packet.Position += 2;
            int num = (int)packet.ReadInt16();

            packet.Position += 38;
            packet.Position += 200;
            uint parametr = 0;

            try
            {
                parametr = packet.ReadUInt32();
            }
            catch (EndOfStreamException ex)
            {
            }

            client.ActiveCharacter.AddMessage((Action)(() =>
                                                       FunctionalItemsHandler.ProcessFunctionalItem(client, parametr, slot)));
        }
 public static void ResetSkills(Character chr)
 {
     chr.Spells.Clear();
     chr.Spells.AddDefaultSpells();
     FunctionalItemsHandler.SendPreResurectResponse(chr.Client);
     FunctionalItemsHandler.SendAllSkillsResetedInfoMsgResponse(chr.Client);
     FunctionalItemsHandler.SendAllSkillsResetedResponse(chr.Client);
 }
        public static void UseChangeFactionItemRequest(IRealmClient client, RealmPacketIn packet)
        {
            packet.Position += 5;
            short     slotInq      = packet.ReadInt16();
            Asda2Item shopShopItem = client.ActiveCharacter.Asda2Inventory.GetShopShopItem(slotInq);

            if (shopShopItem == null || shopShopItem.Category != Asda2ItemCategory.ResetFaction ||
                client.ActiveCharacter.Asda2FactionId == (short)-1)
            {
                FunctionalItemsHandler.SendFactionResetedResponse(client, false, (Asda2Item)null);
            }
            else
            {
                --shopShopItem.Amount;
                client.ActiveCharacter.Asda2FactionId = (short)-1;
                FunctionalItemsHandler.SendFactionResetedResponse(client, true, shopShopItem);
            }
        }
        private static void ProcessFunctionalItem(IRealmClient client, uint parametr, short slot)
        {
            Asda2Item item = client.ActiveCharacter.Asda2Inventory.GetShopShopItem(slot);

            if (item == null)
            {
                FunctionalItemsHandler.SendUpdateShopItemInfoResponse(client,
                                                                      UseFunctionalItemError.FunctionalItemDoesNotExist, (Asda2Item)null);
            }
            else
            {
                UseFunctionalItemError status = UseFunctionalItemError.Ok;
                if ((int)item.RequiredLevel > client.ActiveCharacter.Level)
                {
                    FunctionalItemsHandler.SendUpdateShopItemInfoResponse(client,
                                                                          UseFunctionalItemError.YorLevelIsNotHightEnoght, item);
                }
                else
                {
                    ServerApp <WCell.RealmServer.RealmServer> .IOQueue.AddMessage((Action)(() =>
                    {
                        try
                        {
                            switch (item.Category)
                            {
                            case Asda2ItemCategory.IncPAtk:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncMAtk:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncPDef:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncMdef:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncHp:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncMp:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncStr:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncSta:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncInt:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncSpi:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncDex:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncLuck:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncMoveSpeed:
                                if (client.ActiveCharacter.LastTransportUsedTime +
                                    TimeSpan.FromMilliseconds(30000.0) > DateTime.Now)
                                {
                                    status = UseFunctionalItemError.CoolingTimeRemain;
                                    break;
                                }

                                if (item.Record.IsSoulBound && item.Record.AuctionEndTime != DateTime.MinValue &&
                                    DateTime.Now > item.Record.AuctionEndTime)
                                {
                                    Asda2InventoryHandler.ItemRemovedFromInventoryResponse(client.ActiveCharacter,
                                                                                           item, DeleteOrSellItemStatus.Ok, 0);
                                    item.Destroy();
                                    client.ActiveCharacter.SendInfoMsg("Vehicle expired.");
                                    status = UseFunctionalItemError.TheDurationOfTheShopitemHaExprised;
                                    break;
                                }

                                if (item.Record.AuctionEndTime == DateTime.MinValue)
                                {
                                    item.Record.AuctionEndTime =
                                        DateTime.Now + TimeSpan.FromDays((double)item.AttackTime);
                                }
                                client.ActiveCharacter.LastTransportUsedTime = DateTime.Now;
                                item.IsSoulbound = true;
                                client.ActiveCharacter.TransportItemId = item.ItemId;
                                AchievementProgressRecord progressRecord1 =
                                    client.ActiveCharacter.Achievements.GetOrCreateProgressRecord(85U);
                                switch (++progressRecord1.Counter)
                                {
                                case 1:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.DiscoverTitle(Asda2TitleId.Rapid219)));
                                    break;

                                case 1000:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.GetTitle(Asda2TitleId.Rapid219)));
                                    break;
                                }

                                progressRecord1.SaveAndFlush();
                                break;

                            case Asda2ItemCategory.IncExp:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncDropChance:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncDigChance:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncExpStackable:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.IncAtackSpeed:
                                client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, false);
                                FunctionalItemsHandler.SendShopItemUsedResponse(client, item.ItemId,
                                                                                (int)item.Template.AtackRange);
                                break;

                            case Asda2ItemCategory.ExpandWarehouse:
                                if (client.ActiveCharacter.Record.PremiumWarehouseBagsCount >= (byte)8)
                                {
                                    status = UseFunctionalItemError.WarehouseHasReachedMaxCapacity;
                                    break;
                                }

                                ++client.ActiveCharacter.Record.PremiumWarehouseBagsCount;
                                FunctionalItemsHandler.SendWarehouseSlotsExpandedResponse(client, false);
                                break;

                            case Asda2ItemCategory.ResetAllSkill:
                                FunctionalItemsHandler.ResetSkills(client.ActiveCharacter);
                                Asda2CharacterHandler.SendLearnedSkillsInfo(client.ActiveCharacter);
                                AchievementProgressRecord progressRecord2 =
                                    client.ActiveCharacter.Achievements.GetOrCreateProgressRecord(84U);
                                switch (++progressRecord2.Counter)
                                {
                                case 3:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.DiscoverTitle(Asda2TitleId
                                                                                                                         .Perfectionist218)));
                                    break;

                                case 5:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.GetTitle(Asda2TitleId.Perfectionist218)));
                                    break;
                                }

                                progressRecord2.SaveAndFlush();
                                break;

                            case Asda2ItemCategory.ResetOneSkill:
                                Spell spell1 =
                                    client.ActiveCharacter.Spells.First <Spell>(
                                        (Func <Spell, bool>)(s => (long)s.RealId == (long)parametr));
                                if (spell1 != null)
                                {
                                    int num1 = 0 + spell1.Cost;
                                    for (int index = spell1.Level - 1; index > 0; --index)
                                    {
                                        Spell spell2 =
                                            SpellHandler.Get((uint)spell1.RealId + (uint)(index * 1000));
                                        if (spell2 != null)
                                        {
                                            num1 += spell2.Cost;
                                        }
                                    }

                                    uint num2 = (uint)(num1 / 2);
                                    client.ActiveCharacter.Spells.Remove(spell1);
                                    client.ActiveCharacter.AddMoney(num2);
                                    Asda2CharacterHandler.SendPreResurectResponse(client.ActiveCharacter);
                                    FunctionalItemsHandler.SendSkillResetedResponse(client, spell1.RealId,
                                                                                    (short)spell1.Level, num2);
                                    Asda2CharacterHandler.SendUpdateStatsOneResponse(client);
                                    Asda2CharacterHandler.SendUpdateStatsResponse(client);
                                    client.ActiveCharacter.SendMoneyUpdate();
                                    AchievementProgressRecord progressRecord3 =
                                        client.ActiveCharacter.Achievements.GetOrCreateProgressRecord(84U);
                                    switch (++progressRecord3.Counter)
                                    {
                                    case 3:
                                        client.ActiveCharacter.Map.CallDelayed(500,
                                                                               (Action)(() =>
                                                                                        client.ActiveCharacter.DiscoverTitle(Asda2TitleId
                                                                                                                             .Perfectionist218)));
                                        break;

                                    case 5:
                                        client.ActiveCharacter.Map.CallDelayed(500,
                                                                               (Action)(() =>
                                                                                        client.ActiveCharacter.GetTitle(Asda2TitleId
                                                                                                                        .Perfectionist218)));
                                        break;
                                    }

                                    progressRecord3.SaveAndFlush();
                                    break;
                                }

                                status = UseFunctionalItemError.FailedToUse;
                                client.ActiveCharacter.SendInfoMsg("Skill is not learned. Restart client.");
                                break;

                            case Asda2ItemCategory.TeleportToCharacter:
                                if (parametr >= 10U || client.ActiveCharacter.TeleportPoints[parametr] == null)
                                {
                                    status = UseFunctionalItemError.FailedToUse;
                                    break;
                                }

                                Asda2TeleportingPointRecord teleportPoint =
                                    client.ActiveCharacter.TeleportPoints[parametr];
                                client.ActiveCharacter.TeleportTo(teleportPoint.MapId,
                                                                  new Vector3((float)teleportPoint.X, (float)teleportPoint.Y));
                                AchievementProgressRecord progressRecord4 =
                                    client.ActiveCharacter.Achievements.GetOrCreateProgressRecord(89U);
                                switch (++progressRecord4.Counter)
                                {
                                case 50:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.DiscoverTitle(Asda2TitleId.Traveler223)));
                                    break;

                                case 100:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.GetTitle(Asda2TitleId.Traveler223)));
                                    break;
                                }

                                progressRecord4.SaveAndFlush();
                                break;

                            case Asda2ItemCategory.InstantRecover100PrcHP:
                                if (client.ActiveCharacter.Last100PrcRecoveryUsed + 30000U >
                                    (uint)Environment.TickCount)
                                {
                                    status = UseFunctionalItemError.CoolingTimeRemain;
                                    break;
                                }

                                client.ActiveCharacter.Last100PrcRecoveryUsed = (uint)Environment.TickCount;
                                client.ActiveCharacter.HealPercent(100, (Unit)null, (SpellEffect)null);
                                break;

                            case Asda2ItemCategory.InstantRecover100PrcHPandMP:
                                if (client.ActiveCharacter.Last100PrcRecoveryUsed + 30000U <
                                    (uint)Environment.TickCount)
                                {
                                    status = UseFunctionalItemError.CoolingTimeRemain;
                                }
                                client.ActiveCharacter.HealPercent(100, (Unit)null, (SpellEffect)null);
                                client.ActiveCharacter.Power = client.ActiveCharacter.MaxPower;
                                client.ActiveCharacter.Last100PrcRecoveryUsed = (uint)Environment.TickCount;
                                break;

                            case Asda2ItemCategory.RecoverHp10TimesByPrcOver30Sec:
                                PereodicAction pereodicAction = (PereodicAction)null;
                                if (client.ActiveCharacter.PereodicActions.ContainsKey(Asda2PereodicActionType
                                                                                       .HpRegenPrc))
                                {
                                    pereodicAction =
                                        client.ActiveCharacter.PereodicActions[Asda2PereodicActionType.HpRegenPrc];
                                }
                                if (pereodicAction != null && pereodicAction.CallsNum >= 10 &&
                                    pereodicAction.Value >= item.Template.ValueOnUse)
                                {
                                    status = UseFunctionalItemError.CoolingTimeRemain;
                                    break;
                                }

                                if (client.ActiveCharacter.PereodicActions.ContainsKey(Asda2PereodicActionType
                                                                                       .HpRegenPrc))
                                {
                                    client.ActiveCharacter.PereodicActions.Remove(
                                        Asda2PereodicActionType.HpRegenPrc);
                                }
                                client.ActiveCharacter.PereodicActions.Add(Asda2PereodicActionType.HpRegenPrc,
                                                                           new PereodicAction(client.ActiveCharacter, item.Template.ValueOnUse, 10, 3000,
                                                                                              Asda2PereodicActionType.HpRegenPrc));
                                break;

                            case Asda2ItemCategory.ShopBanner:
                                if (client.ActiveCharacter.Level < 10)
                                {
                                    status = UseFunctionalItemError.YorLevelIsNotHightEnoght;
                                    break;
                                }

                                FunctionalItemsHandler.SendPremiumLongBuffInfoResponse(client,
                                                                                       (byte)client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, true),
                                                                                       item.ItemId, (short)item.Template.PackageId);
                                break;

                            case Asda2ItemCategory.OpenWarehouse:
                                break;

                            case Asda2ItemCategory.PremiumPotions:
                                FunctionalItemsHandler.SendPremiumLongBuffInfoResponse(client,
                                                                                       (byte)client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, true),
                                                                                       item.ItemId, (short)item.Template.PackageId);
                                client.ActiveCharacter.Asda2WingsItemId = (short)item.ItemId;
                                AchievementProgressRecord progressRecord5 =
                                    client.ActiveCharacter.Achievements.GetOrCreateProgressRecord(86U);
                                switch (++progressRecord5.Counter)
                                {
                                case 50:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.DiscoverTitle(Asda2TitleId.Winged220)));
                                    break;

                                case 100:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.GetTitle(Asda2TitleId.Winged220)));
                                    break;
                                }

                                progressRecord5.SaveAndFlush();
                                break;

                            case Asda2ItemCategory.ExpandInventory:
                                FunctionalItemsHandler.SendPremiumLongBuffInfoResponse(client,
                                                                                       (byte)client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, true),
                                                                                       item.ItemId, (short)item.Template.PackageId);
                                AchievementProgressRecord progressRecord6 =
                                    client.ActiveCharacter.Achievements.GetOrCreateProgressRecord(87U);
                                switch (++progressRecord6.Counter)
                                {
                                case 3:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.DiscoverTitle(Asda2TitleId.Packrat221)));
                                    break;

                                case 5:
                                    client.ActiveCharacter.Map.CallDelayed(500,
                                                                           (Action)(() =>
                                                                                    client.ActiveCharacter.GetTitle(Asda2TitleId.Packrat221)));
                                    break;
                                }

                                progressRecord6.SaveAndFlush();
                                break;

                            case Asda2ItemCategory.PetNotEatingByDays:
                                FunctionalItemsHandler.SendPremiumLongBuffInfoResponse(client,
                                                                                       (byte)client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, true),
                                                                                       item.ItemId, (short)item.Template.PackageId);
                                client.ActiveCharacter.Map.CallDelayed(500,
                                                                       (Action)(() => client.ActiveCharacter.GetTitle(Asda2TitleId.Treat366)));
                                break;

                            case Asda2ItemCategory.RemoveDeathPenaltiesByDays:
                                FunctionalItemsHandler.SendPremiumLongBuffInfoResponse(client,
                                                                                       (byte)client.ActiveCharacter.ApplyFunctionItemBuff(item.ItemId, true),
                                                                                       item.ItemId, (short)item.Template.PackageId);
                                break;

                            default:
                                status = UseFunctionalItemError.NotAunctionalItem;
                                break;
                            }
                        }
                        catch (AlreadyBuffedExcepton ex)
                        {
                            status = UseFunctionalItemError.AlreadyFeelingTheEffectOfSimilarSkillType;
                        }

                        if (status == UseFunctionalItemError.Ok && item.Category != Asda2ItemCategory.IncMoveSpeed)
                        {
                            item.ModAmount(-1);
                        }
                        FunctionalItemsHandler.SendUpdateShopItemInfoResponse(client, status, item);
                    }));
                }
            }
        }