mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-13 23:44:45 +01:00
properly implement character level up
currency is now subtracted
This commit is contained in:
@@ -44,14 +44,15 @@ Stage, character, outpost and story information is saved and works, as well as p
|
|||||||
- [X] Profile UI
|
- [X] Profile UI
|
||||||
- [X] Open Archives UI
|
- [X] Open Archives UI
|
||||||
- [X] Inventory system
|
- [X] Inventory system
|
||||||
|
- [X] Character level up
|
||||||
|
- [ ] Skill level up
|
||||||
- [ ] Outpost jukebox / relics saving
|
- [ ] Outpost jukebox / relics saving
|
||||||
- [ ] Field obtain object
|
- [ ] Field obtain object
|
||||||
- [ ] Admin panel
|
- [ ] Admin panel
|
||||||
- [ ] Test hard stage support
|
- [ ] Test hard stage support
|
||||||
- [ ] Event system
|
- [ ] Event system
|
||||||
- [ ] Download all game assets ahead of time
|
- [ ] Download all game assets ahead of time
|
||||||
- [ ] Level up/skill level up support
|
- [ ] Basic friend list support
|
||||||
- [ ] Basic friend list support / allow using other servers except 127.0.0.1
|
|
||||||
- [ ] Aegis Diver minigame, MOG minigame, etc
|
- [ ] Aegis Diver minigame, MOG minigame, etc
|
||||||
- [ ] Outpost claim rewards
|
- [ ] Outpost claim rewards
|
||||||
- [ ] Daily, weekly missions etc
|
- [ ] Daily, weekly missions etc
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using nksrv.Utils;
|
using nksrv.StaticInfo;
|
||||||
|
using nksrv.Utils;
|
||||||
|
using Swan.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -15,14 +17,40 @@ namespace nksrv.LobbyServer.Msgs.Character
|
|||||||
var req = await ReadData<ReqCharacterLevelUp>();
|
var req = await ReadData<ReqCharacterLevelUp>();
|
||||||
var user = GetUser();
|
var user = GetUser();
|
||||||
var response = new ResCharacterLevelUp();
|
var response = new ResCharacterLevelUp();
|
||||||
|
var data = StaticDataParser.Instance.GetCharacterLevelUpData();
|
||||||
|
|
||||||
foreach (var item in user.Characters.ToArray())
|
foreach (var item in user.Characters.ToArray())
|
||||||
{
|
{
|
||||||
if (item.Csn == req.Csn)
|
if (item.Csn == req.Csn)
|
||||||
{
|
{
|
||||||
item.Level = req.Level;
|
// item.Level = req.Level;
|
||||||
// TODO: subtract currency
|
|
||||||
|
|
||||||
|
int requiredCredit = 0;
|
||||||
|
int requiredBattleData = 0;
|
||||||
|
int requiredCoreDust = 0;
|
||||||
|
for (int i = item.Level; i < req.Level; i++)
|
||||||
|
{
|
||||||
|
var levelUpData = data[i];
|
||||||
|
requiredCredit += levelUpData.gold;
|
||||||
|
requiredBattleData += levelUpData.character_exp;
|
||||||
|
requiredCoreDust += levelUpData.character_exp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.CanSubtractCurrency(CurrencyType.Gold, requiredCredit) &&
|
||||||
|
user.CanSubtractCurrency(CurrencyType.CharacterExp, requiredBattleData) &&
|
||||||
|
user.CanSubtractCurrency(CurrencyType.CharacterExp2, requiredCoreDust))
|
||||||
|
{
|
||||||
|
user.SubtractCurrency(CurrencyType.Gold, requiredCredit);
|
||||||
|
user.SubtractCurrency(CurrencyType.CharacterExp, requiredBattleData);
|
||||||
|
user.SubtractCurrency(CurrencyType.CharacterExp2, requiredCoreDust);
|
||||||
|
item.Level = req.Level;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TOOD: log this
|
||||||
|
Logger.Error("ERROR: Not enough currency for upgrade");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
response.Character = new() {
|
response.Character = new() {
|
||||||
CostumeId = item.CostumeId,
|
CostumeId = item.CostumeId,
|
||||||
@@ -43,6 +71,11 @@ namespace nksrv.LobbyServer.Msgs.Character
|
|||||||
response.SynchroStandardCharacters.Add(c.Tid);
|
response.SynchroStandardCharacters.Add(c.Tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var currency in user.Currency)
|
||||||
|
{
|
||||||
|
response.Currencies.Add(new NetUserCurrencyData() { Type = (int)currency.Key, Value = currency.Value });
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace nksrv.LobbyServer.Msgs.User
|
|||||||
// todo tutorial playcount of gacha
|
// todo tutorial playcount of gacha
|
||||||
response.TutorialGachaPlayCount = user.GachaTutorialPlayCount;
|
response.TutorialGachaPlayCount = user.GachaTutorialPlayCount;
|
||||||
|
|
||||||
await WriteDataAsync(response);
|
await WriteDataAsync(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,4 +57,28 @@ namespace nksrv.StaticInfo
|
|||||||
public int NextId;
|
public int NextId;
|
||||||
public bool SaveTutorial;
|
public bool SaveTutorial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CharacterLevelData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// level
|
||||||
|
/// </summary>
|
||||||
|
public int level;
|
||||||
|
/// <summary>
|
||||||
|
/// can be CharacterLevel or SynchroLevel
|
||||||
|
/// </summary>
|
||||||
|
public string type = "";
|
||||||
|
/// <summary>
|
||||||
|
/// amount of credits required
|
||||||
|
/// </summary>
|
||||||
|
public int gold = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// amount of battle data required
|
||||||
|
/// </summary>
|
||||||
|
public int character_exp = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// amount of core dust required
|
||||||
|
/// </summary>
|
||||||
|
public int character_exp2 = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ namespace nksrv.StaticInfo
|
|||||||
private JArray characterTable;
|
private JArray characterTable;
|
||||||
private JArray tutorialTable;
|
private JArray tutorialTable;
|
||||||
private JArray itemEquipTable;
|
private JArray itemEquipTable;
|
||||||
|
private Dictionary<int, CharacterLevelData> LevelData = [];
|
||||||
|
|
||||||
public byte[] Sha256Hash;
|
public byte[] Sha256Hash;
|
||||||
public int Size;
|
public int Size;
|
||||||
@@ -230,7 +231,7 @@ namespace nksrv.StaticInfo
|
|||||||
if (questdata == null) throw new Exception("failed to parse " + entry);
|
if (questdata == null) throw new Exception("failed to parse " + entry);
|
||||||
|
|
||||||
var records = (JArray?)questdata["records"];
|
var records = (JArray?)questdata["records"];
|
||||||
if (records == null ) throw new Exception(entry + " is missing records element");
|
if (records == null) throw new Exception(entry + " is missing records element");
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
@@ -245,6 +246,16 @@ namespace nksrv.StaticInfo
|
|||||||
characterTable = await LoadZip("CharacterTable.json");
|
characterTable = await LoadZip("CharacterTable.json");
|
||||||
tutorialTable = await LoadZip("ContentsTutorialTable.json");
|
tutorialTable = await LoadZip("ContentsTutorialTable.json");
|
||||||
itemEquipTable = await LoadZip("ItemEquipTable.json");
|
itemEquipTable = await LoadZip("ItemEquipTable.json");
|
||||||
|
var characterLevelTable = await LoadZip("CharacterLevelTable.json");
|
||||||
|
|
||||||
|
foreach (JToken item in characterLevelTable)
|
||||||
|
{
|
||||||
|
var obj = item.ToObject<CharacterLevelData>();
|
||||||
|
if (obj != null)
|
||||||
|
LevelData.Add(obj.level, obj);
|
||||||
|
else
|
||||||
|
Logger.Warn("failed to read character level table entry");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainQuestCompletionData? GetMainQuestForStageClearCondition(int stage)
|
public MainQuestCompletionData? GetMainQuestForStageClearCondition(int stage)
|
||||||
@@ -257,7 +268,7 @@ namespace nksrv.StaticInfo
|
|||||||
int value = id.ToObject<int>();
|
int value = id.ToObject<int>();
|
||||||
if (value == stage)
|
if (value == stage)
|
||||||
{
|
{
|
||||||
MainQuestCompletionData? data = JsonConvert.DeserializeObject<MainQuestCompletionData>(item.ToString());
|
MainQuestCompletionData? data = item.ToObject<MainQuestCompletionData>();
|
||||||
if (data == null) throw new Exception("failed to deserialize main quest data item");
|
if (data == null) throw new Exception("failed to deserialize main quest data item");
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -275,7 +286,7 @@ namespace nksrv.StaticInfo
|
|||||||
int value = id.ToObject<int>();
|
int value = id.ToObject<int>();
|
||||||
if (value == tid)
|
if (value == tid)
|
||||||
{
|
{
|
||||||
MainQuestCompletionData? data = JsonConvert.DeserializeObject<MainQuestCompletionData>(item.ToString());
|
MainQuestCompletionData? data = item.ToObject<MainQuestCompletionData>();
|
||||||
if (data == null) throw new Exception("failed to deserialize main quest data item");
|
if (data == null) throw new Exception("failed to deserialize main quest data item");
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -417,7 +428,7 @@ namespace nksrv.StaticInfo
|
|||||||
int idValue = id.ToObject<int>();
|
int idValue = id.ToObject<int>();
|
||||||
if (idValue == TableId)
|
if (idValue == TableId)
|
||||||
{
|
{
|
||||||
ClearedTutorialData? data = JsonConvert.DeserializeObject<ClearedTutorialData>(item.ToString());
|
ClearedTutorialData? data = item.ToObject<ClearedTutorialData>();
|
||||||
if (data == null) throw new Exception("failed to deserialize reward data");
|
if (data == null) throw new Exception("failed to deserialize reward data");
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -454,7 +465,7 @@ namespace nksrv.StaticInfo
|
|||||||
string mod = normal ? "Normal" : "Hard";
|
string mod = normal ? "Normal" : "Hard";
|
||||||
foreach (JObject item in stageDataRecords)
|
foreach (JObject item in stageDataRecords)
|
||||||
{
|
{
|
||||||
CampaignStageRecord? data = JsonConvert.DeserializeObject<CampaignStageRecord>(item.ToString());
|
CampaignStageRecord? data = item.ToObject<CampaignStageRecord>();
|
||||||
if (data == null) throw new Exception("failed to deserialize stage data");
|
if (data == null) throw new Exception("failed to deserialize stage data");
|
||||||
|
|
||||||
int chVal = data.chapter_id - 1;
|
int chVal = data.chapter_id - 1;
|
||||||
@@ -465,5 +476,10 @@ namespace nksrv.StaticInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Dictionary<int, CharacterLevelData> GetCharacterLevelUpData()
|
||||||
|
{
|
||||||
|
return LevelData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,47 @@ namespace nksrv.Utils
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long GetCurrencyVal(CurrencyType type)
|
||||||
|
{
|
||||||
|
if (Currency.ContainsKey(type))
|
||||||
|
return Currency[type];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Currency.Add(type, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void AddCurrency(CurrencyType type, long val)
|
||||||
|
{
|
||||||
|
if (Currency.ContainsKey(type)) Currency[type] += val;
|
||||||
|
else Currency.Add(type, val);
|
||||||
|
}
|
||||||
|
public bool SubtractCurrency(CurrencyType type, long val)
|
||||||
|
{
|
||||||
|
if (Currency.ContainsKey(type)) Currency[type] -= val;
|
||||||
|
else return false;
|
||||||
|
|
||||||
|
if (Currency[type] < 0)
|
||||||
|
{
|
||||||
|
Currency[type] += val;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool CanSubtractCurrency(CurrencyType type, long val)
|
||||||
|
{
|
||||||
|
if (Currency.ContainsKey(type))
|
||||||
|
{
|
||||||
|
if (Currency[type] >= val) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (val == 0) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public class CoreInfo
|
public class CoreInfo
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user