internal void AutoTurn() { if (!string.IsNullOrEmpty(AppVars.ContentMainPhp)) { var fight = new LezFight(AppVars.ContentMainPhp); if (fight.IsValid) { if (fight.LezCombinations.Count > 0 && fight.LezCombination != null) { //fight.PrintDebug(); var mainTop = GetFrame("main_top"); if (mainTop == null || mainTop.Document == null) { return; } AppVars.LastBoiTimer = DateTime.Now; mainTop.Document.InvokeScript("AutoSubmit", new object[] { fight.Result }); } else { WriteChatMsgSafe("Не выбрано ни одной правильной комбинации ударов/блоков/абилок. Измените настройки автобоя."); } } else { WriteChatMsgSafe("Фрейм боя содержит ошибки либо мы не в бою."); } } }
internal void AutoSelect() { if (!string.IsNullOrEmpty(AppVars.ContentMainPhp)) { var fight = new LezFight(AppVars.ContentMainPhp); if (fight.IsValid) { if (fight.LezCombinations.Count > 0 && fight.LezCombination != null) { //fight.PrintDebug(); var mainTop = GetFrame("main_top"); if (mainTop == null || mainTop.Document == null) { return; } for (var i = 0; i < fight.LezCombination.MagicFlags.Length; i++) { var m = string.Format($"m{i}"); var e = mainTop.Document.GetElementById(m); if (e != null) { e.SetAttribute("bgColor", "#cccccc"); } } for (var i = 0; i < fight.LezCombination.MagicFlags.Length; i++) { var m = string.Format($"m{i}"); var e = mainTop.Document.GetElementById(m); if (e != null) { if (fight.LezCombination.MagicFlags[i]) { e.SetAttribute("bgColor", "#cc0000"); } } } for (var i = 0; i < 4; i++) { var u = string.Format($"u{i}"); var e = mainTop.Document.GetElementById(u); if (e != null) { e.SetAttribute("SelectedIndex", fight.LezCombination.HitOps[i].ToString()); e.InvokeMember("onChange"); } if (LezSpell.IsMagHit(fight.LezCombination.HitCodes[i])) { var mb = string.Format($"mbu{i}"); e = mainTop.Document.GetElementById(mb); if (e != null) { e.SetAttribute("Value", fight.FoeGroup.MagHits.ToString()); } } } for (var i = 0; i < 4; i++) { var b = string.Format($"b{i}"); var e = mainTop.Document.GetElementById(b); if (e != null) { e.SetAttribute("SelectedIndex", "0"); e.InvokeMember("onChange"); } } var bl = string.Format($"b{fight.LezCombination.BlockCombo}"); var el = mainTop.Document.GetElementById(bl); if (el != null) { el.SetAttribute("SelectedIndex", fight.LezCombination.BlockOp.ToString()); el.InvokeMember("onChange"); } } else { WriteChatMsgSafe("Не выбрано ни одной правильной комбинации ударов/блоков/абилок. Измените настройки автобоя."); } } else { WriteChatMsgSafe("Фрейм боя содержит ошибки либо мы не в бою."); } } }
private static string MainPhpFight(string htmlFight) { if (htmlFight == null) { throw new ArgumentNullException(nameof(htmlFight)); } //htmlFight = File.ReadAllText("f4.txt", AppVars.Codepage); //AppVars.ContentMainPhp = htmlFight; //var fight = new Fight.Module(); var fight = new LezFight(htmlFight); // Даже, если автобой отключен, надо делать разбор боя (проверка на испорченный фрейм) //if (!fight.Parse(htmlFight)) if (!fight.IsValid) { return(AppVars.ContentMainPhp); } // Ожидаем хода противника? if (fight.IsWaitingForNextTurn && AppVars.AutoRefresh) { return(fight.Frame); } // Автобой включен? if (AppVars.Profile.LezDoAutoboi) { if (fight.IsBoi) { // Мы находимся в активном бою if (!fight.DoStop && !fight.IsLowHp && !fight.IsLowMa && !fight.DoExit) { // Никаких сдерживающих факторов нет, продолжаем быстрый бой return(fight.Frame); } if ((fight.DoStop && fight.FoeGroup.DoExit) || fight.DoExit) { // Закрыть клиент ! var message = string.Format($"Выход из боя ({fight.FoeName})"); try { if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new UpdateWriteChatMsgDelegate(AppVars.MainForm.FormMainClose), message); } } catch (InvalidOperationException) { } } // Продолжать бой опасно if (AppVars.Autoboi != AutoboiState.Timeout) { try { var sb = new StringBuilder(); if (fight.IsLowHp) { sb.AppendFormat($"Здоровье упало ниже {fight.FoeGroup.StopLowHp}%"); } else { if (fight.IsLowMa) { sb.AppendFormat($"Мана упала ниже {fight.FoeGroup.StopLowMa}%"); } else { sb.AppendFormat("Опасный противник."); } } sb.AppendFormat($" Группа <b>\"{fight.FoeGroup}\"</b>. Бой остановлен."); if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new UpdateWriteChatMsgDelegate(AppVars.MainForm.WriteChatMsg), sb.ToString()); } } catch (InvalidOperationException) { } AppVars.Autoboi = AutoboiState.Timeout; if (!fight.LogBoi.Equals(AppVars.Profile.Pers.LogReady, StringComparison.Ordinal) || (fight.LogBoi.Equals(AppVars.Profile.Pers.LogReady, StringComparison.Ordinal) && DateTime.Now.Ticks > AppVars.Profile.Pers.Ready)) { AppVars.Profile.Pers.LogReady = fight.LogBoi; AppVars.Profile.Pers.Ready = DateTime.Now.Add(new TimeSpan(0, 15, 0)).Ticks; } } } else { // Бой завершился. if (AppVars.Autoboi != AutoboiState.Restoring) { // Возможно, мы ожидали таймаута и вот бой закончился. if (AppVars.Autoboi == AutoboiState.Timeout) { AppVars.Profile.Pers.Ready = 0; AppVars.Profile.Pers.LogReady = string.Empty; AppVars.Autoboi = AutoboiState.AutoboiOn; } // Нужно ли лечиться после него? var newReady = fight.CalcRestoreAfterBoi(); if (newReady >= 60) { AppVars.Autoboi = AutoboiState.Restoring; if (!fight.LogBoi.Equals(AppVars.Profile.Pers.LogReady, StringComparison.Ordinal) || (fight.LogBoi.Equals(AppVars.Profile.Pers.LogReady, StringComparison.Ordinal) && DateTime.Now.Ticks > AppVars.Profile.Pers.Ready)) { AppVars.Profile.Pers.LogReady = fight.LogBoi; AppVars.Profile.Pers.Ready = newReady; } } else { AppVars.Profile.Pers.Ready = 0; AppVars.Profile.Pers.LogReady = string.Empty; AppVars.Autoboi = AutoboiState.AutoboiOn; if (!string.IsNullOrEmpty(AppVars.FightLink) && (AppVars.FightLink.IndexOf("????", StringComparison.Ordinal) == -1)) { var fightLink = AppVars.FightLink; AppVars.FightLink = string.Empty; return(BuildRedirect("Завершение боя", fightLink)); } } } else { // Лечение выполнено? if (!fight.LogBoi.Equals(AppVars.Profile.Pers.LogReady, StringComparison.Ordinal) || (fight.LogBoi.Equals(AppVars.Profile.Pers.LogReady, StringComparison.Ordinal) && DateTime.Now.Ticks > AppVars.Profile.Pers.Ready)) { AppVars.Profile.Pers.Ready = 0; AppVars.Profile.Pers.LogReady = string.Empty; AppVars.Autoboi = AutoboiState.AutoboiOn; if (!string.IsNullOrEmpty(AppVars.FightLink)) { var fightLink = AppVars.FightLink; AppVars.FightLink = string.Empty; return(BuildRedirect("Завершение боя после лечения", fightLink)); } } } } } return(AppVars.ContentMainPhp); }