public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();

            if(version < 5)
            {
                // have to add the XmlDialog attachment
                m_DialogAttachment = new XmlDialog((string)null);
                XmlAttach.AttachTo(this, m_DialogAttachment);
            }

            switch ( version )
            {
                case 7:
                    m_EItemID = reader.ReadInt();
                    m_Duration = reader.ReadInt();
                    m_Offset = reader.ReadPoint3D();
                    m_EHue = reader.ReadInt();
                    goto case 6;
                case 6:
                    TalkText = reader.ReadString();
                    break;
                case 5:
                {
                    break;
                }
                case 4:
                {
                    int count = reader.ReadInt();

                    SpeechEntries = new ArrayList();
                    for(int i = 0; i<count;i++)
                    {
                        XmlDialog.SpeechEntry newentry = new XmlDialog.SpeechEntry();

                        newentry.Condition = reader.ReadString();

                        SpeechEntries.Add(newentry);
                    }

                    goto case 3;
                }
                case 3:
                {
                    TriggerOnCarried = reader.ReadString();
                    NoTriggerOnCarried = reader.ReadString();
                    goto case 2;
                }
                case 2:
                {
                    SpeechPace = reader.ReadInt();

                    int count = reader.ReadInt();
                    if(version < 4)
                    {
                        SpeechEntries = new ArrayList();
                    }
                    for(int i = 0; i<count;i++)
                    {
                        if(version < 4)
                        {
                            XmlDialog.SpeechEntry newentry = new XmlDialog.SpeechEntry();

                            newentry.PrePause = reader.ReadInt();
                            newentry.LockConversation = reader.ReadBool();
                            newentry.AllowNPCTrigger = reader.ReadBool();
                            newentry.SpeechStyle = (MessageType)reader.ReadInt();

                            SpeechEntries.Add(newentry);
                        }
                        else
                        {
                            XmlDialog.SpeechEntry newentry = (XmlDialog.SpeechEntry)SpeechEntries[i];

                            newentry.PrePause = reader.ReadInt();
                            newentry.LockConversation = reader.ReadBool();
                            newentry.AllowNPCTrigger = reader.ReadBool();
                            newentry.SpeechStyle = (MessageType)reader.ReadInt();
                        }
                    }
                    goto case 1;
                }
                case 1:
                {
                    ActivePlayer = reader.ReadMobile();
                    goto case 0;
                }
                case 0:
                {
                    IsActive = reader.ReadBool();
                    ResetTime = reader.ReadTimeSpan();
                    LastInteraction = reader.ReadDateTime();
                    AllowGhostTrig = reader.ReadBool();
                    ProximityRange = reader.ReadInt();
                    Running = reader.ReadBool();
                    ConfigFile = reader.ReadString();
                    int count = reader.ReadInt();
                    if(version < 2)
                    {
                        SpeechEntries = new ArrayList();
                    }
                    for(int i = 0; i<count;i++)
                    {

                        if(version < 2)
                        {
                            XmlDialog.SpeechEntry newentry = new XmlDialog.SpeechEntry();

                            newentry.EntryNumber = reader.ReadInt();
                            newentry.ID = reader.ReadInt();
                            newentry.Text = reader.ReadString();
                            newentry.Keywords = reader.ReadString();
                            newentry.Action = reader.ReadString();
                            newentry.DependsOn = reader.ReadInt().ToString();
                            newentry.Pause = reader.ReadInt();

                            SpeechEntries.Add(newentry);
                        }
                        else
                        {
                            XmlDialog.SpeechEntry newentry = (XmlDialog.SpeechEntry)SpeechEntries[i];

                            newentry.EntryNumber = reader.ReadInt();
                            newentry.ID = reader.ReadInt();
                            newentry.Text = reader.ReadString();
                            newentry.Keywords = reader.ReadString();
                            newentry.Action = reader.ReadString();
                            newentry.DependsOn = reader.ReadInt().ToString();
                            newentry.Pause = reader.ReadInt();
                        }
                    }
                    // read in the current entry number. Note this will also set the current entry
                    EntryNumber = reader.ReadInt();
                    // restart the timer if it was active
                    bool isrunning = reader.ReadBool();
                    if(isrunning)
                    {
                        Mobile trigmob = reader.ReadMobile();
                        TimeSpan delay = reader.ReadTimeSpan();
                        if(DialogAttachment != null)
                            DialogAttachment.DoTimer(delay,trigmob);
                    }
                    break;
                }
            }
        }
Beispiel #2
0
        public override void OnResponse( NetState state, RelayInfo info )
        {
            if(info == null || state == null || state.Mobile == null || m_Dialog == null) return;

            int radiostate = -1;
            if(info.Switches.Length > 0)
            {
                radiostate = info.Switches[0];
            }

            TextRelay tr = info.GetTextEntry( 400 );        // displayfrom info
            try
            {
                DisplayFrom = int.Parse(tr.Text);
            }
            catch{}

            tr = info.GetTextEntry( 300 );        // savefilename info
            if(tr != null)
                SaveFilename = tr.Text;

            if(m_Dialog != null)
            {
                tr = info.GetTextEntry( 140 );        // proximity range
                if(tr != null)
                {
                    try
                    {
                        m_Dialog.ProximityRange = int.Parse(tr.Text);
                    }
                    catch{}
                }
                tr = info.GetTextEntry( 141 );        // reset time
                if(tr != null)
                {
                    try
                    {
                        m_Dialog.ResetTime = TimeSpan.Parse(tr.Text);
                    }
                    catch{}
                }
                tr = info.GetTextEntry( 142 );        // speech pace
                if(tr != null)
                {
                    try
                    {
                        m_Dialog.SpeechPace = int.Parse(tr.Text);
                    }
                    catch{}
                }

                tr = info.GetTextEntry( 150 );        // trig on carried
                if(tr != null && (m_Dialog.TriggerOnCarried == null || m_Dialog.TriggerOnCarried.Length < 230))
                {
                    if(tr.Text != null && tr.Text.Trim().Length > 0)
                    {
                        m_Dialog.TriggerOnCarried = tr.Text;
                    }
                    else
                    {
                        m_Dialog.TriggerOnCarried = null;
                    }
                }

                tr = info.GetTextEntry( 151 );        // notrig on carried
                if(tr != null && (m_Dialog.NoTriggerOnCarried == null || m_Dialog.NoTriggerOnCarried.Length < 230))
                {
                    if(tr.Text != null && tr.Text.Trim().Length > 0)
                    {
                        m_Dialog.NoTriggerOnCarried = tr.Text;
                    }
                    else
                    {
                        m_Dialog.NoTriggerOnCarried = null;
                    }
                }

                m_Dialog.AllowGhostTrig = info.IsSwitched(260);	// allow ghost triggering
            }

            if(m_SearchList != null && Selected >= 0 && Selected + DisplayFrom >= 0 && Selected + DisplayFrom < m_SearchList.Count)
            {
                // entry information
                XmlDialog.SpeechEntry entry = (XmlDialog.SpeechEntry)m_SearchList[Selected + DisplayFrom];

                tr = info.GetTextEntry( 200 );        // entry number
                if(tr != null)
                {
                    try
                    {
                        entry.EntryNumber = int.Parse(tr.Text);
                    }
                    catch {}
                }

                tr = info.GetTextEntry( 201 );        // entry id
                if(tr != null)
                {
                    try
                    {
                        entry.ID = int.Parse(tr.Text);
                    }
                    catch {}
                }

                tr = info.GetTextEntry( 202 );        // depends on
                if(tr != null)
                {
                    try
                    {
                        entry.DependsOn = tr.Text;
                    }
                    catch {}
                }

                tr = info.GetTextEntry( 203 );        // prepause
                if(tr != null)
                {
                    try
                    {
                        entry.PrePause = int.Parse(tr.Text);
                    }
                    catch {}
                }

                tr = info.GetTextEntry( 204 );        // pause
                if(tr != null)
                {
                    try
                    {
                        entry.Pause = int.Parse(tr.Text);
                    }
                    catch {}
                }

                tr = info.GetTextEntry( 205 );        // hue
                if(tr != null)
                {
                    try
                    {
                        entry.SpeechHue = int.Parse(tr.Text);
                    }
                    catch {}
                }

                tr = info.GetTextEntry( 101 );        // keywords
                if(tr != null && (entry.Keywords == null || entry.Keywords.Length < 230))
                {
                    if(tr.Text != null && tr.Text.Trim().Length > 0)
                    {
                        entry.Keywords = tr.Text;
                    }
                    else
                    {
                        entry.Keywords = null;
                    }

                }

                tr = info.GetTextEntry( 100 );        // text
                if(tr != null && (entry.Text == null || entry.Text.Length < 230))
                {
                    if(tr.Text != null && tr.Text.Trim().Length > 0)
                    {
                        entry.Text = tr.Text;
                    }
                    else
                    {
                        entry.Text = null;
                    }
                }

                tr = info.GetTextEntry( 102 );        // condition
                if(tr != null && (entry.Condition == null || entry.Condition.Length < 230))
                {
                    if(tr.Text != null && tr.Text.Trim().Length > 0)
                    {
                        entry.Condition = tr.Text;
                    }
                    else
                    {
                        entry.Condition = null;
                    }
                }

                tr = info.GetTextEntry( 103 );        // action
                if(tr != null && (entry.Action == null || entry.Action.Length < 230))
                {
                    if(tr.Text != null && tr.Text.Trim().Length > 0)
                    {
                        entry.Action = tr.Text;
                    }
                    else
                    {
                        entry.Action = null;
                    }
                }

                tr = info.GetTextEntry( 104 );        // gump
                if(tr != null && (entry.Gump == null || entry.Gump.Length < 230))
                {
                    if(tr.Text != null && tr.Text.Trim().Length > 0)
                    {
                        entry.Gump = tr.Text;
                    }
                    else
                    {
                        entry.Gump = null;
                    }
                }

                entry.LockConversation = info.IsSwitched(250);	// lock conversation
                entry.AllowNPCTrigger = info.IsSwitched(251);	// allow npc
                entry.IgnoreCarried = info.IsSwitched(252);	// ignorecarried
            }

            switch ( info.ButtonID )
            {

                case 0: // Close
                {

                    m_Dialog.DeleteTextEntryBook();

                    return;
                }
                case 100: // toggle running status
                {

                    m_Dialog.Running = !m_Dialog.Running;

                    break;
                }
                case 155: // add new entry
                {

                    if(m_SearchList != null)
                    {
                        // find the last entry
                        int lastentry = 0;
                        foreach(XmlDialog.SpeechEntry e in m_SearchList)
                        {
                            if(e.EntryNumber > lastentry)
                                lastentry = e.EntryNumber;
                        }
                        lastentry += 10;
                        XmlDialog.SpeechEntry se = new XmlDialog.SpeechEntry();
                        se.EntryNumber = lastentry;
                        se.ID = lastentry;
                        m_SearchList.Add(se);
                        Selected = m_SearchList.Count -1;
                    }
                    break;
                }

                case 156: // Delete selected entries
                {
                    XmlEditDialogGump g = Refresh(state);
                    int allcount = 0;
                    if(m_SearchList != null)
                        allcount = m_SearchList.Count;
                    state.Mobile.SendGump( new XmlConfirmDeleteGump(state.Mobile, g, m_SearchList, m_SelectionList, DisplayFrom, SelectAll, allcount) );
                    return;
                }

                case 159: // save to a .npc file
                {

                    // Create a new gump
                    Refresh(state);
                    // try to save
                    m_Dialog.DoSaveNPC(state.Mobile, SaveFilename, true);

                    return;
                }

                case 201: // forward block
                {
                    // clear the selections
                    if(m_SelectionList != null && !SelectAll) Array.Clear(m_SelectionList,0,m_SelectionList.Length);
                    if(m_SearchList != null && DisplayFrom + MaxEntries < m_SearchList.Count)
                    {
                        DisplayFrom += MaxEntries;
                        // clear any selection
                        Selected = -1;
                    }
                    break;
                }
                case 202: // backward block
                {
                    // clear the selections
                    if(m_SelectionList != null && !SelectAll) Array.Clear(m_SelectionList,0,m_SelectionList.Length);
                    DisplayFrom -= MaxEntries;
                    if(DisplayFrom < 0) DisplayFrom = 0;
                    // clear any selection
                    Selected = -1;
                    break;
                }

                case 700: // Sort
                {
                    // clear any selection
                    Selected = -1;
                    // clear the selections
                    if(m_SelectionList != null && !SelectAll) Array.Clear(m_SelectionList,0,m_SelectionList.Length);

                    SortFindList();
                    break;
                }

                case 9998:  // refresh the gump
                {
                    // clear any selection
                    Selected = -1;
                    break;
                }
                default:
                {

                    if(info.ButtonID >= 1000 && info.ButtonID < 1000+ MaxEntries)
                    {
                        // flag the entry selected
                        Selected = info.ButtonID - 1000;
                    }
                    else
                        if(info.ButtonID == 3998)
                    {

                        SelectAll = !SelectAll;

                        // dont allow individual selection with the selectall button selected
                        if(m_SelectionList != null)
                        {
                            for(int i = 0; i < MaxEntries;i++)
                            {
                                if(i < m_SelectionList.Length)
                                {
                                    // only toggle the selection list entries for things that actually have entries
                                    m_SelectionList[i] = SelectAll;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                        if(info.ButtonID == 3999)
                    {

                        // dont allow individual selection with the selectall button selected
                        if(m_SelectionList != null && m_SearchList != null && !SelectAll)
                        {
                            for(int i = 0; i < MaxEntries;i++)
                            {
                                if(i < m_SelectionList.Length)
                                {
                                    // only toggle the selection list entries for things that actually have entries
                                    if((m_SearchList.Count - DisplayFrom > i))
                                    {
                                        m_SelectionList[i] = !m_SelectionList[i];
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                        if(info.ButtonID >= 4000 && info.ButtonID < 4000+ MaxEntries)
                    {
                        int i = info.ButtonID - 4000;
                        // dont allow individual selection with the selectall button selected
                        if(m_SelectionList != null && i >= 0  && i < m_SelectionList.Length && !SelectAll)
                        {
                            // only toggle the selection list entries for things that actually have entries
                            if(m_SearchList != null && (m_SearchList.Count - DisplayFrom > i))
                            {
                                m_SelectionList[i] = !m_SelectionList[i];
                            }
                        }
                    }
                    else
                        if(info.ButtonID >= 5000 && info.ButtonID < 5100)
                    {

                        // text entry book buttons
                        int textid = info.ButtonID - 5000;

                        // entry information
                        XmlDialog.SpeechEntry entry = null;

                        if(m_SearchList != null && Selected >= 0 && Selected + DisplayFrom >= 0 && Selected + DisplayFrom < m_SearchList.Count)
                        {
                            entry = (XmlDialog.SpeechEntry)m_SearchList[Selected + DisplayFrom];
                        }

                        string text = String.Empty;
                        string title = String.Empty;
                        switch(textid)
                        {
                            case 0: // text
                                if(entry != null)
                                    text = entry.Text;
                                title = "Text";
                                break;
                            case 1: // keywords
                                if(entry != null)
                                    text = entry.Keywords;
                                title = "Keywords";
                                break;
                            case 2: // condition
                                if(entry != null)
                                    text = entry.Condition;
                                title = "Condition";
                                break;
                            case 3: // action
                                if(entry != null)
                                    text = entry.Action;
                                title = "Action";
                                break;
                            case 4: // gump
                                if(entry != null)
                                    text = entry.Gump;
                                title = "Gump";
                                break;
                            case 5: // trigoncarried
                                text = m_Dialog.TriggerOnCarried;
                                title = "TrigOnCarried";
                                break;
                            case 6: // notrigoncarried
                                text = m_Dialog.NoTriggerOnCarried;
                                title = "NoTrigOnCarried";
                                break;
                        }

                        object [] args = new object[6];

                        args[0] = m_Dialog;
                        args[1] = entry;
                        args[2] = textid;
                        args[3] = Selected;
                        args[4] = DisplayFrom;
                        args[5] = SaveFilename;

                        XmlTextEntryBook book = new XmlTextEntryBook(0, String.Empty, m_Dialog.Name, 20, true, new XmlTextEntryBookCallback(ProcessXmlEditBookEntry), args);

                        if(m_Dialog.m_TextEntryBook == null)
                        {
                            m_Dialog.m_TextEntryBook = new ArrayList();
                        }
                        m_Dialog.m_TextEntryBook.Add(book);

                        book.Title = title;
                        book.Author = Name;

                        // fill the contents of the book with the current text entry data
                        book.FillTextEntryBook(text);

                        // put the book at the location of the player so that it can be opened, but drop it below visible range
                        book.Visible = false;
                        book.Movable = false;
                        book.MoveToWorld(new Point3D(state.Mobile.Location.X,state.Mobile.Location.Y,state.Mobile.Location.Z-100), state.Mobile.Map);

                        // Create a new gump
                        Refresh(state);

                        // and open it
                        book.OnDoubleClick(state.Mobile);

                        return;

                    }
                    break;
                }
            }
            // Create a new gump
            Refresh(state);
        }