Skip to content

Commit b4245e1

Browse files
committed
Implement AP/BP/Expedition notification
1 parent c56accc commit b4245e1

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

Patch.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Text;
34
using System.Text.RegularExpressions;
45
using BepInEx;
56
using DMM.OLG.Unity.Engine;
7+
using Hachiroku;
68
using Hachiroku.Novel;
79
using Hachiroku.Novel.UI;
10+
using Hachiroku.Response;
811
using HarmonyLib;
912
using TMPro;
1013
using UnityEngine;
@@ -162,4 +165,20 @@ public static void ParseLoginResp(ref ResponseData res)
162165
File.WriteAllText($"{Paths.PluginPath}/user.txt", token);
163166
}
164167
}
168+
169+
[HarmonyPrefix]
170+
[HarmonyPatch(typeof(UserData), "UpdateData", new Type[] { typeof(CommonUserData) })]
171+
public static void UpdateUserData(ref CommonUserData data)
172+
{
173+
if (!data.recovery_ap_at.IsNullOrWhiteSpace()) Tasker.Set(1, data.recovery_ap_at);
174+
if (!data.recovery_bp_at.IsNullOrWhiteSpace()) Tasker.Set(2, data.recovery_bp_at);
175+
}
176+
177+
[HarmonyPrefix]
178+
[HarmonyPatch(typeof(ExpeditionInfo), "Parse", new Type[] { typeof(MypageResponse) })]
179+
public static void ExpeditionParse(ref MypageResponse response)
180+
{
181+
if (!response.contents.expedition.expedition_schedule_at.IsNullOrWhiteSpace())
182+
Tasker.Set(3, response.contents.expedition.expedition_schedule_at);
183+
}
165184
}

Tasker.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Timers;
4+
5+
namespace IMYSHook;
6+
7+
public class Tasker
8+
{
9+
private static Timer _apTimer = new();
10+
private static Timer _bpTimer = new();
11+
private static Timer _expeditionTimer = new();
12+
13+
private static Timer GetTimer(int eventType)
14+
{
15+
switch (eventType)
16+
{
17+
case 1:
18+
return _apTimer;
19+
case 2:
20+
return _bpTimer;
21+
case 3:
22+
return _expeditionTimer;
23+
}
24+
return null;
25+
}
26+
27+
public static void Set(int eventType, string scheduleAt)
28+
{
29+
var timer = GetTimer(eventType);
30+
31+
if (timer == null) return;
32+
33+
if (timer.Enabled) timer.Stop();
34+
35+
var interval = GetInterval(scheduleAt);
36+
37+
if (interval <= 0) return;
38+
39+
timer = new Timer(interval * 1000);
40+
timer.Elapsed += (sender, e) => EventNotification(sender, e, eventType);
41+
timer.AutoReset = false;
42+
timer.Enabled = true;
43+
}
44+
45+
private static int GetInterval(string scheduleTime)
46+
{
47+
if (scheduleTime == "") return 0;
48+
49+
var result = DateTime.ParseExact(scheduleTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
50+
result = result.AddHours(-1);
51+
52+
var now = DateTime.Now;
53+
54+
var interval = (int)(result - now).TotalSeconds;
55+
56+
return interval;
57+
}
58+
59+
private static void EventNotification(object source, ElapsedEventArgs e, int eventType)
60+
{
61+
switch (eventType)
62+
{
63+
case 1:
64+
Notification.Popup("回復提示", "AP已回復完成!");
65+
break;
66+
case 2:
67+
Notification.Popup("回復提示", "BP已回復完成!");
68+
break;
69+
case 3:
70+
Notification.Popup("遠征提示", "遠征完成!");
71+
break;
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)