API.lua 22 KB

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