1.0.2
This commit is contained in:
parent
c87e632d59
commit
f2cb2e3787
|
@ -0,0 +1,253 @@
|
||||||
|
-- 猫猫虫的 LuaEngine 插件管理框架
|
||||||
|
-- @version: 1.0.2
|
||||||
|
--
|
||||||
|
-- 自动加载以下目录的lua模块:
|
||||||
|
-- ./eigeen_modules
|
||||||
|
--
|
||||||
|
-- 模块编写:
|
||||||
|
-- 样例:
|
||||||
|
-- return {
|
||||||
|
-- version = 1,
|
||||||
|
-- name = "chong_qiang",
|
||||||
|
-- onTime = onTime,
|
||||||
|
-- conditions = {{
|
||||||
|
-- type = "weapon",
|
||||||
|
-- value = {
|
||||||
|
-- eq = 7
|
||||||
|
-- }
|
||||||
|
-- }},
|
||||||
|
-- priority = 0,
|
||||||
|
-- }
|
||||||
|
--
|
||||||
|
-- 具体用法请参考具体插件示例
|
||||||
|
--
|
||||||
|
local Speed = require("utils/Speed")
|
||||||
|
local Keypad = require("utils/Keypad")
|
||||||
|
|
||||||
|
-- consts
|
||||||
|
local MODULE_ROOT = "./Lua/eigeen_modules"
|
||||||
|
-- local NON_ACTIVE_MAPS = {301, 302, 303, 305, 306}
|
||||||
|
|
||||||
|
-- globals
|
||||||
|
-- 所有模块列表,仅在初始化时加载。后续处理都基于此列表,因此增删改mod需要重载此框架。
|
||||||
|
local Modules = {}
|
||||||
|
|
||||||
|
-- 需要执行的模块函数,每次执行前进行处理。
|
||||||
|
local ExecuteModules = {}
|
||||||
|
|
||||||
|
-- 上一次使用的武器ID,用于判断武器是否变更。
|
||||||
|
local LastWeaponType = 0
|
||||||
|
-- 上一次的地图ID
|
||||||
|
local LastMapID = 0
|
||||||
|
|
||||||
|
local function isIn(tbl, target)
|
||||||
|
for key, value in pairs(tbl) do
|
||||||
|
if target == value then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function loadAllModules()
|
||||||
|
local modules = {}
|
||||||
|
-- 自动导入
|
||||||
|
local moduleFiles = engine.GetAllFiles(MODULE_ROOT)
|
||||||
|
for _, mFile in pairs(moduleFiles) do
|
||||||
|
-- 模块合法性判断
|
||||||
|
if mFile.file:sub(-4) ~= ".lua" then
|
||||||
|
goto continueIterModules
|
||||||
|
end
|
||||||
|
|
||||||
|
local eModule = dofile(MODULE_ROOT .. "/" .. mFile.file)
|
||||||
|
if eModule == nil or eModule.version ~= 1 then
|
||||||
|
goto continueIterModules
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(modules, eModule)
|
||||||
|
|
||||||
|
::continueIterModules::
|
||||||
|
end
|
||||||
|
|
||||||
|
return modules
|
||||||
|
end
|
||||||
|
|
||||||
|
local function _checkCondition(value, condValue)
|
||||||
|
local result = true
|
||||||
|
local function setCondResult(_res)
|
||||||
|
if result == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if result == true and _res == false then
|
||||||
|
result = false
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for key, condVal in pairs(condValue) do
|
||||||
|
if key == "eq" then
|
||||||
|
setCondResult(value == condVal)
|
||||||
|
elseif key == "gt" then
|
||||||
|
setCondResult(value > condVal)
|
||||||
|
elseif key == "lt" then
|
||||||
|
setCondResult(value < condVal)
|
||||||
|
elseif key == "ne" then
|
||||||
|
setCondResult(value ~= condVal)
|
||||||
|
elseif key == "ge" then
|
||||||
|
setCondResult(value >= condVal)
|
||||||
|
elseif key == "le" then
|
||||||
|
setCondResult(value <= condVal)
|
||||||
|
elseif key == "in" then
|
||||||
|
setCondResult(isIn(condVal, value))
|
||||||
|
elseif key == "nin" then
|
||||||
|
setCondResult(not isIn(condVal, value))
|
||||||
|
else
|
||||||
|
setCondResult(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local function checkCondition(ctx, module)
|
||||||
|
local conds = module.conditions
|
||||||
|
if conds == nil or #conds == 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = true
|
||||||
|
local function setCondResult(_res)
|
||||||
|
if result == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if result == true and _res == false then
|
||||||
|
result = false
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, cond in ipairs(conds) do
|
||||||
|
if type(cond) == "function" then
|
||||||
|
setCondResult(cond(ctx))
|
||||||
|
elseif cond.type == "weapon" then
|
||||||
|
setCondResult(_checkCondition(ctx.playerData.Weapon.type, cond.value))
|
||||||
|
elseif cond.type == "map" then
|
||||||
|
setCondResult(_checkCondition(ctx.worldData.MapId, cond.value))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local function executeOnInit(modules)
|
||||||
|
for _, module in ipairs(modules) do
|
||||||
|
if module.onInit ~= nil then
|
||||||
|
module.onInit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function executeOnSwitchScenes(ctx, modules)
|
||||||
|
for _, module in ipairs(modules) do
|
||||||
|
if module.onSwitchScenes ~= nil then
|
||||||
|
module.onSwitchScenes(ctx)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function executeOnImgui(ctx, modules)
|
||||||
|
for _, module in ipairs(modules) do
|
||||||
|
if module.onImgui ~= nil then
|
||||||
|
module.onImgui(ctx)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function executeOnTime(ctx, modules)
|
||||||
|
for _, module in ipairs(modules) do
|
||||||
|
if module.onTime ~= nil then
|
||||||
|
module.onTime(ctx)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function buildExecuteModules(ctx)
|
||||||
|
local exeModules = {}
|
||||||
|
-- 条件检查
|
||||||
|
for _, module in ipairs(Modules) do
|
||||||
|
if checkCondition(ctx, module) then
|
||||||
|
table.insert(exeModules, module)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- 优先级调整
|
||||||
|
for i = 1, #exeModules do
|
||||||
|
if exeModules[i].priority == nil or exeModules[i].priority < 0 then
|
||||||
|
exeModules[i].priority = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.sort(exeModules, function(m1, m2)
|
||||||
|
return m1.priority > m2.priority
|
||||||
|
end)
|
||||||
|
|
||||||
|
return exeModules
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Hooks
|
||||||
|
|
||||||
|
function on_time()
|
||||||
|
local playerData = engine.Player:new()
|
||||||
|
local ctx = {
|
||||||
|
playerData = playerData,
|
||||||
|
worldData = engine.World:new(),
|
||||||
|
questData = engine.Quest:new(),
|
||||||
|
Speed = Speed:new(playerData),
|
||||||
|
Keypad = Keypad
|
||||||
|
}
|
||||||
|
-- local MetaCtx = {
|
||||||
|
-- Speed = Speed:new(ctx.playerData),
|
||||||
|
-- Keypad = Keypad
|
||||||
|
-- }
|
||||||
|
-- MetaCtx.__index = MetaCtx
|
||||||
|
-- setmetatable(ctx, MetaCtx)
|
||||||
|
-- 建立遍历专用表,而不是遍历modules主表。条件判断操作更改后刷新遍历专用表。
|
||||||
|
local wpType = ctx.playerData.Weapon.type
|
||||||
|
if ctx.playerData.Weapon.type ~= LastWeaponType then
|
||||||
|
ExecuteModules = buildExecuteModules(ctx)
|
||||||
|
LastWeaponType = ctx.playerData.Weapon.type
|
||||||
|
end
|
||||||
|
if ctx.worldData.MapId ~= LastMapID then
|
||||||
|
ExecuteModules = buildExecuteModules(ctx)
|
||||||
|
LastMapID = ctx.worldData.MapId
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 执行onTime方法
|
||||||
|
executeOnTime(ctx, ExecuteModules)
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_imgui()
|
||||||
|
local ctx = {
|
||||||
|
playerData = engine.Player:new(),
|
||||||
|
worldData = engine.World:new(),
|
||||||
|
questData = engine.Quest:new()
|
||||||
|
}
|
||||||
|
executeOnImgui(ctx, ExecuteModules)
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_init()
|
||||||
|
Modules = loadAllModules()
|
||||||
|
executeOnInit(Modules)
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_switch_scenes()
|
||||||
|
local ctx = {
|
||||||
|
playerData = engine.Player:new(),
|
||||||
|
worldData = engine.World:new(),
|
||||||
|
questData = engine.Quest:new()
|
||||||
|
}
|
||||||
|
executeOnSwitchScenes(ctx, ExecuteModules)
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_monster_create()
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_monster_destroy()
|
||||||
|
end
|
|
@ -0,0 +1,44 @@
|
||||||
|
local ToWayPosition = false
|
||||||
|
local Camera = false
|
||||||
|
local function setMotionState(stateFlag) -- 人物状态
|
||||||
|
local stateAddress = GetAddress(0x145011760,{0x50,0xE470}) + 0x0B
|
||||||
|
if stateAddress then
|
||||||
|
local stateData = SetAddressData(stateAddress,'byte',stateFlag)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onTime(ctx)
|
||||||
|
local Data_Player = ctx.playerData
|
||||||
|
local Data_World = ctx.worldData
|
||||||
|
if Data_Player.Action.fsm.fsmID == 639 or Data_Player.Action.fsm.fsmID == 640 then
|
||||||
|
setMotionState(0x8A)
|
||||||
|
end
|
||||||
|
if Data_Player.Action.lmtID == 12707 or Data_Player.Action.lmtID == 12708 then
|
||||||
|
SetCameraData(true, Data_Player.Position.cntrposition.x, Data_Player.Position.cntrposition.y, Data_Player.Position.cntrposition.z)
|
||||||
|
Camera = true
|
||||||
|
elseif Camera then
|
||||||
|
Camera = false
|
||||||
|
SetCameraData(false,0,0,0)
|
||||||
|
end
|
||||||
|
|
||||||
|
if Data_Player.Action.lmtID == 12708 then
|
||||||
|
if not ToWayPosition then
|
||||||
|
ToWayPosition = true
|
||||||
|
if not (Data_World.Position.wayPosition.x == 0 and Data_World.Position.wayPosition.y == 0 and Data_World.Position.wayPosition.z == 0) then
|
||||||
|
Data_Player.Position.position = Data_World.Position.wayPosition
|
||||||
|
Data_Player.Position.reposition = Data_World.Position.wayPosition
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif ToWayPosition then
|
||||||
|
ToWayPosition = false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
version = 1,
|
||||||
|
name = "dragon_riding_jump",
|
||||||
|
onTime = onTime,
|
||||||
|
conditions = nil,
|
||||||
|
priority = 0,
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
-- 加速挖素材 8273 8274
|
||||||
|
-- 挖矿 8377-8379
|
||||||
|
-- 采集 8276-8278,8281
|
||||||
|
local GATHERING_LMT_ID = {8273, 8274, 8377, 8378, 8379, 8276, 8277, 8278, 8281}
|
||||||
|
|
||||||
|
local function isIn(tbl, target)
|
||||||
|
for key, value in pairs(tbl) do
|
||||||
|
if target == value then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function isGatheringLmtID(lmtID)
|
||||||
|
return isIn(GATHERING_LMT_ID, lmtID)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onTime(ctx)
|
||||||
|
local playerData = ctx.playerData
|
||||||
|
|
||||||
|
if isGatheringLmtID(playerData.Action.lmtID) then
|
||||||
|
ctx.Speed:setSpeedMutex(5, "加速挖素材")
|
||||||
|
else
|
||||||
|
ctx.Speed:resetSpeedMutex("加速挖素材")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
version = 1,
|
||||||
|
name = "fast_gathering",
|
||||||
|
onTime = onTime,
|
||||||
|
conditions = nil,
|
||||||
|
priority = 10
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
-- 猫猫虫的 LuaEngine 工具模块:Keypad
|
||||||
|
-- @version: 1.0.0
|
||||||
|
|
||||||
|
local Keypad = {}
|
||||||
|
|
||||||
|
--- 带计时器的按键触发操作(注:暂不支持组合键)
|
||||||
|
---@param keypadID number|string
|
||||||
|
---@param chrono number
|
||||||
|
---@param func fun()
|
||||||
|
---@param xbox boolean|nil
|
||||||
|
function Keypad.UseChronoscope(keypadID, chrono, func, xbox)
|
||||||
|
if keypadID == nil or chrono == nil or func == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if chrono < 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if xbox ~= true and xbox ~= false then
|
||||||
|
xbox = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: 暂不支持组合键
|
||||||
|
if type(keypadID) == "table" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local keypadIDStr = keypadID
|
||||||
|
if type(keypadID) == "number" then
|
||||||
|
keypadIDStr = tostring(keypadID)
|
||||||
|
end
|
||||||
|
local keypadShortcut = "keypad_keyCD_"..keypadIDStr
|
||||||
|
|
||||||
|
if engine.keypad(keypadID, xbox) and (CheckChronoscope(keypadShortcut) or
|
||||||
|
not CheckPresenceChronoscope(keypadShortcut)) then
|
||||||
|
|
||||||
|
AddChronoscope(chrono, keypadShortcut)
|
||||||
|
func()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Keypad
|
|
@ -0,0 +1,79 @@
|
||||||
|
-- 猫猫虫的 LuaEngine 工具模块:Speed
|
||||||
|
-- @version: 1.0.0
|
||||||
|
|
||||||
|
local Speed = {
|
||||||
|
lock = nil,
|
||||||
|
instance = nil
|
||||||
|
}
|
||||||
|
Speed.__index = Speed
|
||||||
|
|
||||||
|
function Speed:new(playerData)
|
||||||
|
if self.instance ~= nil then
|
||||||
|
self.instance.playerData = playerData
|
||||||
|
return self.instance
|
||||||
|
end
|
||||||
|
|
||||||
|
local instance = setmetatable({
|
||||||
|
playerData = playerData
|
||||||
|
}, Speed)
|
||||||
|
self.instance = instance
|
||||||
|
return self.instance
|
||||||
|
end
|
||||||
|
|
||||||
|
function Speed:setSpeed(speed)
|
||||||
|
self.playerData.Frame.frameSpeedMultiplies = speed
|
||||||
|
end
|
||||||
|
|
||||||
|
function Speed:resetSpeed()
|
||||||
|
self.playerData.Frame.frameSpeedMultiplies = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function Speed:withSpeed(speed, func)
|
||||||
|
if speed == nil or func == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
self:setSpeed(speed)
|
||||||
|
func()
|
||||||
|
self:resetSpeed()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Speed:checkAndReleaseLock(lockID)
|
||||||
|
if self.lock == nil then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if self.lock == lockID then
|
||||||
|
self.lock = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Speed:checkAndSetupLock(lockID)
|
||||||
|
if self.lock == nil then
|
||||||
|
self.lock = lockID
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if self.lock == lockID then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Speed:setSpeedMutex(speed, lockID)
|
||||||
|
if self:checkAndSetupLock(lockID) then
|
||||||
|
self:setSpeed(speed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Speed:resetSpeedMutex(lockID)
|
||||||
|
if self:checkAndReleaseLock(lockID) then
|
||||||
|
self:resetSpeed()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Speed:forceReleaseLock()
|
||||||
|
self.lock = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return Speed
|
Loading…
Reference in New Issue