Files
AVA2/tests/skill_test.cpp
shenleiandClaude Opus 5.5 9077aa389a AVA2 client Windows parity passes (gr2 BitKnit2/64-bit, GamePhase handlers, python modules)
- gr2: BitKnit2 decompression, 64-bit LE files, compressed curves
- net: remaining GamePhase handlers, generated GC packet table
- python: event/chat/chr/minimap/guild/quest/messenger/shop-search and
  other native modules ported against the AVA2 Windows client
- render: D3D8 fixed-function lighting in Gr2ModelRenderer, terrain
  without baked shade; cape/NPC equipment attachment
- tests + audits updated; docs/PORT-PLAN.md and WINDOWS-PARITY.md

Batch 4 (render pipeline: background.*, app.RenderGame/UpdateGame,
camera bindings, main.cpp fake-content removal) is still in progress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:43:01 +09:00

115 lines
8.2 KiB
C++

// CPythonSkill / skill module against the original AVA2 PythonSkill.cpp: skilldesc icon paths per
// job column, RegisterSkill per-skill files, the never-filled requirement data, icon handles and
// instances, GetGradeData's std::string varargs quirk and the TEST dump.
#include "python_native_modules.h"
#include "python_runtime.h"
#include "skill_description.h"
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdexcept>
using namespace ava2;
namespace fs = std::filesystem;
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
void spit(const fs::path& p,const std::string& s) { fs::create_directories(p.parent_path());std::ofstream f(p,std::ios::binary);f<<s; }
std::string slurp(const fs::path& p) { std::ifstream f(p,std::ios::binary);std::stringstream s;s<<f.rdbuf();return s.str(); }
int main(int argc,char** argv) {
if(argc!=3)return 2;
const fs::path cwd=fs::current_path();
try {
const fs::path root=fs::temp_directory_path()/"ava2_skill_test";
fs::remove_all(root);fs::create_directories(root);
// id job name grade1 grade2 desc cond0..2 (9) attributes weapons icon motion
spit(root/"locale/skilldesc.txt",
"1\tWARRIOR\tBase\tMid\t\tCut\tc1\t\t\t\tTOGGLE\tSWORD|BOW\tsamyeon\t2\n"
"2\tSUPPORT\tLeadershipSkill\t\t\tLead\t\t\t\t\tPASSIVE|CANNOT_LEVEL_UP\t\tleadership\n"
"3\twarrior\tLower\t\t\tlower-case job: no m_PathNameMap entry\t\t\t\t\t\t\tlower\n"
"130\tHORSE\tRiding\t\t\tRide\t\t\t\t\t\t\triding\n"
"131\tHORSE\tHorseSkillLongName\t\t\tHorse\t\t\t\t\t\t\thorse_icon\n");
spit(root/"skill/fire.txt",
"type\tactive\n"
"attribute\tTIME_INCREASE_SKILL\tNEED_TARGET\n"
"needweapon\tFAN\tBELL\n"
"949name\tFireKr\n"
"name\tFireEn\n"
"description\t\"burns things\"\n"
"iconfilename\tskill/fire.sub\n"
"List\t949GradeData\n{\n\t\"G1\"\t\"skill/fire_01.sub\"\n\t\"G2\"\t\"skill/fire_02.sub\"\n}\n"
"List\tAffectData\n{\n\t\"Damage\"\t\"10*k\"\t\"20*k\"\n}\n"
"maxlevel\t30\nleveluppoint\t2\nmotionindex\t7\nmotionindexforme\t9\n");
spit(root/"skill/broken.txt","type\tactive\nname\tNoIcon\n");
PythonRuntime python(argv[1],root);
require(LoadSkillDescriptions("locale/skilldesc.txt"),"skilldesc");
auto* active=FindSkillDescription(1);
require(active && active->imageFile.empty(),"active skills have no pImage");
require(active->gradeImageFiles[0]=="d:/ymir work/ui/skill/warrior/samyeon_01.sub" &&
active->gradeImageFiles[2]=="d:/ymir work/ui/skill/warrior/samyeon_03.sub" && active->gradeImageFiles[3].empty(),"grade icons");
auto* support=FindSkillDescription(2);
require(support->imageFile=="d:/ymir work/ui/skill/common/support/leadership.sub" &&
support->gradeImageFiles[0]==support->imageFile && support->gradeImageFiles[2]==support->imageFile,"normal icon");
require(FindSkillDescription(3)->gradeImageFiles[0].empty() && FindSkillDescription(3)->imageFile.empty(),"job map is case-sensitive");
require(FindSkillDescription(130)->gradeImageFiles[1]=="d:/ymir work/ui/skill/common/support/riding_02.sub" &&
FindSkillDescription(130)->imageFile.empty(),"riding grade icons");
require(FindSkillDescription(131)->imageFile=="d:/ymir work/ui/skill/common/horse/horse_icon.sub","horse icon");
fs::current_path(root);
python.execute(
"import skill\n"
"def raises(f,*a):\n try:\n f(*a)\n except RuntimeError:\n return True\n return False\n"
// Requirement data is never loaded, so every query has the constructor-state answer.
"assert skill.IsSkillRequirement(1)==0 and raises(skill.IsSkillRequirement,99)\n"
"assert skill.GetSkillRequirementData(1)==(None,0)\n"
"assert skill.GetSkillRequireStatCount(1)==0 and skill.GetSkillRequireStatData(1,5)==(0,0)\n"
"assert skill.CanLevelUpSkill(1,19)==1 and skill.CanLevelUpSkill(1,20)==0\n"
"assert skill.CanLevelUpSkill(2,0)==0 and raises(skill.CanLevelUpSkill,99,0)\n"
"assert skill.IsLevelUpSkill(1)==1 and skill.CheckRequirementSueccess(1)==1 and skill.GetNeedCharacterLevel(1)==0\n"
"assert raises(skill.GetNeedCharacterLevel,99) and raises(skill.CheckRequirementSueccess,99)\n"
"assert skill.CanUseSkill(1)==1 and skill.CanUseSkill(2)==0 and raises(skill.CanUseSkill,99)\n"
// Icons: no image assets in this mount, so NULL handles; unknown skills are 0, not errors.
"assert skill.GetIconName(1)=='' and skill.GetIconName(99)==''\n"
"assert skill.GetIconImage(99)==0 and skill.GetIconImageNew(99,0)==0\n"
"assert skill.GetIconImage(2)==0 and skill.GetIconImageNew(1,-5)==0 and skill.GetIconImageNewEx('missing.sub')==0\n"
"h=skill.GetIconInstance(1)\nh2=skill.GetIconInstanceNew(1,7)\n"
"assert h and h2 and h!=h2\n"
"skill.DeleteIconInstance(h)\nskill.DeleteIconInstance(h2)\nskill.DeleteIconInstance(h)\nskill.DeleteIconInstance(12345)\n"
"assert raises(skill.GetIconInstance,99) and raises(skill.GetIconInstanceNew,99,0)\n"
// GetGradeData: the first four bytes of the MSVC std::string (inline buffer for short names).
"assert skill.GetGradeData(1,0)==0x65736142, hex(skill.GetGradeData(1,0))\n"
"assert skill.GetGradeData(1,1)==ord('M')|ord('i')<<8|ord('d')<<16\n"
"assert skill.GetGradeData(2,0)==0x6461654C\n" // 15 chars: still the inline buffer
"assert skill.GetGradeData(131,0)==0\n" // 16+ chars: heap pointer, 0 here
"try:\n skill.GetGradeData(1,3)\n raise AssertionError\nexcept RuntimeError, e:\n assert str(e)=='Strange grade index [1]', str(e)\n"
// RegisterSkill: per-skill file relative to SetPathName; 949 keys win; no overwrite.
"skill.SetPathName('skill/')\n"
"skill.RegisterSkill(200,'fire.txt')\n"
"assert skill.GetSkillName(200)=='FireKr' and skill.GetSkillDescription(200)=='burns things'\n"
"assert skill.GetIconName(200)=='d:/ymir work/ui/skill/fire.sub'\n"
"assert skill.GetSkillMaxLevel(200)==30 and skill.GetSkillLevelUpPoint(200)==2\n"
"assert skill.GetSkillAffectDescriptionCount(200)==1\n"
"assert skill.GetGradeData(200,1)==ord('G')|ord('2')<<8\n"
"skill.RegisterSkill(1,'fire.txt')\nassert skill.GetSkillName(1)=='Base'\n"
"try:\n skill.RegisterSkill(201,'broken.txt')\n raise AssertionError\nexcept RuntimeError, e:\n"
" assert str(e)=='skill.RegisterSkill - Failed to find skill data file : 201, skill/broken.txt', str(e)\n"
"assert raises(skill.RegisterSkill,202,'nothere.txt')\n"
"skill.LoadSkillData()\nskill.ClearSkillData()\n"
"skill.TEST()\n");
auto* fire=FindSkillDescription(200);
require(fire && fire->needWeapon==(16u|32u) && fire->attributes==((1u<<15)|1u) && fire->motion==7 && fire->motionForMe==9,"RegisterSkill fields");
require(fire->gradeImageFiles[0]=="d:/ymir work/ui/skill/fire_01.sub" && fire->gradeImageFiles[2].empty() &&
fire->imageFile=="d:/ymir work/ui/skill/fire.sub","RegisterSkill icons");
const std::string dump=slurp(root/"test.txt");
std::istringstream lines(dump);std::string first,line,fireRow;std::getline(lines,first);
while(std::getline(lines,line))if(line.rfind("FireKr",0)==0)fireRow=line;
// ARROW shares SWORD's bit, so the map walk prints both.
if(first!="Base\t\t\tCut\tc1\t\t\t\tTOGGLE\tARROW|BOW|SWORD\t\t2\t\t\t\t") { std::cerr<<'['<<first<<"]\n";throw std::runtime_error("TEST row"); }
if(fireRow!="FireKr\t\t\tburns things\t\t\t\t\tNEED_TARGET|TIME_INCREASE_SKILL\tBELL|FAN\tfire\t7\t9\tDamage\t10*k\t20*k\t\t") {
std::cerr<<'['<<fireRow<<"]\n";throw std::runtime_error("TEST fire row");
}
fs::current_path(cwd);
fs::remove_all(root);
std::cout<<"AVA2 skill parity passed\n";
} catch(const std::exception& e) { fs::current_path(cwd);std::cerr<<e.what()<<'\n';return 1; }
}