private static MessageCallback OnDictates(MessageInfo message) { Kingdom kingdom = KingdomsManager.FindKingdom(message.UserInfo); Guid hid = Guid.Parse(kingdom.Temp as string); Human h = null; foreach (Human hh in kingdom.Humans) { if (hh.HumanId == hid) { h = hh; break; } } int i; for (i = 0; i < h.TasksToDo.Count; ++i) { if (h.TasksToDo[i].TaskType == ETask.ListeningKing) { break; } } h.TasksToDo[i].TaskType = ETask.SendingMessage; h.TasksToDo[i].Context = message.Text; h.TasksToDo[i].CalculateTaskTime(h); UpdateState(message.UserInfo, EState.Main); KingdomsManager.OnJorney(h, kingdom); return(new MessageCallback(Locale.Get("answers.yes", kingdom.Language))); }
public static void SetLanguage(MessageInfo message) { UpdateUserInfo(message.UserInfo); message.UserInfo.Language = message.Text; DatabaseManager.Users.ReplaceOneAsync(ui => message.UserInfo.Equals(ui), message.UserInfo); KingdomsManager.FindKingdom(message.UserInfo).Language = message.Text; }
private static MessageCallback OnCommand(MessageInfo message) { Kingdom kingdom = KingdomsManager.FindKingdom(message.UserInfo); List <ExecutionResult> exec = new List <ExecutionResult>(); bool cont = true, succ = false; string text = message.Text; while (cont && (exec.Count == 0 || exec.Last().Successful)) { cont = false; foreach (Command c in Commands) { ExecutionResult res = c.Check(text, kingdom); if (res.Applied) { KingdomsManager.SaveKingdom(kingdom); res.Text = text.Substring(0, res.CommandLength).ToLower(); text = text.Substring(res.CommandLength); succ |= (cont = res.Successful); exec.Add(res); break; } } } if (succ) { Human selected = null; for (int i = 0; i < exec.Count; ++i) { foreach (Human h in kingdom.Humans) { // TODO: Do something with that if (exec[i].Text.Contains(h.Name.Split(' ')[0].ToLower()) || exec[i].Text.Contains(h.Name.Split(' ')[1].ToLower())) { selected = h; break; } } if (selected != null) { exec[i].Parsed["human"] = selected; } exec[i] = exec[i].Execute(kingdom); if (exec[i].NewState.HasValue) { UpdateState(message.UserInfo, exec[i].NewState.Value); } if (!exec[i].Successful || exec[i].LastCommand) { return(exec[i].Message); } else if (selected != null && exec[i].HumanBusy) { selected = null; } } } if (exec.Count == 0) { return(new MessageCallback("nyet.", ECharacter.Knight)); } else { return(exec.Last().Message); } }