"implemented" gacha system

This commit is contained in:
Mikhail Thompson
2024-07-02 15:11:52 -04:00
parent 76ecf031b5
commit 53dab52b9a
5 changed files with 98 additions and 45 deletions

View File

@@ -1,4 +1,5 @@
using nksrv.Utils;
using nksrv.StaticInfo;
using nksrv.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,11 +13,12 @@ namespace nksrv.LobbyServer.Msgs.Character
{
protected override async Task HandleAsync()
{
var req = ReadData<ReqGetCharacterCostumeData>();
var req = await ReadData<ReqGetCharacterCostumeData>();
var response = new ResGetCharacterCostumeData();
// TODO implement
// return all
response.CostumeIds.AddRange(StaticDataParser.Instance.GetAllCostumes());
WriteData(response);
}

View File

@@ -0,0 +1,33 @@
using nksrv.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace nksrv.LobbyServer.Msgs.Character
{
[PacketPath("/character/costume/set")]
public class SetCharacterCostume : LobbyMsgHandler
{
protected override async Task HandleAsync()
{
var req = await ReadData<ReqSetCharacterCostume>();
var user = GetUser();
foreach (var item in user.Characters)
{
if(item.Csn == req.Csn)
{
item.CostumeId = req.CostumeId;
break;
}
}
JsonDb.Save();
var response = new ResSetCharacterCostume();
WriteData(response);
}
}
}

View File

@@ -1,4 +1,5 @@
using nksrv.Utils;
using nksrv.StaticInfo;
using nksrv.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,6 +14,7 @@ namespace nksrv.LobbyServer.Msgs.Gacha
protected override async Task HandleAsync()
{
var req = await ReadData<ReqExecuteGacha>();
var user = GetUser();
var response = new ResExecuteGacha();
@@ -21,12 +23,16 @@ namespace nksrv.LobbyServer.Msgs.Gacha
// TODO implement
response.Reward = new NetRewardData();
for (int i = 0; i < 10; i++)
foreach (var c in StaticDataParser.Instance.GetAllCharacterTids())
{
response.Gacha.Add(new NetGachaEntityData() { Corporation = 0, PieceCount = 1, CurrencyValue = 5, Sn = 130201, Tid = 2500601, Type = 1 });
response.Gacha.Add(new NetGachaEntityData() { Corporation = 0, PieceCount = 1, CurrencyValue = 5, Sn = 130201, Tid = c, Type = 1 });
user.Characters.Add(new Utils.Character() { CostumeId = 0, Csn = c, Grade = 0, Level = 1, Skill1Lvl = 1, Skill2Lvl= 1, Tid = c, UltimateLevel = 1 });
// response.Characters.Add(new NetUserCharacterDefaultData() { Lv = 1, Skill1Lv = 1, Grade = 0, Csn = 1, Tid = 130201 });
}
JsonDb.Save();
WriteData(response);

View File

@@ -1751,4 +1751,10 @@ message ResShowOutpostBattleReward {
repeated NetTimeReward timeRewardBuffs = 6;
NetOutpostBattleLevel outpostBattleLevel = 7;
NetOutpostBattleTime outpostBattleTime = 8;
}
}
message ReqSetCharacterCostume {
int64 csn = 2;
int32 costumeId = 3;
}
message ResSetCharacterCostume {}

View File

@@ -46,6 +46,8 @@ namespace nksrv.StaticInfo
private JArray rewardDataRecords;
private JArray userExpDataRecords;
private JArray chapterCampaignData;
private JArray characterCostumeTable;
private JArray characterTable;
public StaticDataParser(string filePath)
{
if (!File.Exists(filePath)) throw new ArgumentException("Static data file must exist", nameof(filePath));
@@ -198,52 +200,33 @@ namespace nksrv.StaticInfo
Instance = new(targetFile);
}
#endregion
public async Task Parse()
{
var mainQuestData = MainZip.GetEntry("MainQuestTable.json");
var campaignStageData = MainZip.GetEntry("CampaignStageTable.json");
var rewardDataEntry = MainZip.GetEntry("RewardTable.json");
var userExpTable = MainZip.GetEntry("UserExpTable.json");
var chapterCampaignEntry = MainZip.GetEntry("CampaignChapterTable.json");
if (mainQuestData == null) throw new Exception("MainQuestTable.json does not exist in static data");
if (campaignStageData == null) throw new Exception("CampaignStageTable.json does not exist in static data");
if (rewardDataEntry == null) throw new Exception("RewardTable.json does not exist in static data");
if (userExpTable == null) throw new Exception("UserExpTable.json does not exist in static data");
if (chapterCampaignEntry == null) throw new Exception("CampaignChapterTable.json does not exist in static data");
private async Task<JArray> LoadZip(string entry)
{
var mainQuestData = MainZip.GetEntry(entry);
if (mainQuestData == null) throw new Exception(entry + " does not exist in static data");
using StreamReader mainQuestReader = new StreamReader(MainZip.GetInputStream(mainQuestData));
var mainQuestDataString = await mainQuestReader.ReadToEndAsync();
using StreamReader campaignStageDataReader = new StreamReader(MainZip.GetInputStream(campaignStageData));
var campaignStageDataString = await campaignStageDataReader.ReadToEndAsync();
using StreamReader rewardDataReader = new StreamReader(MainZip.GetInputStream(rewardDataEntry));
var rewardJsonString = await rewardDataReader.ReadToEndAsync();
using StreamReader userExpTableReader = new StreamReader(MainZip.GetInputStream(userExpTable));
var userExpTableString = await userExpTableReader.ReadToEndAsync();
using StreamReader chapterCampaignReader = new StreamReader(MainZip.GetInputStream(chapterCampaignEntry));
var chapterCampaignString = await chapterCampaignReader.ReadToEndAsync();
var questdata = JObject.Parse(mainQuestDataString);
var stagedata = JObject.Parse(campaignStageDataString);
var rewardData = JObject.Parse(rewardJsonString);
var userExpTableData = JObject.Parse(userExpTableString);
var chapterCampaignData = JObject.Parse(chapterCampaignString);
if (questdata == null) throw new Exception("failed to parse " + entry);
questDataRecords = (JArray?)questdata["records"];
stageDataRecords = (JArray?)stagedata["records"];
rewardDataRecords = (JArray?)rewardData["records"];
userExpDataRecords = (JArray?)userExpTableData["records"];
this.chapterCampaignData = (JArray?)chapterCampaignData["records"];
var records = (JArray?)questdata["records"];
if (records == null ) throw new Exception(entry + " is missing records element");
if (questDataRecords == null) throw new Exception("MainQuestTable.json does not contain records array");
if (stageDataRecords == null) throw new Exception("CampaignStageTable.json does not contain records array");
if (rewardDataRecords == null) throw new Exception("RewardTable.json does not contain records array");
if (userExpDataRecords == null) throw new Exception("UserExpTable.json does not contain records array");
if (this.chapterCampaignData == null) throw new Exception("CampaignChapterTable.json does not contain records array");
return records;
}
public async Task Parse()
{
questDataRecords = await LoadZip("MainQuestTable.json");
stageDataRecords = await LoadZip("CampaignStageTable.json");
rewardDataRecords = await LoadZip("RewardTable.json");
userExpDataRecords = await LoadZip("UserExpTable.json");
chapterCampaignData = await LoadZip("CampaignChapterTable.json");
characterCostumeTable = await LoadZip("CharacterCostumeTable.json");
characterTable = await LoadZip("CharacterTable.json");
}
public MainQuestCompletionData? GetMainQuestForStageClearCondition(int stage)
@@ -335,7 +318,7 @@ namespace nksrv.StaticInfo
if (exp == null) throw new Exception("expected exp field in user exp table data");
int expValue = exp.ToObject<int>();
if (prevValue < targetExp)
{
prevLevel = levelValue;
@@ -373,5 +356,28 @@ namespace nksrv.StaticInfo
return -1;
}
public IEnumerable<int> GetAllCharacterTids()
{
foreach (JObject item in characterTable)
{
var id = item["id"];
if (id == null) throw new Exception("expected id field in reward data");
int value = id.ToObject<int>();
yield return value;
}
}
public IEnumerable<int> GetAllCostumes()
{
foreach (JObject item in characterCostumeTable)
{
var id = item["id"];
if (id == null) throw new Exception("expected id field in reward data");
int value = id.ToObject<int>();
yield return value;
}
}
}
}