传奇复古三职业自动化脚本装备修理与物品回收模块代码实现

来源: 作者: 点击:
在长时间挂机环境中,装备耐久度的损耗与背包空间的占用是制约角色持续作战能力的核心瓶颈。自动修理与回收模块通过实时监控装备状态与背包容量,实现无人值守下的物资循环,确保角色始终处于最佳战斗状态。

一、 自动修理模块

该模块通过检测装备栏中各部位物品的耐久度,在耐久低于设定阈值时自动寻路至武器店或修理NPC进行修复。

-- 自动修理配置
local REPAIR_CONFIG = {
threshold = 5, -- 耐久度低于5点触发修理
repair_all = false, -- 是否修理全身装备
npcs = { -- 各主城修理NPC坐标
{map = "比奇省", x = 330, y = 330},
{map = "盟重省", x = 330, y = 330}
}
}

-- 装备部位枚举
local EQUIP_SLOTS = {
"武器", "项链", "头盔", "项链", "手镯左", "手镯右",
"戒指左", "戒指右", "衣服", "腰带", "靴子", "勋章"
}

function AutoRepairEquipment()
-- 1. 检测是否需要修理
local need_repair = false
for _, slot in ipairs(EQUIP_SLOTS) do
local durability = GetEquipDurability(slot)
if durability ~= -1 and durability < REPAIR_CONFIG.threshold then
need_repair = true
PrintLog("检测到 " .. slot .. " 耐久度不足: " .. durability)
break
end
end

if not need_repair then return end

PrintLog("开始自动修理装备...")

-- 2. 回城并寻路至修理NPC
UseReturnScroll()
Delay(3000)

local current_map = GetCurrentMap()
local target_npc = nil
for _, npc in ipairs(REPAIR_CONFIG.npcs) do
if npc.map == current_map then
target_npc = npc
break
end
end

if not target_npc then
PrintLog("当前地图无修理NPC,前往盟重省")
MoveToMap("盟重省", 330, 330)
Delay(3000)
target_npc = REPAIR_CONFIG.npcs[2]
end

MoveToNPC(target_npc.x, target_npc.y)
Delay(1000)

-- 3. 执行修理操作
ClickNPCOption("修理装备")
Delay(500)

if REPAIR_CONFIG.repair_all then
-- 一键修理全身
ClickButton("修理全身")
Delay(1000)
else
-- 逐件修理低耐久装备
for _, slot in ipairs(EQUIP_SLOTS) do
local durability = GetEquipDurability(slot)
if durability ~= -1 and durability < REPAIR_CONFIG.threshold then
SelectEquipSlot(slot)
ClickButton("修理")
Delay(300)
end
end
end

-- 4. 关闭NPC窗口
CloseNPCWindow()
PrintLog("装备修理完成")

-- 5. 重新进图
ReEnterMap()
end


二、 自动回收模块

回收模块采用白名单过滤机制,仅保留指定高价值物品,其余垃圾装备自动出售或存入仓库,防止背包溢出导致打宝中断。

-- 自动回收配置
local RECYCLE_CONFIG = {
-- 保留物品白名单(不回收)
keep_list = {
"裁决之杖", "龙纹剑", "骨玉权杖", "开天", "镇天", "玄天",
"沃玛号角", "祖玛头像", "猪洞卷轴", "祝福油", "强效太阳水"
},
-- 回收价格阈值(低于此价格的物品自动出售)
min_price = 1000,
-- 背包空位阈值(低于此值触发回收)
bag_space_threshold = 10
}

function AutoRecycleItems()
-- 1. 检测背包空位
local empty_slots = GetBagEmptySlots()
if empty_slots > RECYCLE_CONFIG.bag_space_threshold then
return
end

PrintLog("背包空间不足,开始自动回收...")

-- 2. 回城并寻路至回收NPC
UseReturnScroll()
Delay(3000)
MoveToNPC(330, 450) -- 假设回收NPC坐标
Delay(1000)

-- 3. 打开回收界面
ClickNPCOption("装备回收")
Delay(800)

-- 4. 遍历背包执行回收
local recycled_count = 0
local total_gold = 0

for slot = 1, 46 do -- 假设背包46格
local item_info = GetItemInSlot(slot)
if item_info then
local should_keep = false

-- 检查是否在保留白名单
for _, keep_item in ipairs(RECYCLE_CONFIG.keep_list) do
if item_info.name == keep_item then
should_keep = true
break
end
end

-- 检查价格阈值
if not should_keep and item_info.price < RECYCLE_CONFIG.min_price then
should_keep = false
end

if not should_keep then
-- 执行回收
SelectBagSlot(slot)
ClickButton("回收")
Delay(200)
recycled_count = recycled_count + 1
total_gold = total_gold + item_info.price
end
end
end

-- 5. 关闭回收界面
ClickButton("关闭回收")
Delay(500)
CloseNPCWindow()

PrintLog("回收完成,共回收 " .. recycled_count .. " 件物品,获得金币: " .. total_gold)

-- 6. 自动买药并重新进图
AutoBuyPotions()
ReEnterMap()
end


三、 模块集成与主循环更新

将修理与回收模块嵌入主循环,确保在战斗间隙或回城时自动触发。

-- 更新后的主循环片段
function MainLoop()
while IS_RUNNING do
-- ... (前置断网检测与状态监控)

-- 1. 日常任务处理
if not IsInCombat() then
HandleDailyTasks()
end

-- 2. 战斗逻辑
local target = FindTarget()
if target then
-- 职业分发战斗
if CURRENT_JOB == 1 then WarriorCombat(target)
elseif CURRENT_JOB == 2 then MageCombat(target)
elseif CURRENT_JOB == 3 then TaoistCombat(target)
end
else
RandomWalk()
end

-- 3. 装备修理检测(每5分钟检测一次)
if GetTickCount() - last_repair_check > 300000 then
AutoRepairEquipment()
last_repair_check = GetTickCount()
end

-- 4. 背包满或药品不足时触发回收与补给
if CheckBagFull() or CheckPotionLow() then
AutoRecycleItems()
end

Delay(100)
end
end


四、 运行注意事项

耐久度检测兼容性:不同引擎获取装备耐久度的方式可能不同,若GetEquipDurability函数无法正常工作,可改用图像识别方式检测装备图标上的耐久度数字。
回收NPC交互:部分版本的回收功能集成在武器店NPC的二级菜单中,需根据实际情况调整ClickNPCOption的参数。
白名单维护:随着游戏版本更新,高价值物品可能发生变化,需定期更新keep_list数组,避免误回收稀有装备。
金币管理:自动回收会消耗大量金币进行修理,建议在回收模块中加入金币余额检测,当金币低于一定数额时停止自动修理,改为手动处理。

至此,完整的自动化脚本已涵盖战斗、补给、任务、修理与回收五大核心模块。需要我为你整理一份脚本部署与参数配置的完整说明文档吗?