public bool IsMatch(string input, SpeechEntry entry) { string[] split = entry.Keywords; for (int i = 0; i < split.Length; i++) { if (split[i].Length > 0 && split[i].Length <= input.Length) { if (!entry.CheckStart) { if (input.IndexOf(split[i], 0) < 0) { continue; } } if (!entry.CheckEnd) { if (input.IndexOf(split[i], input.Length - split[i].Length) < 0) { continue; } } if (input.IndexOf(split[i]) >= 0) { return(true); } } } return(false); }
public SpeechEntryController(EntryChunkController entrychunkcontroller, SpeechEntry speechentry) : base(entrychunkcontroller, speechentry) { this.speechentry = speechentry; Node.Text = string.Format("Speech Entry ({0})", speechentry.EIDString); Node.ImageKey = "speechentry"; Node.SelectedImageKey = "speechentry"; }
internal static List <ushort> GetKeywords(string text) { List <ushort> keynumber = new List <ushort>(); if (m_Speech == null) { LoadSpeechTable(); } text = text.ToLower(); List <SpeechEntry> keywords = new List <SpeechEntry>(); List <SpeechEntry> speech = m_Speech.ToList(); foreach (SpeechEntry entry in speech) { if (IsMatch(text, entry.m_Keywords)) { keywords.Add(entry); } } keywords.Sort(); bool flag = false; int numk = keywords.Count & 15; int index = 0; while (index < keywords.Count) { SpeechEntry entry = keywords[index]; int keywordID = entry.m_KeywordID; if (flag) { keynumber.Add((byte)(keywordID >> 4)); numk = keywordID & 15; } else { keynumber.Add((byte)((numk << 4) | ((keywordID >> 8) & 15))); keynumber.Add((byte)keywordID); } index++; flag = !flag; } if (!flag) { keynumber.Add((byte)(numk << 4)); } return(keynumber); }
private SpeechEntry SelectEntry(string speech) { if (m_Speech.Count == 0) { return(null); } if (m_Sequence) { if (m_SpeechIndex < 0 || m_SpeechIndex >= m_Speech.Count) { m_SpeechIndex = 0; // Reset when out of bounds } // Reset sequence if timed out (players left the NPC or whatever) if (m_SpeechStart + m_SequenceTimeOut <= DateTime.Now) { m_SpeechIndex = 0; } SpeechEntry next = m_Speech[m_SpeechIndex] as SpeechEntry; if (next.Match(speech)) { m_SpeechStart = DateTime.Now; m_SpeechIndex++; if (m_SpeechIndex == m_Speech.Count) { // Last one, reset to 0 m_SpeechIndex = 0; } return(next); } } else { // Not in sequence, just select appropriate entry foreach (SpeechEntry entry in m_Speech) { if (entry.Match(speech)) { return(entry); } } } return(null); }
public void SayNext() { Say((string)m_SelectedEntry.Speech[m_NextLine]); m_NextLine++; if (m_NextLine >= m_SelectedEntry.Speech.Count) { // End here m_Timer.Stop(); m_Timer = null; m_SelectedEntry = null; m_Speaking = false; } }
protected override void DoWorkItem(object item) { #if WINDOWS_UWP try { SpeechEntry speechEntry = item as SpeechEntry; // Need await, so most of this will be run as a new Task in its own thread. // This is good since it frees up Unity to keep running anyway. Task.Run(async() => { this.ChangeVoice(voice); var buffer = await UnityAudioHelper.SynthesizeToUnityDataAsync( speechEntry.Text, speechEntry.SpeechGenerator); // Convert raw WAV data into Unity audio data int sampleCount = 0; int frequency = 0; float[] unityData = null; unityData = UnityAudioHelper.ToUnityAudio( buffer, out sampleCount, out frequency); // The remainder must be done back on Unity's main thread UnityEngine.WSA.Application.InvokeOnAppThread( () => { // Convert to an audio clip var clip = UnityAudioHelper.ToClip( "Speech", unityData, sampleCount, frequency); // Set the source on the audio clip audioSource.clip = clip; // Play audio audioSource.Play(); }, false); }); } catch (Exception ex) { Debug.LogErrorFormat("Speech generation problem: \"{0}\"", ex.Message); } #endif }
private void Speak() { if (m_SpeechStartDelay) { // First run timer then talk m_Speaking = true; if (m_Timer != null) { m_Timer.Stop(); m_Timer = null; } m_NextLine = 0; m_Timer = new SpeechTimer(this, m_SpeechInterval); m_Timer.Start(); } else { // Start talking right away Say((string)m_SelectedEntry.Speech[0]); m_Speaking = true; if (m_SelectedEntry.Speech.Count > 1) { if (m_Timer != null) { m_Timer.Stop(); m_Timer = null; } m_NextLine = 1; m_Timer = new SpeechTimer(this, m_SpeechInterval); m_Timer.Start(); } else { m_SelectedEntry = null; m_Speaking = false; } } }
public SpeechEntryGump(Mobile user, Speaker speaker, SpeechEntry entry, int keyIndex, int speechIndex, bool editMode) : base(50, 50) { m_User = user; m_Speaker = speaker; m_KeyIndex = keyIndex; m_SpeechIndex = speechIndex; m_EditMode = editMode; m_User.CloseGump(typeof(SpeechEntryGump)); if (entry != null) { m_Entry = entry; } else { m_Entry = new SpeechEntry(); } MakeGump(); }
public static SpeechEntry Deserialize(GenericReader reader, int version) { SpeechEntry entry = new SpeechEntry(); entry.m_MatchAll = reader.ReadBool(); int NumOfKeywords = reader.ReadInt(); for (int i = 0; i < NumOfKeywords; i++) { entry.m_Keywords.Add(reader.ReadString()); } int NumOfSpeech = reader.ReadInt(); for (int i = 0; i < NumOfSpeech; i++) { entry.m_Speech.Add(reader.ReadString()); } return(entry); }
public override void OnSpeech(SpeechEventArgs e) { if (m_Speaking) // Ignore anything while speaking { return; } if (m_Updating) { Say("I apologize, but I am very busy organizing my thoughts. Please come back shortly..."); return; } if (e.Mobile.InRange(this, m_ResponseRange)) { m_SelectedEntry = SelectEntry(e.Speech); if (m_SelectedEntry != null) { Speak(); } } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); switch (version) { case 1: m_SpeechStartDelay = reader.ReadBool(); m_Sequence = reader.ReadBool(); m_SequenceTimeOut = reader.ReadTimeSpan(); m_SpeechIndex = reader.ReadInt(); goto case 0; case 0: m_SpeechInterval = reader.ReadInt(); m_ResponseRange = reader.ReadInt(); int NumOfEntries = reader.ReadInt(); m_Speech = new ArrayList(); for (int i = 0; i < NumOfEntries; i++) { m_Speech.Add(SpeechEntry.Deserialize(reader, version)); } break; } EndUpdate(); }
private static ArrayList LoadSpeechFile() { ArrayList tables = new ArrayList(); int lastIndex = -1; Hashtable table = null; string path = Core.FindDataFile( "Speech.mul" ); if ( File.Exists( path ) ) { using ( FileStream ip = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryReader bin = new BinaryReader( ip ); while ( bin.PeekChar() >= 0 ) { int index = (bin.ReadByte() << 8) | bin.ReadByte(); int length = (bin.ReadByte() << 8) | bin.ReadByte(); string text = Encoding.UTF8.GetString( bin.ReadBytes( length ) ).Trim(); if ( text.Length == 0 ) continue; if ( table == null || lastIndex > index ) { if ( index == 0 && text == "*withdraw*" ) tables.Insert( 0, table = new Hashtable() ); else tables.Add( table = new Hashtable() ); } lastIndex = index; SpeechEntry entry = (SpeechEntry)table[index]; if ( entry == null ) table[index] = entry = new SpeechEntry( index ); entry.Strings.Add( text ); } } } return tables; }
public SpeechEntryGump( Mobile user, Speaker speaker, SpeechEntry entry, int keyIndex, int speechIndex, bool editMode ) : base( 50, 50 ) { m_User = user; m_Speaker = speaker; m_KeyIndex = keyIndex; m_SpeechIndex = speechIndex; m_EditMode = editMode; m_User.CloseGump( typeof( SpeechEntryGump ) ); if ( entry != null ) m_Entry = entry; else m_Entry = new SpeechEntry(); MakeGump(); }
public SpeechEntryGump( Mobile user, Speaker speaker, SpeechEntry entry ) : this( user, speaker, entry, entry.Keywords.Count, entry.Speech.Count, true ) { }
public static SpeechEntry Deserialize( GenericReader reader, int version ) { SpeechEntry entry = new SpeechEntry(); entry.m_MatchAll = reader.ReadBool(); int NumOfKeywords = reader.ReadInt(); for ( int i = 0; i < NumOfKeywords; i++ ) entry.m_Keywords.Add( reader.ReadString() ); int NumOfSpeech = reader.ReadInt(); for ( int i = 0; i < NumOfSpeech; i++ ) entry.m_Speech.Add( reader.ReadString() ); return entry; }
private SpeechEntry GetEntry(int entryid) { if(entryid < 0) return null; if(m_SpeechEntries == null) { m_SpeechEntries = new ArrayList(); } // find the speech entry that matches the current entry number foreach(SpeechEntry s in m_SpeechEntries) { if(s.EntryNumber == entryid) return s; } // didnt find it so make a new entry SpeechEntry newentry = new SpeechEntry(); newentry.EntryNumber = entryid; newentry.ID = entryid; m_SpeechEntries.Add(newentry); return newentry; }
public SoundBox(SpeechEntry entry) : this(entry.Samples) { }
public SpeechEntryGump(Mobile user, Speaker speaker, SpeechEntry entry) : this(user, speaker, entry, entry.Keywords.Count, entry.Speech.Count, true) { }
public override void OnSpeech(SpeechEventArgs e) { if ( m_Speaking ) // Ignore anything while speaking return; if ( m_Updating ) { Say( "I apologize, but I am very busy organizing my thoughts. Please come back shortly..." ); return; } if ( e.Mobile.InRange( this, m_ResponseRange ) ) { m_SelectedEntry = SelectEntry( e.Speech ); if ( m_SelectedEntry != null ) { Speak(); } } }
public override void Deserialize( GenericReader reader ) { base.Deserialize( reader ); int version = reader.ReadInt(); switch ( version ) { case 8: { int count = reader.ReadInt(); m_SpeechEntries = new ArrayList(); for (int i = 0; i < count; i++) { SpeechEntry newentry = new SpeechEntry(); newentry.IgnoreCarried = reader.ReadBool(); m_SpeechEntries.Add(newentry); } goto case 7; } case 7: { goto case 6; } case 6: { int count = reader.ReadInt(); if (version < 8) { m_SpeechEntries = new ArrayList(); } for(int i = 0; i<count;i++) { if (version < 8) { SpeechEntry newentry = new SpeechEntry(); newentry.SpeechHue = reader.ReadInt(); m_SpeechEntries.Add(newentry); } else { SpeechEntry newentry = (SpeechEntry)m_SpeechEntries[i]; newentry.SpeechHue = reader.ReadInt(); } } goto case 5; } case 5: { int count = reader.ReadInt(); if(version < 6) { m_SpeechEntries = new ArrayList(); } for(int i = 0; i<count;i++) { if(version < 6) { SpeechEntry newentry = new SpeechEntry(); newentry.Gump = reader.ReadString(); m_SpeechEntries.Add(newentry); } else { SpeechEntry newentry = (SpeechEntry)m_SpeechEntries[i]; newentry.Gump = reader.ReadString(); } } goto case 4; } case 4: { int count = reader.ReadInt(); if(version < 5) { m_SpeechEntries = new ArrayList(); } for(int i = 0; i<count;i++) { if(version < 5) { SpeechEntry newentry = new SpeechEntry(); newentry.Condition = reader.ReadString(); m_SpeechEntries.Add(newentry); } else { SpeechEntry newentry = (SpeechEntry)m_SpeechEntries[i]; newentry.Condition = reader.ReadString(); } } goto case 3; } case 3: { TriggerOnCarried = reader.ReadString(); NoTriggerOnCarried = reader.ReadString(); goto case 2; } case 2: { m_SpeechPace = reader.ReadInt(); int count = reader.ReadInt(); if(version < 4) { m_SpeechEntries = new ArrayList(); } for(int i = 0; i<count;i++) { if(version < 4) { SpeechEntry newentry = new SpeechEntry(); newentry.PrePause = reader.ReadInt(); newentry.LockConversation = reader.ReadBool(); newentry.AllowNPCTrigger = reader.ReadBool(); newentry.SpeechStyle = (MessageType)reader.ReadInt(); m_SpeechEntries.Add(newentry); } else { SpeechEntry newentry = (SpeechEntry)m_SpeechEntries[i]; newentry.PrePause = reader.ReadInt(); newentry.LockConversation = reader.ReadBool(); newentry.AllowNPCTrigger = reader.ReadBool(); newentry.SpeechStyle = (MessageType)reader.ReadInt(); } } goto case 1; } case 1: { m_ActivePlayer = reader.ReadMobile(); goto case 0; } case 0: { m_IsActive = reader.ReadBool(); m_ResetTime = reader.ReadTimeSpan(); m_LastInteraction = reader.ReadDateTime(); m_AllowGhostTriggering = reader.ReadBool(); m_ProximityRange = reader.ReadInt(); m_Running = reader.ReadBool(); m_ConfigFile = reader.ReadString(); int count = reader.ReadInt(); if(version < 2) { m_SpeechEntries = new ArrayList(); } for(int i = 0; i<count;i++) { if(version < 2) { SpeechEntry newentry = new 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(); m_SpeechEntries.Add(newentry); } else { SpeechEntry newentry = (SpeechEntry)m_SpeechEntries[i]; newentry.EntryNumber = reader.ReadInt(); newentry.ID = reader.ReadInt(); newentry.Text = reader.ReadString(); newentry.Keywords = reader.ReadString(); newentry.Action = reader.ReadString(); if(version < 7) { newentry.DependsOn = reader.ReadInt().ToString(); } else { newentry.DependsOn = reader.ReadString(); } 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(); DoTimer(delay,trigmob); } break; } } }
// see if the DependsOn property contains the specified id public bool CheckDependsOn(SpeechEntry s, int id) { if(s == null || s.DependsOn == null) return false; // parse the DependsOn string string [] args = s.DependsOn.Split(','); for(int i=0;i<args.Length;i++) { try { if(int.Parse(args[i].Trim()) == id) return true; } catch {} } return false; }
private void Speak() { Say( (string) m_SelectedEntry.Speech[ 0 ] ); m_Speaking = true; if ( m_SelectedEntry.Speech.Count > 1 ) { if ( m_Timer != null ) { m_Timer.Stop(); m_Timer = null; } m_NextLine = 1; m_Timer = new SpeechTimer( this, m_SpeechInterval ); m_Timer.Start(); } else { m_SelectedEntry = null; m_Speaking = false; } }
public void DoLoadNPC(Mobile from, string filename) { if(filename == null || filename.Length <= 0) return; string dirname; if( System.IO.Directory.Exists( DefsDir ) == true ) { // look for it in the defaults directory dirname = String.Format("{0}/{1}.npc",DefsDir,filename); // Check if the file exists if( System.IO.File.Exists( dirname ) == false ) { // didnt find it so just look in the main install dir dirname = String.Format("{0}.npc",filename); } } else { // look in the main installation dir dirname = String.Format("{0}.npc",filename); } // Check if the file exists if( System.IO.File.Exists( dirname ) == true ) { FileStream fs = null; try { fs = File.Open(dirname, FileMode.Open, FileAccess.Read); } catch {} if(fs == null) { from.SendMessage("Unable to open {0} for loading",dirname); return; } // Create the data set DataSet ds = new DataSet( NPCDataSetName ); // Read in the file bool fileerror = false; try { ds.ReadXml( fs); } catch{fileerror = true;} // close the file fs.Close(); if(fileerror) { if(from != null && !from.Deleted) from.SendMessage( 33, "Error reading npc file {0}", dirname); return; } // Check that at least a single table was loaded if( ds.Tables != null && ds.Tables.Count > 0 ) { // get the npc info if(ds.Tables[NPCPointName] != null && ds.Tables[NPCPointName].Rows.Count > 0) { DataRow dr = ds.Tables[NPCPointName].Rows[0]; try { if(AttachedTo is Item) { ((Item)AttachedTo).Name = (string)dr["Name"]; } else if(AttachedTo is Mobile) { ((Mobile)AttachedTo).Name = (string)dr["Name"]; } } catch{} try{this.ProximityRange = int.Parse((string)dr["ProximityRange"]);} catch{} try{this.TriggerOnCarried = (string)dr["TriggerOnCarried"];} catch{} try{this.NoTriggerOnCarried = (string)dr["NoTriggerOnCarried"];} catch{} try{this.m_AllowGhostTriggering = bool.Parse((string)dr["AllowGhost"]);} catch{} try{this.m_SpeechPace = int.Parse((string)dr["SpeechPace"]);} catch{} try{this.Running = bool.Parse((string)dr["Running"]);} catch{} try{this.ResetTime = TimeSpan.FromMinutes(double.Parse((string)dr["ResetTime"]));} catch{} try{this.ConfigFile = (string)dr["ConfigFile"];} catch{} int entrycount = 0; try{entrycount = int.Parse((string)dr["SpeechEntries"]);} catch{} } // get the speech entry info if(ds.Tables[NPCPointName] != null && ds.Tables[NPCPointName].Rows.Count > 0) { m_SpeechEntries = new ArrayList(); foreach( DataRow dr in ds.Tables[SpeechPointName].Rows ) { SpeechEntry s = new SpeechEntry(); // Populate the speech entry data try{s.EntryNumber = int.Parse((string)dr["EntryNumber"]);} catch{} try{s.ID = int.Parse((string)dr["ID"]);} catch{} try{s.Text = (string)dr["Text"];} catch{} try{s.Keywords = (string)dr["Keywords"];} catch{} try{s.Action = (string)dr["Action"];} catch{} try{s.Condition = (string)dr["Condition"];} catch{} try{s.DependsOn = (string)dr["DependsOn"];} catch{} try{s.Pause = int.Parse((string)dr["Pause"]);} catch{} try{s.PrePause = int.Parse((string)dr["PrePause"]);} catch{} try{s.LockConversation = bool.Parse((string)dr["LockConversation"]);} catch{} try { s.IgnoreCarried = bool.Parse((string)dr["IgnoreCarried"]); } catch { } try{s.AllowNPCTrigger = bool.Parse((string)dr["AllowNPCTrigger"]);} catch{} try{s.SpeechStyle = (MessageType)Enum.Parse(typeof(MessageType),(string)dr["SpeechStyle"]);} catch{} try{s.SpeechHue = int.Parse((string)dr["SpeechHue"]);} catch{} try{s.Gump = (string)dr["Gump"];} catch{} m_SpeechEntries.Add(s); } } Reset(); if(from != null && !from.Deleted) from.SendMessage("Loaded npc from file {0}", dirname); } else { if(from != null && !from.Deleted) from.SendMessage( 33, "No npc data found in: {0}", dirname); } } else { if(from != null && !from.Deleted) from.SendMessage( 33, "File not found: {0}", dirname); } }
public void SayNext() { Say( (string) m_SelectedEntry.Speech[ m_NextLine ] ); m_NextLine++; if ( m_NextLine >= m_SelectedEntry.Speech.Count ) { // End here m_Timer.Stop(); m_Timer = null; m_SelectedEntry = null; m_Speaking = false; } }