Skip to content

Commit

Permalink
feature: add deius and fury timer (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Hoang Vu Bui <[email protected]>
  • Loading branch information
hoangbv15 and hoangvubui authored May 7, 2024
1 parent 33e8475 commit 230858e
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 52 deletions.
12 changes: 10 additions & 2 deletions src/Alarming/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private async Task Announce(IList<Tuple<IBoss, int>> toBeAnnounced)
for (var i = 0; i < announceCategories[minute].Count; i++)
{
var boss = announceCategories[minute][i];
sb.Append(boss.Name);
sb.Append(GetTextToAnnounce(boss));
if (i == announceCategories[minute].Count - 2)
{
sb.Append(", and ");
Expand All @@ -91,7 +91,15 @@ private async Task Announce(IList<Tuple<IBoss, int>> toBeAnnounced)
Log.Info(announceSentence);
await TextToSpeech.Default.SpeakAsync(announceSentence);
}

}

private string GetTextToAnnounce(IBoss boss)
{
if (boss.TextToSpeech != null)
{
return boss.TextToSpeech;
}
return boss.Name;
}

public void SetAlarm(IBoss boss, bool isSet)
Expand Down
16 changes: 12 additions & 4 deletions src/BossTiming/BossTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ public async Task Initialise()

public TimeSpan GetTimeTillBoss(IBoss boss)
{
var nextBossHour = DateTime.Today.AddHours(boss.ReferenceHour).AddMinutes(_serverTime.BossTimeMinute);
var nextBossTime = DateTime.Today.AddHours(boss.FirstHour);

var minute = _serverTime.BossTimeMinute;
if (boss.MinuteOverride != null)
{
minute = boss.MinuteOverride.Value;
}

nextBossTime = nextBossTime.AddMinutes(minute);

while (nextBossHour < _serverTime.Now && TimeSpan.FromHours(boss.IntervalHours) > TimeSpan.Zero)
while (nextBossTime < _serverTime.Now && TimeSpan.FromHours(boss.IntervalHours) > TimeSpan.Zero)
{
nextBossHour = nextBossHour.AddHours(boss.IntervalHours);
nextBossTime = nextBossTime.AddHours(boss.IntervalHours);
}

var result = nextBossHour - _serverTime.Now;
var result = nextBossTime - _serverTime.Now;
return result;
}
}
10 changes: 8 additions & 2 deletions src/BossTiming/Dto/Boss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ public class Boss: IBoss
{
[JsonPropertyName("name")]
public string Name { get; set; }

Check warning on line 18 in src/BossTiming/Dto/Boss.cs

View workflow job for this annotation

GitHub Actions / MacCatalyst Build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 18 in src/BossTiming/Dto/Boss.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[JsonPropertyName("textToSpeech")]
public string? TextToSpeech { get; set; }

[JsonPropertyName("referenceHour")]
public int ReferenceHour { get; set; }
[JsonPropertyName("firstHour")]
public int FirstHour { get; set; }

[JsonPropertyName("intervalHours")]
public int IntervalHours { get; set; }

[JsonPropertyName("minuteOverride")]
public int? MinuteOverride { get; set; }
}

public class BossArray
Expand Down
4 changes: 3 additions & 1 deletion src/BossTiming/IBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ namespace PristonToolsEU.BossTiming;
public interface IBoss
{
public string Name { get; set; }
public int ReferenceHour { get; set; }
public string? TextToSpeech { get; set; }
public int FirstHour { get; set; }
public int IntervalHours { get; set; }
public int? MinuteOverride { get; set; }
}
11 changes: 11 additions & 0 deletions src/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ public static void Info(string msg, params object[] parameters)
{
Instance.InternalLog(LogLevel.Info, msg, parameters);
}

public static void Warn(string msg, params object[] parameters)
{
Instance.InternalLog(LogLevel.Warn, msg, parameters);
}

public static void Error(string msg, params object[] parameters)
{
Instance.InternalLog(LogLevel.Error, msg, parameters);
}

}
21 changes: 15 additions & 6 deletions src/Networking/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ public RestClient()
public async Task<T> Get<T>(string url) where T : new()
{
Log.Info("Beginning sending rest request to {0}", url);
await using Stream stream =
await _httpClient.GetStreamAsync(url);
var deserialised =
await JsonSerializer.DeserializeAsync<T>(stream);
Log.Debug("Got rest response \n{0}", deserialised);
return deserialised ?? new T();
try
{
await using Stream stream =
await _httpClient.GetStreamAsync(url);
var deserialised =
await JsonSerializer.DeserializeAsync<T>(stream);

Log.Debug("Got rest response \n{0}", deserialised);

Check warning on line 30 in src/Networking/RestClient.cs

View workflow job for this annotation

GitHub Actions / MacCatalyst Build

Possible null reference argument for parameter 'parameters' in 'void Log.Debug(string msg, params object[] parameters)'.

Check warning on line 30 in src/Networking/RestClient.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Possible null reference argument for parameter 'parameters' in 'void Log.Debug(string msg, params object[] parameters)'.
return deserialised ?? new T();
}
catch (Exception e)
{
Log.Error("Got exception with rest: {0}", e);
throw;
}
}
}
36 changes: 22 additions & 14 deletions src/Resources/Raw/bosses.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,76 @@
"bosses": [
{
"name": "Valento",
"referenceHour": 1,
"firstHour": 1,
"intervalHours": 2
},
{
"name": "Kelvezu",
"referenceHour": 0,
"firstHour": 0,
"intervalHours": 3
},
{
"name": "Mokova",
"referenceHour": 2,
"firstHour": 2,
"intervalHours": 3
},
{
"name": "Devil Shy",
"referenceHour": 0,
"firstHour": 0,
"intervalHours": 4
},
{
"name": "Tulla",
"referenceHour": 1,
"firstHour": 1,
"intervalHours": 4
},
{
"name": "Draxos",
"referenceHour": 3,
"firstHour": 3,
"intervalHours": 4
},
{
"name": "Yagditha",
"referenceHour": 1,
"firstHour": 1,
"intervalHours": 6
},
{
"name": "Ignis",
"referenceHour": 2,
"firstHour": 2,
"intervalHours": 6
},
{
"name": "Primal Golem",
"referenceHour": 4,
"firstHour": 4,
"intervalHours": 6
},
{
"name": "Skillmaster",
"referenceHour": 0,
"firstHour": 0,
"intervalHours": 3
},
{
"name": "Greedy",
"referenceHour": 0,
"firstHour": 0,
"intervalHours": 6
},
{
"name": "Aragonian",
"referenceHour": 0,
"firstHour": 0,
"intervalHours": 6
},
{
"name": "Deius",
"referenceHour": 0,
"intervalHours": 2
"firstHour": 0,
"intervalHours": 2,
"minuteOverride": 0
},
{
"name": "Wrath (104+)",
"textToSpeech": "Fury",
"firstHour": 2,
"intervalHours": 3,
"minuteOverride": 0
}
]
}
8 changes: 4 additions & 4 deletions src/ServerTiming/Dto/PteuTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace PristonToolsEU.ServerTiming.Dto;

public class PteuTime
{
[JsonPropertyName("online_babel")]
public bool IsBabelOnline { get; set; }
// [JsonPropertyName("online_babel")]
// public bool IsBabelOnline { get; set; }

[JsonPropertyName("online_seasonal")]
public bool IsSeasonalOnline { get; set; }
// [JsonPropertyName("online_seasonal")]
// public bool IsSeasonalOnline { get; set; }

[JsonPropertyName("babel")]
public ServerDetail? Babel { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions src/ServerTiming/ServerTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace PristonToolsEU.ServerTiming;
public class ServerTime : IServerTime, IDisposable
{
private const int SyncIntervalMs = 1800000; // 30 minutes
private const string PteuTimeUrl = $"https://pristontale.eu/api/api.php?key={ApiKey}";
private const string ApiKey = "c4b90e23c554d10c3c9deadcdbfcf93b";
private const string PteuTimeUrl = $"https://pristontale.eu/api/api.php?key=c4b90e23c554d10c3c9deadcdbfcf93b";

private readonly IRestClient _restClient;
private TimeSpan _serverTimeOffset = TimeSpan.Zero;
Expand Down
17 changes: 0 additions & 17 deletions src/Time/IBossTimer.cs

This file was deleted.

0 comments on commit 230858e

Please sign in to comment.