// 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 #include #include #include #include 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<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<<'['<