item enhane

This commit is contained in:
rfi 2023-11-29 21:01:00 +07:00
parent 2039ae32d0
commit 228dacb901
7 changed files with 3584 additions and 8 deletions

View File

@ -6,21 +6,27 @@ using AscNet.Table.share.character.skill;
using AscNet.Common.MsgPack; using AscNet.Common.MsgPack;
using AscNet.Common.Util; using AscNet.Common.Util;
using Newtonsoft.Json; using Newtonsoft.Json;
using AscNet.Table.V2.share.equip;
namespace AscNet.Common.Database namespace AscNet.Common.Database
{ {
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public class Character public class Character
{ {
public static readonly List<CharacterLevelUpTemplate> levelUpTemplates; public static readonly List<CharacterLevelUpTemplate> characterLevelUpTemplates;
public static readonly List<EquipLevelUpTemplate> equipLevelUpTemplates;
public static readonly IMongoCollection<Character> collection = Common.db.GetCollection<Character>("characters"); public static readonly IMongoCollection<Character> collection = Common.db.GetCollection<Character>("characters");
static Character() static Character()
{ {
if (File.Exists("Data/CharacterLevelUpTemplate.json")) if (File.Exists("Data/CharacterLevelUpTemplate.json"))
levelUpTemplates = JsonConvert.DeserializeObject<List<CharacterLevelUpTemplate>>(File.ReadAllText("Data/CharacterLevelUpTemplate.json")) ?? new(); characterLevelUpTemplates = JsonConvert.DeserializeObject<List<CharacterLevelUpTemplate>>(File.ReadAllText("Data/CharacterLevelUpTemplate.json")) ?? new();
else else
levelUpTemplates = new(); characterLevelUpTemplates = new();
if (File.Exists("Data/EquipLevelUpTemplate.json"))
equipLevelUpTemplates = JsonConvert.DeserializeObject<List<EquipLevelUpTemplate>>(File.ReadAllText("Data/EquipLevelUpTemplate.json")) ?? new();
else
equipLevelUpTemplates = new();
} }
private uint NextEquipId => Equips.MaxBy(x => x.Id)?.Id + 1 ?? 1; private uint NextEquipId => Equips.MaxBy(x => x.Id)?.Id + 1 ?? 1;
@ -102,7 +108,7 @@ namespace AscNet.Common.Database
if (character is not null && characterData is not null) if (character is not null && characterData is not null)
{ {
levelCheck: levelCheck:
CharacterLevelUpTemplate? levelUpTemplate = levelUpTemplates.FirstOrDefault(x => x.Level == character.Level && x.Type == characterData.Type); CharacterLevelUpTemplate? levelUpTemplate = characterLevelUpTemplates.FirstOrDefault(x => x.Level == character.Level && x.Type == characterData.Type);
if (levelUpTemplate is not null) if (levelUpTemplate is not null)
{ {
if (levelUpTemplate.Exp > exp) if (levelUpTemplate.Exp > exp)
@ -182,6 +188,39 @@ namespace AscNet.Common.Database
Equips.Add(equipData); Equips.Add(equipData);
} }
public NotifyEquipDataList.NotifyEquipDataListEquipData? AddEquipExp(int equipId, int exp)
{
var equip = Equips.FirstOrDefault(x => x.Id == equipId);
EquipTable? equipData = TableReaderV2.Parse<EquipTable>().FirstOrDefault(x => x.Id == equip?.TemplateId);
EquipBreakThroughTable? equipBreakThroughTable = TableReaderV2.Parse<EquipBreakThroughTable>().FirstOrDefault(x => x.EquipId == equip?.TemplateId && x.Times == equip?.Breakthrough);
if (equip is not null && equipData is not null && equipBreakThroughTable is not null)
{
EquipLevelUpTemplate? levelUpTemplate = equipLevelUpTemplates.FirstOrDefault(x => x.TemplateId == equipBreakThroughTable.LevelUpTemplateId && x.Level == equip.Level);
if (levelUpTemplate is not null)
{
if (exp + equip.Exp < levelUpTemplate.Exp)
{
equip.Exp += Math.Max(0, exp);
}
else if (equip.Level < equipBreakThroughTable.LevelLimit)
{
equip.Level++;
exp -= levelUpTemplate.Exp - equip.Exp;
equip.Exp = 0;
return AddEquipExp(equipId, exp);
}
else
{
equip.Exp = levelUpTemplate.Exp;
}
}
}
return equip;
}
public void Save() public void Save()
{ {
collection.ReplaceOne(Builders<Character>.Filter.Eq(x => x.Id, Id), this); collection.ReplaceOne(Builders<Character>.Filter.Eq(x => x.Id, Id), this);
@ -228,4 +267,19 @@ namespace AscNet.Common.Database
[JsonProperty("Type")] [JsonProperty("Type")]
public int Type { get; set; } public int Type { get; set; }
} }
public partial class EquipLevelUpTemplate
{
[JsonProperty("Level")]
public int Level { get; set; }
[JsonProperty("Exp")]
public int Exp { get; set; }
[JsonProperty("AllExp")]
public int AllExp { get; set; }
[JsonProperty("TemplateId")]
public int TemplateId { get; set; }
}
} }

View File

@ -21,6 +21,40 @@ namespace AscNet.Common
return 0; return 0;
} }
public static EquipUpgradeInfo GetEquipUpgradeInfo(this ItemTable item)
{
if (item.ItemType == (int)ItemType.EquipExp && item.SubTypeParams.Count >= 3)
{
int classify = item.SubTypeParams[0];
int exp = item.SubTypeParams[1];
int cost = item.SubTypeParams[2];
return new EquipUpgradeInfo()
{
Cost = cost,
Exp = exp
};
}
return new EquipUpgradeInfo()
{
Cost = 0,
Exp = 0
};
}
public struct EquipUpgradeInfo
{
public int Cost { get; init; }
public int Exp { get; init; }
public static EquipUpgradeInfo operator *(EquipUpgradeInfo a, int b) => new()
{
Cost = a.Cost * b,
Exp = a.Exp * b
};
}
} }
enum ItemType enum ItemType

View File

@ -134,7 +134,6 @@ namespace AscNet.GameServer.Handlers
BaseEquipLoginData = new(), BaseEquipLoginData = new(),
FubenData = new() FubenData = new()
{ {
StageData = session.stage.Stages,
FubenBaseData = new() FubenBaseData = new()
}, },
FubenMainLineData = new(), FubenMainLineData = new(),
@ -148,6 +147,12 @@ namespace AscNet.GameServer.Handlers
#if DEBUG #if DEBUG
notifyLogin.PlayerData.GuideData = GuideGroupTableReader.Instance.All.Select(x => (long)x.Id).ToList(); notifyLogin.PlayerData.GuideData = GuideGroupTableReader.Instance.All.Select(x => (long)x.Id).ToList();
#endif
NotifyStageData notifyStageData = new()
{
StageList = session.stage.Stages.Values.ToList()
};
StageDatum stageForChat = new() StageDatum stageForChat = new()
{ {
@ -166,9 +171,9 @@ namespace AscNet.GameServer.Handlers
BestCardIds = new List<long> { 1021001 }, BestCardIds = new List<long> { 1021001 },
LastCardIds = new List<long> { 1021001 } LastCardIds = new List<long> { 1021001 }
}; };
if (!notifyLogin.FubenData.StageData.ContainsKey(stageForChat.StageId))
notifyLogin.FubenData.StageData = notifyLogin.FubenData.StageData.Append(new(stageForChat.StageId, stageForChat)).ToDictionary(x => x.Key, x => x.Value); if (!notifyStageData.StageList.Any(x => x.StageId == stageForChat.StageId))
#endif notifyStageData.StageList = notifyStageData.StageList.Append(stageForChat).ToList();
NotifyCharacterDataList notifyCharacterData = new(); NotifyCharacterDataList notifyCharacterData = new();
notifyCharacterData.CharacterDataList.AddRange(session.character.Characters); notifyCharacterData.CharacterDataList.AddRange(session.character.Characters);
@ -203,6 +208,7 @@ namespace AscNet.GameServer.Handlers
}; };
session.SendPush(notifyLogin); session.SendPush(notifyLogin);
session.SendPush(notifyStageData);
session.SendPush(notifyCharacterData); session.SendPush(notifyCharacterData);
session.SendPush(notifyEquipData); session.SendPush(notifyEquipData);
session.SendPush(notifyAssistData); session.SendPush(notifyAssistData);

View File

@ -0,0 +1,74 @@
using AscNet.Common;
using AscNet.Common.Database;
using AscNet.Common.MsgPack;
using AscNet.Common.Util;
using AscNet.Table.V2.share.item;
using MessagePack;
namespace AscNet.GameServer.Handlers
{
#region MsgPackScheme
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
[MessagePackObject(true)]
public class EquipLevelUpRequest
{
public int EquipId;
public Dictionary<int, int> UseItems;
public List<int> UseEquipIdList;
}
[MessagePackObject(true)]
public class EquipLevelUpResponse
{
public int Code;
public int Level;
public int Exp;
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#endregion
internal class EquipModule
{
[RequestPacketHandler("EquipLevelUpRequest")]
public static void EquipLevelUpRequestHandler(Session session, Packet.Request packet)
{
EquipLevelUpRequest request = packet.Deserialize<EquipLevelUpRequest>();
NotifyItemDataList notifyItemData = new();
int totalExp = 0;
int totalCost = 0;
foreach (var item in request.UseItems)
{
ItemTable? itemTable = TableReaderV2.Parse<ItemTable>().FirstOrDefault(x => x.Id == item.Key);
if (itemTable is not null)
{
var upgradeInfo = itemTable.GetEquipUpgradeInfo() * item.Value;
totalExp += upgradeInfo.Exp;
totalCost += upgradeInfo.Cost;
notifyItemData.ItemDataList.Add(session.inventory.Do(item.Key, item.Value * -1));
}
}
notifyItemData.ItemDataList.Add(session.inventory.Do(Inventory.Coin, totalCost * -1));
session.SendPush(notifyItemData);
EquipLevelUpResponse rsp = new()
{
Code = 0
};
var upEquip = session.character.AddEquipExp(request.EquipId, totalExp);
if (upEquip != null)
{
rsp.Level = upEquip.Level;
rsp.Exp = upEquip.Exp;
NotifyEquipDataList notifyEquipDataList = new();
notifyEquipDataList.EquipDataList.Add(upEquip);
session.SendPush(notifyEquipDataList);
}
session.SendResponse(rsp, packet.Id);
}
}
}

View File

@ -208,6 +208,10 @@ namespace AscNet.GameServer.Handlers
List<RewardGoods> rewards = new(); List<RewardGoods> rewards = new();
List<RewardTable> rewardTables = TableReaderV2.Parse<RewardTable>().Where(x => session.stage.Stages.ContainsKey(req.Result.StageId) ? x.Id == stageTable.FinishDropId : (x.Id == stageTable.FinishDropId || x.Id == stageTable.FirstRewardId)).ToList(); List<RewardTable> rewardTables = TableReaderV2.Parse<RewardTable>().Where(x => session.stage.Stages.ContainsKey(req.Result.StageId) ? x.Id == stageTable.FinishDropId : (x.Id == stageTable.FinishDropId || x.Id == stageTable.FirstRewardId)).ToList();
if (rewardTables.Count == 0)
{
rewardTables.AddRange(TableReaderV2.Parse<RewardTable>().Where(x => session.stage.Stages.ContainsKey(req.Result.StageId) ? x.Id == stageTable.FinishRewardShow : (x.Id == stageTable.FinishRewardShow || x.Id == stageTable.FirstRewardShow)));
}
NotifyItemDataList notifyItemData = new(); NotifyItemDataList notifyItemData = new();
notifyItemData.ItemDataList.Add(session.inventory.Do(Inventory.TeamExp, stageTable.TeamExp ?? 0)); notifyItemData.ItemDataList.Add(session.inventory.Do(Inventory.TeamExp, stageTable.TeamExp ?? 0));

View File

@ -23,5 +23,17 @@ namespace AscNet.GameServer.Handlers
session.SendResponse(rsp, packet.Id); session.SendResponse(rsp, packet.Id);
} }
[RequestPacketHandler("GetShopInfoRequest")]
public static void GetShopInfoRequestHandler(Session session, Packet.Request packet)
{
GetShopInfoResponse rsp = new()
{
Code = 0,
ClientShop = { }
};
session.SendResponse(rsp, packet.Id);
}
} }
} }

File diff suppressed because it is too large Load Diff