拉取文件方式,涉及文件保存,更新.过于复杂,已弃用
--[[
Author: SLWS_Gao_Q1968023646
Date: 2024-07-30 16:00:01
Description: 元宝转区
--]]
require("Envir/Market_Def/NpcLua/zh.lua")
local tq_util = require("Envir/Market_def/NpcLua/lib/tq_util.lua")
local ini_util = require("Envir/Market_def/NpcLua/lib/ini_util.lua")
local save_path, file_name, file, account, uid, username, sn_file, sn_path
function transfer_init(actor) --全局变量 保存路径初始化
account = getconst(actor, "<$USERACCOUNT>")
uid = getbaseinfo(actor, 2)
username = getconst(actor, "<$USERNAME>")
save_path = "/QuestDiary/转区数据/实时记录/" .. getconst(actor, "<$YEAR>") .. getconst(actor, "<$MONTH>") .. "/"
file_name = account .. ".ini"
file = save_path .. file_name
sn_path = "/QuestDiary/转区数据/历史记录/" .. getconst(actor, "<$YEAR>") .. getconst(actor, "<$MONTH>") .. "/"
end
function gameglod_transfer(actor, num) --转出元宝
local num = tonumber(num) or 0
if num < 24 then
return sendmsg9(actor, "转区元宝数量最低24!")
end
if getingot(actor) < num then
return sendmsg9(actor, "你的元宝不足" .. num .. "个")
end
if server_id == main_server_id then
return gameglod_transfer_ok(actor, num)
end
-- delaygoto(actor, 350, "gameglod_transfer_ok," .. num)
if zq_check_tq_server(actor) then
return delaygoto(actor, 300, "gameglod_transfer_ok," .. num)
end
end
function gameglod_transfer_ok(actor, num) --当前分区写入转区数据
local num = tonumber(num) or 0
transfer_init(actor)
if subingot(actor, num, "人物转区消耗的元宝") then
local date_time_str = os.date("%Y-%m-%d %H:%M:%S", os.time() )
local sn = server_id .. "_" .. uid .. "_" .. os.time() --转区唯一标识
callscriptex(actor, "ForceDirectories", save_path)
local tbl = {
["t_sid"] = server_id,
["t_server_name"] = servername,
["t_uid"] = uid,
["t_username"] = username,
["t_num"] = num,
["g_num"] = math.floor(num / 1.2 ),
["status"] = "未领取",
["sn"] = sn,
["t_time"] = date_time_str,
["g_time"] = "",
["g_uid"] = "",
["g_sid"] = "",
["g_server_name"] = "",
["g_username"] = "",
}
ini_util.init(file)
ini_util.write_many(account, tbl)
sendmsg6(actor, "file=" .. file )
callscriptex(actor, "ForceDirectories", sn_path)
ini_util.init(sn_path .. sn .. ".ini")
ini_util.write_many(sn, tbl)
if server_id ~= main_server_id then
delaygoto(actor, 300, "update_ini_data," .. sn)
end
sendmsg9(actor, "转区元宝扣除成功,转区元宝数量" .. num .. "个")
close(actor)
else
return sendmsg9(actor, "扣除转区元宝失败!转区无法完成")
end
end
function update_ini_data(actor, sn) --清理本地保存的转区数据
updatemaintongfile(main_server_id, ".." .. file)
updatemaintongfile(main_server_id, ".." .. sn_path .. sn .. ".ini")
-- ini_util.init(file)
-- ini_util.del_section(account)
-- ini_util.init(sn_path .. sn .. ".ini")
-- ini_util.del_section(sn)
end
function get_gameglod_transfer(actor) --读取转区数据
if server_id == main_server_id then
return get_gameglod_transfer_ok(actor)
end
if zq_check_tq_server(actor) then
getmaintongfile(main_server_id, ".." .. file)
return delaygoto(actor, 300, "get_gameglod_transfer_ok")
end
end
function get_gameglod_transfer_ok(actor) --转区领取数据更新
transfer_init(actor)
ini_util.init(".." .. file)
local res = ini_util.get_many(account, {"t_sid" ,"status", "g_num", "t_server_name", "t_username", "sn"})
if not res or #res == 0 or res.status == "" then
return sendmsg9(actor, "转区数据读取失败")
end
if res.t_sid == server_id then
return sendmsg9(actor, "不能在同一个区领取转区元宝")
end
if res.status == "已领取" then
return sendmsg9(actor, "没有查询到可领取的转区元宝")
end
if res.status == "未领取" then
local num = tonumber(res.g_num) or nil
if num then
local data = {
["status"] = "已领取",
["g_time"] = os.date("%Y-%m-%d %H:%M:%S", os.time() ),
["g_uid"] = uid,
["g_sid"] = sid,
["g_server_name"] = servername,
["g_username"] = username,
}
ini_util.init(file)
ini_util.write_many(account, data)
sn_file = sn_path .. res.sn .. ".ini"
ini_util.init(sn_file)
ini_util.write_many(res.sn, data)
sendmail("#"..getname(actor), 3, "转区|" .. res.sn, "元宝转区:" .. res.t_server_name .. "区,角色[" .. res.t_username .. "]转入" .. num .. "元宝.", "元宝#".. num .."#0")
sendmsg6(actor, "转区元宝" .. num .. "已发放,请邮件中提取")
sendmsg9(actor, "转区元宝" .. num .. "已发放,请邮件中提取")
if server_id ~= main_server_id then
-- updatemaintongfile(main_server_id, file)
-- updatemaintongfile(main_server_id, sn_path .. sn .. ".ini")
delaygoto(actor, 2000, "update_ini_data," .. sn)
end
close(actor)
else
sendmsg9(actor, "转区元宝数量无法识别!")
end
end
end
function get_gameglod_transfer_info(actor) --点NPC显示转区可以领取的元宝
transfer_init(actor)
ini_util.init(file)
if server_id == main_server_id then
get_gameglod_transfer_info_ok(actor)
end
if zq_check_tq_server(actor) then
getmaintongfile(main_server_id, ".." .. file)
return delaygoto(actor, 300, "get_gameglod_transfer_info_ok")
end
end
function get_gameglod_transfer_info_ok(actor)
transfer_init(actor)
ini_util.init(".." .. file)
sendmsg6(actor, "account=" .. account )
local tbl = {"status", "g_num", "t_sid"}
local res = ini_util.get_many(account, tbl)
local n = 0
sendmsg6(actor, "res=" .. #res)
if not res or #res == 0 or res.t_sid == server_id then --没有拉取到主区转区数据情况
return setint(actor, "转区可领元宝", n)
end
if res.status == "未领取" then
n = tonumber(res.g_num) or 0
end
setint(actor, "转区可领元宝", n)
-- if server_id ~= main_server_id then --清除拉取过来的数据
-- ini_util.del_section(account)
-- end
end
--检查通区状态
function zq_check_tq_server(actor)
if not tq_util.check_isexsit() then
sendmsg6(actor, "无主区设置,联系客服反馈")
return false
end
if server_id == main_server_id then
return true
end
if not tq_util.get_zserver_status() then
sendmsg6(actor, "主区离线,联系客服反馈")
return false
end
return true
end
function transfer_check(actor, sn, str) --检查有没有重复领取
transfer_init(actor)
if server_id == main_server_id then
transfer_check_ok(actor, sn, str)
end
if zq_check_tq_server(actor) then
callscriptex(actor, "ForceDirectories", sn_path .. sn)
getmaintongfile(main_server_id, ".." .. sn_file)
return delaygoto(actor, 300, "transfer_check_ok")
end
end
function transfer_check_ok(actor, sn, str)
sn_file = sn_path .. sn .. ".ini"
ini_util.init(sn_file)
local res = ini_util.get_many(sn, {"status", "g_uid", "g_num"})
if not res or #res == 0 then --没有拉取到主区转区数据,不作校验
return sendmsg6(actor, "转区数据拉取校验失败")
end
local countStart, countEnd = string.find(str, "%d+", countStart) -- 找到所有连续的数字的位置
local countStr = string.sub(str, countStart, countEnd) -- 提取数字部分的字符串
local count = tonumber(countStr) -- 将字符串转换成数字
if res.status == "未领取" then
sendmsg9(actor, "转区元宝领取状态错误,元宝已扣除" .. res.g_num .. "个")
sendmsg6(actor, "转区元宝领取状态错误,元宝已扣除" .. res.g_num .. "个")
subingot(actor, res.g_num, "转区取消的元宝")
elseif res.g_uid ~= uid then
sendmsg6(actor, "uid=" .. uid)
sendmsg6(actor, "g_uid=" .. res.g_uid)
sendmsg9(actor, "转区元宝重复领取,元宝已扣除" .. res.g_num .. "个")
sendmsg6(actor, "转区元宝重复领取,元宝已扣除" .. res.g_num .. "个")
subingot(actor, res.g_num, "转区取消的元宝")
elseif tonumber(res.g_num) ~= count then
sendmsg9(actor, "转区元宝数据错误,元宝已扣除" .. count .. "个")
sendmsg6(actor, "转区元宝数据错误,元宝已扣除" .. count .. "个")
subingot(actor, res.g_num, "转区取消的元宝")
end
end