Beispiel #1
0
        public void VoidTargetPlayer(string command, string arguments)
        {
            if (_pluginInterface.ClientState.Actors
                .SingleOrDefault(x => x is PlayerCharacter &&
                                 x.ActorId != 0 &&
                                 x.ActorId != _pluginInterface.ClientState.LocalPlayer?.ActorId &&
                                 x.ActorId == _pluginInterface.ClientState.LocalPlayer?.TargetActorID) is PlayerCharacter actor)
            {
                var voidItem = new VoidItem(actor, arguments, false);
                var icon     = Encoding.UTF8.GetString(new byte[] { 2, 18, 2, 89, 3 });

                if (!_pluginConfig.VoidList.Any(x =>
                                                (x.Name == voidItem.Name && x.HomeworldId == voidItem.HomeworldId) ||
                                                (x.ActorId == voidItem.ActorId && x.ActorId != 0)))
                {
                    _pluginConfig.VoidList.Add(voidItem);
                    _pluginConfig.Save();
                    Print($"VoidList: {actor.Name}{icon}{actor.HomeWorld.GameData.Name} has been added.");
                }
                else
                {
                    Print($"VoidList: {actor.Name}{icon}{actor.HomeWorld.GameData.Name} entry already exists.");
                }
            }
            else
            {
                Print("VoidList: Invalid target.");
            }
        }
        public void WhitelistTargetPlayer(string command, string arguments)
        {
            if (PluginInterface.ClientState.Actors
                .SingleOrDefault(x => x is PlayerCharacter &&
                                 x.ActorId != 0 &&
                                 x.ActorId != PluginInterface.ClientState.LocalPlayer?.ActorId &&
                                 x.ActorId == PluginInterface.ClientState.LocalPlayer?.TargetActorID) is PlayerCharacter actor)
            {
                var item = new VoidItem(actor, arguments, false);
                var icon = Encoding.UTF8.GetString(new byte[] { 2, 18, 2, 89, 3 });

                if (!PluginConfiguration.Whitelist.Any(x =>
                                                       x.Name == item.Name && x.HomeworldId == item.HomeworldId))
                {
                    PluginConfiguration.Whitelist.Add(item);
                    PluginConfiguration.Save();
                    UnhidePlayer((uint)actor.ActorId);
                    Print($"Whitelist: {actor.Name}{icon}{actor.HomeWorld.GameData.Name} has been added.");
                }
                else
                {
                    Print($"Whitelist: {actor.Name}{icon}{actor.HomeWorld.GameData.Name} entry already exists.");
                }
            }
            else
            {
                Print("Whitelist: Invalid target.");
            }
        }
Beispiel #3
0
        void HandleVoidStorageQuery(QueryVoidStorage queryVoidStorage)
        {
            Player player = GetPlayer();

            Creature unit = player.GetNPCIfCanInteractWith(queryVoidStorage.Npc, NPCFlags.Transmogrifier | NPCFlags.VaultKeeper);

            if (!unit)
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageQuery - {0} not found or player can't interact with it.", queryVoidStorage.Npc.ToString());
                SendPacket(new VoidStorageFailed());
                return;
            }

            if (!GetPlayer().IsVoidStorageUnlocked())
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageQuery - {0} name: {1} queried void storage without unlocking it.", player.GetGUID().ToString(), player.GetName());
                SendPacket(new VoidStorageFailed());
                return;
            }

            byte count = 0;

            for (byte i = 0; i < SharedConst.VoidStorageMaxSlot; ++i)
            {
                if (player.GetVoidStorageItem(i) != null)
                {
                    ++count;
                }
            }

            VoidStorageContents voidStorageContents = new VoidStorageContents();

            for (byte i = 0; i < SharedConst.VoidStorageMaxSlot; ++i)
            {
                VoidStorageItem item = player.GetVoidStorageItem(i);
                if (item == null)
                {
                    continue;
                }

                VoidItem voidItem = new VoidItem();
                voidItem.Guid    = ObjectGuid.Create(HighGuid.Item, item.ItemId);
                voidItem.Creator = item.CreatorGuid;
                voidItem.Slot    = i;
                voidItem.Item    = new ItemInstance(item);

                voidStorageContents.Items.Add(voidItem);
            }

            SendPacket(voidStorageContents);
        }
Beispiel #4
0
        public override void Repeat()
        {
            ProductMenuList soldProducts = new ProductMenuList();

            foreach (FiscalItem fi in cr.Document.Items)
            {
                if (fi is SalesItem)
                {
                    VoidItem voidItem = cr.Item.Clone() as VoidItem;
                    voidItem.Product = fi.Product;
                    if (cr.Document.CanAddItem(voidItem))
                    {
                        soldProducts.Add(fi.Product);
                    }
                }
            }
            cr.State = ListProductRepeat.Instance(soldProducts, new ProcessSelectedItem <IProduct>(cr.Execute));
        }
Beispiel #5
0
        public override void Enter()
        {
            /* when the cancel menu(key) selected without quantity
             * create a list which contains the items whose remaining quantity is bigger than zero
             */
            MenuList cancelMenu = new MenuList();

            foreach (FiscalItem fiscalItem in cr.Document.Items)
            {
                if (fiscalItem is SalesItem)
                {
                    VoidItem voidItem = new VoidItem(fiscalItem);
                    /* quantity of void item is equal to remaining quantity of sale item */
                    if (Math.Abs(voidItem.Quantity) > 0 && cr.Document.CanAddItem(voidItem))
                    {
                        cancelMenu.Add(fiscalItem);
                    }
                }
            }

            cr.State = ListVoid.Instance(cancelMenu, new ProcessSelectedItem <FiscalItem>(VoidSelectedItem));
        }
Beispiel #6
0
        public void WhitelistTargetPlayer(string command, string arguments)
        {
            if (ObjectTable.SingleOrDefault(
                    x => x is PlayerCharacter &&
                    x.ObjectId != 0 &&
                    x.ObjectId != ClientState.LocalPlayer?.ObjectId &&
                    x.ObjectId == ClientState.LocalPlayer?.TargetObjectId) is PlayerCharacter
                actor)
            {
                var item = new VoidItem(actor, arguments, false);

                var playerString = Encoding.UTF8.GetString(
                    new SeString(
                        new TextPayload(actor.Name.TextValue),
                        new IconPayload(BitmapFontIcon.CrossWorld),
                        new TextPayload(actor.HomeWorld.GameData !.Name)).Encode());

                if (!this.Configuration.Whitelist.Any(
                        x =>
                        x.Name == item.Name && x.HomeworldId == item.HomeworldId))
                {
                    this.Configuration.Whitelist.Add(item);
                    this.Configuration.Save();
                    this.ShowPlayer(actor.ObjectId);
                    ChatGui.Print(
                        this.PluginLocalization.EntryAdded(this.PluginLocalization.WhitelistName, playerString));
                }
                else
                {
                    ChatGui.Print(
                        this.PluginLocalization.EntryExistsError(this.PluginLocalization.WhitelistName, playerString));
                }
            }
            else
            {
                ChatGui.Print(
                    this.PluginLocalization.InvalidTargetError(this.PluginLocalization.WhitelistName));
            }
        }
Beispiel #7
0
        public bool DrawConfigUi()
        {
            var drawConfig = true;

            var scale = ImGui.GetIO().FontGlobalScale;

            ImGui.SetNextWindowSize(new Vector2(500 * scale, 262 * scale), ImGuiCond.Always);
            ImGui.Begin($"{_plugin.Name} Config", ref drawConfig, ImGuiWindowFlags.NoResize);

            Checkbox(nameof(Enabled));

            ImGui.SameLine();
            ImGui.Text("Enable");
            ImGui.Separator();

            ImGui.Columns(6, "###cols", false);

            ImGui.NextColumn();
            ImGui.Text("Hide all");
            ImGui.NextColumn();
            ImGui.Text("Show party");
            ImGui.NextColumn();
            ImGui.Text("Show friends");
            ImGui.NextColumn();
            ImGui.Text("Show dead");
            ImGui.NextColumn();
            ImGui.Text("Show FC");
            ImGui.NextColumn();
            ImGui.Separator();
            ImGui.Text("Pets");
            ImGui.NextColumn();
            Checkbox(nameof(HidePet));
            ImGui.NextColumn();
            Checkbox(nameof(ShowPartyPet));
            ImGui.NextColumn();
            Checkbox(nameof(ShowFriendPet));
            ImGui.NextColumn();
            ImGui.NextColumn();
            Checkbox(nameof(ShowCompanyPet));
            ImGui.NextColumn();

            ImGui.Text("Chocobos");
            ImGui.NextColumn();
            Checkbox(nameof(HideChocobo));
            ImGui.NextColumn();
            Checkbox(nameof(ShowPartyChocobo));
            ImGui.NextColumn();
            Checkbox(nameof(ShowFriendChocobo));
            ImGui.NextColumn();
            ImGui.NextColumn();
            Checkbox(nameof(ShowCompanyChocobo));
            ImGui.NextColumn();

            ImGui.Text("Players");
            ImGui.NextColumn();
            Checkbox(nameof(HidePlayer));
            ImGui.NextColumn();
            Checkbox(nameof(ShowPartyPlayer));
            ImGui.NextColumn();
            Checkbox(nameof(ShowFriendPlayer));
            ImGui.NextColumn();
            Checkbox(nameof(ShowDeadPlayer));
            ImGui.NextColumn();
            Checkbox(nameof(ShowCompanyPlayer));
            ImGui.NextColumn();

            ImGui.Text("Minions");
            ImGui.NextColumn();
            Checkbox(nameof(HideMinion));
            ImGui.NextColumn();
            Checkbox(nameof(ShowPartyMinion));
            ImGui.NextColumn();
            Checkbox(nameof(ShowFriendMinion));
            ImGui.NextColumn();
            ImGui.NextColumn();
            Checkbox(nameof(ShowCompanyMinion));
            ImGui.NextColumn();
            ImGui.Separator();

            ImGui.Columns(1, "###cols", false);

            Checkbox(nameof(HideStar));
            ImGui.SameLine();
            ImGui.Text("Hide non-party Earthly Star");
            if (ImGui.IsItemHovered())
            {
                ImGui.SetTooltip("Hides Earthly Star not belonging to players in your party (Only works in combat)");
            }

            ImGui.NextColumn();
            ImGui.Separator();

            ImGui.Columns(6, "###cols", false);

            if (ImGui.Button("Refresh"))
            {
                _plugin.RefreshActors();
            }

            ImGui.NextColumn();
            ImGui.NextColumn();
            ImGui.NextColumn();
            ImGui.NextColumn();

            if (ImGui.Button("Whitelist"))
            {
                _showListWindow[1] = !_showListWindow[1];
            }

            ImGui.NextColumn();

            if (ImGui.Button("VoidList"))
            {
                _showListWindow[0] = !_showListWindow[0];
            }

            ImGui.NextColumn();
            ImGui.End();

            if (_showListWindow[0])
            {
                ImGui.SetNextWindowSize(new Vector2(700 * scale, 500), ImGuiCond.FirstUseEver);
                ImGui.Begin($"{_plugin.Name}: VoidList", ref _showListWindow[0]);

                var footer2 = (ImGui.GetStyle().ItemSpacing.Y) / 2 + ImGui.GetFrameHeightWithSpacing();
                ImGui.BeginChild("scrollingVoidList", new Vector2(0, -footer2), false);

                ImGui.Columns(6, "###voidCols");
                ImGui.Text("Firstname");
                ImGui.NextColumn();
                ImGui.Text("Lastname");
                ImGui.NextColumn();
                ImGui.Text("World");
                ImGui.NextColumn();
                ImGui.Text("Date");
                ImGui.NextColumn();
                ImGui.Text("Reason");
                ImGui.NextColumn();
                ImGui.NextColumn();

                VoidItem itemToRemove = null;

                foreach (var item in VoidList)
                {
                    ImGui.TextUnformatted(item.Firstname);
                    ImGui.NextColumn();
                    ImGui.TextUnformatted(item.Lastname);
                    ImGui.NextColumn();
                    ImGui.TextUnformatted(item.HomeworldName);
                    ImGui.NextColumn();
                    ImGui.Text(item.Time.ToString(CultureInfo.CurrentCulture));
                    ImGui.NextColumn();
                    ImGui.TextUnformatted(item.Reason);
                    ImGui.NextColumn();

                    if (ImGui.Button($"Remove##{item.Name}"))
                    {
                        itemToRemove = item;
                    }

                    ImGui.NextColumn();
                }

                if (itemToRemove != null)
                {
                    if (_pluginInterface.ClientState.Actors
                        .SingleOrDefault(x => x is PlayerCharacter &&
                                         itemToRemove.ActorId != 0 &&
                                         x.ObjectKind != ObjectKind.Companion &&
                                         x.ActorId == itemToRemove.ActorId) is PlayerCharacter actor)
                    {
                        actor.Render();
                    }

                    VoidList.Remove(itemToRemove);
                    Save();
                }

                var manual = true;

                if (_pluginInterface.ClientState.LocalPlayer?.TargetActorID > 0)
                {
                    Array.Clear(_buffer[0], 0, _buffer[0].Length);
                    Array.Clear(_buffer[1], 0, _buffer[1].Length);
                    Array.Clear(_buffer[2], 0, _buffer[2].Length);

                    if (_pluginInterface.ClientState.Actors
                        .SingleOrDefault(x => x is PlayerCharacter &&
                                         x.ObjectKind != ObjectKind.Companion &&
                                         x.ActorId == _pluginInterface.ClientState.LocalPlayer
                                         ?.TargetActorID) is
                        PlayerCharacter actor)
                    {
                        Encoding.Default.GetBytes(actor.GetFirstname()).CopyTo(_buffer[0], 0);
                        Encoding.Default.GetBytes(actor.GetLastname()).CopyTo(_buffer[1], 0);
                        Encoding.Default.GetBytes(actor.HomeWorld.GameData.Name).CopyTo(_buffer[2], 0);

                        manual = false;
                    }
                }

                ImGui.InputText("###playerFirstName", _buffer[0], (uint)_buffer[0].Length,
                                ImGuiInputTextFlags.CharsNoBlank);
                ImGui.NextColumn();
                ImGui.InputText("###playerLastName", _buffer[1], (uint)_buffer[1].Length,
                                ImGuiInputTextFlags.CharsNoBlank);
                ImGui.NextColumn();
                ImGui.InputText("###homeworldName", _buffer[2], (uint)_buffer[2].Length,
                                ImGuiInputTextFlags.CharsNoBlank);
                ImGui.NextColumn();
                ImGui.NextColumn();
                ImGui.InputText("###reason", _buffer[3], (uint)_buffer[3].Length);
                ImGui.NextColumn();

                if (ImGui.Button("Void player"))
                {
                    _plugin.VoidPlayer(manual ? "VoidUIManual" : string.Empty,
                                       $"{_buffer[0].ByteToString()} {_buffer[1].ByteToString()} {_buffer[2].ByteToString()} {_buffer[3].ByteToString()}");

                    foreach (var item in _buffer)
                    {
                        Array.Clear(item, 0, item.Length);
                    }
                }

                ImGui.NextColumn();

                ImGui.EndChild();
            }

            if (_showListWindow[1])
            {
                ImGui.SetNextWindowSize(new Vector2(700 * scale, 500), ImGuiCond.FirstUseEver);
                ImGui.Begin($"{_plugin.Name}: Whitelist", ref _showListWindow[1]);

                var footer2 = (ImGui.GetStyle().ItemSpacing.Y) / 2 + ImGui.GetFrameHeightWithSpacing();
                ImGui.BeginChild("scrollingWhitelist", new Vector2(0, -footer2), false);

                ImGui.Columns(6, "###whitelistCols");
                ImGui.Text("Firstname");
                ImGui.NextColumn();
                ImGui.Text("Lastname");
                ImGui.NextColumn();
                ImGui.Text("World");
                ImGui.NextColumn();
                ImGui.Text("Date");
                ImGui.NextColumn();
                ImGui.Text("Reason");
                ImGui.NextColumn();
                ImGui.NextColumn();

                VoidItem itemToRemove = null;

                foreach (var item in Whitelist)
                {
                    ImGui.TextUnformatted(item.Firstname);
                    ImGui.NextColumn();
                    ImGui.TextUnformatted(item.Lastname);
                    ImGui.NextColumn();
                    ImGui.TextUnformatted(item.HomeworldName);
                    ImGui.NextColumn();
                    ImGui.Text(item.Time.ToString(CultureInfo.CurrentCulture));
                    ImGui.NextColumn();
                    ImGui.TextUnformatted(item.Reason);
                    ImGui.NextColumn();

                    if (ImGui.Button($"Remove##{item.Name}"))
                    {
                        itemToRemove = item;
                    }

                    ImGui.NextColumn();
                }

                if (itemToRemove != null)
                {
                    Whitelist.Remove(itemToRemove);
                    Save();
                }

                var manual = true;

                if (_pluginInterface.ClientState.LocalPlayer?.TargetActorID > 0)
                {
                    Array.Clear(_buffer[4], 0, _buffer[4].Length);
                    Array.Clear(_buffer[5], 0, _buffer[5].Length);
                    Array.Clear(_buffer[6], 0, _buffer[6].Length);

                    if (_pluginInterface.ClientState.Actors
                        .SingleOrDefault(x => x is PlayerCharacter &&
                                         x.ObjectKind != ObjectKind.Companion &&
                                         x.ActorId == _pluginInterface.ClientState.LocalPlayer
                                         ?.TargetActorID) is
                        PlayerCharacter actor)
                    {
                        Encoding.Default.GetBytes(actor.GetFirstname()).CopyTo(_buffer[4], 0);
                        Encoding.Default.GetBytes(actor.GetLastname()).CopyTo(_buffer[5], 0);
                        Encoding.Default.GetBytes(actor.HomeWorld.GameData.Name).CopyTo(_buffer[6], 0);

                        manual = false;
                    }
                }

                ImGui.InputText("###playerFirstName", _buffer[4], (uint)_buffer[4].Length,
                                ImGuiInputTextFlags.CharsNoBlank);
                ImGui.NextColumn();
                ImGui.InputText("###playerLastName", _buffer[5], (uint)_buffer[5].Length,
                                ImGuiInputTextFlags.CharsNoBlank);
                ImGui.NextColumn();
                ImGui.InputText("###homeworldName", _buffer[6], (uint)_buffer[6].Length,
                                ImGuiInputTextFlags.CharsNoBlank);
                ImGui.NextColumn();
                ImGui.NextColumn();
                ImGui.InputText("###reason", _buffer[7], (uint)_buffer[7].Length);
                ImGui.NextColumn();

                if (ImGui.Button("Add player"))
                {
                    _plugin.WhitelistPlayer(manual ? "WhitelistUIManual" : string.Empty,
                                            $"{_buffer[4].ByteToString()} {_buffer[5].ByteToString()} {_buffer[6].ByteToString()} {_buffer[7].ByteToString()}");

                    foreach (var item in _buffer)
                    {
                        Array.Clear(item, 0, item.Length);
                    }
                }

                ImGui.NextColumn();

                ImGui.EndChild();
            }

            ImGui.End();

            return(drawConfig);
        }
Beispiel #8
0
        private void DrawWhitelist()
        {
            ImGui.SetNextWindowSize(new Vector2(700, 500), ImGuiCond.FirstUseEver);
            if (!ImGui.Begin($"{_plugin.Name}: 白名单", ref _showListWindow[1]))
            {
                ImGui.End();
                return;
            }

            if (ImGui.BeginTable("WhitelistTable", 5,
                                 ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollY | ImGuiTableFlags.Sortable))
            {
                ImGui.TableSetupColumn("角色名");
                ImGui.TableSetupColumn("服务器");
                ImGui.TableSetupColumn("时间", ImGuiTableColumnFlags.DefaultSort);
                ImGui.TableSetupColumn("原因");
                ImGui.TableSetupColumn("操作", ImGuiTableColumnFlags.NoSort);
                ImGui.TableSetupScrollFreeze(0, 1);
                ImGui.TableHeadersRow();

                VoidItem itemToRemove = null;

                if (_sortedContainer[1] == null)
                {
                    _sortedContainer[1] = Whitelist;
                }

                var sortSpecs = ImGui.TableGetSortSpecs();

                if (sortSpecs.SpecsDirty)
                {
                    _sortAscending[1] = sortSpecs.Specs.SortDirection == ImGuiSortDirection.Ascending;

                    switch (sortSpecs.Specs.ColumnIndex)
                    {
                    case 0:
                        _sortedContainer[1] = SortContainer(Whitelist, x => x.Charactername,
                                                            _sortAscending[1], out _sortKeySelector[1]);
                        break;

                    case 1:
                        _sortedContainer[1] = SortContainer(Whitelist, x => x.HomeworldName,
                                                            _sortAscending[1], out _sortKeySelector[1]);
                        break;

                    case 2:
                        _sortedContainer[1] = SortContainer(Whitelist, x => x.Time,
                                                            _sortAscending[1], out _sortKeySelector[1]);
                        break;

                    case 3:
                        _sortedContainer[1] = SortContainer(Whitelist, x => x.Reason,
                                                            _sortAscending[1], out _sortKeySelector[1]);
                        break;
                    }

                    sortSpecs.SpecsDirty = false;
                }

                foreach (var item in _sortedContainer[1])
                {
                    ImGui.TableNextColumn();
                    ImGui.TextUnformatted(item.Charactername);
                    ImGui.TableNextColumn();
                    ImGui.TextUnformatted(item.HomeworldName);
                    ImGui.TableNextColumn();
                    ImGui.Text(item.Time.ToString(CultureInfo.CurrentCulture));
                    ImGui.TableNextColumn();
                    ImGui.TextUnformatted(item.Reason);
                    ImGui.TableNextColumn();

                    if (ImGui.Button($"移除##{item.Name}"))
                    {
                        itemToRemove = item;
                    }

                    ImGui.TableNextRow();
                }

                if (itemToRemove != null)
                {
                    Whitelist.Remove(itemToRemove);
                    Save();
                    _sortedContainer[1] = SortContainer(Whitelist, _sortKeySelector[1], _sortAscending[1],
                                                        out _sortKeySelector[1]);
                }

                var manual = true;

                if (_pluginInterface.ClientState.LocalPlayer?.TargetActorID > 0 &&
                    _pluginInterface.ClientState.Actors
                    .SingleOrDefault(x => x is PlayerCharacter &&
                                     x.ObjectKind != ObjectKind.Companion &&
                                     x.ActorId == _pluginInterface.ClientState.LocalPlayer
                                     ?.TargetActorID) is
                    PlayerCharacter actor)
                {
                    Array.Clear(_buffer[4], 0, _buffer[4].Length);
                    //Array.Clear(_buffer[5], 0, _buffer[5].Length);
                    Array.Clear(_buffer[6], 0, _buffer[6].Length);

                    Encoding.UTF8.GetBytes(actor.GetFirstname()).CopyTo(_buffer[4], 0);
                    //Encoding.UTF8.GetBytes(actor.GetLastname()).CopyTo(_buffer[5], 0);
                    Encoding.UTF8.GetBytes(actor.HomeWorld.GameData.Name).CopyTo(_buffer[6], 0);

                    manual = false;
                }

                ImGui.TableNextColumn();
                ImGui.InputText("###playerName", _buffer[4], (uint)_buffer[4].Length,
                                ImGuiInputTextFlags.CharsNoBlank);
                ImGui.TableNextColumn();
                ImGui.InputText("###homeworldName", _buffer[6], (uint)_buffer[6].Length,
                                ImGuiInputTextFlags.CharsNoBlank);
                ImGui.TableNextColumn();
                ImGui.TableNextColumn();
                ImGui.InputText("###reason", _buffer[7], (uint)_buffer[7].Length);
                ImGui.TableNextColumn();

                if (ImGui.Button("添加到白名单"))
                {
                    _plugin.WhitelistPlayer(manual ? "WhitelistUIManual" : string.Empty,
                                            $"{_buffer[4].ByteToString()} {_buffer[6].ByteToString()} {_buffer[7].ByteToString()}");

                    foreach (var item in _buffer)
                    {
                        Array.Clear(item, 0, item.Length);
                    }

                    _sortedContainer[1] = SortContainer(Whitelist, _sortKeySelector[1], _sortAscending[1],
                                                        out _sortKeySelector[1]);
                }

                ImGui.EndTable();
            }

            ImGui.End();
        }
Beispiel #9
0
        public override void Correction()
        {
            if (cr.Document.LastItem == null)
            {
                throw new NoCorrectionException();
            }

            try
            {
                if (cr.Document.LastItem.Adjustments == null || cr.Document.LastItem.Adjustments.Count == 0)
                {
                    if (cr.Document.LastItem is VoidItem)
                    {
                        throw new CmdSequenceException();
                    }

                    cr.Printer.Correct(cr.Document.LastItem);
                    FiscalItem voidItem = new VoidItem(cr.Document.LastItem);
                    ((SalesItem)cr.Document.LastItem).VoidQuantity = cr.Document.LastItem.Quantity;
                    ((SalesItem)cr.Document.LastItem).VoidAmount   = cr.Document.LastItem.TotalAmount;
                    cr.Document.AddItem(voidItem, true);
                    DisplayAdapter.Both.ShowVoid(voidItem);
                    return;
                }

                FiscalItem fi = cr.Document.LastItem;

                Adjustment lastAdjustment = fi.Adjustments[fi.Adjustments.Count - 1];
                if (lastAdjustment.IsCorrection)
                {
                    throw new CmdSequenceException();
                }

                Adjustment     adjustment = null;
                AdjustmentType adjType    = lastAdjustment.NetAmount > 0 ? AdjustmentType.Discount : AdjustmentType.Fee;
                if (cr.Document.State is DocumentOpen)
                {
                    adjustment = new Adjustment(cr.Document.LastItem, adjType, Math.Abs(lastAdjustment.NetAmount));
                    adjustment.IsCorrection = true;

                    if (!(cr.Document.CanAdjust(adjustment)))
                    {
                        cr.State = States.AlertCashier.Instance(new Error(new AdjustmentLimitException(adjustment.Label)));
                        return;
                    }

                    IPrinterResponse printerReponse = cr.Printer.Correct(lastAdjustment);

                    cr.Document.LastItem.Adjust(adjustment);

                    DisplayAdapter.Both.ShowCorrect(adjustment, false);

                    cr.State = Selling.Instance();
                }
                if (cr.Document.State is DocumentSubTotal)
                {
                    throw new CmdSequenceException();
                }
            }
            catch (CmdSequenceException)
            {
                cr.State = AlertCashier.Instance(new Error(new NoCorrectionException()));
            }
            catch (NoAdjustmentException ae)
            {
                AlertCashier.Instance(new Error(ae));
            }
        }