API.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. API = {}
  2. -----------------------------------------
  3. ---------------通用处理------------------
  4. -----------------------------------------
  5. function API.MapMove(actor, mapCfgId, line, x, y, range)
  6. info("接口管理传送")
  7. info(mapCfgId, "mapCfgId")
  8. if mapCfgId == 0 then
  9. mapCfgId = getbaseinfo(actor, "mapid")
  10. end
  11. if x ~= nil and y ~= nil then
  12. maptransfer(actor, x, y, mapCfgId, line, range)
  13. else
  14. maptransfer(actor, 0, 0, mapCfgId, line, 300)
  15. end
  16. end
  17. --根据角色名获取对象
  18. function API.Name2Guid(name)
  19. local rid = getroleidbyname(name)
  20. local playerActor = getactor(rid)
  21. return playerActor
  22. end
  23. --获取指定范围内的成员列表
  24. function API.GetRangeTeamList(actor, range)
  25. local list = API.GetTeamList(actor)
  26. local list1 = {}
  27. if next(list) then
  28. for i = 1, #list do
  29. local player = list[i]
  30. if getbaseinfo(actor, "unimapid") == getbaseinfo(player, "unimapid") then
  31. local distance = mapobjectdistance(actor, actor, player)
  32. if distance <= range then
  33. table.insert(list1, player)
  34. end
  35. end
  36. end
  37. end
  38. -- info(#list1,"#list1")
  39. return list1
  40. end
  41. --获取队伍成员列表
  42. function API.GetTeamList(actor)
  43. local list = {}
  44. local teamId = getbaseinfo(actor, "teamid")
  45. if teamId ~= 0 then
  46. local teamInfo = getteaminfo(actor, teamId)
  47. local allteammemberinfo = teamInfo.allteammemberinfo
  48. for i = 1, #allteammemberinfo do
  49. local rid = allteammemberinfo[i].rid
  50. local player = getactor(rid)
  51. table.insert(list, player)
  52. end
  53. end
  54. return list
  55. end
  56. --获取队伍平均等级
  57. function API.GetTeamPingJunLevel(actor)
  58. local teamId = getbaseinfo(actor, "teamid")
  59. if teamId == 0 then
  60. return 0
  61. end
  62. local teamInfo = getteaminfo(actor, teamId)
  63. local allteammemberinfo = teamInfo.allteammemberinfo
  64. local allLevel = 0
  65. for i = 1, #allteammemberinfo do
  66. local rid = allteammemberinfo[i].rid
  67. local player = getactor(rid)
  68. local level = getbaseinfo(player, "level")
  69. allLevel = allLevel + level
  70. end
  71. local pinJunLevel = math.floor(allLevel / #allteammemberinfo)
  72. return pinJunLevel
  73. end
  74. --根据物品的唯一ID获取物品
  75. function API.ItemId2WearBarAndPos(actor, itemId)
  76. local equipInfo = getequipinfo(actor, itemId, 1)
  77. local cfgid = equipInfo.cfgid
  78. local wearBar = ConfigDataManager.getTableValue("cfg_item", "wearBarID", "id", cfgid)
  79. local equipPos = ConfigDataManager.getTableValue("cfg_item", "strPart", "id", cfgid)
  80. wearBar = tonumber(wearBar)
  81. if string.find(equipPos, "#") then
  82. local tab = string.split(equipPos, "#")
  83. equipPos = tonumber(tab[1])
  84. else
  85. equipPos = tonumber(equipPos)
  86. end
  87. return wearBar, equipPos
  88. end
  89. --根据权重取下标
  90. function API.GetQZ(tab)
  91. local idx = 0
  92. if tab == nil or #tab <= 0 then
  93. return 0
  94. end
  95. local Min, Max = 0, 0
  96. for i = 1, #tab do
  97. Max = Max + tab[i].qz
  98. end
  99. local RanNum = math.random(1, Max)
  100. for i = 1, #tab do
  101. Min = Min + tab[i].qz
  102. if RanNum <= Min then
  103. idx = i
  104. break
  105. end
  106. end
  107. return idx
  108. end
  109. --检测CD
  110. function API.checkCD(lastTime, cd)
  111. local nowTime = os.time()
  112. return nowTime - lastTime > cd
  113. end
  114. --复制表格
  115. function API.deepCopy(original)
  116. local copy
  117. if type(original) == "table" then
  118. copy = {}
  119. for k, v in next, original, nil do
  120. copy[API.deepCopy(k)] = API.deepCopy(v)
  121. end
  122. setmetatable(copy, API.deepCopy(getmetatable(original)))
  123. else
  124. copy = original
  125. end
  126. return copy
  127. end
  128. function API.TableDeepcopy(tmp)
  129. if nil == tmp then
  130. return nil
  131. end
  132. local res = {}
  133. for key, val in pairs(tmp) do
  134. if type(val) == "table" then
  135. res[key] = API.TableDeepcopy(val)
  136. else
  137. res[key] = val
  138. end
  139. end
  140. return res
  141. end
  142. --道具列表放大
  143. function API.ItemListMulti(itemList, multi)
  144. local list = API.deepCopy(itemList)
  145. for k, v in pairs(list) do
  146. v[2] = v[2] * multi
  147. end
  148. return list
  149. end
  150. --道具名字列表转换为id
  151. function API.ItemListNameToID(itemList)
  152. local list = {}
  153. for k, v in pairs(itemList) do
  154. local itemName = v[1]
  155. local itemNum = tonumber(v[2])
  156. local itemID = ConfigDataManager.getTableValue("cfg_item", "id", "name", itemName)
  157. list[tonumber(itemID)] = itemNum
  158. end
  159. return list
  160. end
  161. ---消耗 奖励 检查
  162. function API.Check(check_str, have_count, itemNum)
  163. check_str = check_str or ">="
  164. info("来了66", check_str, have_count, itemNum, type(have_count), type(itemNum))
  165. local result = true
  166. if check_str == ">" or check_str == nil then
  167. if have_count <= itemNum then
  168. result = false
  169. end
  170. elseif check_str == "<" then
  171. if have_count >= itemNum then
  172. result = false
  173. end
  174. elseif check_str == "==" then
  175. if have_count ~= itemNum then
  176. result = false
  177. end
  178. elseif check_str == ">=" then
  179. -- info("你干嘛",check_str,have_count,itemNum,type(have_count),type(itemNum),result)
  180. if have_count < itemNum then
  181. result = false
  182. end
  183. elseif check_str == "<=" then
  184. if have_count > itemNum then
  185. result = false
  186. end
  187. end
  188. return result
  189. end
  190. function API.CheckStrengthenItem(actor, tcl, desc)
  191. end
  192. function API.CheckItem(actor, tcl, desc)
  193. if not next(tcl) then
  194. return false
  195. end
  196. for k, v in pairs(tcl) do
  197. if type(k) ~= "string" then
  198. local itemName = v[1] --类型为变化或者道具时可用 道具名或者变量名
  199. local itemNum = tonumber(v[2]) --对应类型需要的检查值
  200. local bangding = v[3] or v.bind --是否绑定 道具用 暂无用
  201. local item_type = v[4] or v.mold --类型 1或者nil道具 2 Int变量 3开服天数 4龙魂连击等级 5所有充值挡位 玩家等级 转职
  202. local var_type = v[5] or v.var_type --变量类型 nil 存盘 0日变量 1 缓存小退清零
  203. local check_str = v[6] or v.checkStr -- == > < >= <=
  204. local def_str = v[7] or v.desc --检查失败后的默认消息提示 不传没有
  205. -- info(v,itemName)
  206. if not item_type or item_type == 1 then
  207. --2 Int变量
  208. local itemID = ConfigDataManager.getTableValue("cfg_item", "id", "name", itemName)
  209. local hasCount = getbagitemcountbyid(actor, itemID)
  210. if hasCount < itemNum then
  211. if desc then
  212. if desc ~= "" then
  213. API.SendCenterMsg(actor, desc)
  214. end
  215. else
  216. API.SendCenterMsg(actor, itemName .. "不足")
  217. end
  218. return false
  219. end
  220. elseif item_type == 2 then
  221. --3 开服天数
  222. local have_count = API.GetInt(actor, itemName, var_type)
  223. -- info(v,itemName,have_count)
  224. def_str = def_str or "变量不足!"
  225. if API.Check(check_str, have_count, itemNum) == false then
  226. if def_str and desc ~= "" then
  227. API.SendCenterMsg(actor, def_str)
  228. end
  229. return false
  230. end
  231. elseif item_type == 3 then
  232. local have_count = tonumber(getserveropendays(actor))
  233. -- info("开服天数",have_count)
  234. if API.Check(check_str, have_count, itemNum) == false then
  235. if def_str then
  236. API.SendCenterMsg(actor, def_str)
  237. end
  238. return false
  239. end
  240. elseif item_type == 4 then
  241. -- local comboSkill = getrolefield(actor,"role.roleskill.comboskill")
  242. -- local have_count = comboSkill.skillLv
  243. local have_count = API.GetInt(actor, VarCfg.ZC_NewDragonSoulComboLevel)
  244. if not API.Check(check_str, have_count, itemNum) then
  245. if desc then
  246. if desc ~= "" then
  247. API.SendCenterMsg(actor, desc)
  248. end
  249. else
  250. API.SendCenterMsg(actor, "龙魂连击等级不足")
  251. end
  252. return false
  253. end
  254. elseif item_type == 5 then
  255. if not RechargeStall.checkAllBuy(actor, desc) then
  256. return
  257. end
  258. elseif item_type == "玩家等级" then
  259. local cur_level = tonumber(getbaseinfo(actor, "level")) or 0
  260. if API.Check(check_str, cur_level, itemNum) == false then
  261. if desc then
  262. if desc ~= "" then
  263. API.SendCenterMsg(actor, desc)
  264. end
  265. else
  266. API.SendCenterMsg(actor, "等级不足,需要" .. itemNum .. "级")
  267. end
  268. return false
  269. end
  270. elseif item_type == "转职" then
  271. local data = API.GetTable(actor, VarCfg.ZC_ZhuanZhiVar) or {}
  272. local count = data.count or 0
  273. if API.Check(check_str, count, itemNum) == false then
  274. if desc then
  275. if desc ~= "" then
  276. API.SendCenterMsg(actor, desc)
  277. end
  278. else
  279. API.SendCenterMsg(actor, "请" .. itemNum .. "转后再来吧")
  280. end
  281. return false
  282. end
  283. end
  284. end
  285. end
  286. return true
  287. end
  288. function API.CheckItemMap(actor, map)
  289. for k, v in pairs(map) do
  290. local hasCount = getbagitemcountbyid(actor, k)
  291. if hasCount < v then
  292. return false
  293. end
  294. end
  295. return true
  296. end
  297. function API.TakeItemMap(actor, map, desc)
  298. for k, v in pairs(map) do
  299. removeitemfrombag(actor, k, v, 0, 9999, desc)
  300. end
  301. end
  302. function API.takeItem(actor, tcl, desc)
  303. if not next(tcl) then
  304. return false
  305. end
  306. if API.CheckItem(actor, tcl) == false then
  307. return false
  308. end
  309. for k, v in pairs(tcl) do
  310. if type(k) ~= "string" then
  311. local itemName = v[1]
  312. local itemNum = tonumber(v[2])
  313. local bangding = v[3]
  314. local item_type = v[4] or v.mold --检查 1或者nil道具 2 Int变量
  315. local var_type = v[5]
  316. if not item_type or item_type == 1 then
  317. --2 Int变量
  318. local itemID = ConfigDataManager.getTableValue("cfg_item", "id", "name", itemName)
  319. removeitemfrombag(actor, itemID, itemNum, 0, 9999, desc)
  320. elseif item_type == 2 then
  321. local var = API.GetInt(actor, itemName, var_type)
  322. var = var - itemNum
  323. API.SetInt(actor, itemName, var, var_type)
  324. end
  325. end
  326. end
  327. return true
  328. end
  329. function API.GiveItem(actor, twp, desc, notPush)
  330. if not next(twp) then
  331. return false
  332. end
  333. local itemIdList = {}
  334. for k, v in pairs(twp) do
  335. local newTwp = {}
  336. local itemName = v[1]
  337. local itemNum = v[2]
  338. local bangding = v[3]
  339. local item_type = v[4] --检查 1或者nil道具 2 Int变量
  340. local var_type = v[5]
  341. if not item_type or item_type == 1 then
  342. --2 Int变量
  343. local itemID = ConfigDataManager.getTableValue("cfg_item", "id", "name", itemName)
  344. newTwp[itemID] = itemNum
  345. local id = Bag.addItemMapToBag(actor, newTwp, bangding, 9999, desc)
  346. table.insert(itemIdList, {id = id, cfgId = itemID, count = itemNum})
  347. elseif item_type == 2 then
  348. local var = API.GetInt(actor, itemName, var_type)
  349. var = var + itemNum
  350. API.SetInt(actor, itemName, var, var_type)
  351. end
  352. end
  353. if #itemIdList > 0 and (not notPush) then
  354. -- info("走了没",itemIdList,LuaMessageIdToClient.COMMON_REWARD_PANEL)
  355. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, itemIdList)
  356. end
  357. return true, itemIdList
  358. end
  359. ---发送消息
  360. function API.SendCenterMsg(actor, msg, color, log)
  361. if not color then
  362. tipinfo(actor, msg)
  363. else
  364. tipinfo(actor, "<color='" .. color .. "'>" .. msg .. "</color>")
  365. end
  366. if log then
  367. error(getbaseinfo(actor, "rolename"), msg)
  368. end
  369. end
  370. --打印表格消息
  371. function API.PrintTable(table, level, key)
  372. if type(table) ~= "table" then
  373. info(table)
  374. return
  375. end
  376. level = level or 1
  377. local indent = ""
  378. for i = 1, level do
  379. indent = indent .. " "
  380. end
  381. if key ~= "" and key ~= nil then
  382. -- info(tostring(key)..type(key));
  383. info(indent .. key .. " " .. "=" .. " " .. "{")
  384. else
  385. info(indent .. "{")
  386. end
  387. key = ""
  388. if type(table) == "table" then
  389. for k, v in pairs(table) do
  390. if type(v) == "table" then
  391. key = k
  392. API.PrintTable(v, level + 1, key)
  393. else
  394. local content = string.format("%s%s = %s", indent .. " ", tostring(k), tostring(v))
  395. info(content)
  396. end
  397. end
  398. end
  399. info(indent .. "}")
  400. end
  401. -----------------------------------------
  402. ---------------伤害相关------------------
  403. -----------------------------------------
  404. --获取玩家当前剩余血量百分比
  405. function API.GetHpPctNow(actor)
  406. local hpNow = getbaseinfo(actor, "hp")
  407. local hpMax = getattrinfo(actor, "maxHP")
  408. local hpPctNow = hpNow / hpMax
  409. return hpPctNow * 100
  410. end
  411. --获取玩家当前剩余蓝量百分比
  412. -- function API.GetMpPctNow(play)
  413. -- local hpNow = getbaseinfo(play,11)
  414. -- local hpMax = getbaseinfo(play,12)
  415. -- local hpPctNow = math.floor(hpNow/hpMax)
  416. -- return hpPctNow*100
  417. -- end
  418. --获取对应百分比的血量
  419. function API.GetHpPctNum(actor, pct)
  420. local hpMax = getattrinfo(actor, "maxHP")
  421. local hpPctNum = hpMax * (pct / 100)
  422. return hpPctNum
  423. end
  424. --获取对应百分比的蓝量
  425. -- function API.GetMpPctNum(play,pct)
  426. -- local mpMax = getbaseinfo(play,12)
  427. -- local mpPctNum = mpMax*(pct/100)
  428. -- return mpPctNum
  429. -- end
  430. --获取指定BUFF堆叠层数
  431. function API.GetBuffState(actor, buffId)
  432. local buff_info = getbuffinfo(actor)
  433. local idx = 0
  434. if buff_info and next(buff_info) then
  435. for i = 1, #buff_info do
  436. if buff_info[i].buffcfgid == buffId then
  437. idx = buff_info[idx].layers
  438. end
  439. end
  440. end
  441. return idx
  442. end
  443. -----------------------------------------
  444. ---------------变量控制------------------
  445. -----------------------------------------
  446. --物品变量
  447. --获取物品变量(注意此接口服务端只支持一种数据结构 map或list 不能都有)
  448. --[[
  449. setDurability:是否初始化过耐久
  450. Durability:耐久度
  451. strengthlv:强化等级
  452. tZhuoYueAttIndex:卓越属性
  453. appendlv:追加等级
  454. IsLuck:是否激活幸运
  455. skillName:激活技能名
  456. zaisheng_attr:再生属性
  457. ]]
  458. function API.GetItemData(actor, itemId, varName)
  459. local itemData = getitemextdata(actor, itemId) or {}
  460. return itemData["" .. varName]
  461. end
  462. function API.GetItemDataSrc(actor, itemId)
  463. local itemData = getitemextdata(actor, itemId)
  464. return itemData
  465. end
  466. function API.GetItemLuck(actor, itemId)
  467. local itemData = getequipinfo(actor, itemId, 1)
  468. local isLuck = false
  469. for index, _ in ipairs(itemData.entries) do
  470. if itemData.entries[index].attrid == 900 then
  471. isLuck = true
  472. break
  473. end
  474. end
  475. return isLuck
  476. end
  477. --设置物品变量
  478. function API.SetItemData(actor, itemId, varName, var)
  479. local itemData = getitemextdata(actor, itemId) or {}
  480. itemData["" .. varName] = var
  481. setitemextdata(actor, itemId, itemData)
  482. end
  483. --推送流光数据等级
  484. function API.refreshLiuGuang(actor, itemId, val)
  485. -- info("推送流光数据等级")
  486. local itemData = {}
  487. local val = val or EquipFunc.getEquipStrengthLevel(actor, itemId)
  488. itemData.strengthlv = val
  489. setequipgmext(actor, itemId, itemData)
  490. end
  491. ---个人变量说明
  492. ---T$ 无类型限制 自动保存数据库
  493. ---J$ 无类型限制 天变量 存入数据库
  494. ---@ 下线不保存 小退清空
  495. --- 获取玩家Int变量 默认为0 var_type nil 存盘 0日变量 1 缓存小退清零
  496. function API.GetInt(actor, varName, var_type)
  497. local val = 0
  498. if var_type == 0 then
  499. val = getplaydef(actor, "J$" .. varName)
  500. elseif var_type == 1 then
  501. val = getplaydef(actor, "@" .. varName)
  502. else
  503. val = getplaydef(actor, "T$" .. varName)
  504. end
  505. return val or 0
  506. end
  507. ---设置玩家Int变量 val类型必须是number
  508. function API.SetInt(actor, varName, val, var_type)
  509. if type(val) ~= "number" then
  510. return
  511. end
  512. if var_type == 0 then
  513. return setplaydef(actor, "J$" .. varName, val)
  514. elseif var_type == 1 then
  515. return setplaydef(actor, "@" .. varName, val)
  516. else
  517. return setplaydef(actor, "T$" .. varName, val)
  518. end
  519. end
  520. ---获取玩家string类型的变量 默认为 ""
  521. function API.GetStr(actor, varName, var_type)
  522. local val = ""
  523. if var_type == 0 then
  524. val = getplaydef(actor, "J$" .. varName)
  525. elseif var_type == 1 then
  526. val = getplaydef(actor, "@" .. varName)
  527. else
  528. val = getplaydef(actor, "T$" .. varName)
  529. end
  530. return val or ""
  531. end
  532. ---设置玩家string变量 val类型必须是string
  533. function API.SetStr(actor, varName, val, var_type)
  534. if type(val) ~= "string" then
  535. return
  536. end
  537. if var_type == 0 then
  538. return setplaydef(actor, "J$" .. varName, val)
  539. elseif var_type == 1 then
  540. return setplaydef(actor, "@" .. varName, val)
  541. else
  542. return setplaydef(actor, "T$" .. varName, val)
  543. end
  544. end
  545. ---获取玩家table类型的变量 默认为 nil
  546. function API.GetTable(actor, varName, var_type)
  547. local val = nil
  548. if var_type == 0 then
  549. val = getplaydef(actor, "J$" .. varName)
  550. elseif var_type == 1 then
  551. val = getplaydef(actor, "@" .. varName)
  552. else
  553. val = getplaydef(actor, "T$" .. varName)
  554. end
  555. return val
  556. end
  557. ---设置玩家table变量 val类型必须是table var_type 0天变量 1缓存变量 其它正常保存数据库变量
  558. function API.SetTable(actor, varName, val, var_type)
  559. if type(val) ~= "table" then
  560. return
  561. end
  562. if var_type == 0 then
  563. setplaydef(actor, "J$" .. varName, val)
  564. elseif var_type == 1 then
  565. setplaydef(actor, "@" .. varName, val)
  566. else
  567. -- info("记录成功",val,getplaydef(actor,"T$"..varName))
  568. setplaydef(actor, "T$" .. varName, val)
  569. end
  570. end
  571. --- 获取玩家Int天变量 默认为0
  572. function API.GetDayInt(actor, varName)
  573. local val = getplaydef(actor, "J$" .. varName) or 0
  574. return val
  575. end
  576. ---设置玩家Int天变量 val类型必须是number
  577. function API.SetDayInt(actor, varName, val)
  578. if type(val) ~= "number" then
  579. return
  580. end
  581. return setplaydef(actor, "J$" .. varName, val)
  582. end
  583. ---获取玩家string类型的天变量 默认为 ""
  584. function API.GetDayStr(actor, varName)
  585. local val = getplaydef(actor, "J$" .. varName) or ""
  586. return val
  587. end
  588. ---设置玩家string天变量 val类型必须是string
  589. function API.SetDayStr(actor, varName, val)
  590. if type(val) ~= "string" then
  591. return
  592. end
  593. return setplaydef(actor, "J$" .. varName, val)
  594. end
  595. ---获取玩家table类型的天变量 默认为 nil
  596. function API.GetDayTable(actor, varName)
  597. local val = getplaydef(actor, "J$" .. varName) or nil
  598. return val
  599. end
  600. ---设置玩家table天变量 val类型必须是string
  601. function API.SetDayTable(actor, varName, val)
  602. if type(val) ~= "table" then
  603. return
  604. end
  605. return setplaydef(actor, "J$" .. varName, val)
  606. end
  607. ---全局变量说明
  608. ---G$ 服务器重启清除
  609. ---R$ 保存数据库
  610. ---Q$ 天变量 每天0点清空
  611. --- 获取系统Int变量 值默认为0 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
  612. function API.GetDBNum(varName, varType)
  613. local fh = "R$"
  614. if varType == 1 then
  615. fh = "G$"
  616. elseif varType == 3 then
  617. fh = "Q$"
  618. end
  619. return getsysvar(fh .. "" .. varName) or 0
  620. end
  621. --- 设置系统Int变量 值默认为0 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
  622. function API.SetDBNum(varName, val, varType)
  623. if type(val) ~= "number" then
  624. return
  625. end
  626. local fh = "R$"
  627. if varType == 1 then
  628. fh = "G$"
  629. elseif varType == 3 then
  630. fh = "Q$"
  631. end
  632. return setsysvar(fh .. varName, val)
  633. end
  634. --- 获取系统string变量 值默认为"" 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
  635. function API.GetDBStr(varName, varType)
  636. local fh = "R$"
  637. if varType == 1 then
  638. fh = "G$"
  639. elseif varType == 3 then
  640. fh = "Q$"
  641. end
  642. return getsysvar(fh .. "" .. varName) or ""
  643. end
  644. --- 设置系统string变量 值默认为"" 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
  645. function API.SetDBStr(varName, val, varType)
  646. if type(val) ~= "string" then
  647. return
  648. end
  649. local fh = "R$"
  650. if varType == 1 then
  651. fh = "G$"
  652. elseif varType == 3 then
  653. fh = "Q$"
  654. end
  655. return setsysvar(fh .. varName, val)
  656. end
  657. --- 获取系统string变量 值默认为nil 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
  658. function API.GetDBTable(varName, varType)
  659. local fh = "R$"
  660. if varType == 1 then
  661. fh = "G$"
  662. elseif varType == 3 then
  663. fh = "Q$"
  664. end
  665. return getsysvar(fh .. "" .. varName) or nil
  666. end
  667. --- 设置系统table变量 值默认为nil 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
  668. function API.SetDBTable(varName, val, varType)
  669. if type(val) ~= "table" then
  670. return
  671. end
  672. local fh = "R$"
  673. if varType == 1 then
  674. fh = "G$"
  675. elseif varType == 3 then
  676. fh = "Q$"
  677. end
  678. return setsysvar(fh .. varName, val)
  679. end
  680. function API.SendCenterMsg(actor, msg, color, log)
  681. if not color then
  682. tipinfo(actor, msg)
  683. else
  684. tipinfo(actor, "<color='" .. color .. "'>" .. msg .. "</color>")
  685. end
  686. if log then
  687. error(getbaseinfo(actor, "rolename"), msg)
  688. end
  689. end
  690. function API.InsertAndKeepLen(arr, value, len)
  691. table.insert(arr, value) -- 末尾插入
  692. if #arr > len then
  693. table.remove(arr, 1) -- 删除最早插入的
  694. end
  695. end
  696. ---战盟变量说明
  697. ---U$ 无类型限制 存入数据库
  698. ---消耗 奖励 检查