예제 #1
0
    //Inserts a commit between float and locked without moving it from float to locked first

    private bool _InsertOnLocked(InventoryCommit commit)
    {
        commit.Data.PickedupWithInventory(this, commit.Index);

        //Revert back to the head
        LinkedListNode<InventoryCommit> node;
        for (node = m_commits.Last;
            node != null && node != m_head;
            node = node.Previous)
        {
            node.Value.Revert(this);
        }

        //Apply the new commit onto the head.
        if (commit.Apply(this))
        {
            LinkedListNode<InventoryCommit> newHead;
            if (m_head != null)
                newHead = m_commits.AddAfter(m_head, commit);
            else
                newHead = m_commits.AddFirst(commit);

            if (commit.Lock(this, newHead))
            {
                m_head = newHead;
            }
            else
            {
                m_commits.Remove(newHead);
            }
        }
        else
        {
            commit.Revert(this);
            return false;
        }

        //Push floating commits back onto inventory.
        for (node = _GetFloatingTale(); node != null;)
        {
            InventoryCommit floatingCommit = node.Value;
            if (!floatingCommit.Apply(this))
            {
                LinkedListNode<InventoryCommit> removingNode = node;
                node = node.Next;
                m_commits.Remove(removingNode);
            }
            else
            {
                node = node.Next;
            }
        }

        return true;
    }
예제 #2
0
    private bool _CommitOnFloating(InventoryCommit commit)
    {
        if (commit.Apply(this))
            return false;

        m_commits.AddLast(commit);

        return true;
    }