--------------------------------
-- 文件名       ：  WeekendLoopActRank.lua
-- 文件说明     ：  周末冲刺-排行榜
-- 创建时间     :   2024/12/09
-- 创建人       :   FC
--------------------------------

local Msg = require("core.Msg")
local Util = require("common.Util")
local Lang = require("common.Lang")
local CommonRankDB = require("common.CommonRankDB")
local OpenServerRankDB = require("present.OpenServerRankDB")
local Broadcast = require("broadcast.Broadcast")
local OpenAct = require("present.OpenAct")
local YunYingLogic = require("yunying.YunYingLogic")
local DrawCardLogic = require("drawCard.DrawCardLogic")
local CommonDefine = require("common.CommonDefine")

--[[
    local:

	public:
    	query()					            -- 发送活动信息
        onCharge()			                -- 充值回调
        WeekActRank_ResetData(human)        -- 重置玩家身上的充值
        WeekActRank_ResetDBData()           -- 重置排行榜数据
--]]

----------------------------------------- 内部处理开始 -------------------------------------
-- 重置
function WeekActRank_ResetCharge(human)
    -- if not human then
    --     return
    -- end

    -- human.db.nWeekCharge = 0
end

-- 获取充值额度
function WeekActRank_GetCharge(human)
    -- if not human then
    --     return 0
    -- end

    -- if not human.db.nWeekCharge then
    --     WeekActRank_ResetCharge(human)
    -- end

    -- return human.db.nWeekCharge
end

-- 设置充值额度
function WeekActRank_GetCharge(human, nVal)
    -- if not human or 0 >= nVal then
    --     return
    -- end

    -- if not human.db.nWeekCharge then
    --     WeekActRank_ResetCharge(human)
    -- end

    -- human.db.nWeekCharge = human.db.nWeekCharge + nVal
end


----------------------------------------- 外部调用 -------------------------------------
function WeekActRank_ResetData(human)
    if not human then
        return
    end
    
    --WeekActRank_ResetCharge(human)
end

function WeekActRank_ResetDBData()
    -- CommonRankDB.ResetData() 
end

-- 活动结束
function WeekActRank_End()
    CommonRankDB.onRewardSend(CommonDefine.COMMONRANK_TYPE_WEEKRANK)
end

-- 充值回调
function onCharge(human, price, funcID, buyID)
    CommonRankDB.onValueAdd(human, CommonDefine.COMMONRANK_TYPE_WEEKRANK, price)
end

----------------------------------------- 外部调用 -------------------------------------

-- 客户端请求
function WeekActRank_Query(human)
    local nRankType = CommonDefine.COMMONRANK_TYPE_WEEKRANK
	local maxSendRank = CommonRankDB.getMaxSendRank(nRankType)

	local msgRet = Msg.gc.GC_WEEKLOOP_ACT_RANK_QUERY
	
	CommonRankDB.wrapOwnerData(nRankType, msgRet.ownerData, human.db._id)
	
    for rank = 1,maxSendRank do
		CommonRankDB.wrapOpenServerRankList(nRankType, msgRet.list[rank], rank)
	end
    
	msgRet.list[0] = maxSendRank

	Msg.send(msgRet, human.fd)
end

