mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
retain mission progress
This commit is contained in:
parent
2c195832f5
commit
0e017483f1
@ -223,7 +223,22 @@ public class ContentController : Controller {
|
||||
public IActionResult GetUserActiveMissionState([FromForm] string apiToken, [FromForm] string userId) {
|
||||
Session? session = ctx.Sessions.FirstOrDefault(s => s.ApiToken == apiToken);
|
||||
UserMissionStateResult result = new UserMissionStateResult { Missions = new List<Mission>() };
|
||||
result.Missions.Add(XmlUtil.DeserializeXml<Mission>(XmlUtil.ReadResourceXmlString("tutorialmission")));
|
||||
Mission tutorial = XmlUtil.DeserializeXml<Mission>(XmlUtil.ReadResourceXmlString("tutorialmission"));
|
||||
|
||||
// Update the mission with completed tasks
|
||||
List<Model.TaskStatus> taskStatuses = ctx.TaskStatuses.Where(e => e.VikingId == userId && e.MissionId == tutorial.MissionID).ToList();
|
||||
foreach (var task in taskStatuses) {
|
||||
RuleItem? rule = tutorial.MissionRule.Criteria.RuleItems.Find(x => x.ID == task.Id);
|
||||
if (rule != null && task.Completed) rule.Complete = 1;
|
||||
|
||||
Schema.Task? t = tutorial.Tasks.Find(x => x.TaskID == task.Id);
|
||||
if (t != null) {
|
||||
if (task.Completed) t.Completed = 1;
|
||||
t.Payload = task.Payload;
|
||||
}
|
||||
}
|
||||
|
||||
result.Missions.Add(tutorial);
|
||||
|
||||
if (session is null)
|
||||
return Ok("error");
|
||||
@ -249,8 +264,28 @@ public class ContentController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/SetTaskState")]
|
||||
public IActionResult SetTaskState([FromForm] string apiToken, [FromForm] int missionId, [FromForm] int taskId, [FromForm] bool completed) {
|
||||
// TODO
|
||||
public IActionResult SetTaskState([FromForm] string apiToken, [FromForm] string userId, [FromForm] int missionId, [FromForm] int taskId, [FromForm] bool completed, [FromForm] string xmlPayload) {
|
||||
Session? session = ctx.Sessions.FirstOrDefault(s => s.ApiToken == apiToken);
|
||||
if (session is null || session.VikingId != userId)
|
||||
return Ok(new SetTaskStateResult { Success = false, Status = SetTaskStateStatus.Unknown });
|
||||
|
||||
Model.TaskStatus? status = ctx.TaskStatuses.FirstOrDefault(task => task.Id == taskId && task.MissionId == missionId && task.VikingId == userId);
|
||||
|
||||
if (status is null) {
|
||||
status = new Model.TaskStatus {
|
||||
Id = taskId,
|
||||
MissionId = missionId,
|
||||
VikingId = userId,
|
||||
Payload = xmlPayload,
|
||||
Completed = completed
|
||||
};
|
||||
ctx.TaskStatuses.Add(status);
|
||||
} else {
|
||||
status.Payload = xmlPayload;
|
||||
status.Completed = completed;
|
||||
}
|
||||
ctx.SaveChanges();
|
||||
|
||||
return Ok(new SetTaskStateResult { Success = true, Status = SetTaskStateStatus.TaskCanBeDone });
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ public class DBContext : DbContext {
|
||||
public DbSet<Session> Sessions { get; set; } = null!;
|
||||
public DbSet<Pair> Pairs { get; set; } = null!;
|
||||
public DbSet<PairData> PairData { get; set; } = null!;
|
||||
public DbSet<TaskStatus> TaskStatuses { get; set; } = null!;
|
||||
public string DbPath { get; }
|
||||
|
||||
public DBContext() {
|
||||
@ -49,5 +50,11 @@ public class DBContext : DbContext {
|
||||
.WithMany(pd => pd.Pairs)
|
||||
.HasForeignKey(p => p.MasterId)
|
||||
.HasPrincipalKey(e => e.Id);
|
||||
|
||||
builder.Entity<TaskStatus>().HasKey(e => new { e.Id, e.VikingId, e.MissionId });
|
||||
|
||||
builder.Entity<TaskStatus>()
|
||||
.HasOne(t => t.Viking)
|
||||
.WithMany();
|
||||
}
|
||||
}
|
||||
|
15
src/Model/TaskStatus.cs
Normal file
15
src/Model/TaskStatus.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace sodoff.Model {
|
||||
public class TaskStatus {
|
||||
public int Id { get; set; }
|
||||
|
||||
public int MissionId { get; set; }
|
||||
|
||||
public string VikingId { get; set; } = null!;
|
||||
|
||||
public virtual Viking? Viking { get; set; }
|
||||
|
||||
public string? Payload { get; set; }
|
||||
|
||||
public bool Completed { get; set; } = false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user