fixed quests completion, removed logs
This commit is contained in:
parent
c058d180ae
commit
524c97d9bf
2 changed files with 4 additions and 19 deletions
src/EllieBot/Modules/Games/Quests
|
@ -1,6 +1,5 @@
|
||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
using LinqToDB.EntityFrameworkCore;
|
using LinqToDB.EntityFrameworkCore;
|
||||||
using Microsoft.CodeAnalysis.Operations;
|
|
||||||
using EllieBot.Common.ModuleBehaviors;
|
using EllieBot.Common.ModuleBehaviors;
|
||||||
using EllieBot.Db.Models;
|
using EllieBot.Db.Models;
|
||||||
|
|
||||||
|
@ -46,44 +45,30 @@ public sealed class QuestService(
|
||||||
|
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
Log.Information("Action reported by {UserId}: {EventType} {Metadata}",
|
|
||||||
userId,
|
|
||||||
eventType,
|
|
||||||
metadata.ToJson());
|
|
||||||
metadata ??= new();
|
metadata ??= new();
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
|
|
||||||
Log.Information("done?");
|
|
||||||
var alreadyDone = await botCache.GetAsync(UserCompletedDailiesKey(userId));
|
var alreadyDone = await botCache.GetAsync(UserCompletedDailiesKey(userId));
|
||||||
if (alreadyDone.IsT0)
|
if (alreadyDone.IsT0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log.Information("not done");
|
|
||||||
|
|
||||||
var userQuests = await GetUserQuestsAsync(userId, now);
|
var userQuests = await GetUserQuestsAsync(userId, now);
|
||||||
|
|
||||||
Log.Information("got quests");
|
|
||||||
foreach (var (q, uq) in userQuests)
|
foreach (var (q, uq) in userQuests)
|
||||||
{
|
{
|
||||||
// deleted quest
|
// deleted quest
|
||||||
if (q is null)
|
if (q is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Log.Information("not deleted {QuestEventType} - {EventType}", q.EventType, eventType);
|
|
||||||
|
|
||||||
// user already completed or incorrect event
|
// user already completed or incorrect event
|
||||||
if (uq.IsCompleted || q.EventType != eventType)
|
if (uq.IsCompleted || q.EventType != eventType)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Log.Information("Gonna update progress");
|
|
||||||
|
|
||||||
var newProgress = q.TryUpdateProgress(metadata, uq.Progress);
|
var newProgress = q.TryUpdateProgress(metadata, uq.Progress);
|
||||||
|
|
||||||
// user already did that part of the quest
|
// user already did that part of the quest
|
||||||
if (newProgress == uq.Progress)
|
if (newProgress == uq.Progress)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Log.Information("new progress");
|
|
||||||
|
|
||||||
var isCompleted = newProgress >= q.RequiredAmount;
|
var isCompleted = newProgress >= q.RequiredAmount;
|
||||||
|
|
||||||
|
@ -95,7 +80,7 @@ public sealed class QuestService(
|
||||||
.UpdateAsync();
|
.UpdateAsync();
|
||||||
|
|
||||||
uq.IsCompleted = isCompleted;
|
uq.IsCompleted = isCompleted;
|
||||||
|
|
||||||
if (userQuests.All(x => x.UserQuest.IsCompleted))
|
if (userQuests.All(x => x.UserQuest.IsCompleted))
|
||||||
{
|
{
|
||||||
var timeUntilTomorrow = now.Date.AddDays(1) - DateTime.UtcNow;
|
var timeUntilTomorrow = now.Date.AddDays(1) - DateTime.UtcNow;
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class UserQuest
|
||||||
|
|
||||||
public QuestIds QuestId { get; set; }
|
public QuestIds QuestId { get; set; }
|
||||||
|
|
||||||
public int Progress { get; set; }
|
public long Progress { get; set; }
|
||||||
|
|
||||||
public bool IsCompleted { get; set; }
|
public bool IsCompleted { get; set; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue