implement tactic academy

This commit is contained in:
Mikhail
2024-07-15 14:05:30 -04:00
parent 005ad80095
commit db70b5068e
6 changed files with 131 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
using nksrv.Net;
using nksrv.StaticInfo;
using nksrv.Utils;
using Swan.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace nksrv.LobbyServer.Msgs.Outpost
{
[PacketPath("/outpost/tactic/clearlesson")]
public class ClearTacticAcademyLesson : LobbyMsgHandler
{
protected override async Task HandleAsync()
{
var req = await ReadData<TacticAcademyClearLessonRequest>();
var user = GetUser();
var response = new TacticAcademyClearLessonResponse();
response.LessonId = req.LessonId;
var x = StaticDataParser.Instance.GetTacticAcademyLesson(req.LessonId);
if (user.CanSubtractCurrency(x.CurrencyId, x.CurrencyValue))
{
user.SubtractCurrency(x.CurrencyId, x.CurrencyValue);
user.CompletedTacticAcademyLessons.Add(req.LessonId);
foreach (var currency in user.Currency)
{
response.RemainingCurrency.Add(new NetUserCurrencyData() { Type = (int)currency.Key, Value = currency.Value });
}
}
else
{
Logger.Error($"User {user.PlayerName} tried to clear lesson {req.LessonId} without enough currency");
}
await WriteDataAsync(response);
}
}
}

View File

@@ -0,0 +1,25 @@
using nksrv.Net;
using nksrv.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace nksrv.LobbyServer.Msgs.Outpost
{
[PacketPath("/outpost/tactic/get")]
public class GetTacticAcademyData : LobbyMsgHandler
{
protected override async Task HandleAsync()
{
var req = await ReadData<GetTacticAcademyDataRequest>();
var user = GetUser();
var response = new GetTacticAcademyDataResponse();
response.CompletedLessons.AddRange(user.CompletedTacticAcademyLessons);
await WriteDataAsync(response);
}
}
}

View File

@@ -0,0 +1,22 @@
syntax = "proto3";
option csharp_namespace = "nksrv.Net";
import "google/protobuf/timestamp.proto";
import "google/protobuf/Duration.proto";
import "Protos/allmsgs.proto";
// Get Tactic Academy data
message GetTacticAcademyDataRequest {}
message GetTacticAcademyDataResponse {
repeated int32 CompletedLessons = 2;
}
// Clear Tactic Academy lesson
message TacticAcademyClearLessonRequest {
int32 LessonId = 2;
}
message TacticAcademyClearLessonResponse {
int32 LessonId = 2;
repeated NetUserCurrencyData RemainingCurrency = 4;
}

View File

@@ -67,7 +67,7 @@ namespace nksrv.StaticInfo
/// <summary> /// <summary>
/// can be CharacterLevel or SynchroLevel /// can be CharacterLevel or SynchroLevel
/// </summary> /// </summary>
public string type = ""; public string type = "";
/// <summary> /// <summary>
/// amount of credits required /// amount of credits required
/// </summary> /// </summary>
@@ -81,4 +81,12 @@ namespace nksrv.StaticInfo
/// </summary> /// </summary>
public int character_exp2 = 0; public int character_exp2 = 0;
} }
public class TacticAcademyLessonRecord
{
public CurrencyType CurrencyId;
public int CurrencyValue;
public int Id;
public int GroupId;
}
} }

View File

@@ -13,6 +13,7 @@ using Newtonsoft.Json.Linq;
using Swan.Parsers; using Swan.Parsers;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Drawing; using System.Drawing;
using Google.Protobuf.WellKnownTypes;
namespace nksrv.StaticInfo namespace nksrv.StaticInfo
{ {
@@ -56,6 +57,7 @@ namespace nksrv.StaticInfo
private JArray tutorialTable; private JArray tutorialTable;
private JArray itemEquipTable; private JArray itemEquipTable;
private Dictionary<int, CharacterLevelData> LevelData = []; private Dictionary<int, CharacterLevelData> LevelData = [];
private Dictionary<int, TacticAcademyLessonRecord> TacticAcademyLessons = [];
public byte[] Sha256Hash; public byte[] Sha256Hash;
public int Size; public int Size;
@@ -256,6 +258,29 @@ namespace nksrv.StaticInfo
else else
Logger.Warn("failed to read character level table entry"); Logger.Warn("failed to read character level table entry");
} }
var tacticLessonTable = await LoadZip("TacticAcademyFunctionTable.json");
foreach (JToken item in tacticLessonTable)
{
var idRaw = item["id"];
var groupidRaw = item["group_id"];
var currencyIdRaw = item["currency_id"];
var currencyValueRaw = item["currency_value"];
if (idRaw == null) throw new InvalidDataException();
if (groupidRaw == null) throw new InvalidDataException();
if (currencyIdRaw == null) throw new InvalidDataException();
if (currencyValueRaw == null) throw new InvalidDataException();
var id = idRaw.ToObject<int>();
var currencyId = currencyIdRaw.ToObject<int>();
var currencyValue = currencyValueRaw.ToObject<int>();
var groupid = groupidRaw.ToObject<int>();
var fullId = int.Parse(groupid.ToString() + id.ToString());
TacticAcademyLessons.Add(id, new TacticAcademyLessonRecord() { CurrencyId = (CurrencyType)currencyId, CurrencyValue = currencyValue, GroupId = groupid, Id = id });
}
} }
public MainQuestCompletionData? GetMainQuestForStageClearCondition(int stage) public MainQuestCompletionData? GetMainQuestForStageClearCondition(int stage)
@@ -481,5 +506,10 @@ namespace nksrv.StaticInfo
{ {
return LevelData; return LevelData;
} }
public TacticAcademyLessonRecord GetTacticAcademyLesson(int lessonId)
{
return TacticAcademyLessons[lessonId];
}
} }
} }

View File

@@ -109,6 +109,7 @@ namespace nksrv.Utils
public NetOutpostBattleLevel OutpostBattleLevel = new() { Level = 1 }; public NetOutpostBattleLevel OutpostBattleLevel = new() { Level = 1 };
public int GachaTutorialPlayCount = 0; public int GachaTutorialPlayCount = 0;
public List<int> CompletedTacticAcademyLessons = [];
// Event data // Event data
public Dictionary<int, EventData> EventInfo = new(); public Dictionary<int, EventData> EventInfo = new();