private void ResetParameters() { CHAR_A = CHAR_B = CHAR_ACTIVE = string.Empty; HAS_PERMS = SET_TYPE = false; EMOTION_A = EMOTION_B = DEFAULT_EMOTION; CONVERSATION_TYPE = ConversationTypes.TYPE_1; }
private void ResetParameters() { hasPerms = setType = false; charActive = charA = charB = string.Empty; emotionA = emotionB = DefaultEmotion; CharSide = -1; conversationType = ConversationTypes.Type1; }
public static Conversation CreateNewConversation(Envelope envelope, bool registerConversation = true) { Conversation newConversation = null; if (envelope?.Message != null && ConversationTypes.ContainsKey(envelope.Message.GetType())) { newConversation = Activator.CreateInstance(ConversationTypes[envelope.Message.GetType()]) as Conversation; if (newConversation != null) { newConversation.Id = envelope.ConvId; newConversation.MessageInbox.Enqueue(envelope); } } return(newConversation); }
public string GetParsedCommands(MessageLine line) { //TODO(Robin): Move to CommandTokens? Func <string, bool, string> purify = (s, replaceEnvironment) => { s = s.Replace("\\n", "\n") .Replace("$k\n", "$k\\n"); if (replaceEnvironment) { s = s.Replace("\n", Environment.NewLine); } return(s); }; if (line.SpokenText != string.Empty) { line.UpdateRawWithNewDialogue(); line.RawLine = purify(line.RawLine, false); } line.SpokenText = line.RawLine; for (var i = 0; i < line.SpokenText.Length; i++) { if (line.SpokenText[i] != '$') { continue; } var res = MessageBlock.ParseCommand(line.SpokenText, i); line.SpokenText = res.Item1; var command = res.Item2; var @params = command.Params; if (command.numParams > 0) { if (@params[0] == "ベロア") { @params[0] = "べロア"; // Velour Fix } } switch (command.CommandWithPrefix) { case CommandTokens.E: var emotion = @params[0] != "," ? @params[0] : DefaultEmotion; if (string.IsNullOrEmpty(charActive) || charActive != charB) { emotionA = emotion; } else { Debug.Assert(charActive == charB, $"{charActive} == {charB}"); emotionB = emotion; } break; case CommandTokens.Ws: charActive = @params[0]; break; case CommandTokens.Wm: CharSide = Convert.ToInt32(@params[1]); //NOTE(Robin): Prepare an exception for multiple possible fail states below var unexpectedCharSideException = new ArgumentOutOfRangeException(nameof(CharSide), CharSide, "Unexpected character side parameter."); switch (conversationType) { case ConversationTypes.Type0: { switch (CharSide) { case 0: case 2: charA = @params[0]; emotionA = DefaultEmotion; break; case 6: charB = @params[0]; emotionB = DefaultEmotion; break; default: throw unexpectedCharSideException; } break; } case ConversationTypes.Type1: { switch (CharSide) { case 3: charA = @params[0]; emotionA = DefaultEmotion; break; case 7: charB = @params[0]; emotionB = DefaultEmotion; break; default: throw unexpectedCharSideException; } break; } default: throw new ArgumentOutOfRangeException(nameof(conversationType), conversationType, "Unexpected conversation type."); } break; case CommandTokens.Wd: if (charActive == charB) { charActive = charA; charB = string.Empty; } else { Debug.Assert(charActive == charA, $"{nameof(charActive)} == {nameof(charA)}"); charA = string.Empty; } break; case CommandTokens.a: hasPerms = true; break; case CommandTokens.t0: if (!setType) { conversationType = ConversationTypes.Type0; } setType = true; break; case CommandTokens.t1: if (!setType) { conversationType = ConversationTypes.Type1; } setType = true; break; case CommandTokens.Nu: line.SpokenText = $"{line.SpokenText.Substring(0, i)}$Nu{line.SpokenText.Substring(i)}"; i += 2; break; default: Debug.WriteLine($"Unhandled command: {command.CommandWithPrefix}"); if (!CommandTokens.IsValid(command.CommandWithPrefix)) { throw new ArgumentOutOfRangeException(nameof(command.CommandWithPrefix), command.CommandWithPrefix, "Unexpected command."); } break; } i--; } if (string.IsNullOrWhiteSpace(line.SpokenText)) { line.SpokenText = string.Empty; } line.SpeechIndex = line.RawLine.LastIndexOf(line.SpokenText, StringComparison.Ordinal); line.RawLine = purify(line.RawLine, false); line.SpokenText = purify(line.SpokenText, true); return(line.SpokenText); }
private string UpdateParse(string MSG) { for (int i = 0; i < MSG.Length; i++) { if (MSG[i] == '$') { Tuple <string, Command> res = ParseCommand(MSG, i); MSG = res.Item1; if (res.Item2.NumParams > 0) { if (res.Item2.Params[0] == "ベロア") { res.Item2.Params[0] = "べロア"; // Velouria Fix } } switch (res.Item2.CMD) { case "$E": if (CHAR_ACTIVE != string.Empty && CHAR_ACTIVE == CHAR_B) { EMOTION_B = res.Item2.Params[0]; } else { EMOTION_A = res.Item2.Params[0]; } break; case "$Ws": CHAR_ACTIVE = res.Item2.Params[0]; break; case "$Wm": if (CONVERSATION_TYPE == ConversationTypes.TYPE_1) { if (res.Item2.Params[1] == "3") { CHAR_A = res.Item2.Params[0]; EMOTION_A = DEFAULT_EMOTION; } else if (res.Item2.Params[1] == "7") { CHAR_B = res.Item2.Params[0]; EMOTION_B = DEFAULT_EMOTION; } } else { if (res.Item2.Params[1] == "0" || res.Item2.Params[1] == "2") { CHAR_A = res.Item2.Params[0]; EMOTION_A = DEFAULT_EMOTION; } else if (res.Item2.Params[1] == "6") { CHAR_B = res.Item2.Params[0]; EMOTION_B = DEFAULT_EMOTION; } } break; case "$Wd": if (CHAR_ACTIVE == CHAR_B) { CHAR_ACTIVE = CHAR_A; CHAR_B = string.Empty; } else { CHAR_A = string.Empty; } break; case "$a": HAS_PERMS = true; break; case "$t0": if (!SET_TYPE) { CONVERSATION_TYPE = ConversationTypes.TYPE_0; } SET_TYPE = true; break; case "$t1": if (!SET_TYPE) { CONVERSATION_TYPE = ConversationTypes.TYPE_1; } SET_TYPE = true; break; case "$Nu": if (HAS_PERMS) { MSG = MSG.Substring(0, i) + PLAYER_NAME + MSG.Substring(i); } else { MSG = MSG.Substring(0, i) + "$Nu" + MSG.Substring(i); i += 2; } break; case "$Wa": case "$Wc": default: break; } i--; } } MSG = MSG.Replace("\\n", "\n"); return(MSG); }
private string UpdateParse(string MSG) { for (int i = 0; i < MSG.Length; i++) { if (MSG[i] == '$') { Tuple<string, Command> res = ParseCommand(MSG, i); MSG = res.Item1; switch (res.Item2.CMD) { case "$E": if (CHAR_ACTIVE != string.Empty && CHAR_ACTIVE == CHAR_B) { EMOTION_B = res.Item2.Params[0]; } else { EMOTION_A = res.Item2.Params[0]; } break; case "$Ws": CHAR_ACTIVE = res.Item2.Params[0]; break; case "$Wm": if (CONVERSATION_TYPE == ConversationTypes.TYPE_1) { if (res.Item2.Params[1] == "3") { CHAR_A = res.Item2.Params[0]; EMOTION_A = DEFAULT_EMOTION; } else if (res.Item2.Params[1] == "7") { CHAR_B = res.Item2.Params[0]; EMOTION_B = DEFAULT_EMOTION; } } else { if (res.Item2.Params[1] == "0" || res.Item2.Params[1] == "2") { CHAR_A = res.Item2.Params[0]; EMOTION_A = DEFAULT_EMOTION; } else if (res.Item2.Params[1] == "6") { CHAR_B = res.Item2.Params[0]; EMOTION_B = DEFAULT_EMOTION; } } break; case "$Wd": if (CHAR_ACTIVE == CHAR_B) { CHAR_ACTIVE = CHAR_A; CHAR_B = string.Empty; } else CHAR_A = string.Empty; break; case "$a": HAS_PERMS = true; break; case "$t0": if (!SET_TYPE) CONVERSATION_TYPE = ConversationTypes.TYPE_0; SET_TYPE = true; break; case "$t1": if (!SET_TYPE) CONVERSATION_TYPE = ConversationTypes.TYPE_1; SET_TYPE = true; break; case "$Nu": if (HAS_PERMS) { MSG = MSG.Substring(0, i) + PLAYER_NAME + MSG.Substring(i); } else { MSG = MSG.Substring(0, i) + "$Nu" + MSG.Substring(i); i += 2; } break; case "$Wa": case "$Wc": default: break; } i--; } } MSG = MSG.Replace("\\n", "\n"); return MSG; }