-- Experiment (Config.EnableStatFieldProbe): can every attribute of a summoned unit be set? On the first -- blue/red unit summoned after the mod loads, each of character_stats.allFields is written to a test value, -- held for one support tick, read back (field and native getter) and restored, a chunk of fields at a time. -- A current value whose maximum is too low for its test value gets the maximum raised for the test; those -- go last, so a raised maximum never overlaps that maximum's own test. One log line per field, a summary, -- then the whole set compared with its state before the probe (side effects), restoring what moved. local Attributes=require('character_stats') local Probe={} local BOUND={Health='Health_Max',Shachi='Shachi_Max',Shield='Shield_Max',UltimateCharge='UltimateCharge_Max', UltimateChargeCount='UltimateChargeCount_Max',SpiritShadow='SpiritShadow_Max',Awakening='Awakening_Max'} function Probe.new(options) local adapter=options.adapter or Attributes.new() local fields=options.fields or Attributes.allFields local log=options.log or function()end local perTick=options.perTick or 16 local bound={};for current,max in pairs(BOUND)do bound[current]=max end for _,field in ipairs(fields)do if field:match('_Accumulation$') then bound[field]='Infliction_Max' end end local chunks={} local function chunked(list) for i=1,#list,perTick do local chunk={};for j=i,math.min(i+perTick-1,#list)do chunk[#chunk+1]=list[j] end chunks[#chunks+1]=chunk end end local free,tail={},{} for _,field in ipairs(fields)do if bound[field] then tail[#tail+1]=field else free[#free+1]=field end end chunked(free);chunked(tail) local self={state='idle',counts={},restoreFailed=0} local close=Attributes.close local function fmt(v)return type(v)=='number' and string.format('%.6g',v) or tostring(v) end local function testValue(field,current) if bound[field] then return current>0 and current*0.5 or 1 end return current~=0 and current*1.5 or 1 end local function stop(state,why) self.state=state log('[StatProbe] '..(state=='aborted' and '中止:' or '')..why) end function self:start(actor,unitPath) if self.state~='idle' then return false end self.actor,self.unit,self.state,self.chunk,self.step=actor,unitPath,'snapshot',0,'write' log('[StatProbe] 开始:'..#fields..' 项属性逐项写入测试值、隔一拍读回再恢复;每拍 '..perTick..' 项 unit='..tostring(unitPath)) return true end local function snapshot() local result,missing={},{} for _,field in ipairs(fields)do local entry=adapter:read(self.actor,field) if entry then result[field]=entry else missing[#missing+1]=field end end return result,missing end local function write() local pending,raised={},{} for _,field in ipairs(chunks[self.chunk])do local before,why=adapter:read(self.actor,field) if not before then if not adapter:read(self.actor,'Health_Max') then return stop('aborted','单位已失效或属性集不可读:'..tostring(why)) end self.counts.unreadable=(self.counts.unreadable or 0)+1 log('[StatProbe] '..field..' 不可读:'..tostring(why)) else local want=testValue(field,before.current) local max=bound[field] if max and not raised[max] then local limit=adapter:read(self.actor,max) if limit and limit.current0 and (',不可读:'..table.concat(missing,',')) or '')) return end if self.step=='check' then return check() end self.chunk=self.chunk+1 if self.chunk>#chunks then return finish() end write() end function self:status()return {state=self.state,counts=self.counts,restore_failed=self.restoreFailed}end return self end return Probe