mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-27 07:59:03 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using RadicadeServer.DB;
|
||||
using RadicadeServer.RecNet.Avatar;
|
||||
using RadicadeServer.RecNet.Enums.Store;
|
||||
|
||||
namespace RadicadeServer.Utils
|
||||
{
|
||||
public static class RewardTrace
|
||||
{
|
||||
public const string Prefix = "[QuestReward]";
|
||||
|
||||
public const string ErrorPrefix = "[ERROR][QuestReward]";
|
||||
|
||||
private const string FileName = "game-rewards.log";
|
||||
|
||||
public static void Log(long playerId, string line) => Write(Prefix, playerId, line);
|
||||
|
||||
public static void Error(long playerId, string line) => Write(ErrorPrefix, playerId, line);
|
||||
|
||||
public static void LogAndError(long playerId, string line)
|
||||
{
|
||||
Log(playerId, line);
|
||||
Error(playerId, line);
|
||||
}
|
||||
|
||||
private static void Write(string tag, long playerId, string line)
|
||||
{
|
||||
var text = $"{tag} player={playerId} {line}";
|
||||
|
||||
try
|
||||
{
|
||||
System.IO.File.AppendAllText(
|
||||
System.IO.Path.Join(DBConfig.PersistentLogs, FileName),
|
||||
$"[{DateTime.UtcNow:O}] {text}{Environment.NewLine}");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static string Context(GiftContext context) => $"{context} ({(int)context})";
|
||||
|
||||
public static string Box(Gift? box)
|
||||
{
|
||||
if (box == null) return "<none>";
|
||||
|
||||
var item = string.IsNullOrWhiteSpace(box.AvatarItemDesc) ? "-" : box.AvatarItemDesc;
|
||||
if (item.Length > 120) item = item[..120] + "...";
|
||||
|
||||
var kind = !string.IsNullOrWhiteSpace(box.AvatarItemDesc) ? "AvatarItem"
|
||||
: !string.IsNullOrWhiteSpace(box.ConsumableItemDesc) ? "Consumable"
|
||||
: box.CurrencyType != CurrencyType.Invalid && box.Currency != 0 ? "Tokens"
|
||||
: "Empty";
|
||||
|
||||
return $"{{id={box.GiftDropId} type={kind} name=\"{box.FriendlyName}\" item=\"{item}\" " +
|
||||
$"consumable=\"{box.ConsumableItemDesc}\" currency={box.CurrencyType} {box.Currency} " +
|
||||
$"context={Context(box.Context)}}}";
|
||||
}
|
||||
|
||||
public static string Boxes(IEnumerable<Gift?> boxes)
|
||||
{
|
||||
var list = boxes.ToList();
|
||||
return list.Count == 0 ? "[]" : "[" + string.Join(", ", list.Select(Box)) + "]";
|
||||
}
|
||||
|
||||
public static string Items(IEnumerable<AvatarItem> items, int limit = 12)
|
||||
{
|
||||
var list = items.ToList();
|
||||
if (list.Count == 0) return "[]";
|
||||
|
||||
var names = list.Take(limit).Select(x => $"\"{x.FriendlyName}\"");
|
||||
var more = list.Count > limit ? $", ... +{list.Count - limit} more" : string.Empty;
|
||||
return $"[{string.Join(", ", names)}{more}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user