Skip to content

Commit

Permalink
Claim/Request a new quest when the next UTC day has started
Browse files Browse the repository at this point in the history
  • Loading branch information
PCJones committed Jan 8, 2024
1 parent 8f5dc3d commit d67defe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Api/BattleAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static async Task<JToken> GetTeamFromPublicAPIV2Async(int rating, int ma
new JProperty("focus",
Settings.PrioritizeQuest
&& (!Settings.CardSettings.DISABLE_FOCUS_PRIORITY_BEFORE_CHEST_LEAGUE_RATING || chestTierReached)
&& quest != null && !quest.IsExpired && Settings.QuestTypes.ContainsKey(quest.Name)
&& quest != null && !quest.IsComplete && Settings.QuestTypes.ContainsKey(quest.Name)
? Settings.QuestTypes[quest.Name] : ""),
new JProperty("chest_tier_reached", chestTierReached),
new JProperty("card_settings", Settings.CardSettings.USE_CARD_SETTINGS ? JsonConvert.SerializeObject(Settings.CardSettings) : "")
Expand Down Expand Up @@ -281,7 +281,7 @@ private static async Task<JToken> GetTeamFromPublicAPIV3Async(int rating, int ma
new JProperty("focus",
Settings.PrioritizeQuest
&& (!Settings.CardSettings.DISABLE_FOCUS_PRIORITY_BEFORE_CHEST_LEAGUE_RATING || chestTierReached)
&& quest != null && !quest.IsExpired && Settings.QuestTypes.ContainsKey(quest.Name)
&& quest != null && !quest.IsComplete && Settings.QuestTypes.ContainsKey(quest.Name)
? Settings.QuestTypes[quest.Name] : ""),
new JProperty("chest_tier_reached", chestTierReached),
new JProperty("card_settings", Settings.CardSettings.USE_CARD_SETTINGS ? JsonConvert.SerializeObject(Settings.CardSettings) : "")
Expand Down Expand Up @@ -353,7 +353,7 @@ private static async Task<JToken> GetTeamFromPrivateAPIV3Async(int rating, int m
new JProperty("focus",
Settings.PrioritizeQuest
&& (!Settings.CardSettings.DISABLE_FOCUS_PRIORITY_BEFORE_CHEST_LEAGUE_RATING || chestTierReached)
&& quest != null && !quest.IsExpired && Settings.QuestTypes.ContainsKey(quest.Name)
&& quest != null && !quest.IsComplete && Settings.QuestTypes.ContainsKey(quest.Name)
? Settings.QuestTypes[quest.Name] : ""),
new JProperty("chest_tier_reached", chestTierReached),
new JProperty("card_settings", Settings.CardSettings.USE_CARD_SETTINGS ? JsonConvert.SerializeObject(Settings.CardSettings) : "")
Expand Down Expand Up @@ -430,7 +430,7 @@ private static async Task<JToken> GetTeamFromPrivateAPIV2Async(int rating, int m
new JProperty("focus",
Settings.PrioritizeQuest
&& (!Settings.CardSettings.DISABLE_FOCUS_PRIORITY_BEFORE_CHEST_LEAGUE_RATING || chestTierReached)
&& quest != null && !quest.IsExpired && Settings.QuestTypes.ContainsKey(quest.Name)
&& quest != null && !quest.IsComplete && Settings.QuestTypes.ContainsKey(quest.Name)
? Settings.QuestTypes[quest.Name] : ""),
new JProperty("chest_tier_reached", chestTierReached),
new JProperty("card_settings", Settings.CardSettings.USE_CARD_SETTINGS ? JsonConvert.SerializeObject(Settings.CardSettings) : "")
Expand Down
6 changes: 3 additions & 3 deletions Bot/BotInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ private async Task ClaimQuestRewardAsync()
}
}
// Focus quest
else if (Reward.Quest != null && Reward.Quest.Rewards.Type == JTokenType.Null && Reward.Quest.TotalItems == 0 && Reward.Quest.IsExpired)
else if (Reward.Quest != null && Reward.Quest.Rewards.Type == JTokenType.Null && Reward.Quest.TotalItems == 0 && Reward.Quest.IsComplete)
{
logText = "Focus quest reward can be claimed";
Log.WriteToLog($"{Username}: {logText.Pastel(Color.Green)}");
Expand Down Expand Up @@ -1341,13 +1341,13 @@ private async Task RequestNewQuestViaAPIAsync()
{
return;
}
if (Reward.Quest != null && Reward.Quest.IsExpired && Reward.Quest.Name.Length < 11) // name length for old quest
if (Reward.Quest != null && Reward.Quest.IsComplete && Reward.Quest.Name.Length < 11) // name length for old quest
{
string n = Helper.GenerateRandomString(10);
string json = "{\"type\":\"daily\",\"app\":\"" + Settings.SPLINTERLANDS_APP + "\",\"n\":\"" + n + "\"}";

string tx = BroadcastCustomJsonToHiveNode("sm_start_quest", json);
Log.WriteToLog($"{Username}: Requesting new quest because 24 hours passed: {tx}");
Log.WriteToLog($"{Username}: Requesting new quest because midnight (UTC) has passed: {tx}");
await Task.Delay(12500); // wait for splinterlands to refresh the quest
Reward.Quest = await SplinterlandsAPI.GetPlayerQuestAsync(Username);
}
Expand Down
3 changes: 1 addition & 2 deletions Model/Quest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public record Quest
[JsonProperty("league")]
public int League { get; init; }
[JsonIgnore]
public bool IsExpired => (DateTime.Now - CreatedDate.ToLocalTime()).TotalHours >= 24;
public int MinutesRemaining => (24*60) - (int)(DateTime.Now - CreatedDate.ToLocalTime()).TotalMinutes;
public bool IsComplete => DateTime.UtcNow.Date > CreatedDate.ToUniversalTime().Date;

public Quest(string id, string player, DateTime createdDate, int createdBlock, string name, int totalItems, int completedItems, string? claimTrxId, DateTime claimDate, int rewardQty, string? refreshTrxID, JToken rewards, int chestTier, int rShares, int league)
{
Expand Down

0 comments on commit d67defe

Please sign in to comment.