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,62 @@
|
||||
using RadicadeServer.RecNet.Avatar;
|
||||
using RadicadeServer.RecNet.Enums.Store;
|
||||
|
||||
namespace RadicadeServer.Utils;
|
||||
|
||||
public static class FriendotronService
|
||||
{
|
||||
public const string DefaultMessage = "A gift for you <3";
|
||||
|
||||
public static readonly TimeSpan Cooldown = TimeSpan.FromHours(24);
|
||||
|
||||
public static readonly Rarity[] StarTiers = { Rarity.Common, Rarity.Uncommon, Rarity.Rare };
|
||||
|
||||
public const int MaxRecipients = 50;
|
||||
|
||||
public static string CooldownKey(long accountId) => $"Friendotron.LastSent.{accountId}";
|
||||
|
||||
public static string MessageOr(string? message) =>
|
||||
string.IsNullOrWhiteSpace(message) ? DefaultMessage : message.Trim();
|
||||
|
||||
public static Rarity RollStarTier(Random random) => StarTiers[random.Next(StarTiers.Length)];
|
||||
|
||||
public static ConsumableItem? RollConsumable(string? catalogJson, out Rarity starTier, Random? random = null)
|
||||
{
|
||||
var rng = random ?? Random.Shared;
|
||||
var tier = RollStarTier(rng);
|
||||
starTier = tier;
|
||||
|
||||
var catalogue = ConsumableCatalog.ParseItems(catalogJson)
|
||||
.Where(item => !string.IsNullOrWhiteSpace(item.ConsumableItemDesc))
|
||||
.ToList();
|
||||
if (catalogue.Count == 0) return null;
|
||||
|
||||
var ofTier = catalogue.Where(item => item.Rarity == tier).ToList();
|
||||
var pool = ofTier.Count > 0 ? ofTier : catalogue;
|
||||
return pool[rng.Next(pool.Count)];
|
||||
}
|
||||
|
||||
public static Gift BuildBox(long senderId, string? message, ConsumableItem item, Rarity starTier) => new()
|
||||
{
|
||||
Context = GiftContext.Friendotron_Gift,
|
||||
FromPlayerId = senderId,
|
||||
Rarity = starTier,
|
||||
FriendlyName = item.FriendlyName,
|
||||
Tooltip = MessageOr(message),
|
||||
ConsumableItemDesc = ConsumableCatalog.ToClientDesc(item.ConsumableItemDesc)
|
||||
};
|
||||
|
||||
public static string FormatRemaining(DateTime nowUtc, DateTime lastSentUtc)
|
||||
{
|
||||
var remaining = Cooldown - (nowUtc - lastSentUtc);
|
||||
if (remaining <= TimeSpan.Zero) return "0 minutes";
|
||||
|
||||
var hours = (int)remaining.TotalHours;
|
||||
var minutes = remaining.Minutes;
|
||||
if (hours <= 0) return minutes <= 1 ? "1 minute" : $"{minutes} minutes";
|
||||
|
||||
var hourText = hours == 1 ? "1 hour" : $"{hours} hours";
|
||||
if (minutes == 0) return hourText;
|
||||
return $"{hourText} {minutes} minutes";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user