----- 个人注册函数库 Func = {} Func.color_tbl = require("Envir/QuestDiary/cfgcsv/cfg_颜色对应表") ---* 加载策划表 ---* csv表名 ---* 是加载到玩家上线同步表 ---@param csvFile any function Func.require(csvFile) local tbl = require("Envir/QuestDiary/cfgcsv/" .. csvFile) return tbl end --批量判定(扣除)物品货币是否满足条件 ---* 参数1 玩家对象 ---* 参数2 物品tbl ---* 参数3 是否扣除(true or false) ---* 参数4 是否提示不足 function Func.takeitmes(actor, tbl, istake, msg) if not isnotnull(actor) then return end if tbl == nil then return end if istake == nil then istake = true end for i, v in ipairs(tbl or {}) do local itemidx = getstditeminfo(v[1], 0) if itemidx < 100 then if Func.checkortakemoney(actor, v[1], v[2], v[3], false, msg) == false then return false end else if Func.checkortakeitem(actor, v[1], v[2], true, v[3] > 0 and true or false, msg) == false then return false end end end if istake then for i, v in ipairs(tbl or {}) do local itemidx = getstditeminfo(v[1], 0) if itemidx < 100 then Func.checkortakemoney(actor, v[1], v[2], v[3], true, msg) else Func.checkortakeitem(actor, v[1], v[2], false, v[3] > 0 and true or false, msg) end end end return true end --批量判定(扣除)物品货币是否满足条件 ---* 参数1 玩家对象 ---* 参数2 物品tbl ---* 参数3 是否扣除(true or false) ---* 参数4 是否提示不足 function Func.batchcheckitem(actor, tbl, istake, msg) if not isnotnull(actor) then return end if tbl == nil then return end if istake == nil then istake = true end for i, v in ipairs(tbl or {}) do local itemidx = getstditeminfo(v[1], 0) if itemidx < 100 then if Func.checkortakemoney(actor, v[1], v[2], v[3], false, msg) == false then return false end else if Func.checkortakeitem(actor, v[1], v[2], true, v[3] > 0 and true or false, msg) == false then return false end end end if istake then for i, v in ipairs(tbl or {}) do local itemidx = getstditeminfo(v[1], 0) if itemidx < 100 then Func.checkortakemoney(actor, v[1], v[2], v[3], true, msg) else Func.checkortakeitem(actor, v[1], v[2], false, v[3] > 0 and true or false, msg) end end end return true end ---* 检查或拿走货币 ---* 参数1 玩家对象 ---* 参数2 货币名字 ---* 参数3 货币数量 ---* 参数4 使用多货币,默认不使用 0=不使用,1=使用 ---* 参数5 是否检查模式(不减少货币) true=扣除,false=不扣除 ---* 参数6 提示信息 为空默认通知 flase 不通知 function Func.checkortakemoney(actor, moneyname, moneycount, isbind, ischeck, s_msg) if actor == nil then return false end if moneyname == nil then return false end if moneycount == nil then return false end if isbind == nil then return false end if ischeck == nil then ischeck = false end if s_msg == nil then s_msg = true end -- release_print( moneyname, moneycount, isbind, ischeck) local moneyidx = getstditeminfo(moneyname, 0) local guanlian_money = getstditeminfo(moneyname, 11) --判定是否判定货币 if guanlian_money == "关联货币" then if isbind == 1 then if getbindmoney(actor, moneyname) >= moneycount then if ischeck == true then consumebindmoney(actor, moneyname, moneycount) return true else return true end else if s_msg then Func.sendmsg9(actor, "[系统提示:]#70|你的#251|" .. moneyname .. "#215|不足#251|" .. moneycount .. "#215|!#251") end return false end else if querymoney(actor, moneyidx) >= moneycount then if ischeck == true then if changemoney(actor, moneyidx, "-", moneycount, "通用扣货币", true) then return true else return false end end else if s_msg then Func.sendmsg9(actor, "[系统提示:]#70|你的#251|" .. moneyname .. "#215|不足#251|" .. moneycount .. "#215|!#251") end return false end end else if querymoney(actor, moneyidx) >= moneycount then if ischeck == true then if changemoney(actor, moneyidx, "-", moneycount, "通用扣货币", true) then return true else return false end end else if s_msg then Func.sendmsg9(actor, "[系统提示:]#70|你的#251|" .. moneyname .. "#215|不足#251|" .. moneycount .. "#215|!#251") end return false end end end -- 检查或拿走物品 ---* 参数1 玩家对象 ---* 参数2 物品名字 ---* 参数3 物品数量 ---* 参数4 是否检查模式(true=不拿走物品) ---* 参数5 是否检查已装备 false=不检查 true= 检查 ---* 参数6 提示信息 为空默认通知 flase 不通知 function Func.checkortakeitem(actor, itemName, itemcount, take, ischeck, s_msg) if not actor then callscriptex(actor, "sendmsg", "9", "[系统提示]:人物对象错误!") return false end if itemName == nil then callscriptex(actor, "sendmsg", "9", "[系统提示]:物品名称错误!") return false end if itemcount == nil or itemcount <= 0 then callscriptex(actor, "sendmsg", "9", "[系统提示]:物品数量错误!") return false end if ischeck == nil then ischeck = false end if s_msg == nil then s_msg = true end local itemcount = tonumber(itemcount) local bagitemnum = getbagitemcount(actor, itemName) local checkbag = false if not ischeck then if bagitemnum < itemcount then checkbag = false else if take == false then if takeitem(actor, itemName, itemcount, 0) then checkbag = true else checkbag = false end else checkbag = true end end end if ischeck then if checkitemw(actor, itemName, itemcount) then if take == false then if takew(actor, itemName, itemcount) then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|" .. itemName .. "#215|不足#251|" .. itemcount .. "#215|!#251") end return false end else return true end else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|" .. itemName .. "#215|不足#251|" .. itemcount .. "#215|!#251") end return false end else if checkbag then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|" .. itemName .. "#215|不足#251|" .. itemcount .. "#215|!#251") end return false end end end --自定义sendmsg 9 自定义颜色 --- *参数1 玩家对象 --- *参数2 消息内容 格式 文本#颜色|文本#颜色 (颜色值0-255) --- *参数3 发送消息类型 function Func.sendmsg9(actor, str, _type) if str == nil or str == "" then return end if not isplayer(actor) then return end local content = "" local part = Func.splitString(str, "|") for k, v in pairs(part) do local text = Func.splitString(v, "#") local colornum = tonumber(text[2]) if colornum == nil then colornum = 251 end content = content .. "" .. text[1] .. "" end if content ~= "" then -- callscriptex(actor, "sendmsg", 9, content) sendmsg(actor, 1, '{"Msg":"' .. content .. '","FColor":255,"BColor":0,"Type":' .. (_type ~= nil and _type or 9) .. ',"Time":1}') end end function Func.sendmsg(actor, str, _type) if not str then return end if not isplayer(actor) then return end local new_str = {} if string.match(str, "|") then local part = Func.splitString(str, "|") for i, v in ipairs(part) do local text = Func.splitString(v, "#") local colornum = tonumber(text[2]) if colornum == nil then table.insert(new_str, v) else table.insert(new_str, "" .. text[1] .. "") end end else table.insert(new_str, str) end local msg = { ["Msg"] = table.concat(new_str), ["FColor"] = 255, ["BColor"] = 0, ["Type"] = 1, } sendmsg(actor, _type and _type or 1, tbl2json(msg)) end -- 折分字符串 -- 参数1 待拆分字符 -- 参数2 分割字符 如:* function Func.splitString(str, delimiter) local result = {} local pattern = string.format("([^%s]+)", delimiter) str:gsub(pattern, function(item) table.insert(result, item) end) return result end ---* 百分比几率检查 ---* 种子 function Func.random(num, seed) seed = seed or 100 local random_ex = math.random(1, seed) if random_ex <= num then return true else return false end end ----* 设置战斗状态 function Func.setzhandouu(actor) local state = GetInt(0, actor, VarCfg.playerInt.ZhanDou) local nowTimw = os.time() if nowTimw > state then Player.setstr(actor, VarCfg.playerInt.ZhanDou, nowTimw + ConstCfg.zhandou_time) end end ----* 检测战斗状态 function Func.getzhandou(actor) local state = GetInt(0, actor, VarCfg.playerInt.ZhanDou) local nowTimw = os.time() if nowTimw < state then return true else return false end end Check_contrast = { ["等于"] = function(a, b) if a == b then return true else return false end end, ["大于"] = function(a, b) if a > b then return true else return false end end, ["小于"] = function(a, b) if a < b then return true else return false end end, ["大于等于"] = function(a, b) if a >= b then return true else return false end end, ["小于等于"] = function(a, b) if a <= b then return true else return false end end, ["不等于"] = function(a, b) if a ~= b then return true else return false end end, ["不小于"] = function(a, b) if a >= b then return true else return false end end, ["不大于"] = function(a, b) if a < b then return true else return false end end, ["包含"] = function(a, b) if string.find(a, b, 1, true) ~= nil then return true else return false end end, } Check_cond_tbl = { ["检测合区"] = function(actor, tbl, mode, s_msg) if not s_msg then s_msg = false end local num = globalinfo(3) if num > tbl[2] then return false else return true end end, ["检测货币"] = function(actor, tbl, mode, s_msg) if mode == nil then mode = false end if not s_msg then s_msg = false end if Func.checkortakemoney(actor, tbl[2], tbl[3], tbl[4] and tbl[4] or 0, mode, s_msg) == false then return false else return true end end, ["检测物品"] = function(actor, tbl, mode, s_msg) if mode == nil then mode = false end if not s_msg then s_msg = false end if mode then mode = false else mode = true end if Func.checkortakeitem(actor, tbl[2], tbl[3], mode, false, s_msg) == false then return false else return true end end, ["检测等级"] = function(actor, tbl, mode, s_msg) if not s_msg then s_msg = false end if getbaseinfo(actor, ConstCfg.gbase.level) >= tbl[2] then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|等级不足#251|" .. tbl[2] .. "级#215|!#251") end return false end end, ["检测称号"] = function(actor, tbl, mode, s_msg) if not s_msg then s_msg = false end if checktitle(actor, tbl[2]) then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|您还没有#251|" .. tbl[2] .. "#215|称号!#251") end return false end end, ["检测转生"] = function(actor, tbl, mode, s_msg) if not s_msg then s_msg = false end local func = Check_contrast[tbl[2]] if func then if func(getbaseinfo(actor, ConstCfg.gbase.renew_level), tbl[3]) then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|转生不足#251|" .. tbl[3] .. "转#215|!#251") end return false end end end, ["检测狂暴"] = function(actor, tbl, mode, s_msg) if not s_msg then s_msg = false end if checktitle(actor, "狂暴之力") then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|你还未开启#251|狂暴之力#215|!#251") end return false end end, ["检测键值数字"] = function(actor, tbl, mode, s_msg) if not tbl then return false end if not s_msg then s_msg = false end local func = Check_contrast[tbl[4]] if func then local num = Func.getkeycount(actor, tbl[2], tbl[3]) or 0 -- LOGPrint(num,tbl[5]) if func(num, tbl[5]) then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|条件不满足!#251") end return false end end end, ["比较数字变量"] = function(actor, tbl, mode, s_msg) if not s_msg then s_msg = false end local func = Check_contrast[tbl[4]] if func then local var = 0 if tbl[3] == "永久" then var = Player.getint(actor, tbl[2]) elseif tbl[3] == "临时" then var = Player.gettempint(actor, tbl[2]) elseif tbl[3] == "周期" then var = Player.getTLint(actor, tbl[2]) end if func(var, tbl[5]) then return true else if tbl[6] and s_msg then Func.sendmsg9(actor, string.format("[系统提示]:#70|%s%d!#251", tbl[6], tbl[5])) end return false end end end, ["检测标识"] = function(actor, tbl) if getflagstatus(actor, tbl[2]) == tbl[3] then return true else return false end end, ["检测文本变量"] = function(actor, tbl) if not tbl[4] then tbl[4] = "" end local func = Check_contrast[tbl[3]] if func then if func(getplaydef(actor, tbl[2]), tbl[4]) then return true else return false end end end, ["检测文本包含"] = function(actor, tbl) if not tbl then return end local value = getplaydef(actor, tbl[2]) if string.match(value, tbl[3]) then return true end return false end, ["检测日期区间"] = function(actor, tbl, mode, s_msg) local function isDateInRange(startDate, endDate) local currentDate = os.date("%Y-%m-%d") return currentDate >= startDate and currentDate <= endDate end if isDateInRange(tbl[2], tbl[3]) then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|不在活动时间内:#251|" .. tbl[2] .. "#215|至#251|" .. tbl[3] .. "#215|!") end return false end end, ["检测属性"] = function(actor, tbl, mode, s_msg) s_msg = s_msg or false local func = Check_contrast[tbl[3]] local att = getbaseinfo(actor, ConstCfg.gbase.custom_attr, tbl[2]) if func then if func(att, tbl[4]) then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|" .. tbl[5] .. "不足#251|" .. tbl[4] .. "!#215") end return false end end end, ["检测地图怪物数量"] = function(actor, tbl, mode, s_msg) s_msg = s_msg or false local mon = getmoncount(getbaseinfo(actor, ConstCfg.gbase.mapid), -1, true) if mon == tbl[2] then return true else if s_msg then Func.sendmsg9(actor, "[系统提示]:#70|当前地图怪物数量:#251|" .. mon .. "只#215|,大于#251|" .. tbl[2] .. "#215|,请先清理!") end return false end end, ["穿戴装备"] = function(actor, tbl, mode,s_msg) s_msg = s_msg or false local mon = getmoncount(getbaseinfo(actor, ConstCfg.gbase.mapid), -1, true) if checkitemw(actor,tbl[2],tbl[3]) then return true else -- if s_msg then -- Func.sendmsg9(actor, "[系统提示]:#70|未穿戴装备:#251|" .. tbl[2] .. "#215|" .. tbl[3] .. "件#215|!") -- end return false end end, } ---* 批量判定条件 ---* 参数一 玩家对象 ---* 参数二 检查表 ---* 检测模式 flase = 检测 true = 扣除 ---* 参数四 条件不足时 是否通知 false = 不通知 true = 通知 function Func.checkcontion(actor, tbl, mode, s_msg) if tbl == nil then return true end if not mode then mode = false end if not s_msg then s_msg = false end local tbl_num = 0 for i, v in pairs(tbl) do local func = Check_cond_tbl[v[1]] if func then if func(actor, v, false, s_msg) then tbl_num = tbl_num + 1 else break end end end if tbl_num == #tbl then if mode then local tbl_num = 0 for k, v in pairs(tbl) do local func = Check_cond_tbl[v[1]] if func then if func(actor, v, true, s_msg) then tbl_num = tbl_num + 1 end end end if tbl_num == #tbl then return true else return false end else return true end else return false end end function Func.messagebox(actor, str, flag1, flag2, strZise) if not str then return end if not strZise then strZise = 16 end local new_str = {} if string.match(str, "|") then local part = Func.splitString(str, "|") for i, v in ipairs(part) do local text = Func.splitString(v, "#") local colornum = tonumber(text[2]) if colornum == nil then table.insert(new_str, v) else table.insert(new_str, "" .. text[1] .. "") end end else table.insert(new_str, str) end local msg = { ["Msg"] = table.concat(new_str), ["FColor"] = 255, ["BColor"] = 0, ["Type"] = 1, } messagebox(actor, table.concat(new_str), flag1, flag2) end --发送邮件 ---* 参数1 玩家对象 ---* 参数2 物品内容table ---* 参数3 邮件标签 function Func.mailitem(player, tbl, little) if tbl == nil then return end if little == "" or little == nil then return end local mailconst = {} for i, v in ipairs(tbl) do table.insert(mailconst, string.format("%s#%d#%d", v[1], v[2], v[3])) end if mailconst ~= "" then sendmail(getbaseinfo(player, 2), 1, little, "您的<" .. little .. "/FCOLOR=215>奖励已到达,请点击提取!\\<请注意,系统仅保留最多99封邮件,请及时提取和删除!/FCOLOR=249>", table.concat(mailconst, "&")) Func.sendmsg9(player, "恭喜您获得#251|[" .. little .. "]#215|奖励,已发送到邮件,请查收!#251") local post = {} post["玩家名"] = Player.getname(player) post["邮件标题"] = little post["邮件物品"] = table.concat(mailconst, "|") Func.post("diymail", post) return true else return false end end ---* 合并消耗表 ---* 主表 ---* 次表 ---@param t1 any ---@param t2 any function Func.deep_merge(t1, t2) local new_t = {} for i, v in ipairs(t1) do local item1 = v[1] local found = false for t2_key, t2_v in ipairs(t2) do local item2 = t2_v[1] if item1 == item2 then found = true table.insert(new_t, { item1, t2_v[2] + v[2], v[3] }) end end if not found then table.insert(new_t, v) end end return new_t end ---* post系统 Func.posturl = "http://10.10.10.3/api/data-package?token=kj1L9Qe7aKFqpKvtZj5eUXSew94qLmw6" -- Func.posturl = "http://121.41.174.236:8081/api/table/" -- -- ---* tablename 操作表名 ---* postData post信息 Func.postData = {} function Func.post(tablename, postData) postData["表名"] = string.format("%s_%s", ConstCfg.sever.name, tablename) postData["区服"] = GetServerName() ~= "" and GetServerName() or "本地工具服" postData["时间"] = os.time() table.insert(Func.postData, postData) if #Func.postData > 1 then httppost(string.format("%s", Func.posturl), 0, tbl2json(Func.postData)) -- LOGDump(Func.postData) -- httppost(string.format("%s%s?token=kj1L9Qe7aKFqpKvtZj5eUXSew94qLmw6", Func.posturl,tablename), tbl2json(Func.postData),'{}') Func.postData = {} end end ----* 批量给物品,背包不足时自动发送邮件 function Func.givesitem(actor, itemData, title, sendgbox) if not itemData or not isnotnull(actor) then LOGPrint("发送物品表错误...请联系管理员") return false end if getflagstatus(actor, VarCfg.Falg_fangshua) == 0 then return false end local itemNum = 0 for i, v in ipairs(itemData or {}) do local itemIndex = getstditeminfo(v[1], 0) if itemIndex >= 50000 then itemNum = itemNum + v[2] elseif itemIndex > 100 then local OverLap = getdbitemfieldvalue(itemIndex, ConstCfg.ItemConfig[15][1]) if OverLap == 0 then itemNum = itemNum + v[2] else itemNum = itemNum + math.floor(v[2] / OverLap) end end end setflagstatus(actor, VarCfg.Falg_fangshua, 0) if sendgbox then Message:SubLink(actor, "GivesTipsOBJ_main", itemData) end if getbagblank(actor) > itemNum then local giveStr = {} for i, v in ipairs(itemData or {}) do table.insert(giveStr, table.concat(v, "#")) end gives(actor, table.concat(giveStr, "&")) local post = {} post["玩家名"] = Player.getname(actor) post["邮件标题"] = title post["邮件物品"] = table.concat(giveStr, "|") Func.post("diymail", post) return true else return Func.mailitem(actor, itemData, title) end end return Func