Files
WoW-Hybrid-gateway/tests/native_weapon_skill_test.py
praxis 4200078dac
Launcher frontends / frontend (ubuntu-22.04) (push) Canceled after 0s
Launcher frontends / frontend (windows-2022) (push) Canceled after 0s
Restore equipped weapon statistics and barber window Escape handling to the published addon
2026-11-21 22:56:09 +02:00

166 lines
11 KiB
Python

"""Weapon-skill PvE baselines (Tortoise melee tables), original damage-tooltip posthook, secret-value boundaries."""
from pathlib import Path
import subprocess
ROOT=Path(__file__).resolve().parents[1]
lua=r'''
local hooks, lines = {}, {}
local secret = {}
function issecretvalue(value)return value==secret end
function CreateFrame()
local frame={}
function frame:RegisterEvent()end
function frame:UnregisterEvent()end
function frame:SetScript()end
return frame
end
function CharacterDamageFrame_OnEnter()end
local original=CharacterDamageFrame_OnEnter
function hooksecurefunc(name,fn)assert(not hooks[name]);hooks[name]=fn end
GameTooltip={AddLine=function(_,text)lines[#lines+1]={text}end,
AddDoubleLine=function(_,a,b)lines[#lines+1]={a,b}end,Show=function()end}
INVTYPE_WEAPONOFFHAND='Off Hand';INVTYPE_RANGED='Ranged';CR_HIT_MELEE=6;CR_HIT_RANGED=7
local level,class,form,dual,hit,crit=60,'WARRIOR',0,false,0,20
function UnitLevel()return level end
function UnitClass()return 'x',class end
function GetShapeshiftFormID()return form end
function IsDualWielding()return dual end
function GetCombatRatingBonus()return 0 end
function GetHitModifier()return hit end
local rangedHit=0
function GetRangedHitModifier()return rangedHit end
function GetCritChance()return crit end
function GetRangedCritChance()return 10 end
local items={[16]={2,7},[17]={2,15},[18]={2,2}} -- sword, dagger, bow
local durability,maximum=100,100
function GetInventoryItemID(_,slot)return items[slot] and slot or nil end
function GetInventoryItemDurability()return durability,maximum end
C_Item={GetItemInfoInstant=function(id)return id,nil,nil,nil,nil,items[id][1],items[id][2] end}
local ranks={[43]={rank=300,modifier=5,name='Swords'},[173]={rank=300,modifier=0,name='Daggers'},
[45]={rank=290,modifier=0,name='Bows'},[162]={rank=250,modifier=0,name='Unarmed'},[3014]={rank=1,modifier=0,name='Feral Combat'}}
C_SkillInfo={GetSkillLineInfoByID=function(id)return ranks[id] end}
local nativeUpdate=function()return 11 end
PAPERDOLL_STATINFO={NATIVE={updateFunc=nativeUpdate}}
PAPERDOLL_STATCATEGORIES={{unit="player",stats={{stat="NATIVE"}}}}
local nativeInfo,nativeCategories=PAPERDOLL_STATINFO,PAPERDOLL_STATCATEGORIES
dofile(arg[1]);local info=WoWHybridUI.weaponSkill
assert(info.installed and CharacterDamageFrame_OnEnter==original and hooks.CharacterDamageFrame_OnEnter)
local function close(a,b)assert(math.abs(a-b)<0.00001,tostring(a)..' vs '..tostring(b))end
-- 300 skill, level 60, same-level creature (defense 300).
local same=info.Comparison(60,300,60)
close(same.miss,5);close(same.dodge,5);close(same.parry,5);close(same.block,5)
close(same.glancing,10);close(same.glancingLow,91);close(same.glancingHigh,99);close(same.critChange,0)
assert(same.dualMiss==nil and same.hitKnown==false)
-- 300 skill against a level 63 boss (defense 315): the >10 gap rules apply.
local boss=info.Comparison(60,300,63,{dualWield=true})
close(boss.miss,8);close(boss.dualMiss,27);close(boss.dodge,6.5);close(boss.parry,14);close(boss.block,5)
close(boss.glancing,40);close(boss.glancingLow,55);close(boss.glancingHigh,75);close(boss.critChange,-3)
-- 305 skill: gap 10, linear rules; skill above level*5 keeps the glancing frequency.
local skilled=info.Comparison(60,305,63)
close(skilled.miss,6);close(skilled.dodge,6);close(skilled.parry,14);close(skilled.glancing,40)
close(skilled.glancingLow,80);close(skilled.glancingHigh,90);close(skilled.critChange,-3)
-- Hit bonus: first 1% ignored only when the gap exceeds 10.
close(info.Comparison(60,300,63,{hit=3}).miss,6);close(info.Comparison(60,305,63,{hit=3}).miss,3)
close(info.Comparison(60,300,60,{hit=9}).miss,0)
assert(info.Comparison(60,300,63,{hit=3}).hitKnown==true)
-- Skill above the enemy's defense raises crit by 0.04 per point.
close(info.Comparison(60,310,60).critChange,0.4)
-- Wand classes take the larger glancing penalty.
local caster=info.Comparison(60,300,63,{wandUser=true})
close(caster.glancingLow,1);close(caster.glancingHigh,45)
-- Ranged: miss and crit only. Low-level creature scaling. Miss cap.
local ranged=info.Comparison(60,290,63,{ranged=true,dualWield=true})
close(ranged.miss,10);assert(ranged.dodge==nil and ranged.glancing==nil and ranged.dualMiss==nil)
close(info.Comparison(5,25,5).miss,2.5);close(info.Comparison(5,25,5).dodge,2.5)
close(info.Comparison(60,1,63,{dualWield=true}).dualMiss,60)
assert(not info.Comparison(60,nil,63) and not info.Comparison(60,secret,63))
assert(not info.Comparison(60,0/0,63) and not info.Comparison(61,300,63) and not info.Comparison(60,-1,63))
-- Tooltip rows.
local function find(text,from)
for i=from or 1,#lines do if lines[i][1]==text then return lines[i][2] or true,i end end
end
local frame={unit='player'}
hooks.CharacterDamageFrame_OnEnter(frame)
assert(find('Same-level enemy (level 60)'))
local _,bossAt=find('Boss baseline (level 63)');assert(bossAt)
assert(find('Miss',bossAt)=='6.00%' and find('Enemy parry (from the front)',bossAt)=='14.00%')
assert(find('Glancing blow damage',bossAt)=='80% - 90%')
assert(find('Critical strike',bossAt)=='17.00% (-3.00%)')
assert(lines[#lines][1]:find('Swords skill 305',1,true) and lines[#lines][1]:find('Without hit bonuses',1,true))
-- Off hand uses its own skill; dual-wield splits the miss rows; hit bonus is named.
lines={};dual=true;hit=2;frame.tooltipLabel=INVTYPE_WEAPONOFFHAND;hooks.CharacterDamageFrame_OnEnter(frame)
_,bossAt=find('Boss baseline (level 63)')
assert(find('Miss (special attacks)',bossAt)=='7.00%' and find('Miss (dual-wield auto-attack)',bossAt)=='26.00%')
assert(lines[#lines][1]:find('Daggers skill 300',1,true) and lines[#lines][1]:find('+2.0% hit bonus',1,true))
-- Ranged rows only.
lines={};dual=false;hit=0;frame.tooltipLabel=INVTYPE_RANGED;hooks.CharacterDamageFrame_OnEnter(frame)
_,bossAt=find('Boss baseline (level 63)')
assert(find('Miss',bossAt)=='10.00%' and not find('Enemy dodge') and find('Critical strike',bossAt)=='5.00% (-5.00%)')
-- Broken or missing main hand falls back to Unarmed; missing off hand adds nothing.
lines={};frame.tooltipLabel=nil;durability=0;hooks.CharacterDamageFrame_OnEnter(frame)
assert(lines[#lines][1]:find('Unarmed skill 250',1,true))
lines={};durability=100;items[17]=nil;frame.tooltipLabel=INVTYPE_WEAPONOFFHAND;hooks.CharacterDamageFrame_OnEnter(frame);assert(#lines==0)
-- Feral forms use level * 5; other druid forms use the weapon.
lines={};frame.tooltipLabel=nil;class='DRUID';form=5;hooks.CharacterDamageFrame_OnEnter(frame)
assert(lines[#lines][1]:find('Feral Combat skill 300',1,true))
lines={};form=31;hooks.CharacterDamageFrame_OnEnter(frame);assert(lines[#lines][1]:find('Swords skill 305',1,true))
-- Pet frame, unknown skill line, secret values and unknown crit add nothing or degrade.
lines={};class='WARRIOR';frame.unit='pet';hooks.CharacterDamageFrame_OnEnter(frame);assert(#lines==0)
frame.unit='player';ranks[43]=nil;hooks.CharacterDamageFrame_OnEnter(frame);assert(#lines==0)
ranks[43]={rank=secret,modifier=0,name='Swords'};hooks.CharacterDamageFrame_OnEnter(frame);assert(#lines==0)
ranks[43]={rank=300,modifier=0,name='Swords'};crit=secret;hooks.CharacterDamageFrame_OnEnter(frame)
assert(find('Critical strike change')=='+0.00%' and not find('Critical strike'))
dofile(arg[1]);assert(WoWHybridUI.weaponSkill==info and CharacterDamageFrame_OnEnter==original)
-- The addon-owned Octo panel reads these rows after native OnShow. It may not
-- insert callbacks into Camelot's protected PaperDoll stat traversal.
local newRows=info.GetStandaloneRows()
assert(#newRows==13 and info.GetStandaloneRows()==newRows)
local shown={}
for _,row in ipairs(newRows) do shown[row.key]=row end
local function read(key)
local row=shown[key]
assert(row,key)
return row.read()
end
local function eq(key,want)local actual=read(key);assert(actual==want,key..": "..tostring(actual).." vs "..tostring(want))end
C_Item.GetItemNameByID=function(id)return ({[16]="Training Sword",[17]="Dagger",[18]="Shortbow"})[id]end
items[17]={2,15};ranks[43]={rank=300,modifier=5,name="Swords"};crit=20
eq("HYBRID_MAINHAND","Training Sword");eq("HYBRID_OFFHAND","Dagger");eq("HYBRID_RANGEDWEAPON","Shortbow")
-- A full item name must fit next to the label in the narrow stat pane. The
-- unshortened name stays available through the original stat tooltip.
local fullName="Champion's Ceremonial Greatsword of the Falcon"
C_Item.GetItemNameByID=function(id)if id==16 then return fullName end return "Dagger" end
local narrow={Show=function()end,GetWidth=function()return 150 end,
Label={GetStringWidth=function()return 60 end},
Value={SetText=function(self,text)self.text=text end,
GetStringWidth=function(self)return #self.text*6 end}}
local shownName=info.FitWeaponName(narrow,fullName)
assert(shownName~=fullName and narrow.Value:GetStringWidth()<=63)
C_Item.GetItemNameByID=function(id)return ({[16]="Training Sword",[17]="Dagger",[18]="Shortbow"})[id]end
eq("HYBRID_MAINHAND_SKILL","Swords 305");eq("HYBRID_OFFHAND_SKILL","Daggers 300");eq("HYBRID_RANGEDWEAPON_SKILL","Bows 290")
eq("HYBRID_MELEECRIT","20.00%");eq("HYBRID_RANGEDCRIT","10.00%")
hit=0;eq("HYBRID_MELEEHIT","95.50% base")
rangedHit=3;eq("HYBRID_RANGEDHIT","97.00% est.")
dual=true;hit=2;eq("HYBRID_MELEEHIT","78.50% est.");eq("HYBRID_OFFHANDHIT","78.00% est.")
local _,detail=read("HYBRID_MELEEHIT");assert(detail:find("Special attacks pass the miss roll 97.50%",1,true) and detail:find("+2.00%",1,true))
-- A restricted or missing ranged read cannot silently reuse the melee hit/crit.
rangedHit=secret;eq("HYBRID_RANGEDHIT","94.00% base")
GetRangedCritChance=nil;eq("HYBRID_RANGEDCRIT",nil);eq("HYBRID_MELEECRIT","20.00%")
GatewaySourceWeaponDamageData={primary={[16]={delayMS=2500},[18]={delayMS=2000}}}
function UnitAttackSpeed()return 2 end
function UnitRangedDamage()return 2.5 end
function GetMeleeHaste()return 0 end
function GetRangedHaste()return 11,9 end
eq("HYBRID_MELEEHASTE","25.00%");eq("HYBRID_RANGEDHASTE","-20.00%")
UnitRangedDamage=function()return 2 end;eq("HYBRID_RANGEDHASTE","0.00%")
GatewaySourceWeaponDamageData=nil;eq("HYBRID_MELEEHASTE",nil);eq("HYBRID_RANGEDHASTE","20.00%")
GetRangedHaste=function()return 15,secret end;eq("HYBRID_RANGEDHASTE",nil)
items[17]={4,6};eq("HYBRID_OFFHAND",nil);eq("HYBRID_OFFHAND_SKILL",nil);eq("HYBRID_OFFHANDHIT",nil)
items[18]=nil;eq("HYBRID_RANGEDWEAPON",nil);eq("HYBRID_RANGEDHIT",nil);eq("HYBRID_RANGEDHASTE",nil)
ranks[43].modifier=secret;eq("HYBRID_MAINHAND_SKILL",nil);eq("HYBRID_MELEEHIT",nil)
assert(PAPERDOLL_STATINFO==nativeInfo and PAPERDOLL_STATCATEGORIES==nativeCategories)
assert(nativeInfo.NATIVE.updateFunc==nativeUpdate and #nativeCategories==1 and #nativeCategories[1].stats==1)
'''
subprocess.run(['lua','-',str(ROOT/'client_addons/WoWHybridUI/NativeWeaponSkill.lua')],input=lua.encode(),check=True)
print('Weapon-skill same-level/boss miss, dodge, parry, block, glancing and crit baselines, slot/form skill selection, missing/secret values and original callback ownership PASS.')
print('Addon-owned weapon rows, fitted names, distinct melee/ranged hit and crit, and attack-speed-derived haste PASS.')