mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-16 08:54:47 +01:00
Add basic badge support
This commit is contained in:
@@ -4,6 +4,7 @@ using EpinelPS.Utils;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Paseto.Builder;
|
using Paseto.Builder;
|
||||||
using Paseto;
|
using Paseto;
|
||||||
|
using Google.Protobuf;
|
||||||
|
|
||||||
namespace EpinelPS.Database
|
namespace EpinelPS.Database
|
||||||
{
|
{
|
||||||
@@ -132,7 +133,7 @@ namespace EpinelPS.Database
|
|||||||
public bool ButtonAnimationPlayed = false;
|
public bool ButtonAnimationPlayed = false;
|
||||||
public bool PopupAnimationPlayed = false;
|
public bool PopupAnimationPlayed = false;
|
||||||
|
|
||||||
public UnlockData() {}
|
public UnlockData() { }
|
||||||
public UnlockData(bool button, bool popup)
|
public UnlockData(bool button, bool popup)
|
||||||
{
|
{
|
||||||
ButtonAnimationPlayed = button;
|
ButtonAnimationPlayed = button;
|
||||||
@@ -144,6 +145,33 @@ namespace EpinelPS.Database
|
|||||||
{
|
{
|
||||||
public List<string> CompletedScenarios = [];
|
public List<string> CompletedScenarios = [];
|
||||||
}
|
}
|
||||||
|
public class Badge
|
||||||
|
{
|
||||||
|
public string Location = "";
|
||||||
|
public long Seq;
|
||||||
|
public BadgeContents BadgeContent;
|
||||||
|
public string BadgeGuid;
|
||||||
|
|
||||||
|
public Badge() {}
|
||||||
|
public Badge(NetBadge badge)
|
||||||
|
{
|
||||||
|
Location = badge.Location;
|
||||||
|
Seq = badge.Seq;
|
||||||
|
BadgeContent = badge.BadgeContent;
|
||||||
|
BadgeGuid = new Guid(badge.BadgeGuid.ToArray()).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetBadge ToNet()
|
||||||
|
{
|
||||||
|
return new NetBadge()
|
||||||
|
{
|
||||||
|
BadgeContent = BadgeContent,
|
||||||
|
BadgeGuid = ByteString.CopyFrom(new Guid(BadgeGuid).ToByteArray()),
|
||||||
|
Location = Location,
|
||||||
|
Seq = Seq
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
public class User
|
public class User
|
||||||
{
|
{
|
||||||
// User info
|
// User info
|
||||||
@@ -218,10 +246,36 @@ namespace EpinelPS.Database
|
|||||||
|
|
||||||
public List<NetStageClearInfo> StageClearHistorys = [];
|
public List<NetStageClearInfo> StageClearHistorys = [];
|
||||||
|
|
||||||
|
public List<Badge> Badges = [];
|
||||||
|
|
||||||
// Event data
|
// Event data
|
||||||
public Dictionary<int, EventData> EventInfo = new();
|
public Dictionary<int, EventData> EventInfo = new();
|
||||||
public MogMinigameInfo MogInfo = new();
|
public MogMinigameInfo MogInfo = new();
|
||||||
|
|
||||||
|
public Badge AddBadge(BadgeContents type, string location)
|
||||||
|
{
|
||||||
|
// generate unique badge SEQ
|
||||||
|
var num = Rng.RandomId();
|
||||||
|
|
||||||
|
while (Badges.Any(x => x.Seq == num))
|
||||||
|
{
|
||||||
|
num = Rng.RandomId();
|
||||||
|
}
|
||||||
|
|
||||||
|
var badge = new Badge()
|
||||||
|
{
|
||||||
|
BadgeContent = type,
|
||||||
|
Location = location,
|
||||||
|
BadgeGuid = Guid.NewGuid().ToString(),
|
||||||
|
Seq = num
|
||||||
|
};
|
||||||
|
|
||||||
|
Badges.Add(badge);
|
||||||
|
|
||||||
|
return badge;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetQuest(int tid, bool recievedReward)
|
public void SetQuest(int tid, bool recievedReward)
|
||||||
{
|
{
|
||||||
if (MainQuestData.ContainsKey(tid))
|
if (MainQuestData.ContainsKey(tid))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using EpinelPS.Utils;
|
using EpinelPS.Database;
|
||||||
|
using EpinelPS.Utils;
|
||||||
|
|
||||||
namespace EpinelPS.LobbyServer.Badge
|
namespace EpinelPS.LobbyServer.Badge
|
||||||
{
|
{
|
||||||
@@ -8,9 +9,17 @@ namespace EpinelPS.LobbyServer.Badge
|
|||||||
protected override async Task HandleAsync()
|
protected override async Task HandleAsync()
|
||||||
{
|
{
|
||||||
var req = await ReadData<ReqDeleteBadge>();
|
var req = await ReadData<ReqDeleteBadge>();
|
||||||
|
var user = GetUser();
|
||||||
|
|
||||||
var response = new ResDeleteBadge();
|
var response = new ResDeleteBadge();
|
||||||
|
|
||||||
|
foreach (var badgeId in req.BadgeSeqList)
|
||||||
|
{
|
||||||
|
user.Badges.RemoveAll(x => x.Seq == badgeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonDb.Save();
|
||||||
|
|
||||||
await WriteDataAsync(response);
|
await WriteDataAsync(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using EpinelPS.Utils;
|
using EpinelPS.Utils;
|
||||||
|
using Google.Protobuf;
|
||||||
|
|
||||||
namespace EpinelPS.LobbyServer.Badge
|
namespace EpinelPS.LobbyServer.Badge
|
||||||
{
|
{
|
||||||
@@ -8,8 +9,15 @@ namespace EpinelPS.LobbyServer.Badge
|
|||||||
protected override async Task HandleAsync()
|
protected override async Task HandleAsync()
|
||||||
{
|
{
|
||||||
var req = await ReadData<ReqSyncBadge>();
|
var req = await ReadData<ReqSyncBadge>();
|
||||||
|
var user = GetUser();
|
||||||
|
|
||||||
var response = new ResSyncBadge();
|
var response = new ResSyncBadge();
|
||||||
|
|
||||||
|
foreach (var item in user.Badges)
|
||||||
|
{
|
||||||
|
response.BadgeList.Add(item.ToNet());
|
||||||
|
}
|
||||||
|
|
||||||
await WriteDataAsync(response);
|
await WriteDataAsync(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,6 +196,9 @@ namespace EpinelPS.LobbyServer.Gacha
|
|||||||
Tid = characterData.id,
|
Tid = characterData.id,
|
||||||
UltimateLevel = 1
|
UltimateLevel = 1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add "New Character" Badge
|
||||||
|
user.AddBadge(BadgeContents.BadgeContentsNikkeNew, characterData.name_code.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Gacha.Add(gacha);
|
response.Gacha.Add(gacha);
|
||||||
|
|||||||
Reference in New Issue
Block a user