private void OnCustomServiceAccepted(string command, string[] args) { Thread.Sleep(1100); if (args.Length == 0) { Chat.AddMessage("Введите id игрока, чтобы принять вызов"); return; } int id = int.Parse(args[0]); AmbulanceCall call = new AmbulanceCall { Caller = new Person() }; call.Caller.Id = id; Chat.Send($"/service ac cop {call.Caller.Id}"); Thread.Sleep(1100); for (int i = Chat.ChatHistory.Count - 1; Chat.ChatHistory.Count > 12 ? i > Chat.ChatHistory.Count - 12 : i > 0; i--) { if (Chat.ChatHistory[i].Contains("Место помечено на карте красной меткой")) { string[] words = Chat.ChatHistory[i].Split(' '); call.Distance = double.Parse(words[words.Length - 2].Replace(".", ",")); call.Accepted = true; } else if (Chat.ChatHistory[i].Contains($"Диспетчер: {MyName} принял вызов от")) { string[] words = Chat.ChatHistory[i].Split(' '); string name = words[words.Length - 1].Split('[')[0]; call.Caller.Name = name; } } ProcessCall(call); }
static void SaveAmbulanceCall(AmbulanceCall call) { if (!File.Exists("stats.txt")) { FileStream fs = File.Create("stats.txt"); fs.Close(); } List <Day> days = JsonConvert.DeserializeObject <List <Day> >(File.ReadAllText("stats.txt")); if (days == null) { days = new List <Day>(); } int ind = days.FindIndex(x => x.date.Date == DateTime.Now.Date); if (ind > -1) { //if (HealedCount > days[ind].HealedCount) ///days[ind].HealedCount = HealedCount; days[ind].Calls.Add(call); } else { Day day = new Day { Calls = AmbulanceCalls, date = DateTime.Now, //HealedCount = HealedCount }; days.Add(day); } File.WriteAllText("stats.txt", JsonConvert.SerializeObject(days)); }
private void OnServiceAccepted(string command, string[] args) { Thread.Sleep(1100); string sname = ""; for (int i = Chat.ChatHistory.Count - 1; Chat.ChatHistory.Count > 30 ? i > Chat.ChatHistory.Count - 30 : i > 0; i--) { if (Chat.ChatHistory[i].Contains("Диспетчер: вызов от ")) { AmbulanceCall call = new AmbulanceCall { Caller = new Person() }; string dispCallLine = Chat.ChatHistory[i]; string[] dispCallArgs = dispCallLine.Split(' '); int startBracket = dispCallLine.IndexOf('['); string sid = ""; for (int j = startBracket + 1; j < dispCallLine.Length; j++) { if (dispCallLine[j] == ']') { break; } sid += dispCallLine[j]; } call.Caller.Id = int.Parse(sid); int k = startBracket - 1; while (dispCallLine[k] != 'т') { sname += dispCallLine[k]; k--; } call.Caller.Name = Reverse(sname.Substring(0, sname.Length - 1)); bool x = false; string sdist = dispCallArgs[dispCallArgs.Length - 2].Replace('.', ','); if (sdist.Contains(",")) { x = true; } double distance = double.Parse(sdist); if (x) { distance *= 1000; } call.Distance = distance; Chat.Send($"/service ac cop {call.Caller.Id}"); call.Accepted = true; ProcessCall(call); return; } } Chat.AddMessage("Не найдено вызвов", "f56342"); }
private void ProcessCall(AmbulanceCall call) { AmbulanceCalls.Add(call); SaveAmbulanceCall(call); Thread.Sleep(1170); var pos = World.GetCheckpointPos(); string city = zoneManager.City(pos.X, pos.Y, pos.Z); string zone = zoneManager.Zone(pos.X, pos.Y, pos.Z); Chat.Send($"/f {settings.Tag} Докладываю: Принял вызов из {zone} | Нахожусь в {Player.GetZone()} | {call.Distance} м."); if (!Vehicle.IsSirenEnabled()) { Vehicle.ToggleSirenState(); } Chat.AddMessage($"Вы приняли вызов от {call.Caller.Name} [{call.Caller.Id}]. Расстояние до него - {call.Distance}", "f56342"); Chat.AddMessage($"Местоположение: {city}, {zone}", "f56342"); Thread.Sleep(1210); Chat.Send($"/t {call.Caller.Id} Полиция в пути! Находимся в {Player.GetZone()}"); Thread.Sleep(1210); double timeToPoint = CalculateTime(call.Distance); if (timeToPoint > 1) { Chat.Send($"/t {call.Caller.Id} До {city}, {zone} доберемся за {timeToPoint} минуты!"); } else { if (timeToPoint == 0) { Chat.Send($"/t {call.Caller.Id} До {city}, {zone} скоро доберемся!"); } else { Chat.Send($"/t {call.Caller.Id} До {city}, {zone} доберемся за {timeToPoint} минуту!"); } } Thread.Sleep(1205); Chat.Send($"/t {call.Caller.Id} По возможности опишите проблему, чтобы мы были готовы!"); }