Radicade Public Code

This commit is contained in:
JogmansonReal
2026-10-16 23:33:13 -07:00
commit 55175acdf6
832 changed files with 363261 additions and 0 deletions
+148
View File
@@ -0,0 +1,148 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using RadicadeServer.DB;
using RadicadeServer.Extensions;
using RadicadeServer.RecNet.Config;
using RadicadeServer.RecNet.Leveling;
using RadicadeServer.RecNet.Progression;
using RadicadeServer.RecNet.Progression.Objectives;
using RadicadeServer.RecNet.Responses;
namespace RadicadeServer.API.Progression.Objectives.V1
{
[Route("api/objectives/v1")]
[Route("econ/api/objectives/v1")]
public class ObjectivesV1 : Controller
{
RecDBContext db;
public ObjectivesV1(RecDBContext context)
{
this.db = context;
}
[HttpGet("myprogress"), Authorize]
public async Task<ActionResult<MyProgress>> GetMyProgress()
{
var userId = User.GetUserId();
var data = await db.Progression.FirstOrDefaultAsync(x => x.PlayerId == userId);
if (data == null) return StatusCode(500);
var deserialized = data.GetObjectiveProgress();
if (deserialized == null) return StatusCode(500);
return Ok(deserialized);
}
[HttpPost("cleargroup"), Authorize]
public async Task<ActionResult<ObjectiveGroupProgress>> ClearObjectiveGroup([FromBody] ObjectiveGroupRequest? dto)
{
if (dto == null) return BadRequest();
var userId = User.GetUserId();
var data = await db.Progression.FirstOrDefaultAsync(x => x.PlayerId == userId);
if (data == null) return StatusCode(500);
ProgressionJson? progression = data.Progress.FromJson<ProgressionJson>();
if (progression == null) return StatusCode(500);
progression.ObjectiveProgress.ObjectiveGroups.RemoveAll(x => x.Group == dto.Group);
progression.ObjectiveProgress.Objectives.RemoveAll(x => x.Group == dto.Group);
data.Progress = progression.ToJson();
await db.SaveChangesAsync();
return Ok(ObjectiveGroupProgress.Empty(dto.Group));
}
[HttpPost("completegroup"), Authorize]
public async Task<ActionResult<ObjectiveGroupProgress>> CompleteObjectiveGroup([FromBody] ObjectiveGroupRequest? dto)
{
if (dto == null) return BadRequest();
var userId = User.GetUserId();
var data = await db.Progression.FirstOrDefaultAsync(x => x.PlayerId == userId);
if (data == null) return StatusCode(500);
ProgressionJson? progression = data.Progress.FromJson<ProgressionJson>();
if (progression == null) return StatusCode(500);
var groupIndex = progression.ObjectiveProgress.ObjectiveGroups.FindIndex(x => x.Group == dto.Group);
if (groupIndex >= 0)
{
progression.ObjectiveProgress.ObjectiveGroups[groupIndex].IsCompleted = true;
progression.ObjectiveProgress.ObjectiveGroups[groupIndex].RequiresCompleteOnServer = false;
}
var groupJson = progression.ObjectiveProgress.ObjectiveGroups[groupIndex].ToString();
data.Progress = progression.ToJson();
await db.SaveChangesAsync();
return Ok(groupJson);
}
[HttpPost("updateobjective"), Authorize]
public async Task<ActionResult<Success>> UpdateObjective([FromBody] ObjectiveProgress? progress)
{
MainConfig? config = await db.Config.FirstOrDefaultAsync();
if (config == null) return StatusCode(500);
if (progress == null) return BadRequest();
progress.IsRewarded = true;
progress.VisualProgress = progress.Progress;
try
{
var objectives = config.DailyObjectives.FromJson<Objective[][]>();
if (objectives != null
&& progress.Group >= 0 && progress.Group < objectives.Length
&& progress.Index >= 0 && progress.Index < objectives[progress.Group].Length)
{
var objective = objectives[progress.Group][progress.Index];
if (objective == null) return BadRequest();
if (!float.IsFinite(progress.Progress) || progress.Progress < 0)
progress.Progress = 0;
if (progress.Progress > objective.score)
progress.Progress = objective.score;
progress.IsCompleted = progress.Progress >= objective.score;
progress.VisualProgress = progress.Progress;
}
} catch
{
progress.IsCompleted = false;
}
var userId = User.GetUserId();
var data = await db.Progression.FirstOrDefaultAsync(x => x.PlayerId == userId);
if (data == null) return StatusCode(500);
ProgressionJson? progression = data.Progress.FromJson<ProgressionJson>();
if (progression == null) return StatusCode(500);
var existingIndex = progression.ObjectiveProgress.Objectives.FindIndex(x => x.Index == progress.Index);
if (existingIndex >= 0)
progression.ObjectiveProgress.Objectives.RemoveAt(existingIndex);
progression.ObjectiveProgress.Objectives.Add(progress);
data.Progress = progression.ToJson();
await db.SaveChangesAsync();
return Ok(Success.Ok);
}
}
}