jirenyang.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. function testme(actor, id, subId, param)
  2. -- SL:SendLuaNetMsg(1,{})
  3. -- lg("testme", id, subId)
  4. id = tonumber(id)
  5. subId = tonumber(subId)
  6. end
  7. -- function TestClass()
  8. -- local subObject = MySubClass("Alice", 30)
  9. -- subObject:sayHello()
  10. -- subObject:sayAge()
  11. -- subObject.custom = "test"
  12. -- lg("修改名字", subObject.custom)
  13. -- end
  14. -- -- 创建 getter 函数
  15. -- function Getter(fieldName)
  16. -- return function(self)
  17. -- return self[fieldName]
  18. -- end
  19. -- end
  20. -- -- 创建 setter 函数
  21. -- function Setter(fieldName, validation)
  22. -- return function(self, value)
  23. -- if validation and not validation(value) then
  24. -- error(string.format("Invalid %s value", fieldName))
  25. -- end
  26. -- self[fieldName] = value
  27. -- end
  28. -- end
  29. -- MyClass = class()
  30. -- function MyClass:ctor(name)
  31. -- self.name = name
  32. -- end
  33. -- function MyClass:sayHello()
  34. -- lg("Hello, " .. self.name)
  35. -- end
  36. -- local myObject = MyClass("World")
  37. -- myObject:sayHello()
  38. -- MySubClass = class(MyClass)
  39. -- function MySubClass:ctor(name, age)
  40. -- MyClass:ctor(name) -- 调用父类构造函数
  41. -- self.age = age
  42. -- end
  43. -- function MySubClass:sayAge()
  44. -- lg("I am " .. self.age .. " years old.")
  45. -- end
  46. -- MySubClass.__getterse = {
  47. -- age = Getter("age"),
  48. -- name = Getter("name"),
  49. -- custom = Getter("custom"),
  50. -- }
  51. -- MySubClass.__setterse = {
  52. -- age = Setter("age", function(value)
  53. -- return type(value) == 'number' and value > 0
  54. -- end),
  55. -- name = Setter("name"),
  56. -- custom = Setter("custom"),
  57. -- }
  58. function testspeed(actor)
  59. local attackSpeed = getattrinfo(actor, "attackSpeed")
  60. local attackSpeedBonus = getattrinfo(actor, "attackSpeedBonus")
  61. local AniSpeed = getattrinfo(actor, "AniSpeed")
  62. local atkSpeed = getattrinfo(actor, "atkSpeed")
  63. local AniSpeedBonus = getattrinfo(actor, "AniSpeedBonus")
  64. lg("attackSpeed:", attackSpeed)
  65. lg("attackSpeedBonus:", attackSpeedBonus)
  66. lg("AniSpeed:", AniSpeed)
  67. lg("atkSpeed:", atkSpeed)
  68. lg("AniSpeedBonus:", AniSpeedBonus)
  69. end
  70. function testopentime(actor)
  71. local crossOpenTime = getbaseinfo("crossopentime")
  72. local nowSec = getbaseinfo("nowsec")
  73. local severOpenDays = TimeUtil.diffDays(crossOpenTime / 1000, nowSec) + 1
  74. toclient(actor, lg("本服:",getbaseinfo(actor, "serveropendays")))
  75. toclient(actor, lg("跨服:",severOpenDays))
  76. end
  77. function testflushtask(actor, taskTargetType, param)
  78. Wings.FlushWingsTask(actor, taskTargetType, param)
  79. end
  80. function ttt1(actor)
  81. local equipInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_EQUIPMENT_ATTR_DATA) or {}
  82. local info = {}
  83. for k, v in pairs(equipInfo) do
  84. local grails = v["grails"]
  85. if not table.isNullOrEmpty(grails) then
  86. local grailIds = {}
  87. for grailId, _ in pairs(grails) do
  88. table.insert(grailIds, grailId)
  89. info[k] = grailIds
  90. end
  91. end
  92. end
  93. toclient(actor, lg("大天使装备圣杯ids:", info))
  94. end
  95. function ttt2(actor)
  96. local grailInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_GRAIL_ENTRY_INFO)
  97. local ids = {}
  98. for id, v in pairs(grailInfo) do
  99. table.insert(ids, id)
  100. end
  101. toclient(actor, lg("全部圣杯id:", ids))
  102. end
  103. function ttt3(actor)
  104. AngelMajorGrail.loginDirtyDataClear(actor)
  105. end
  106. function look(actor)
  107. ttt1(actor)
  108. ttt2(actor)
  109. end
  110. function other(actor)
  111. end
  112. -- =============================打印调试========================================
  113. local debug = require 'debug'
  114. local openlog = true
  115. function lg(...)
  116. if not openlog then
  117. return
  118. end
  119. local args = table.pack(...)
  120. local message = FormatArgs(args)
  121. local info = debug.getinfo(2, 'nSlu')
  122. local count = 0
  123. while not info do
  124. if count > 10 then
  125. error("打印栈的深度过深")
  126. print("打印栈的深度过深")
  127. return
  128. end
  129. count = count + 1
  130. info = debug.getinfo(2 + count, 'nSlu')
  131. end
  132. -- local begin = info.linedefined
  133. -- local over = info.lastlinedefined
  134. local currLine = info.currentline
  135. -- local name = info.name
  136. -- local short_src = info.short_src
  137. -- local result = short_src:match("[^\\]+%.lua$")
  138. local callerInfo = string.format(" ===> %s%d%s",
  139. -- result,
  140. -- name,
  141. -- begin,
  142. -- over,
  143. "★",
  144. currLine,
  145. "★")
  146. local msg = callerInfo .. " " .. message
  147. -- error(msg)
  148. print(msg)
  149. return msg
  150. end
  151. -- 格式化参数
  152. function FormatArgs(args)
  153. local formattedMessage = ""
  154. for i = 1, args.n do
  155. if type(args[i]) == "table" then
  156. formattedMessage = formattedMessage .. TableToString(args[i]) .. " "
  157. elseif type(args[i]) == "userdata" then
  158. formattedMessage = formattedMessage .. UserDataToString(args[i]) .. " "
  159. else
  160. formattedMessage = formattedMessage .. tostring(args[i]) .. "(" .. GetLogTip(args[i]) .. ") "
  161. end
  162. end
  163. return formattedMessage
  164. end
  165. function UserDataToString(userdata)
  166. return userdata:toString() .. " (U)"
  167. end
  168. function TableToString(t, indent)
  169. indent = indent or 0
  170. local str = "{\n"
  171. local isFirst = true
  172. if table.isArray(t) then
  173. -- 处理数组类型的表
  174. for k, v in ipairs(t) do
  175. if isFirst then
  176. isFirst = false
  177. else
  178. str = str .. ",\n"
  179. end
  180. str = str .. string.rep(" ", indent + 1) .. k .. ": "
  181. if type(v) == "table" then
  182. str = str .. TableToString(v, indent + 1)
  183. elseif type(v) == "userdata" then
  184. str = str .. UserDataToString(v)
  185. else
  186. str = str .. tostring(v) .. "(" .. GetLogTip(v) .. ") "
  187. end
  188. end
  189. else
  190. -- 处理哈希表
  191. for k, v in pairs(t) do
  192. if isFirst then
  193. isFirst = false
  194. else
  195. str = str .. ",\n"
  196. end
  197. str = str .. string.rep(" ", indent + 1) .. tostring(k) .. ": "
  198. if type(v) == "table" then
  199. str = str .. TableToString(v, indent + 1)
  200. elseif type(v) == "userdata" then
  201. str = str .. UserDataToString(v)
  202. else
  203. str = str .. tostring(v) .. "(" .. GetLogTip(v) .. ") "
  204. end
  205. end
  206. end
  207. str = str .. "\n" .. string.rep(" ", indent) .. "}"
  208. return str
  209. end
  210. function GetLogTip(v)
  211. if type(v) == "string" then
  212. if string.trim(v) == "" then
  213. return "空"
  214. end
  215. return "S"
  216. elseif type(v) == "boolean" then
  217. return "B"
  218. elseif type(v) == "number" then
  219. return "N"
  220. elseif type(v) == "nil" then
  221. return "×"
  222. end
  223. end
  224. local msgId = 112233
  225. function toclient(actor, msg)
  226. if not openlog then
  227. return
  228. end
  229. msg = string.gsub(msg, "\n", "")
  230. sendluamsg(actor, msgId, "日志信息:" .. msg)
  231. end