mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 23:49:02 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using System.Globalization;
|
||||
using RadicadeServer.RecNet.Enums.Store;
|
||||
|
||||
namespace RadicadeServer.Utils
|
||||
{
|
||||
public sealed class RewardDayLedger
|
||||
{
|
||||
public string Day { get; set; } = string.Empty;
|
||||
|
||||
public bool FirstActivityPaid { get; set; }
|
||||
|
||||
public bool DailyChallengePaid { get; set; }
|
||||
|
||||
public int ActivityBoxes { get; set; }
|
||||
}
|
||||
|
||||
public static class RewardDay
|
||||
{
|
||||
public const int ActivityBoxesPerDay = 12;
|
||||
|
||||
public const int BoxesPerDay = 1 + 1 + ActivityBoxesPerDay;
|
||||
|
||||
public static string DayKey(DateTime nowUtc) =>
|
||||
nowUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
|
||||
|
||||
public static RewardDayLedger For(RecNet.Progression.ProgressionJson json, DateTime nowUtc)
|
||||
{
|
||||
var day = DayKey(nowUtc);
|
||||
var ledger = json.RewardDay;
|
||||
if (ledger == null || !string.Equals(ledger.Day, day, StringComparison.Ordinal))
|
||||
{
|
||||
ledger = new RewardDayLedger { Day = day };
|
||||
json.RewardDay = ledger;
|
||||
}
|
||||
return ledger;
|
||||
}
|
||||
|
||||
public static RewardType CompletionType(RewardDayLedger ledger, RewardType claimed)
|
||||
{
|
||||
if (claimed == RewardType.PostQuestActivity) return RewardType.PostQuestActivity;
|
||||
return ledger.FirstActivityPaid ? RewardType.PostGameActivity : RewardType.FirstActivityOfDay;
|
||||
}
|
||||
|
||||
public static bool TryTakeFirstActivity(RewardDayLedger ledger)
|
||||
{
|
||||
if (ledger.FirstActivityPaid) return false;
|
||||
ledger.FirstActivityPaid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryTakeActivityBox(RewardDayLedger ledger)
|
||||
{
|
||||
if (ledger.ActivityBoxes >= ActivityBoxesPerDay) return false;
|
||||
ledger.ActivityBoxes++;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryTakeDailyChallengeBox(RewardDayLedger ledger)
|
||||
{
|
||||
if (ledger.DailyChallengePaid) return false;
|
||||
ledger.DailyChallengePaid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static RewardDayLedger NewDay(DateTime nowUtc) => new() { Day = DayKey(nowUtc) };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user