private IEnumerator <float> StartTalkCoroutine(Player p) { if (TalkingStates.ContainsKey(p)) { p.SendConsoleMessage($"[{Name}] {Plugin.Instance.Config.TranslationAlreadyTalking}", "yellow"); } else { IsLocked = true; LockHandler = p; TalkingStates.Add(p, RootNode); bool end = RootNode.Send(Name, p); IsActionLocked = true; foreach (NodeAction action in RootNode.Actions.Keys) { action.Process(this, p, RootNode.Actions[action]); float dur = 0; try { dur = float.Parse(RootNode.Actions[action]["next_action_delay"].Replace('.', ',')); } catch (Exception) { } yield return(Timing.WaitForSeconds(dur)); } IsActionLocked = false; if (end) { TalkingStates.Remove(p); p.SendConsoleMessage(Name + $" {Plugin.Instance.Config.TranslationTalkEnd}", "yellow"); IsLocked = false; } } }
private IEnumerator <float> UpdateTalking() { List <Player> invalid_players = new List <Player>(); for (; ;) { invalid_players.Clear(); foreach (Player p in TalkingStates.Keys) { if (!p.IsAlive || !Player.Dictionary.ContainsKey(p.GameObject)) { invalid_players.Add(p); } } foreach (Player p in invalid_players) { TalkingStates.Remove(p); if (p == LockHandler) { LockHandler = null; IsLocked = false; } } yield return(Timing.WaitForSeconds(0.5f)); } }
private IEnumerator <float> HandleAnswerCoroutine(Player p, string answer) { if (TalkingStates.ContainsKey(p)) { TalkNode cur_node = TalkingStates[p]; if (int.TryParse(answer, out int node)) { if (cur_node.NextNodes.TryGet(node, out TalkNode new_node)) { TalkingStates[p] = new_node; IsActionLocked = true; bool end = new_node.Send(Name, p); foreach (NodeAction action in new_node.Actions.Keys) { try { action.Process(this, p, new_node.Actions[action]); } catch (Exception e) { Log.Error($"Exception during processing action {action.Name}: {e}"); } float dur = 0; try { dur = float.Parse(new_node.Actions[action]["next_action_delay"].Replace('.', ',')); } catch (Exception) { } yield return(Timing.WaitForSeconds(dur)); } IsActionLocked = false; if (end) { TalkingStates.Remove(p); p.SendConsoleMessage(Name + $" {Plugin.Instance.Config.TranslationTalkEnd}", "yellow"); IsLocked = false; } } else { p.SendConsoleMessage(Plugin.Instance.Config.TranslationInvalidAnswer, "red"); } } else { p.SendConsoleMessage(Plugin.Instance.Config.TranslationIncorrectFormat, "red"); } } else { p.SendConsoleMessage(Plugin.Instance.Config.TranslationNotTalking, "red"); } }