function testme(actor, id, subId, param) -- SL:SendLuaNetMsg(1,{}) -- lg("testme", id, subId) id = tonumber(id) subId = tonumber(subId) end -- function TestClass() -- local subObject = MySubClass("Alice", 30) -- subObject:sayHello() -- subObject:sayAge() -- subObject.custom = "test" -- lg("修改名字", subObject.custom) -- end -- -- 创建 getter 函数 -- function Getter(fieldName) -- return function(self) -- return self[fieldName] -- end -- end -- -- 创建 setter 函数 -- function Setter(fieldName, validation) -- return function(self, value) -- if validation and not validation(value) then -- error(string.format("Invalid %s value", fieldName)) -- end -- self[fieldName] = value -- end -- end -- MyClass = class() -- function MyClass:ctor(name) -- self.name = name -- end -- function MyClass:sayHello() -- lg("Hello, " .. self.name) -- end -- local myObject = MyClass("World") -- myObject:sayHello() -- MySubClass = class(MyClass) -- function MySubClass:ctor(name, age) -- MyClass:ctor(name) -- 调用父类构造函数 -- self.age = age -- end -- function MySubClass:sayAge() -- lg("I am " .. self.age .. " years old.") -- end -- MySubClass.__getterse = { -- age = Getter("age"), -- name = Getter("name"), -- custom = Getter("custom"), -- } -- MySubClass.__setterse = { -- age = Setter("age", function(value) -- return type(value) == 'number' and value > 0 -- end), -- name = Setter("name"), -- custom = Setter("custom"), -- } function testspeed(actor) local attackSpeed = getattrinfo(actor, "attackSpeed") local attackSpeedBonus = getattrinfo(actor, "attackSpeedBonus") local AniSpeed = getattrinfo(actor, "AniSpeed") local atkSpeed = getattrinfo(actor, "atkSpeed") local AniSpeedBonus = getattrinfo(actor, "AniSpeedBonus") lg("attackSpeed:", attackSpeed) lg("attackSpeedBonus:", attackSpeedBonus) lg("AniSpeed:", AniSpeed) lg("atkSpeed:", atkSpeed) lg("AniSpeedBonus:", AniSpeedBonus) end function testopentime(actor) local crossOpenTime = getbaseinfo("crossopentime") local nowSec = getbaseinfo("nowsec") local severOpenDays = TimeUtil.diffDays(crossOpenTime / 1000, nowSec) + 1 toclient(actor, lg("本服:",getbaseinfo(actor, "serveropendays"))) toclient(actor, lg("跨服:",severOpenDays)) end function testflushtask(actor, taskTargetType, param) Wings.FlushWingsTask(actor, taskTargetType, param) end function ttt1(actor) local equipInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_EQUIPMENT_ATTR_DATA) or {} local info = {} for k, v in pairs(equipInfo) do local grails = v["grails"] if not table.isNullOrEmpty(grails) then local grailIds = {} for grailId, _ in pairs(grails) do table.insert(grailIds, grailId) info[k] = grailIds end end end toclient(actor, lg("大天使装备圣杯ids:", info)) end function ttt2(actor) local grailInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_GRAIL_ENTRY_INFO) local ids = {} for id, v in pairs(grailInfo) do table.insert(ids, id) end toclient(actor, lg("全部圣杯id:", ids)) end function ttt3(actor) AngelMajorGrail.loginDirtyDataClear(actor) end function look(actor) ttt1(actor) ttt2(actor) end function other(actor) end -- =============================打印调试======================================== local debug = require 'debug' local openlog = true function lg(...) if not openlog then return end local args = table.pack(...) local message = FormatArgs(args) local info = debug.getinfo(2, 'nSlu') local count = 0 while not info do if count > 10 then error("打印栈的深度过深") print("打印栈的深度过深") return end count = count + 1 info = debug.getinfo(2 + count, 'nSlu') end -- local begin = info.linedefined -- local over = info.lastlinedefined local currLine = info.currentline -- local name = info.name -- local short_src = info.short_src -- local result = short_src:match("[^\\]+%.lua$") local callerInfo = string.format(" ===> %s%d%s", -- result, -- name, -- begin, -- over, "★", currLine, "★") local msg = callerInfo .. " " .. message -- error(msg) print(msg) return msg end -- 格式化参数 function FormatArgs(args) local formattedMessage = "" for i = 1, args.n do if type(args[i]) == "table" then formattedMessage = formattedMessage .. TableToString(args[i]) .. " " elseif type(args[i]) == "userdata" then formattedMessage = formattedMessage .. UserDataToString(args[i]) .. " " else formattedMessage = formattedMessage .. tostring(args[i]) .. "(" .. GetLogTip(args[i]) .. ") " end end return formattedMessage end function UserDataToString(userdata) return userdata:toString() .. " (U)" end function TableToString(t, indent) indent = indent or 0 local str = "{\n" local isFirst = true if table.isArray(t) then -- 处理数组类型的表 for k, v in ipairs(t) do if isFirst then isFirst = false else str = str .. ",\n" end str = str .. string.rep(" ", indent + 1) .. k .. ": " if type(v) == "table" then str = str .. TableToString(v, indent + 1) elseif type(v) == "userdata" then str = str .. UserDataToString(v) else str = str .. tostring(v) .. "(" .. GetLogTip(v) .. ") " end end else -- 处理哈希表 for k, v in pairs(t) do if isFirst then isFirst = false else str = str .. ",\n" end str = str .. string.rep(" ", indent + 1) .. tostring(k) .. ": " if type(v) == "table" then str = str .. TableToString(v, indent + 1) elseif type(v) == "userdata" then str = str .. UserDataToString(v) else str = str .. tostring(v) .. "(" .. GetLogTip(v) .. ") " end end end str = str .. "\n" .. string.rep(" ", indent) .. "}" return str end function GetLogTip(v) if type(v) == "string" then if string.trim(v) == "" then return "空" end return "S" elseif type(v) == "boolean" then return "B" elseif type(v) == "number" then return "N" elseif type(v) == "nil" then return "×" end end local msgId = 112233 function toclient(actor, msg) if not openlog then return end msg = string.gsub(msg, "\n", "") sendluamsg(actor, msgId, "日志信息:" .. msg) end