mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-16 17:04:44 +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
|
||||||
{
|
{
|
||||||
@@ -62,8 +63,8 @@ namespace EpinelPS.Database
|
|||||||
public class EventData
|
public class EventData
|
||||||
{
|
{
|
||||||
public List<string> CompletedScenarios = new();
|
public List<string> CompletedScenarios = new();
|
||||||
public int Diff = 0; // Default value for Diff
|
public int Diff = 0; // Default value for Diff
|
||||||
public int LastStage = 0; // Default value for LastStage
|
public int LastStage = 0; // Default value for LastStage
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SynchroSlot
|
public class SynchroSlot
|
||||||
@@ -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
|
||||||
@@ -161,7 +189,7 @@ namespace EpinelPS.Database
|
|||||||
public bool IsAdmin = false;
|
public bool IsAdmin = false;
|
||||||
public bool sickpulls = false;
|
public bool sickpulls = false;
|
||||||
public bool IsBanned = false;
|
public bool IsBanned = false;
|
||||||
public int TitleId = 1;
|
public int TitleId = 1;
|
||||||
public DateTime BanStart;
|
public DateTime BanStart;
|
||||||
public DateTime BanEnd;
|
public DateTime BanEnd;
|
||||||
public int BanId = 0;
|
public int BanId = 0;
|
||||||
@@ -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))
|
||||||
@@ -313,43 +367,43 @@ namespace EpinelPS.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasCharacter(int c)
|
public bool HasCharacter(int c)
|
||||||
{
|
{
|
||||||
// Step 1: Get the 'name_code' of the input character with Tid 'c'
|
// Step 1: Get the 'name_code' of the input character with Tid 'c'
|
||||||
if (GameData.Instance.characterTable.TryGetValue(c, out var inputCharacterRecord))
|
if (GameData.Instance.characterTable.TryGetValue(c, out var inputCharacterRecord))
|
||||||
{
|
{
|
||||||
int targetNameCode = inputCharacterRecord.name_code;
|
int targetNameCode = inputCharacterRecord.name_code;
|
||||||
// Step 2: Find all character IDs in 'characterTable' that have the same 'name_code'
|
// Step 2: Find all character IDs in 'characterTable' that have the same 'name_code'
|
||||||
var matchingCharacterIds = GameData.Instance.characterTable.Where(kvp => kvp.Value.name_code == targetNameCode).Select(kvp => kvp.Key).ToHashSet();
|
var matchingCharacterIds = GameData.Instance.characterTable.Where(kvp => kvp.Value.name_code == targetNameCode).Select(kvp => kvp.Key).ToHashSet();
|
||||||
|
|
||||||
// Step 3: Check if any of your owned characters have a 'Tid' in the set of matching IDs
|
// Step 3: Check if any of your owned characters have a 'Tid' in the set of matching IDs
|
||||||
return Characters.Any(ownedCharacter => matchingCharacterIds.Contains(ownedCharacter.Tid));
|
return Characters.Any(ownedCharacter => matchingCharacterIds.Contains(ownedCharacter.Tid));
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // The character with Tid 'c' does not exist in 'characterTable'
|
{ // The character with Tid 'c' does not exist in 'characterTable'
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Character? GetCharacter(int c)
|
public Character? GetCharacter(int c)
|
||||||
{
|
{
|
||||||
// Step 1: Get the 'name_code' of the input character with Tid 'c'
|
// Step 1: Get the 'name_code' of the input character with Tid 'c'
|
||||||
if (GameData.Instance.characterTable.TryGetValue(c, out var inputCharacterRecord))
|
if (GameData.Instance.characterTable.TryGetValue(c, out var inputCharacterRecord))
|
||||||
{
|
{
|
||||||
int targetNameCode = inputCharacterRecord.name_code;
|
int targetNameCode = inputCharacterRecord.name_code;
|
||||||
// Step 2: Find all character IDs in 'characterTable' that have the same 'name_code'
|
// Step 2: Find all character IDs in 'characterTable' that have the same 'name_code'
|
||||||
var matchingCharacterIds = GameData.Instance.characterTable.Where(kvp => kvp.Value.name_code == targetNameCode).Select(kvp => kvp.Key).ToHashSet();
|
var matchingCharacterIds = GameData.Instance.characterTable.Where(kvp => kvp.Value.name_code == targetNameCode).Select(kvp => kvp.Key).ToHashSet();
|
||||||
|
|
||||||
// Step 3: Check if any of your owned characters have a 'Tid' in the set of matching IDs
|
// Step 3: Check if any of your owned characters have a 'Tid' in the set of matching IDs
|
||||||
return Characters.Where(ownedCharacter => matchingCharacterIds.Contains(ownedCharacter.Tid)).First();
|
return Characters.Where(ownedCharacter => matchingCharacterIds.Contains(ownedCharacter.Tid)).First();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // The character with Tid 'c' does not exist in 'characterTable'
|
{ // The character with Tid 'c' does not exist in 'characterTable'
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Character? GetCharacterBySerialNumber(long value)
|
public Character? GetCharacterBySerialNumber(long value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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