2023-10-19 07:07:48 +00:00
|
|
|
using AscNet.Common.MsgPack;
|
2023-12-10 02:22:33 +00:00
|
|
|
using AscNet.Common.Util;
|
|
|
|
using AscNet.Table.V2.share.guide;
|
2023-10-19 07:07:48 +00:00
|
|
|
using MongoDB.Bson;
|
|
|
|
using MongoDB.Bson.Serialization.Attributes;
|
|
|
|
using MongoDB.Bson.Serialization.Options;
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
|
|
|
namespace AscNet.Common.Database
|
|
|
|
{
|
|
|
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
|
|
|
public class Stage
|
|
|
|
{
|
|
|
|
public static readonly IMongoCollection<Stage> collection = Common.db.GetCollection<Stage>("stages");
|
|
|
|
|
|
|
|
public static Stage FromUid(long uid)
|
|
|
|
{
|
|
|
|
return collection.AsQueryable().FirstOrDefault(x => x.Uid == uid) ?? Create(uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Stage Create(long uid)
|
|
|
|
{
|
|
|
|
Stage stage = new()
|
|
|
|
{
|
2023-11-11 07:28:21 +00:00
|
|
|
Uid = uid,
|
2023-10-19 07:07:48 +00:00
|
|
|
Stages = new()
|
|
|
|
};
|
2023-12-10 02:22:33 +00:00
|
|
|
foreach (var guideFight in TableReaderV2.Parse<GuideFightTable>())
|
2023-10-19 07:07:48 +00:00
|
|
|
{
|
|
|
|
stage.AddStage(new StageDatum()
|
|
|
|
{
|
|
|
|
StageId = guideFight.StageId,
|
|
|
|
StarsMark = 7,
|
|
|
|
Passed = true,
|
|
|
|
PassTimesToday = 0,
|
|
|
|
PassTimesTotal = 1,
|
|
|
|
BuyCount = 0,
|
|
|
|
Score = 0,
|
|
|
|
LastPassTime = DateTimeOffset.Now.ToUnixTimeSeconds(),
|
|
|
|
RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(),
|
|
|
|
CreateTime = DateTimeOffset.Now.ToUnixTimeSeconds(),
|
|
|
|
BestRecordTime = guideFight.DefaultRecordTime,
|
|
|
|
LastRecordTime = guideFight.DefaultRecordTime,
|
|
|
|
BestCardIds = new List<long>() { 1021001 },
|
|
|
|
LastCardIds = new List<long>() { 1021001 }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
collection.InsertOne(stage);
|
|
|
|
|
|
|
|
return stage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddStage(StageDatum stageData)
|
|
|
|
{
|
2023-11-13 12:10:02 +00:00
|
|
|
if (Stages.ContainsKey(stageData.StageId))
|
|
|
|
Stages[stageData.StageId] = stageData;
|
|
|
|
else
|
|
|
|
Stages.Add(stageData.StageId, stageData);
|
2023-10-19 07:07:48 +00:00
|
|
|
}
|
2023-11-11 01:12:11 +00:00
|
|
|
|
|
|
|
public void Save()
|
|
|
|
{
|
|
|
|
collection.ReplaceOne(Builders<Stage>.Filter.Eq(x => x.Id, Id), this);
|
|
|
|
}
|
|
|
|
|
2023-10-19 07:07:48 +00:00
|
|
|
[BsonId]
|
|
|
|
public ObjectId Id { get; set; }
|
|
|
|
|
|
|
|
[BsonElement("uid")]
|
|
|
|
[BsonRequired]
|
|
|
|
public long Uid { get; set; }
|
|
|
|
|
|
|
|
[BsonElement("stages")]
|
|
|
|
[BsonRequired]
|
|
|
|
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)]
|
|
|
|
public Dictionary<long, StageDatum> Stages { get; set; }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|