| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753 |
- API = {}
- -----------------------------------------
- ---------------通用处理------------------
- -----------------------------------------
- function API.MapMove(actor, mapCfgId, line, x, y, range)
- info("接口管理传送")
- info(mapCfgId, "mapCfgId")
- if mapCfgId == 0 then
- mapCfgId = getbaseinfo(actor, "mapid")
- end
- if x ~= nil and y ~= nil then
- maptransfer(actor, x, y, mapCfgId, line, range)
- else
- maptransfer(actor, 0, 0, mapCfgId, line, 300)
- end
- end
- --根据角色名获取对象
- function API.Name2Guid(name)
- local rid = getroleidbyname(name)
- local playerActor = getactor(rid)
- return playerActor
- end
- --获取指定范围内的成员列表
- function API.GetRangeTeamList(actor, range)
- local list = API.GetTeamList(actor)
- local list1 = {}
- if next(list) then
- for i = 1, #list do
- local player = list[i]
- if getbaseinfo(actor, "unimapid") == getbaseinfo(player, "unimapid") then
- local distance = mapobjectdistance(actor, actor, player)
- if distance <= range then
- table.insert(list1, player)
- end
- end
- end
- end
- -- info(#list1,"#list1")
- return list1
- end
- --获取队伍成员列表
- function API.GetTeamList(actor)
- local list = {}
- local teamId = getbaseinfo(actor, "teamid")
- if teamId ~= 0 then
- local teamInfo = getteaminfo(actor, teamId)
- local allteammemberinfo = teamInfo.allteammemberinfo
- for i = 1, #allteammemberinfo do
- local rid = allteammemberinfo[i].rid
- local player = getactor(rid)
- table.insert(list, player)
- end
- end
- return list
- end
- --获取队伍平均等级
- function API.GetTeamPingJunLevel(actor)
- local teamId = getbaseinfo(actor, "teamid")
- if teamId == 0 then
- return 0
- end
- local teamInfo = getteaminfo(actor, teamId)
- local allteammemberinfo = teamInfo.allteammemberinfo
- local allLevel = 0
- for i = 1, #allteammemberinfo do
- local rid = allteammemberinfo[i].rid
- local player = getactor(rid)
- local level = getbaseinfo(player, "level")
- allLevel = allLevel + level
- end
- local pinJunLevel = math.floor(allLevel / #allteammemberinfo)
- return pinJunLevel
- end
- --根据物品的唯一ID获取物品
- function API.ItemId2WearBarAndPos(actor, itemId)
- local equipInfo = getequipinfo(actor, itemId, 1)
- local cfgid = equipInfo.cfgid
- local wearBar = ConfigDataManager.getTableValue("cfg_item", "wearBarID", "id", cfgid)
- local equipPos = ConfigDataManager.getTableValue("cfg_item", "strPart", "id", cfgid)
- wearBar = tonumber(wearBar)
- if string.find(equipPos, "#") then
- local tab = string.split(equipPos, "#")
- equipPos = tonumber(tab[1])
- else
- equipPos = tonumber(equipPos)
- end
- return wearBar, equipPos
- end
- --根据权重取下标
- function API.GetQZ(tab)
- local idx = 0
- if tab == nil or #tab <= 0 then
- return 0
- end
- local Min, Max = 0, 0
- for i = 1, #tab do
- Max = Max + tab[i].qz
- end
- local RanNum = math.random(1, Max)
- for i = 1, #tab do
- Min = Min + tab[i].qz
- if RanNum <= Min then
- idx = i
- break
- end
- end
- return idx
- end
- --检测CD
- function API.checkCD(lastTime, cd)
- local nowTime = os.time()
- return nowTime - lastTime > cd
- end
- --复制表格
- function API.deepCopy(original)
- local copy
- if type(original) == "table" then
- copy = {}
- for k, v in next, original, nil do
- copy[API.deepCopy(k)] = API.deepCopy(v)
- end
- setmetatable(copy, API.deepCopy(getmetatable(original)))
- else
- copy = original
- end
- return copy
- end
- function API.TableDeepcopy(tmp)
- if nil == tmp then return nil end
- local res = {}
- for key, val in pairs(tmp) do
- if type(val) == "table" then
- res[key] = API.TableDeepcopy(val)
- else
- res[key] = val
- end
- end
- return res
- end
- --道具列表放大
- function API.ItemListMulti(itemList, multi)
- local list = API.deepCopy(itemList)
- for k, v in pairs(list) do
- v[2] = v[2] * multi
- end
- return list
- end
- --道具名字列表转换为id
- function API.ItemListNameToID(itemList)
- local list = {};
- for k, v in pairs(itemList) do
- local itemName = v[1];
- local itemNum = tonumber(v[2]);
- local itemID = ConfigDataManager.getTableValue("cfg_item", "id", "name", itemName)
- list[tonumber(itemID)] = itemNum
- end
- return list
- end
- ---消耗 奖励 检查
- function API.Check(check_str, have_count, itemNum)
- check_str = check_str or ">="
- info("来了66", check_str, have_count, itemNum, type(have_count), type(itemNum))
- local result = true;
- if check_str == ">" or check_str == nil then
- if have_count <= itemNum then
- result = false
- end
- elseif check_str == "<" then
- if have_count >= itemNum then
- result = false
- end
- elseif check_str == "==" then
- if have_count ~= itemNum then
- result = false
- end
- elseif check_str == ">=" then
- if have_count < itemNum then
- result = false
- end
- -- info("你干嘛",check_str,have_count,itemNum,type(have_count),type(itemNum),result)
- elseif check_str == "<=" then
- if have_count > itemNum then
- result = false
- end
- end
- return result
- end
- function API.CheckStrengthenItem(actor, tcl, desc)
- end
- function API.CheckItem(actor, tcl, desc)
- if not next(tcl) then
- return false
- end
- for k, v in pairs(tcl) do
- if type(k) ~= "string" then
- local itemName = v[1]; --类型为变化或者道具时可用 道具名或者变量名
- local itemNum = tonumber(v[2]); --对应类型需要的检查值
- local bangding = v[3] or v.bind; --是否绑定 道具用 暂无用
- local item_type = v[4] or v.mold; --类型 1或者nil道具 2 Int变量 3开服天数 4龙魂连击等级 5所有充值挡位 玩家等级 转职
- local var_type = v[5] or v.var_type; --变量类型 nil 存盘 0日变量 1 缓存小退清零
- local check_str = v[6] or v.checkStr; -- == > < >= <=
- local def_str = v[7] or v.desc --检查失败后的默认消息提示 不传没有
- -- info(v,itemName)
- if not item_type or item_type == 1 then
- local itemID = ConfigDataManager.getTableValue("cfg_item", "id", "name", itemName)
- local hasCount = getbagitemcountbyid(actor, itemID)
- if hasCount < itemNum then
- if desc then
- if desc ~= "" then
- API.SendCenterMsg(actor, desc)
- end
- else
- API.SendCenterMsg(actor, itemName .. "不足")
- end
- return false
- end
- --2 Int变量
- elseif item_type == 2 then
- local have_count = API.GetInt(actor, itemName, var_type)
- -- info(v,itemName,have_count)
- def_str = def_str or "变量不足!"
- if API.Check(check_str, have_count, itemNum) == false then
- if def_str and desc ~= "" then
- API.SendCenterMsg(actor, def_str)
- end
- return false
- end
- --3 开服天数
- elseif item_type == 3 then
- local have_count = tonumber(getserveropendays(actor))
- -- info("开服天数",have_count)
- if API.Check(check_str, have_count, itemNum) == false then
- if def_str then
- API.SendCenterMsg(actor, def_str)
- end
- return false
- end
- elseif item_type == 4 then
- -- local comboSkill = getrolefield(actor,"role.roleskill.comboskill")
- -- local have_count = comboSkill.skillLv
- local have_count = API.GetInt(actor, VarCfg.ZC_NewDragonSoulComboLevel)
- if not API.Check(check_str, have_count, itemNum) then
- if desc then
- if desc ~= "" then
- API.SendCenterMsg(actor, desc)
- end
- else
- API.SendCenterMsg(actor, "龙魂连击等级不足")
- end
- return false
- end
- elseif item_type == 5 then
- if not RechargeStall.checkAllBuy(actor, desc) then
- return
- end
- elseif item_type == "玩家等级" then
- local cur_level = tonumber(getbaseinfo(actor, "level")) or 0
- if API.Check(check_str, cur_level, itemNum) == false then
- if desc then
- if desc ~= "" then
- API.SendCenterMsg(actor, desc)
- end
- else
- API.SendCenterMsg(actor, "等级不足,需要" .. itemNum .. "级")
- end
- return false
- end
- elseif item_type == "转职" then
- local data = API.GetTable(actor, VarCfg.ZC_ZhuanZhiVar) or {}
- local count = data.count or 0;
- if API.Check(check_str, count, itemNum) == false then
- if desc then
- if desc ~= "" then
- API.SendCenterMsg(actor, desc)
- end
- else
- API.SendCenterMsg(actor, "请" .. itemNum .. "转后再来吧")
- end
- return false
- end
- end
- end
- end
- return true
- end
- function API.CheckItemMap(actor, map)
- for k, v in pairs(map) do
- local hasCount = getbagitemcountbyid(actor, k)
- if hasCount < v then
- return false
- end
- end
- return true
- end
- function API.TakeItemMap(actor, map, desc)
- for k, v in pairs(map) do
- removeitemfrombag(actor, k, v, 0, 9999, desc)
- end
- end
- function API.takeItem(actor, tcl, desc)
- if not next(tcl) then
- return false
- end
- if API.CheckItem(actor, tcl) == false then
- return false
- end
- for k, v in pairs(tcl) do
- if type(k) ~= "string" then
- local itemName = v[1]
- local itemNum = tonumber(v[2])
- local bangding = v[3];
- local item_type = v[4] or v.mold; --检查 1或者nil道具 2 Int变量
- local var_type = v[5];
- if not item_type or item_type == 1 then
- local itemID = ConfigDataManager.getTableValue("cfg_item", "id", "name", itemName)
- removeitemfrombag(actor, itemID, itemNum, 9999, desc)
- --2 Int变量
- elseif item_type == 2 then
- local var = API.GetInt(actor, itemName, var_type)
- var = var - itemNum
- API.SetInt(actor, itemName, var, var_type)
- end
- end
- end
- return true
- end
- function API.GiveItem(actor, twp, desc, notPush)
- if not next(twp) then
- return false
- end
- local itemIdList = {};
- for k, v in pairs(twp) do
- local newTwp = {}
- local itemName = v[1]
- local itemNum = v[2]
- local bangding = v[3];
- local item_type = v[4]; --检查 1或者nil道具 2 Int变量
- local var_type = v[5];
- if not item_type or item_type == 1 then
- local itemID = ConfigDataManager.getTableValue("cfg_item", "id", "name", itemName)
- newTwp[itemID] = itemNum
- local id = additemmaptobag(actor, newTwp, bangding, 9999, desc)
- table.insert(itemIdList, { id = id, cfgId = itemID, count = itemNum, });
- --2 Int变量
- elseif item_type == 2 then
- local var = API.GetInt(actor, itemName, var_type)
- var = var + itemNum
- API.SetInt(actor, itemName, var, var_type)
- end
- end
- if #itemIdList > 0 and (not notPush) then
- -- info("走了没",itemIdList,LuaMessageIdToClient.COMMON_REWARD_PANEL)
- sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, itemIdList)
- end
- return true, itemIdList
- end
- ---发送消息
- function API.SendCenterMsg(actor, msg, color, log)
- if not color then
- tipinfo(actor, msg)
- else
- tipinfo(actor, "<color='" .. color .. "'>" .. msg .. "</color>")
- end
- if log then
- error(getbaseinfo(actor, "rolename"), msg)
- end
- end
- --打印表格消息
- function API.PrintTable(table, level, key)
- if type(table) ~= "table" then
- info(table)
- return
- end
- level = level or 1
- local indent = ""
- for i = 1, level do
- indent = indent .. " "
- end
- if key ~= "" and key ~= nil then
- -- info(tostring(key)..type(key));
- info(indent .. key .. " " .. "=" .. " " .. "{")
- else
- info(indent .. "{")
- end
- key = ""
- if type(table) == "table" then
- for k, v in pairs(table) do
- if type(v) == "table" then
- key = k
- API.PrintTable(v, level + 1, key)
- else
- local content = string.format("%s%s = %s", indent .. " ", tostring(k), tostring(v))
- info(content)
- end
- end
- end
- info(indent .. "}")
- end
- -----------------------------------------
- ---------------伤害相关------------------
- -----------------------------------------
- --获取玩家当前剩余血量百分比
- function API.GetHpPctNow(actor)
- local hpNow = getbaseinfo(actor, "hp")
- local hpMax = getattrinfo(actor, "maxHP")
- local hpPctNow = hpNow / hpMax
- return hpPctNow * 100
- end
- --获取玩家当前剩余蓝量百分比
- -- function API.GetMpPctNow(play)
- -- local hpNow = getbaseinfo(play,11)
- -- local hpMax = getbaseinfo(play,12)
- -- local hpPctNow = math.floor(hpNow/hpMax)
- -- return hpPctNow*100
- -- end
- --获取对应百分比的血量
- function API.GetHpPctNum(actor, pct)
- local hpMax = getattrinfo(actor, "maxHP")
- local hpPctNum = hpMax * (pct / 100)
- return hpPctNum
- end
- --获取对应百分比的蓝量
- -- function API.GetMpPctNum(play,pct)
- -- local mpMax = getbaseinfo(play,12)
- -- local mpPctNum = mpMax*(pct/100)
- -- return mpPctNum
- -- end
- --获取指定BUFF堆叠层数
- function API.GetBuffState(actor, buffId)
- local buff_info = getbuffinfo(actor)
- local idx = 0
- if buff_info and next(buff_info) then
- for i = 1, #buff_info do
- if buff_info[i].buffcfgid == buffId then
- idx = buff_info[idx].layers
- end
- end
- end
- return idx
- end
- -----------------------------------------
- ---------------变量控制------------------
- -----------------------------------------
- --物品变量
- --获取物品变量(注意此接口服务端只支持一种数据结构 map或list 不能都有)
- --[[
- setDurability:是否初始化过耐久
- Durability:耐久度
- strengthlv:强化等级
- tZhuoYueAttIndex:卓越属性
- appendlv:追加等级
- IsLuck:是否激活幸运
- skillName:激活技能名
- zaisheng_attr:再生属性
- ]]
- function API.GetItemData(actor, itemId, varName)
- local itemData = getitemextdata(actor, itemId) or {}
- return itemData["" .. varName]
- end
- function API.GetItemDataSrc(actor, itemId)
- local itemData = getitemextdata(actor, itemId)
- return itemData
- end
- function API.GetItemLuck(actor, itemId)
- local itemData = getequipinfo(actor, itemId, 1)
- local isLuck = false
- for index, _ in ipairs(itemData.entries) do
- if itemData.entries[index].attrid == 900 then
- isLuck = true
- break
- end
- end
- return isLuck
- end
- --设置物品变量
- function API.SetItemData(actor, itemId, varName, var)
- local itemData = getitemextdata(actor, itemId) or {}
- itemData["" .. varName] = var
- setitemextdata(actor, itemId, itemData)
- end
- --推送流光数据等级
- function API.refreshLiuGuang(actor, itemId, val)
- -- info("推送流光数据等级")
- local itemData = {}
- local val = val or EquipFunc.getEquipStrengthLevel(actor, itemId)
- itemData.strengthlv = val
- setequipgmext(actor, itemId, itemData)
- end
- ---个人变量说明
- ---T$ 无类型限制 自动保存数据库
- ---J$ 无类型限制 天变量 存入数据库
- ---@ 下线不保存 小退清空
- --- 获取玩家Int变量 默认为0 var_type nil 存盘 0日变量 1 缓存小退清零
- function API.GetInt(actor, varName, var_type)
- local val = 0
- if var_type == 0 then
- val = getplaydef(actor, "J$" .. varName)
- elseif var_type == 1 then
- val = getplaydef(actor, "@" .. varName)
- else
- val = getplaydef(actor, "T$" .. varName)
- end
- return val or 0
- end
- ---设置玩家Int变量 val类型必须是number
- function API.SetInt(actor, varName, val, var_type)
- if type(val) ~= "number" then
- return
- end
- if var_type == 0 then
- return setplaydef(actor, "J$" .. varName, val)
- elseif var_type == 1 then
- return setplaydef(actor, "@" .. varName, val)
- else
- return setplaydef(actor, "T$" .. varName, val)
- end
- end
- ---获取玩家string类型的变量 默认为 ""
- function API.GetStr(actor, varName, var_type)
- local val = ""
- if var_type == 0 then
- val = getplaydef(actor, "J$" .. varName)
- elseif var_type == 1 then
- val = getplaydef(actor, "@" .. varName)
- else
- val = getplaydef(actor, "T$" .. varName)
- end
- return val or ""
- end
- ---设置玩家string变量 val类型必须是string
- function API.SetStr(actor, varName, val, var_type)
- if type(val) ~= "string" then
- return
- end
- if var_type == 0 then
- return setplaydef(actor, "J$" .. varName, val)
- elseif var_type == 1 then
- return setplaydef(actor, "@" .. varName, val)
- else
- return setplaydef(actor, "T$" .. varName, val)
- end
- end
- ---获取玩家table类型的变量 默认为 nil
- function API.GetTable(actor, varName, var_type)
- local val = nil
- if var_type == 0 then
- val = getplaydef(actor, "J$" .. varName)
- elseif var_type == 1 then
- val = getplaydef(actor, "@" .. varName)
- else
- val = getplaydef(actor, "T$" .. varName)
- end
- return val
- end
- ---设置玩家table变量 val类型必须是table var_type 0天变量 1缓存变量 其它正常保存数据库变量
- function API.SetTable(actor, varName, val, var_type)
- if type(val) ~= "table" then
- return
- end
- if var_type == 0 then
- setplaydef(actor, "J$" .. varName, val)
- elseif var_type == 1 then
- setplaydef(actor, "@" .. varName, val)
- else
- setplaydef(actor, "T$" .. varName, val)
- -- info("记录成功",val,getplaydef(actor,"T$"..varName))
- end
- end
- --- 获取玩家Int天变量 默认为0
- function API.GetDayInt(actor, varName)
- local val = getplaydef(actor, "J$" .. varName) or 0
- return val
- end
- ---设置玩家Int天变量 val类型必须是number
- function API.SetDayInt(actor, varName, val)
- if type(val) ~= "number" then
- return
- end
- return setplaydef(actor, "J$" .. varName, val)
- end
- ---获取玩家string类型的天变量 默认为 ""
- function API.GetDayStr(actor, varName)
- local val = getplaydef(actor, "J$" .. varName) or ""
- return val
- end
- ---设置玩家string天变量 val类型必须是string
- function API.SetDayStr(actor, varName, val)
- if type(val) ~= "string" then
- return
- end
- return setplaydef(actor, "J$" .. varName, val)
- end
- ---获取玩家table类型的天变量 默认为 nil
- function API.GetDayTable(actor, varName)
- local val = getplaydef(actor, "J$" .. varName) or nil
- return val
- end
- ---设置玩家table天变量 val类型必须是string
- function API.SetDayTable(actor, varName, val)
- if type(val) ~= "table" then
- return
- end
- return setplaydef(actor, "J$" .. varName, val)
- end
- ---全局变量说明
- ---G$ 服务器重启清除
- ---R$ 保存数据库
- ---Q$ 天变量 每天0点清空
- --- 获取系统Int变量 值默认为0 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
- function API.GetDBNum(varName, varType)
- local fh = "R$"
- if varType == 1 then
- fh = "G$"
- elseif varType == 3 then
- fh = "Q$"
- end
- return getsysvar(fh .. "" .. varName) or 0
- end
- --- 设置系统Int变量 值默认为0 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
- function API.SetDBNum(varName, val, varType)
- if type(val) ~= "number" then
- return
- end
- local fh = "R$"
- if varType == 1 then
- fh = "G$"
- elseif varType == 3 then
- fh = "Q$"
- end
- return setsysvar(fh .. varName, val)
- end
- --- 获取系统string变量 值默认为"" 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
- function API.GetDBStr(varName, varType)
- local fh = "R$"
- if varType == 1 then
- fh = "G$"
- elseif varType == 3 then
- fh = "Q$"
- end
- return getsysvar(fh .. "" .. varName) or ""
- end
- --- 设置系统string变量 值默认为"" 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
- function API.SetDBStr(varName, val, varType)
- if type(val) ~= "string" then
- return
- end
- local fh = "R$"
- if varType == 1 then
- fh = "G$"
- elseif varType == 3 then
- fh = "Q$"
- end
- return setsysvar(fh .. varName, val)
- end
- --- 获取系统string变量 值默认为nil 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
- function API.GetDBTable(varName, varType)
- local fh = "R$"
- if varType == 1 then
- fh = "G$"
- elseif varType == 3 then
- fh = "Q$"
- end
- return getsysvar(fh .. "" .. varName) or nil
- end
- --- 设置系统table变量 值默认为nil 默认类型为2 varType=1 服务器重启清除 =2存入数据库 =3每天0点清除
- function API.SetDBTable(varName, val, varType)
- if type(val) ~= "table" then
- return
- end
- local fh = "R$"
- if varType == 1 then
- fh = "G$"
- elseif varType == 3 then
- fh = "Q$"
- end
- return setsysvar(fh .. varName, val)
- end
- ---战盟变量说明
- ---U$ 无类型限制 存入数据库
- ---消耗 奖励 检查
|