以上代码看起来密密麻麻的,但实际上稍微有点悟性的同学都能一眼看出,这个函数其实就是获取hp命令输出的人物各种状态,然后回调 f 这个函数,如果有的话。也就是说,你在机器的任意一个地方,如果调用了 Me.check_state() 的话,那么得到了人物的各种状态。 这个函数其实没什么要说明的,无法就是一行行获取信息罢了。
再来看一段代码:
Me.heal = function(f)
if Me.pmp < 95 then
Execute("yun inspire")
wait.regexp ("^[> ]*(你现在精神饱满,有什么好激励的?|.*缓缓睁开双目,精光四射,神清意爽。)$")
end
if Me.php < 90 then
repeat
Execute("halt;yun heal")
local l, w = wait.regexp("^[> ]*你现在气血充盈,不需要疗伤。$", 1)
until l
end
if Me.mp < Me.maxmp - 1000 then Execute("yun regenerate") end
if Me.hp < Me.maxhp - 1000 then Execute("yun recover") end
if Me.mana < Me.maxmana - 1000 then Execute("yun refresh") end
if f then f() end
end
Me.eat = function(feat, buy)
if feat or Me.food < Me.maxfood then
Execute("eat gan liang")
Me.noFood = mywait({"你身上没有.*?这样东西.*"}, {"你摸出一块干粮啃了几口。", "你已经吃太饱了,再也塞不下任何东西了。"}, {"没有"})
end
if feat or Me.water < Me.maxwater then
Execute("drink shui dai")
Me.noWater = mywait({"你身上没有.*?这样东西.*"}, {"你拿起牛皮水袋咕噜噜地喝了几口清水。", "你已经喝太多了,再也灌不下一滴水了。"}, {"没有"})
end
if Me.noFood or Me.noWater then
if buy then
Execute("r gc;n;n;e")
if Me.noFood then Me.buy("20 gan liang", "xiao er") end
if Me.noWater then Me.buy("shui dai", "xiao er") end
Execute("w;s;s")
wait.time(0.5)
end
end
end
Me.buy = function(b, s)
Execute("give " .. b .. " to " .. s)
if mywait({"你身上没有.+?这样东西。", "你没有那么多的.+?。"}, {"你拿出.*给.*。"}, {"没有"}, {"你拿出"}) then
myrepeat("buy " .. b .. " from " .. s, {".+?不耐烦道:“没看见我这儿正忙着么?”"}, {"你从.+?那里买下了.+?。"}, {"不耐烦道:“没看见我这儿正忙着么?”"}, {"买下了"}, 1)
end
end