private void BattleNotifying() { if (Depot.Notification) { Battle battle = Depot.Battle; // Send battle notification DateTime endTime = battle.StartTime.AddSeconds(battle.ElapsedTime); double diffTime = (DateTime.Now - endTime).TotalSeconds; if (diffTime <= 300) { // Format title string title; if (battle.IsWin) { title = string.Format(Translate("{0}_(No._{1})", true), Translate("win", true), Translate(battle.Number.ToString())); } else { title = string.Format(Translate("{0}_(No._{1})", true), Translate("lose", true), Translate(battle.Number.ToString())); } // Format content string content = string.Format(Translate("{0}_-_{1}", true), Translate(battle.Stage.Id.ToString()), battle.StartTime.ToString("yyyy/M/dd HH:mm")); // Format progressTitle string scoreTitle = string.Format(Translate("{0}_-_{1}", true), Translate(battle.Mode.ToString()), Translate(battle.Rule.ToString())); // Format status and value string string myScore, otherScore; switch (battle.Type) { case Mode.Key.regular_battle: case Mode.Key.splatfest: myScore = string.Format("{0}{1}", battle.MyScore, Translate("%", true)); otherScore = string.Format("{0}{1}", battle.OtherScore, Translate("%", true)); break; case Mode.Key.ranked_battle: if ((battle as RankedBattle).IsKo) { myScore = Translate("knock_out", true); otherScore = string.Format(Translate("{0}_count", true), battle.OtherScore); } else if ((battle as RankedBattle).IsBeKoed) { myScore = string.Format(Translate("{0}_count", true), battle.MyScore); otherScore = Translate("knock_out", true); } else { myScore = string.Format(Translate("{0}_count", true), battle.MyScore); otherScore = string.Format(Translate("{0}_count", true), battle.OtherScore); } break; case Mode.Key.league_battle: if ((battle as LeagueBattle).IsKo) { myScore = Translate("knock_out", true); otherScore = string.Format(Translate("{0}_count", true), battle.OtherScore); } else if ((battle as LeagueBattle).IsBeKoed) { myScore = string.Format(Translate("{0}_count", true), battle.MyScore); otherScore = Translate("knock_out", true); } else { myScore = string.Format(Translate("{0}_count", true), battle.MyScore); otherScore = string.Format(Translate("{0}_count", true), battle.OtherScore); } break; default: throw new ArgumentOutOfRangeException(); } // Get player icon Player player = battle.SelfPlayer; string image = FileFolderUrl.ApplicationData + FileFolderUrl.IconFolder + @"\" + System.IO.Path.GetFileName(player.Image) + ".jpg"; try { // Show notification NotificationHelper.SendBattleNotification(title, content, scoreTitle, myScore, otherScore, battle.ScoreRatio, image); } catch { // Download the image Downloader downloader = new Downloader(player.Image, image, Downloader.SourceType.Battle, Depot.Proxy); DownloadHelper.AddDownloader(downloader, new DownloadCompletedEventHandler(() => { if (player != null) { if (System.IO.Path.GetFileName(image) == System.IO.Path.GetFileName(player.Image) + ".jpg") { // Show notification NotificationHelper.SendBattleNotification(title, content, scoreTitle, myScore, otherScore, battle.ScoreRatio, image); } } })); } } } }
private void JobNotifying() { if (Depot.Notification) { Job job = Depot.Job; // Send job notification DateTime endTime = job.StartTime.AddSeconds(60 * 7); double diffTime = (DateTime.Now - endTime).TotalSeconds; if (diffTime <= 300) { // Format title string title; if (job.IsClear) { title = string.Format(Translate("{0}_(No._{1})", true), Translate("clear", true), Translate(job.Number.ToString())); } else { title = string.Format(Translate("{0}_(No._{1})", true), Translate("defeat", true), Translate(job.Number.ToString())); } // Format content string content = Translate(job.Stage.Id.ToString()); // Format scoreTitle string scoreTitle; if (job.HazardLevel == 200) { scoreTitle = string.Format("{0} {1}{2}", Translate("hazard_level", true), Translate("max", true), Translate("%", true)); } else { scoreTitle = string.Format("{0} {1}{2}", Translate("hazard_level", true), job.HazardLevel.ToString(), Translate("%", true)); } // Format status and value string string goldenEgg = job.GoldenEgg.ToString(); string quota = job.Quota.ToString(); // Format ratio double ratio = 0; if (job.IsClear) { ratio = 1; } else { switch (job.FailureWave) { case 1: ratio = job.Waves[0].GoldenEgg * 1.0 / job.Waves[0].Quota; break; case 2: ratio = 1.0 / 3 + job.Waves[1].GoldenEgg * 1.0 / job.Waves[1].Quota; break; case 3: ratio = 2.0 / 3 + job.Waves[2].GoldenEgg * 1.0 / job.Waves[2].Quota; break; default: throw new ArgumentOutOfRangeException(); } } // Get player icon JobPlayer player = job.MyPlayer; string image = FileFolderUrl.ApplicationData + FileFolderUrl.IconFolder + @"\" + System.IO.Path.GetFileName(player.Image) + ".jpg"; try { // Show notification NotificationHelper.SendJobNotification(title, content, scoreTitle, goldenEgg, quota, ratio, image); } catch { // Download the image Downloader downloader = new Downloader(player.Image, image, Downloader.SourceType.Battle, Depot.Proxy); DownloadHelper.AddDownloader(downloader, new DownloadCompletedEventHandler(() => { if (player != null) { if (System.IO.Path.GetFileName(image) == System.IO.Path.GetFileName(player.Image) + ".jpg") { // Show notification NotificationHelper.SendJobNotification(title, content, scoreTitle, goldenEgg, quota, ratio, image); } } })); } } } }
public MainWindow() { // Add handler for unhandled exception AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException; // Load user and system configuration Depot.LoadSystemConfiguration(); Depot.LoadUserConfiguration(); // Load language if (Depot.Language != null && Depot.Language != "") { try { ResourceDictionary lang = (ResourceDictionary)Application.LoadComponent(new Uri(@"assets/lang/" + Depot.Language + ".xaml", UriKind.Relative)); if (Resources.MergedDictionaries.Count > 0) { Resources.MergedDictionaries.Clear(); } Resources.MergedDictionaries.Add(lang); } catch { } } // Initialize component InitializeComponent(); // Set properties for controls RenderOptions.SetBitmapScalingMode(bdStage1, BitmapScalingMode.HighQuality); RenderOptions.SetBitmapScalingMode(bdStage2, BitmapScalingMode.HighQuality); RenderOptions.SetBitmapScalingMode(bdShiftStage, BitmapScalingMode.HighQuality); // Add handler for global member Depot.AlwaysOnTopChanged += new AlwaysOnTopChangedEventHandler(AlwaysOnTopChanged); Depot.LanguageChanged += new LanguageChangedEventHandler(LanguageChanged); Depot.ScheduleChanged += new ContentChangedEventHandler(ScheduleChanged); Depot.ScheduleUpdated += new ContentUpdatedEventHandler(ScheduleUpdated); Depot.ScheduleFailed += new ContentFailedEventHandler(ScheduleFailed); Depot.ShiftChanged += new ContentChangedEventHandler(ShiftChanged); Depot.ShiftUpdated += new ContentUpdatedEventHandler(ShiftUpdated); Depot.ShiftFailed += new ContentFailedEventHandler(ShiftFailed); Depot.BattleChanged += new ContentChangedEventHandler(BattleChanged); Depot.BattleFound += new ContentFoundEventHandler(BattleFound); Depot.BattleUpdated += new ContentUpdatedEventHandler(BattleUpdated); Depot.BattleFailed += new ContentFailedEventHandler(BattleFailed); Depot.BattleNotifying += new ContentNotifyingHandler(BattleNotifying); Depot.JobChanged += new ContentChangedEventHandler(JobChanged); Depot.JobFound += new ContentFoundEventHandler(JobFound); Depot.JobUpdated += new ContentUpdatedEventHandler(JobUpdated); Depot.JobFailed += new ContentFailedEventHandler(JobFailed); Depot.JobNotifying += new ContentNotifyingHandler(JobNotifying); Depot.CookieUpdated += new CookieUpdatedEventHandler(CookieUpdated); // Prepare windows scheduleWindow = new ScheduleWindow(); scheduleWindow.Opacity = 0; scheduleWindow.Visibility = Visibility.Hidden; shiftWindow = new ShiftWindow(); shiftWindow.Opacity = 0; shiftWindow.Visibility = Visibility.Hidden; battleWindow = new BattleWindow(); battleWindow.Opacity = 0; battleWindow.Visibility = Visibility.Hidden; jobWindow = new JobWindow(); jobWindow.Opacity = 0; jobWindow.Visibility = Visibility.Hidden; settingsWindow = new SettingsWindow(); settingsWindow.Opacity = 0; settingsWindow.Visibility = Visibility.Hidden; // Create timers tmSchedule = new DispatcherTimer(); tmSchedule.Tick += new EventHandler((object source, EventArgs e) => { Depot.GetSchedule(); }); tmSchedule.Interval = new TimeSpan(0, 0, 15); tmShift = new DispatcherTimer(); tmShift.Tick += new EventHandler((object source, EventArgs e) => { Depot.GetShift(); }); tmShift.Interval = new TimeSpan(0, 0, 15); tmBattle = new DispatcherTimer(); tmBattle.Tick += new EventHandler((object source, EventArgs e) => { if (battleWindow.Visibility == Visibility.Hidden) { Depot.GetLastBattle(); } }); tmBattle.Interval = new TimeSpan(0, 0, 30); tmJob = new DispatcherTimer(); tmJob.Tick += new EventHandler((object source, EventArgs e) => { if (jobWindow.Visibility == Visibility.Hidden) { Depot.GetLastJob(); } }); tmJob.Interval = new TimeSpan(0, 0, 30); // Initialize notification NotificationHelper.InitializeNotification(); }