diff --git a/Server/Protocol/Packets/0B-QuestPacket/0B-16-QuestAvailablePacket.cs b/Server/Protocol/Packets/0B-QuestPacket/0B-16-QuestAvailablePacket.cs index 380864f..9ed1225 100644 --- a/Server/Protocol/Packets/0B-QuestPacket/0B-16-QuestAvailablePacket.cs +++ b/Server/Protocol/Packets/0B-QuestPacket/0B-16-QuestAvailablePacket.cs @@ -173,6 +173,110 @@ namespace PSO2SERVER.Protocol.Packets { QuestType.Stars6, packet => { Unk16[0]++; AvailableTypes |= AvailableQuestType.STARS6; } }, }; + // 处理每个 QuestData + foreach (var quest in quests) + { + if (quest?.QuestDefiniton == null) + { + Logger.WriteError("QuestAvailablePacket Load: Invalid quest definition."); + continue; + } + + var questType = quest.QuestDefiniton.QuestType; + + if (questActions.TryGetValue(questType, out var action)) + { + try + { + action(amount); + } + catch (Exception ex) + { + Logger.WriteError($"Error processing quest type {questType}: {ex.Message}"); + } + } + else + { + Logger.WriteWarning($"No action defined for quest type {questType}"); + } + } + } + + public static QuestAvailablePacket Load(List quests) + { + var amount = new QuestAvailablePacket(); + + // 定义一个字典,映射 QuestType 到相应的更新方法 + var questActions = new Dictionary> + { + { QuestType.Unk0, packet => { packet.Unk1++; packet.AvailableTypes |= AvailableQuestType.UNK1; } }, + { QuestType.Extreme, packet => { packet.ExtremeCount++; packet.AvailableTypes |= AvailableQuestType.EXTREME; } }, + { QuestType.ARKS, packet => { packet.ArksCount++; packet.AvailableTypes |= AvailableQuestType.ARKS; } }, + { QuestType.LimitedTime, packet => { packet.LimitedTimeCount++; packet.AvailableTypes |= AvailableQuestType.LIMITED_TIME; } }, + { QuestType.ExtremeDebug, packet => { packet.ExtremeDebugCount++; packet.AvailableTypes |= AvailableQuestType.EXTREME_DEBUG; } }, + { QuestType.Blank1, packet => { packet.Blank1Count++; packet.AvailableTypes |= AvailableQuestType.BLANK1; } }, + { QuestType.NetCafe, packet => { packet.NetCafeCount++; packet.AvailableTypes |= AvailableQuestType.NET_CAFE; } }, + { QuestType.WarmingDebug, packet => { packet.WarmingDebugCount++; packet.AvailableTypes |= AvailableQuestType.WARMING_DEBUG; } }, + { QuestType.Blank2, packet => { packet.Blank2Count++; packet.AvailableTypes |= AvailableQuestType.BLANK2; } }, + { QuestType.Advance, packet => { packet.AdvanceCount++; packet.AvailableTypes |= AvailableQuestType.ADVANCE; } }, + { QuestType.Expedition, packet => { packet.ExpeditionCount++; packet.AvailableTypes |= AvailableQuestType.EXPEDITION; } }, + { QuestType.FreeDebug, packet => { packet.ExpeditionDebugCount++; packet.AvailableTypes |= AvailableQuestType.FREE_DEBUG; } }, + { QuestType.ArksDebug, packet => { packet.ArksDebugCount++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG; } }, + { QuestType.Challenge, packet => { packet.ChallengeCount++; packet.AvailableTypes |= AvailableQuestType.CHALLENGE; } }, + { QuestType.Urgent, packet => { packet.UrgentCount++; packet.AvailableTypes |= AvailableQuestType.URGENT; } }, + { QuestType.UrgentDebug, packet => { packet.UrgentDebugCount++; packet.AvailableTypes |= AvailableQuestType.URGENT_DEBUG; } }, + { QuestType.TimeAttack, packet => { packet.TimeAttackCount++; packet.AvailableTypes |= AvailableQuestType.TIME_ATTACK; } }, + { QuestType.TimeDebug, packet => { packet.TimeAttackDebugCount++; packet.AvailableTypes |= AvailableQuestType.TIME_DEBUG; } }, + { QuestType.ArksDebug2, packet => { packet.ArksDebug2Count[0]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG2; } }, + { QuestType.ArksDebug3, packet => { packet.ArksDebug2Count[1]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG3; } }, + { QuestType.ArksDebug4, packet => { packet.ArksDebug2Count[2]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG4; } }, + { QuestType.ArksDebug5, packet => { packet.ArksDebug2Count[3]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG5; } }, + { QuestType.ArksDebug6, packet => { packet.ArksDebug2Count[4]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG6; } }, + { QuestType.ArksDebug7, packet => { packet.ArksDebug2Count[5]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG7; } }, + { QuestType.ArksDebug8, packet => { packet.ArksDebug2Count[6]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG8; } }, + { QuestType.ArksDebug9, packet => { packet.ArksDebug2Count[7]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG9; } }, + { QuestType.ArksDebug10, packet => { packet.ArksDebug2Count[8]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG10; } }, + { QuestType.Blank3, packet => { packet.Blank3Count++; packet.AvailableTypes |= AvailableQuestType.BLANK3; } }, + { QuestType.Ultimate, packet => { packet.Unk6++; packet.AvailableTypes |= AvailableQuestType.ULTIMATE; } }, + { QuestType.UltimateDebug, packet => { packet.UltimateDebugCount++; packet.AvailableTypes |= AvailableQuestType.ULTIMATE_DEBUG; } }, + { QuestType.AGP, packet => { packet.AgpCount++; packet.AvailableTypes |= AvailableQuestType.AGP; } }, + { QuestType.Bonus, packet => { packet.BonusCount++; packet.AvailableTypes |= AvailableQuestType.BONUS; } }, + { QuestType.StandardTraining, packet => { packet.TrainingCount[0]++; packet.AvailableTypes |= AvailableQuestType.STANDARD_TRAINING; } }, + { QuestType.HunterTraining, packet => { packet.TrainingCount[1]++; packet.AvailableTypes |= AvailableQuestType.HUNTER_TRAINING; } }, + { QuestType.RangerTraining, packet => { packet.TrainingCount[2]++; packet.AvailableTypes |= AvailableQuestType.RANGER_TRAINING; } }, + { QuestType.ForceTraining, packet => { packet.TrainingCount[3]++; packet.AvailableTypes |= AvailableQuestType.FORCE_TRAINING; } }, + { QuestType.FighterTraining, packet => { packet.TrainingCount[4]++; packet.AvailableTypes |= AvailableQuestType.FIGHTER_TRAINING; } }, + { QuestType.GunnerTraining, packet => { packet.TrainingCount[5]++; packet.AvailableTypes |= AvailableQuestType.GUNNER_TRAINING; } }, + { QuestType.TechterTraining, packet => { packet.TrainingCount[6]++; packet.AvailableTypes |= AvailableQuestType.TECHTER_TRAINING; } }, + { QuestType.BraverTraining, packet => { packet.TrainingCount[7]++; packet.AvailableTypes |= AvailableQuestType.BRAVER_TRAINING; } }, + { QuestType.BouncerTraining, packet => { packet.TrainingCount[8]++; packet.AvailableTypes |= AvailableQuestType.BOUNCER_TRAINING; } }, + { QuestType.SummonerTraining, packet => { packet.TrainingCount[9]++; packet.AvailableTypes |= AvailableQuestType.SUMMONER_TRAINING; } }, + { QuestType.AutoAccept, packet => { packet.AvailableTypes |= AvailableQuestType.AUTO_ACCEPT; } }, + { QuestType.Ridroid, packet => { packet.RidroidCount++; packet.AvailableTypes |= AvailableQuestType.RIDROID; } }, + { QuestType.CafeAGP, packet => { packet.NetCafeAgpCount++; packet.AvailableTypes |= AvailableQuestType.NET_CAFE_AGP; } }, + { QuestType.BattleBroken, packet => { packet.BattleBrokenCount++; packet.AvailableTypes |= AvailableQuestType.BATTLE_BROKEN; } }, + { QuestType.BusterDebug, packet => { packet.BusterDebugCount++; packet.AvailableTypes |= AvailableQuestType.BUSTER_DEBUG; } }, + { QuestType.Poka12, packet => { packet.Poka12Count++; packet.AvailableTypes |= AvailableQuestType.POKA12; } }, + { QuestType.StoryEP1, packet => { packet.Unk9++; packet.AvailableTypes |= AvailableQuestType.STORY_EP1; } }, + { QuestType.Buster, packet => { packet.BusterCount++; packet.AvailableTypes |= AvailableQuestType.BUSTER; } }, + { QuestType.HeroTraining, packet => { packet.HeroTrainingCount++; packet.AvailableTypes |= AvailableQuestType.HERO_TRAINING; } }, + { QuestType.Amplified, packet => { packet.AmplifiedCount++; packet.AvailableTypes |= AvailableQuestType.AMPLIFIED; } }, + { QuestType.DarkBlastTraining, packet => { packet.DarkBlastTrainingCount++; packet.AvailableTypes |= AvailableQuestType.DARK_BLAST_TRAINING; } }, + { QuestType.Endless, packet => { packet.EndlessCount++; packet.AvailableTypes |= AvailableQuestType.ENDLESS; } }, + { QuestType.Blank4, packet => { packet.Unk13++; packet.AvailableTypes |= AvailableQuestType.BLANK4; } }, + { QuestType.PhantomTraining, packet => { packet.PhantomTrainingCount++; packet.AvailableTypes |= AvailableQuestType.PHANTOM_TRAINING; } }, + { QuestType.AISTraining, packet => { packet.AisTrainingCount++; packet.AvailableTypes |= AvailableQuestType.AIS_TRAINING; } }, + { QuestType.DamageCalculation, packet => { packet.DamageCalcCount++; packet.AvailableTypes |= AvailableQuestType.DAMAGE_CALC; } }, + { QuestType.EtoileTraining, packet => { packet.EtoileTrainingCount++; packet.AvailableTypes |= AvailableQuestType.ETOILE_TRAINING; } }, + { QuestType.Divide, packet => { packet.DivideCount++; packet.AvailableTypes |= AvailableQuestType.DIVIDE; } }, + { QuestType.Stars1, packet => { packet.Stars1Count++; packet.AvailableTypes |= AvailableQuestType.STARS1; } }, + { QuestType.Stars2, packet => { packet.Stars2Count++; packet.AvailableTypes |= AvailableQuestType.STARS2; } }, + { QuestType.Stars3, packet => { packet.Stars3Count++; packet.AvailableTypes |= AvailableQuestType.STARS3; } }, + { QuestType.Stars4, packet => { packet.Unk15[0]++; packet.AvailableTypes |= AvailableQuestType.STARS4; } }, + { QuestType.Stars5, packet => { packet.Unk15[1]++; packet.AvailableTypes |= AvailableQuestType.STARS5; } }, + { QuestType.Stars6, packet => { packet.Unk16[0]++; packet.AvailableTypes |= AvailableQuestType.STARS6; } }, + }; + // 遍历 quests 列表并执行相应的更新操作 for (int i = 0; i < quests.Count; i++) { @@ -181,7 +285,7 @@ namespace PSO2SERVER.Protocol.Packets // 确保 quest 和 QuestDefiniton 不为 null if (quest?.QuestDefiniton == null) { - Logger.WriteError($"PartyQuest at index {i} is invalid (QuestDefiniton is null)."); + Logger.WriteError($"队伍任务索引 {i} 无效 (QuestDefiniton 为空)."); continue; // 跳过当前无效的 quest } @@ -206,6 +310,8 @@ namespace PSO2SERVER.Protocol.Packets Logger.WriteWarning($"未知 QuestType {questType} 索引 {i}. 跳过."); } } + + return amount; } //public short[] amount = new short[Enum.GetValues(typeof(QuestType)).Length]; @@ -339,116 +445,5 @@ namespace PSO2SERVER.Protocol.Packets return new PacketHeader(0x0B, 0x16, PacketFlags.None); } - public static QuestAvailablePacket Load(List quests) - { - var amount = new QuestAvailablePacket(); - - // 定义一个字典,映射 QuestType 到相应的更新方法 - var questActions = new Dictionary> - { - { QuestType.Unk0, packet => { packet.Unk1++; packet.AvailableTypes |= AvailableQuestType.UNK1; } }, - { QuestType.Extreme, packet => { packet.ExtremeCount++; packet.AvailableTypes |= AvailableQuestType.EXTREME; } }, - { QuestType.ARKS, packet => { packet.ArksCount++; packet.AvailableTypes |= AvailableQuestType.ARKS; } }, - { QuestType.LimitedTime, packet => { packet.LimitedTimeCount++; packet.AvailableTypes |= AvailableQuestType.LIMITED_TIME; } }, - { QuestType.ExtremeDebug, packet => { packet.ExtremeDebugCount++; packet.AvailableTypes |= AvailableQuestType.EXTREME_DEBUG; } }, - { QuestType.Blank1, packet => { packet.Blank1Count++; packet.AvailableTypes |= AvailableQuestType.BLANK1; } }, - { QuestType.NetCafe, packet => { packet.NetCafeCount++; packet.AvailableTypes |= AvailableQuestType.NET_CAFE; } }, - { QuestType.WarmingDebug, packet => { packet.WarmingDebugCount++; packet.AvailableTypes |= AvailableQuestType.WARMING_DEBUG; } }, - { QuestType.Blank2, packet => { packet.Blank2Count++; packet.AvailableTypes |= AvailableQuestType.BLANK2; } }, - { QuestType.Advance, packet => { packet.AdvanceCount++; packet.AvailableTypes |= AvailableQuestType.ADVANCE; } }, - { QuestType.Expedition, packet => { packet.ExpeditionCount++; packet.AvailableTypes |= AvailableQuestType.EXPEDITION; } }, - { QuestType.FreeDebug, packet => { packet.ExpeditionDebugCount++; packet.AvailableTypes |= AvailableQuestType.FREE_DEBUG; } }, - { QuestType.ArksDebug, packet => { packet.ArksDebugCount++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG; } }, - { QuestType.Challenge, packet => { packet.ChallengeCount++; packet.AvailableTypes |= AvailableQuestType.CHALLENGE; } }, - { QuestType.Urgent, packet => { packet.UrgentCount++; packet.AvailableTypes |= AvailableQuestType.URGENT; } }, - { QuestType.UrgentDebug, packet => { packet.UrgentDebugCount++; packet.AvailableTypes |= AvailableQuestType.URGENT_DEBUG; } }, - { QuestType.TimeAttack, packet => { packet.TimeAttackCount++; packet.AvailableTypes |= AvailableQuestType.TIME_ATTACK; } }, - { QuestType.TimeDebug, packet => { packet.TimeAttackDebugCount++; packet.AvailableTypes |= AvailableQuestType.TIME_DEBUG; } }, - { QuestType.ArksDebug2, packet => { packet.ArksDebug2Count[0]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG2; } }, - { QuestType.ArksDebug3, packet => { packet.ArksDebug2Count[1]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG3; } }, - { QuestType.ArksDebug4, packet => { packet.ArksDebug2Count[2]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG4; } }, - { QuestType.ArksDebug5, packet => { packet.ArksDebug2Count[3]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG5; } }, - { QuestType.ArksDebug6, packet => { packet.ArksDebug2Count[4]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG6; } }, - { QuestType.ArksDebug7, packet => { packet.ArksDebug2Count[5]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG7; } }, - { QuestType.ArksDebug8, packet => { packet.ArksDebug2Count[6]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG8; } }, - { QuestType.ArksDebug9, packet => { packet.ArksDebug2Count[7]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG9; } }, - { QuestType.ArksDebug10, packet => { packet.ArksDebug2Count[8]++; packet.AvailableTypes |= AvailableQuestType.ARKS_DEBUG10; } }, - { QuestType.Blank3, packet => { packet.Blank3Count++; packet.AvailableTypes |= AvailableQuestType.BLANK3; } }, - { QuestType.Ultimate, packet => { packet.Unk6++; packet.AvailableTypes |= AvailableQuestType.ULTIMATE; } }, - { QuestType.UltimateDebug, packet => { packet.UltimateDebugCount++; packet.AvailableTypes |= AvailableQuestType.ULTIMATE_DEBUG; } }, - { QuestType.AGP, packet => { packet.AgpCount++; packet.AvailableTypes |= AvailableQuestType.AGP; } }, - { QuestType.Bonus, packet => { packet.BonusCount++; packet.AvailableTypes |= AvailableQuestType.BONUS; } }, - { QuestType.StandardTraining, packet => { packet.TrainingCount[0]++; packet.AvailableTypes |= AvailableQuestType.STANDARD_TRAINING; } }, - { QuestType.HunterTraining, packet => { packet.TrainingCount[1]++; packet.AvailableTypes |= AvailableQuestType.HUNTER_TRAINING; } }, - { QuestType.RangerTraining, packet => { packet.TrainingCount[2]++; packet.AvailableTypes |= AvailableQuestType.RANGER_TRAINING; } }, - { QuestType.ForceTraining, packet => { packet.TrainingCount[3]++; packet.AvailableTypes |= AvailableQuestType.FORCE_TRAINING; } }, - { QuestType.FighterTraining, packet => { packet.TrainingCount[4]++; packet.AvailableTypes |= AvailableQuestType.FIGHTER_TRAINING; } }, - { QuestType.GunnerTraining, packet => { packet.TrainingCount[5]++; packet.AvailableTypes |= AvailableQuestType.GUNNER_TRAINING; } }, - { QuestType.TechterTraining, packet => { packet.TrainingCount[6]++; packet.AvailableTypes |= AvailableQuestType.TECHTER_TRAINING; } }, - { QuestType.BraverTraining, packet => { packet.TrainingCount[7]++; packet.AvailableTypes |= AvailableQuestType.BRAVER_TRAINING; } }, - { QuestType.BouncerTraining, packet => { packet.TrainingCount[8]++; packet.AvailableTypes |= AvailableQuestType.BOUNCER_TRAINING; } }, - { QuestType.SummonerTraining, packet => { packet.TrainingCount[9]++; packet.AvailableTypes |= AvailableQuestType.SUMMONER_TRAINING; } }, - { QuestType.AutoAccept, packet => { packet.AvailableTypes |= AvailableQuestType.AUTO_ACCEPT; } }, - { QuestType.Ridroid, packet => { packet.RidroidCount++; packet.AvailableTypes |= AvailableQuestType.RIDROID; } }, - { QuestType.CafeAGP, packet => { packet.NetCafeAgpCount++; packet.AvailableTypes |= AvailableQuestType.NET_CAFE_AGP; } }, - { QuestType.BattleBroken, packet => { packet.BattleBrokenCount++; packet.AvailableTypes |= AvailableQuestType.BATTLE_BROKEN; } }, - { QuestType.BusterDebug, packet => { packet.BusterDebugCount++; packet.AvailableTypes |= AvailableQuestType.BUSTER_DEBUG; } }, - { QuestType.Poka12, packet => { packet.Poka12Count++; packet.AvailableTypes |= AvailableQuestType.POKA12; } }, - { QuestType.StoryEP1, packet => { packet.Unk9++; packet.AvailableTypes |= AvailableQuestType.STORY_EP1; } }, - { QuestType.Buster, packet => { packet.BusterCount++; packet.AvailableTypes |= AvailableQuestType.BUSTER; } }, - { QuestType.HeroTraining, packet => { packet.HeroTrainingCount++; packet.AvailableTypes |= AvailableQuestType.HERO_TRAINING; } }, - { QuestType.Amplified, packet => { packet.AmplifiedCount++; packet.AvailableTypes |= AvailableQuestType.AMPLIFIED; } }, - { QuestType.DarkBlastTraining, packet => { packet.DarkBlastTrainingCount++; packet.AvailableTypes |= AvailableQuestType.DARK_BLAST_TRAINING; } }, - { QuestType.Endless, packet => { packet.EndlessCount++; packet.AvailableTypes |= AvailableQuestType.ENDLESS; } }, - { QuestType.Blank4, packet => { packet.Unk13++; packet.AvailableTypes |= AvailableQuestType.BLANK4; } }, - { QuestType.PhantomTraining, packet => { packet.PhantomTrainingCount++; packet.AvailableTypes |= AvailableQuestType.PHANTOM_TRAINING; } }, - { QuestType.AISTraining, packet => { packet.AisTrainingCount++; packet.AvailableTypes |= AvailableQuestType.AIS_TRAINING; } }, - { QuestType.DamageCalculation, packet => { packet.DamageCalcCount++; packet.AvailableTypes |= AvailableQuestType.DAMAGE_CALC; } }, - { QuestType.EtoileTraining, packet => { packet.EtoileTrainingCount++; packet.AvailableTypes |= AvailableQuestType.ETOILE_TRAINING; } }, - { QuestType.Divide, packet => { packet.DivideCount++; packet.AvailableTypes |= AvailableQuestType.DIVIDE; } }, - { QuestType.Stars1, packet => { packet.Stars1Count++; packet.AvailableTypes |= AvailableQuestType.STARS1; } }, - { QuestType.Stars2, packet => { packet.Stars2Count++; packet.AvailableTypes |= AvailableQuestType.STARS2; } }, - { QuestType.Stars3, packet => { packet.Stars3Count++; packet.AvailableTypes |= AvailableQuestType.STARS3; } }, - { QuestType.Stars4, packet => { packet.Unk15[0]++; packet.AvailableTypes |= AvailableQuestType.STARS4; } }, - { QuestType.Stars5, packet => { packet.Unk15[1]++; packet.AvailableTypes |= AvailableQuestType.STARS5; } }, - { QuestType.Stars6, packet => { packet.Unk16[0]++; packet.AvailableTypes |= AvailableQuestType.STARS6; } }, - }; - - // 遍历 quests 列表并执行相应的更新操作 - for (int i = 0; i < quests.Count; i++) - { - var quest = quests[i]; - - // 确保 quest 和 QuestDefiniton 不为 null - if (quest?.QuestDefiniton == null) - { - Logger.WriteError($"PartyQuest at index {i} is invalid (QuestDefiniton is null)."); - continue; // 跳过当前无效的 quest - } - - // 获取 quest type - var questType = quest.QuestDefiniton.QuestType; - - // 如果字典中包含该 quest type,则执行对应的操作 - if (questActions.TryGetValue(questType, out var action)) - { - try - { - action(amount); // 执行更新操作 - } - catch (Exception ex) - { - Logger.WriteError($"Error executing action for QuestType {questType} at index {i}: {ex.Message}"); - } - } - else - { - // 可以在此处处理未定义的 QuestType(例如记录警告或错误) - Logger.WriteWarning($"Unknown QuestType {questType} at index {i}. Skipping."); - } - } - - return amount; - } } } diff --git a/Server/packages.config b/Server/packages.config index 9faeb61..ca481dc 100644 --- a/Server/packages.config +++ b/Server/packages.config @@ -67,7 +67,7 @@ - + \ No newline at end of file diff --git a/ServerTest/ServerTest.csproj b/ServerTest/ServerTest.csproj index f7e5be4..865a9bf 100644 --- a/ServerTest/ServerTest.csproj +++ b/ServerTest/ServerTest.csproj @@ -1,7 +1,6 @@  - - + Debug AnyCPU @@ -9,7 +8,7 @@ Library ServerTest ServerTest - v4.8 + v4.8.1 0.1.0-pre @@ -40,12 +39,6 @@ False ..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll - - ..\packages\NUnit.4.2.2\lib\net462\nunit.framework.dll - - - ..\packages\NUnit.4.2.2\lib\net462\nunit.framework.legacy.dll - ..\packages\System.Buffers.4.6.0\lib\net462\System.Buffers.dll @@ -66,6 +59,21 @@ ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + ..\packages\TestEssentials.Xunit.2.1.0\lib\netstandard2.0\TestEssentials.Xunit.dll + + + ..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.6.6\lib\netstandard1.1\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.6.6\lib\net452\xunit.core.dll + + + ..\packages\xunit.extensibility.execution.2.6.6\lib\net452\xunit.execution.desktop.dll + @@ -104,7 +112,8 @@ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - + + + \ No newline at end of file diff --git a/ServerTest/Test.cs b/ServerTest/Test.cs index fc546ad..47ca373 100644 --- a/ServerTest/Test.cs +++ b/ServerTest/Test.cs @@ -1,55 +1,51 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using System.Runtime.InteropServices; - -using Newtonsoft.Json; -using NUnit.Framework; - +using Newtonsoft.Json; +using Xunit; using PSO2SERVER.Models; using PSO2SERVER.Protocol; using PSO2SERVER.Protocol.Handlers; using PSO2SERVER.Zone; +using System; +using System.Runtime.InteropServices; using static PSO2SERVER.Models.CharacterStruct; namespace ServerTest { - [TestFixture] public class ReflectionTests { - [SetUp] - public void Setup() + public ReflectionTests() { + // Setup 方法:在构造函数中加载 PacketHandlers PacketHandlers.LoadPacketHandlers(); } - [Test] + [Fact] public void TestLoginLookup() { - Assert.IsNotNull(PacketHandlers.GetHandlerFor(0x11, 0x0)); + // 使用 xUnit 的 Assert.NotNull 代替 NUnit 的 Assert.IsNotNull + Assert.NotNull(PacketHandlers.GetHandlerFor(0x11, 0x0)); } - [Test] + [Fact] public void TestAllHandlers() { + // 遍历每个加载的处理程序,检查是否为 null 和正确类型 foreach (var p in PacketHandlers.GetLoadedHandlers()) { - Assert.IsNotNull(p); - Assert.IsInstanceOf(typeof(PacketHandler), p, "加载的PacketHandler不是一个包处理程序!"); + Assert.NotNull(p); // 确保 p 不是 null + Assert.IsType(p); // 确保 p 是 PacketHandler 类型 } } } - [TestFixture] public class UnsafeTests { private readonly JobParam _jp = new JobParam(); - [Test] + [Fact] public void CheckJobParam() { var size = Marshal.SizeOf(typeof(JobParam)); - Assert.IsNotNull(_jp); + Assert.NotNull(_jp); var jpArr = new byte[size]; var ptr = Marshal.AllocHGlobal(size); @@ -59,24 +55,22 @@ namespace ServerTest foreach (var b in jpArr) { - Assert.AreEqual(0, b); + Assert.Equal(0, b); } - Assert.AreEqual(size, jpArr.Length); + Assert.Equal(size, jpArr.Length); } } - [TestFixture] public class WriterTests { private PacketWriter _writer; - [SetUp] - public void Setup() + public WriterTests() // 构造函数初始化 { _writer = new PacketWriter(); } - [Test] + [Fact] public void TestStructureWrite() { var structureSize = Marshal.SizeOf(typeof(JobParam)); @@ -84,15 +78,15 @@ namespace ServerTest jp.entries.hunter.level = 7; _writer.WriteStruct(jp); var structArray = _writer.ToArray(); - Assert.AreEqual(structureSize, structArray.Length); - Assert.AreEqual(7, structArray[12]); + + Assert.Equal(structureSize, structArray.Length); // xUnit 中使用 Assert.Equal + Assert.Equal(7, structArray[12]); // xUnit 中使用 Assert.Equal } } - [TestFixture] public class JsonTests { - [Test] + [Fact] public void TestObjectSerialize() { var testObject = new PSOObject @@ -116,14 +110,13 @@ namespace ServerTest var thingData = BitConverter.ToUInt32(new byte[] { 0xff, 0xff, 0xff, 0xff }, 0); testObject.Things[0] = new PSOObject.PSOObjectThing { Data = thingData }; var output = JsonConvert.SerializeObject(testObject); - Console.Out.WriteLine(output); + Console.WriteLine(output); // 在 xUnit 中,控制台输出会显示在日志中 } } - [TestFixture] public class DataTests { - [Test] + [Fact] public void TestShiftEnum() { byte[] bytes = { 0x1, 0x1, 0x1 }; @@ -131,12 +124,12 @@ namespace ServerTest dataFlags |= (uint)(bytes[1] << 8); dataFlags |= (uint)(bytes[2] << 16); - Assert.AreEqual((PackedData.ENT1_ID | PackedData.ROT_Y | PackedData.UNK_Y), - (PackedData)dataFlags); - Console.Out.WriteLine((PackedData)dataFlags); + Assert.Equal(PackedData.ENT1_ID | PackedData.ROT_Y | PackedData.UNK_Y, + (PackedData)dataFlags); // xUnit 中使用 Assert.Equal + Console.WriteLine((PackedData)dataFlags); // 在 xUnit 中,控制台输出会显示在日志中 } - [Test] + [Fact] public void TestItemGUID() { byte[] itemData = @@ -147,13 +140,13 @@ namespace ServerTest 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; PSO2Items item = PSO2Items.FromByteArray(itemData); + ulong oldguid = 0x03FF2E79609940DA; ulong guid = item.GetGUID(); ulong newguid = 0x0123456789ABCDEF; - Assert.AreEqual(guid, 0x03FF2E79609940DA); - + Assert.Equal(oldguid, guid); // xUnit 中使用 Assert.Equal item.SetGUID(newguid); - Assert.AreEqual(item.GetGUID(), 0x0123456789ABCDEF); + Assert.Equal(newguid, item.GetGUID()); // xUnit 中使用 Assert.Equal } } } \ No newline at end of file diff --git a/ServerTest/app.config b/ServerTest/app.config index 78190d7..557a6a7 100644 --- a/ServerTest/app.config +++ b/ServerTest/app.config @@ -36,4 +36,4 @@ - + diff --git a/ServerTest/packages.config b/ServerTest/packages.config index b659cda..38133ac 100644 --- a/ServerTest/packages.config +++ b/ServerTest/packages.config @@ -1,11 +1,17 @@  - - + + + + + + + + \ No newline at end of file