private void UpdateTimers() { again: var arrayAppTimers = AppTimerManager.GetTimers(); for (var i = 0; i < arrayAppTimers.Length; i++) { if (DateTime.Now <= arrayAppTimers[i].TriggerTime) { continue; } if (AppVars.FastNeed) { return; } if (!string.IsNullOrEmpty(arrayAppTimers[i].Potion)) { FastStartSafe(arrayAppTimers[i].Potion, AppVars.Profile.UserNick, arrayAppTimers[i].DrinkCount); if (arrayAppTimers[i].IsRecur) { var nextTimer = new AppTimer { TriggerTime = arrayAppTimers[i].TriggerTime.AddMinutes( arrayAppTimers[i].EveryMinutes), Description = arrayAppTimers[i].Description, Potion = arrayAppTimers[i].Potion, DrinkCount = arrayAppTimers[i].DrinkCount, IsRecur = true, EveryMinutes = arrayAppTimers[i].EveryMinutes }; AppTimerManager.RemoveTimerAt(i); AppTimerManager.AddAppTimer(nextTimer); } else { AppTimerManager.RemoveTimerAt(i); } EventSounds.PlayTimer(); ReloadMainFrame(); return; } var destination = arrayAppTimers[i].Destination; if (!string.IsNullOrEmpty(destination)) { AppTimerManager.RemoveTimerAt(i); EventSounds.PlayTimer(); MoveTo(destination); return; } var complect = arrayAppTimers[i].Complect; if (!string.IsNullOrEmpty(complect)) { AppVars.WearComplect = complect; AppTimerManager.RemoveTimerAt(i); EventSounds.PlayTimer(); ReloadMainFrame(); return; } AppTimerManager.RemoveTimerAt(i); EventSounds.PlayTimer(); goto again; } if (dropdownTimers == null) { return; } var isNewList = true; if (arrayAppTimers.Length == (dropdownTimers.DropDownItems.Count - 1)) { isNewList = false; } else { while (dropdownTimers.DropDownItems.Count > 1) { dropdownTimers.DropDownItems.RemoveAt(1); } } if (arrayAppTimers.Length == 0) { dropdownTimers.Text = "Таймеры..."; } else { dropdownTimers.Text = arrayAppTimers[0].ToString(); for (var i = 0; i < arrayAppTimers.Length; i++) { if (isNewList) { var item = new ToolStripMenuItem(arrayAppTimers[i].ToString()) { Tag = i }; if (arrayAppTimers[i].IsHerb) { item.Image = Resources._15x12_herb; item.ImageAlign = ContentAlignment.MiddleCenter; item.ImageScaling = ToolStripItemImageScaling.None; } item.Click += OnMenuitemWorkingTimerClick; dropdownTimers.DropDownItems.Add(item); } else { dropdownTimers.DropDownItems[i + 1].Text = arrayAppTimers[i].ToString(); dropdownTimers.DropDownItems[i + 1].Tag = i; if (arrayAppTimers[i].IsHerb) { dropdownTimers.DropDownItems[i + 1].Image = Resources._15x12_herb; dropdownTimers.DropDownItems[i + 1].ImageAlign = ContentAlignment.MiddleCenter; dropdownTimers.DropDownItems[i + 1].ImageScaling = ToolStripItemImageScaling.None; } else { dropdownTimers.DropDownItems[i + 1].Image = null; } } } } }
private void buttonOk_Click(object sender, EventArgs e) { var appTimer = new AppTimer(); var text = textName.Text.Trim(); appTimer.Description = text; var textTriggerHour = numTriggerHour.Text.Trim(); int triggerHour; if (!int.TryParse(textTriggerHour, out triggerHour)) { triggerHour = 0; } if (triggerHour < 0) { triggerHour = 0; } var textTriggerMin = numTriggerMin.Text.Trim(); int triggerMin; if (!int.TryParse(textTriggerMin, out triggerMin)) { triggerMin = 0; } if ((triggerMin < 0) || (triggerMin > 59)) { triggerMin = 0; } triggerMin = (triggerHour * 60) + triggerMin; appTimer.TriggerTime = DateTime.Now.AddMinutes(triggerMin); if (radioPotion.Checked) { var selectedIndex = comboPotion.SelectedIndex; if (selectedIndex < 1) { return; } var potion = comboPotion.Text.Trim(); appTimer.Potion = potion; if (string.IsNullOrEmpty(appTimer.Description)) { appTimer.Description = string.Format("Выпьем {0}", appTimer.Potion); } var textDrinks = textDrinkCount.Text.Trim(); int drinks; if (!int.TryParse(textDrinks, out drinks)) { drinks = 1; } if (drinks < 1) { drinks = 1; } appTimer.DrinkCount = drinks; appTimer.IsRecur = checkRecur.Checked; if (appTimer.IsRecur) { appTimer.EveryMinutes = triggerMin; } } if (radioDestination.Checked) { var destination = textCell.Text.Trim(); if (string.IsNullOrEmpty(destination)) { return; } appTimer.Destination = destination; if (string.IsNullOrEmpty(appTimer.Description)) { appTimer.Description = string.Format("Идем на {0}", destination); } } if (radioComplect.Checked) { var complect = textComplect.Text.Trim(); if (string.IsNullOrEmpty(complect)) { return; } appTimer.Complect = complect; if (string.IsNullOrEmpty(appTimer.Description)) { appTimer.Description = string.Format("Одеваем комплект {0}", complect); } } AppTimerManager.AddAppTimer(appTimer); }
internal void TraceDrinkPotion(string wnickname, string wnametxt) { if (!wnickname.Equals(AppVars.Profile.UserNick, StringComparison.OrdinalIgnoreCase)) { return; } var h = 0; switch (wnametxt) { case "Зелье Метаболизма": h = 4; break; case "Зелье Сильной Спины": h = 20; break; case "Зелье Просветления": h = 5; break; case "Зелье Сокрушительных Ударов": h = 3; break; case "Зелье Стойкости": h = 3; break; case "Зелье Недосягаемости": h = 3; break; case "Зелье Точного Попадания": h = 3; break; case "Зелье Ловких Ударов": h = 2; break; case "Зелье Мужества": h = 2; break; case "Зелье Жизни": h = 3; break; case "Зелье Удачи": h = 3; break; case "Зелье Силы": h = 3; break; case "Зелье Ловкости": h = 3; break; case "Зелье Гения": h = 3; break; case "Зелье Боевой Славы": h = 2; break; case "Зелье Невидимости": h = 3; break; case "Зелье Секрет Волшебника": h = 2; break; case "Зелье Медитации": h = 4; break; case "Зелье Иммунитета": h = 10; break; case "Зелье Огненного Ореола": h = 3; break; case "Зелье Колкости": h = 2; break; case "Зелье Загрубелой Кожи": h = 3; break; case "Зелье Панциря": h = 2; break; case "Зелье Человек-гора": h = 2; break; case "Зелье Скорости": h = 1; break; case "Зелье Подвижности": h = 3; break; case "Зелье Соколиный Взор": h = 3; break; case "Секретное Зелье": h = 2; break; } if (h <= 0) { return; } var appTimer = new AppTimer { Description = string.Format("Действует {0}", wnametxt), TriggerTime = DateTime.Now.AddHours(h) }; AppTimerManager.AddAppTimer(appTimer); UpdateTimers(); }
internal static void TraceCutID(string herbid) { string herb = herbid; var colormessage = string.Format("Трава «<b>{0}</b>» спилена. ", herb); var curTime = DateTime.Now.Subtract(AppVars.Profile.ServDiff); var curShift = GetShift(curTime); var h = 1; switch (herb) { case "Инжир": case "Кипарис": case "Брусника": case "Смертоцвет": case "Лимон": case "Дурман": case "Камелия": case "Ландыш": case "Рапонтикум": case "Береза": case "Дуб": case "Алоэ": case "Гравилат": case "Прагениана": case "Айва": case "Дягиль": case "Каперс": case "Секуринега": case "Кентарийская дикая роза": h = 2; break; } var minutes = (h * 60) - 2; var nextTime = curTime.AddMinutes(minutes); var nextShift = GetShift(nextTime); if (curShift != nextShift) { colormessage += "Таймер не установлен, смена трав близка."; } else { minutes += 30; var appTimer = new AppTimer { Description = string.Format("Вырастет {0} на {1}", herb, AppVars.Profile.MapLocation), TriggerTime = DateTime.Now.AddMinutes(minutes), IsHerb = true }; AppTimerManager.AddAppTimer(appTimer); try { if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new UpdateTimersDelegate(AppVars.MainForm.UpdateTimers), new object[] {}); } } catch (InvalidOperationException) { } AppVars.Profile.Save(); colormessage += h == 1 ? "Таймер установлен на <b>1</b> час." : "Таймер установлен на <b>2</b> часа."; } try { if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new UpdateChatDelegate(AppVars.MainForm.UpdateChat), new object[] { colormessage }); } } catch (InvalidOperationException) { } }