This commit is contained in:
aixianling
2024-12-16 13:51:31 +08:00
commit 00ee9dd8ea
1884 changed files with 817815 additions and 0 deletions

View File

@@ -0,0 +1,665 @@
module("ActivityDispatcher", package.seeall)
--[[
个人数据ActorData[AtvId]
{
openTimes, 该全局活动的参与标记
}
全局数据GlobalData[AtvId]
{
openTimes, 该全局活动的开启次数
}
缓存数据CacheData[atvId]
{
fbHandle, 当前活动的副本句柄
}
]]--
local dispatcher = { }
_G.ActivityEvent =
{
OnLoad = 1, --活动加载 [活动id] 注意:若为个人活动,传入 '玩家指针'
OnInit = 2, --活动初始化 [活动id玩家指针] 注意用于处理再次开启的全局活动同一活动id重置初始化旧数据
OnStart = 3, --活动开始 [活动id] 注意:若为个人活动,传入 '玩家指针'
OnEnd = 4, --活动结束 [活动id] 注意:若为个人活动,传入 '玩家指针'
OnUpdate = 5, --活动帧更新 [活动id当前时间] 注意:若为个人活动,传入 '玩家指针'
OnReqData = 6, --请求活动数据 [活动id, 玩家指针, outPack]
OnOperator = 7, --通用操作 [活动id玩家指针inPack]
OnEnterArea = 8, --进入活动区域 [活动id, 玩家指针]
OnExitArea = 9, --离开活动区域 [活动id, 玩家指针]
OnEnterFuben = 10, --玩家进入活动副本[活动id玩家指针副本指针, pOwner]
OnExitFuben = 11, --玩家离开活动副本[活动id玩家指针副本指针, pOwner]
OnEntityDeath = 12, --副本实体死亡 [活动id, 被杀者指针,击杀者指针,副本指针, pOwner]
OnEntityAttacked= 13, --活动副本实体受击[活动id, 副本指针,受击者,攻击者, pOwner]
OnFubenFinish = 14, --活动副本结束 [活动id, 副本指针,结果, pOwner] 1为完成0为失败nil则结果未知需要对应副本设置结果
OnReqFubenAward = 15, --请求副本结算 [活动id, 副本指针pActor, pOwner]
OnGetRedPoint = 16, --请求红点数据 [活动id, 玩家指针] 返回值为红点值
OnLoginGame = 17, --登录游戏 [活动id玩家指针] 活动登录事件 //登陆时活动如果开启会触发
OnUpdateActivity= 18, --更新数据 [活动id玩家指针] 注意:若为个人活动,传入 '玩家指针'
OnAtvAreaDeath = 19, --普通场景活动区域死亡 [活动id玩家指针]
OnCombineSrv = 20, --合服后首次登陆 [活动id合服后的开服天数差值玩家指针] 个人活动
OnGPStart = 21, --全局个人活动的玩家Start [活动id玩家指针] Global_Person_Activity
OnGPEnd = 22, --全局个人活动的玩家End [活动id玩家指针] Global_Person_Activity
OnAtvGG = 23, --活动复活结束 [活动id玩家指针]
OnAtvAreaAtk = 24, --普通场景活动区域实体受击 [活动id受击者攻击者]
OnOnAtvRank = 25, --活动排行榜 [活动id当前时间]
Count = 26,
}
--通用操作协议枚举
_G.ActivityOperate = {
cEnterFuben = 1, --请求进入副本
cGetPhaseAward = 2, --请求领取阶段奖励
cWorship = 3, --请求膜拜操作
cAppraisal = 4, --请求鉴定操作
cGetPersonBox = 5, --请求个人奖励 --npc活动
cGetTreasure = 6, --送宝、排名奖励 --npc活动
cGetBonusNum = 7, --npc请求剩余奖励数量 --独闯天涯
cInspire = 8, --鼓舞 --boss
cGetMonsterNum = 9, --npc请求当前杀怪数 --独闯天涯
cReqAtvQianDao = 10, --打卡活动,请求打卡
cReqLeijichongzhiGift = 11, --请求领取累计充值奖励 --累计充值活动
cReqPurchaseGiftbag = 12, --请求购买特惠礼包/领取首冲奖励/七天登录领奖/打卡活动领奖
cReqPurchaseJiJin = 13, --请求购买基金
cReqGetJiJinAward = 14, --请求领取基金奖励
cReqGetAchieveAward = 15, --请求达标类对应奖励
cReqSaoDang = 16, --扫荡
cReqXunBao = 17, --寻宝 抽奖活动(开服特定寻宝)
cActiveOrderWar = 18, --激活战令
cBuyOrderWarLv = 19, --购买战令等级
cDeleteItem = 20, --删除道具
cGetAllAward = 21, --战令一键领取
cGetZLAward = 22, --战令领取
cGetQuestAward = 23, --任务领取
cDonateRank = 24, --捐献
cReqExchange = 25, --兑换
cZLShopInfo = 26, --战令商店
cBuyZLShop = 27, --购买战令数据
cCheckCSActivity = 28, --跨服入口支持
sSendRankData = 1, --广播排行数据 -- 竞技大乱斗
sSendMyRankData = 2, --发送自己的排行数据 -- 竞技大乱斗
sSendPhaseAward = 3, --发送奖励内容
sEnterFubenResult = 4,--进入活动副本的结果回复
sWorship = 5, --回复膜拜操作
sAppraisal = 6, --回复鉴定操作
sNextAwardIndex = 7, --下一个奖励的索引
sSendPersonBox = 8, --回复个人奖励请求 --npc活动
sSendBigTreasure = 9, --回复送宝、排名奖励 --NPC活动
sSendTime = 10, --发送时间
sSendBonusNum = 11, --回复剩余奖励数量 --独闯天涯
sInspire = 12, --返回鼓舞id --boss
sSendMonsterNum = 13, --回复npc请求当前杀怪数 --独闯天涯
sSendAssignCampTime =14, --发送阵营调整时间 --沃玛三
sSendActorDataTimes = 15, --回复玩家数据 --累计充值活动灰按钮/特惠礼包活动回复玩家参与次数
sSendChouJiangResult = 16, --回复寻宝/抽奖结果 --寻宝活动
sSendzhushoustatus = 17, --回复驻守开始
sSendWorldBossTime = 18, --世界boss 剩余时间
sDuoBaoPickLeftTime = 19, --夺宝 剩余时间
sZLShopInfo = 20, --战令商店
sZLBuyShop = 21, --购买战令商品
sZLShopChange = 22, --战令商品发生变化
sCSSBKGuildRank = 23, --前四名跨服沙巴克排行
sCSSBKMyGuildRank = 24, --个人工会排名
sCSSBKMyRank = 25, --个人排名
sCheckCSActivity = 28, --跨服入口支持
}
--------------------------------------------------------------------
-- Lua接口
--------------------------------------------------------------------
-- @brief 注册事件分发器
-- @param evId 事件id
-- @param atvType 活动类型
-- @param func 回调
function Reg(evId, atvType, func, file)
--参数检查
if atvType == nil or evId == nil or func == nil or file == nil then
print( debug.traceback() )
assert(false)
end
--事件范围检查
if evId <= 0 or evId >= ActivityEvent.Count then
assert(false)
end
--回调表初始化
if dispatcher[evId] == nil then
dispatcher[evId] = {}
end
if dispatcher[evId][atvType] ~= nil then
assert(false) -- 重复注册了
end
--注册
dispatcher[evId][atvType] = func
print("[TIP][ActivityDispatcher] Add Activity(Type:"..atvType..") Event("..evId..") In File("..file.."), And Index="..table.maxn(dispatcher[evId]))
end
-- @brief 获取某个活动的全局数据(这个数据,是存文件的)
-- @param atvId 活动id
function GetGlobalData(atvId)
if atvId == nil then
assert(false)
end
local var = System.getStaticVar();
if var.Activity == nil then
var.Activity = {}
end
if var.Activity[atvId] == nil then
var.Activity[atvId] = {}
end
return var.Activity[atvId]
end
-- @brief 清空某个活动的全局数据(这个数据,是存文件的)
-- @param atvId 活动id
function ClearGlobalData(atvId)
if atvId == nil then
assert(false)
end
local var = System.getStaticVar();
if var.Activity == nil then
var.Activity = {}
end
if var.Activity[atvId] then
var.Activity[atvId] = nil
end
end
-- @brief 获取某个活动的缓存数据(这个数据,不存储仅缓存)
-- @param fbId 活动id
function GetCacheData(atvId)
if atvId == nil then
assert(false)
end
local var = System.getDyanmicVar();
if var.Activity == nil then
var.Activity = {}
end
if var.Activity[atvId] == nil then
var.Activity[atvId] = {}
end
return var.Activity[atvId]
end
-- @brief 清空某个活动的缓存数据(这个数据,不存储仅缓存)
-- @param fbId 活动id
function ClearCacheData(atvId)
if atvId == nil then
assert(false)
end
local var = System.getDyanmicVar();
if var.Activity == nil then
var.Activity = {}
end
if var.Activity[atvId] then
var.Activity[atvId] = nil
end
end
-- @brief 获取某个活动的个人数据(这个数据,是存数据库的)
-- @param atvId 活动id
function GetActorData(pActor, atvId)
if atvId == nil or Actor.getEntityType(pActor) ~= enActor then
assert(false)
end
local var = Actor.getStaticVar(pActor);
if var.Activity == nil then
var.Activity = {}
end
if var.Activity[atvId] == nil then
var.Activity[atvId] = {}
end
return var.Activity[atvId]
end
-- @brief 清空某个活动的个人数据(这个数据,是存数据库的)
-- @param atvId 活动id
function ClearActorData(pActor, atvId)
if atvId == nil or Actor.getEntityType(pActor) ~= enActor then
assert(false)
end
local var = Actor.getStaticVar(pActor);
if var.Activity == nil then
var.Activity = {}
end
if var.Activity[atvId] then
local openTimes = var.Activity[atvId].openTimes
var.Activity[atvId] = {}
var.Activity[atvId].openTimes = openTimes
end
end
-- @brief 分配一个通用旗帜结果包需要外部自己调用flush方法
-- @note result 0失败 1成功
function AllocResultPack(pActor, atvId, result)
local npack = DataPack.allocPacket(pActor, enActivityID, SActivityResult)
if npack then
DataPack.writeUInt(npack, atvId)
DataPack.writeByte(npack, (result or 0))
end
return npack
end
-- @brief 分配一个通用旗帜结果包注意这是广播包需要外部自己调用FreePacketEx释放包
function AllocResultPackEx(atvId, result)
local npack = DataPack.allocPacketEx()
if npack then
DataPack.writeUInt(npack, atvId)
DataPack.writeByte(npack, (result or 0))
end
return npack
end
-- @brief 分配一个通用回复包需要外部自己调用flush方法
function AllocOperReturn(pActor, atvId, operaCode)
local npack = DataPack.allocPacket(pActor, enActivityID, sActivityOperator)
if npack then
DataPack.writeUInt(npack, atvId)
DataPack.writeByte(npack, operaCode)
end
return npack
end
-- @brief 分配一个通用回复包注意这是广播包需要外部自己调用FreePacketEx释放包
function AllocOperReturnEx(atvId, operaCode)
local npack = DataPack.allocPacketEx()
if npack then
DataPack.writeByte(npack,enActivityID)
DataPack.writeByte(npack,sActivityOperator)
DataPack.writeUInt(npack,atvId)
DataPack.writeByte(npack,operaCode)
end
return npack
end
-- @brief 释放一个通用回复(注意:这是广播包)
function FreePacketEx(npack)
if npack then
DataPack.freePacketEx(npack)
end
end
-- @brief 进入活动副本
function EnterFuben(atvId,pActor,fbId)
local result = Actor.reqEnterFuben(pActor, fbId)
if result then
-- 回复活动id与副本句柄的关联
local npack = AllocOperReturn(pActor, atvId, ActivityOperate.sEnterFubenResult)
if npack then
DataPack.flush(npack)
end
-- 建立副本类型跟活动类型的对应关系
local fbHandle = Actor.getFubenHandle(pActor)
local pFuben = Fuben.getFubenPtrByHandle(fbHandle)
local atvType = 0
if (ActivitiesConf[atvId] and ActivitiesConf[atvId].ActivityType) then
atvType = ActivitiesConf[atvId].ActivityType
elseif (PActivitiesConf[atvId] and PActivitiesConf[atvId].ActivityType) then
atvType = PActivitiesConf[atvId].ActivityType
end
FubenDispatcher.MapToActivity(pFuben, atvType, atvId)
return fbHandle
end
return nil
end
-- @brief 通过活动id获取对应副本
-- @param atvId 活动id
-- @return 副本指针
function GetFuben(atvId)
local atvCacheData = GetCacheData(atvId)
local fbHandle = atvCacheData.fbHandle
if fbHandle then
local pFuben = Fuben.getFubenPtrByHandle(fbHandle)
if pFuben then
local nAtvId = FubenDispatcher.GetActivityId(pFuben)
if nAtvId == atvId then
return pFuben
end
end
end
end
-- @brief 发送活动弹框
-- @param pActor 玩家指针
-- @param atvId 活动id
function SendPopup(pActor, atvId)
local npack = DataPack.allocPacket(pActor, enActivityID, SActivityPopup)
if npack then
DataPack.writeUInt(npack, atvId)
DataPack.flush(npack)
end
end
-- @brief 广播活动弹框
-- @param atvId 活动id
-- @param fbHandle 副本句柄
-- @param sceneId 场景id
function BroadPopup(atvId)
--等级 转生限制
local lv = 0;
local zsLv = 0;
local Cfg = ActivitiesConf[atvId];
if Cfg then
if Cfg.TipsLevelLimit then
lv = Cfg.TipsLevelLimit.level
zsLv = Cfg.TipsLevelLimit.zsLevel
end
end
local npack = DataPack.allocPacketEx()
if npack then
DataPack.writeByte(npack,enActivityID)
DataPack.writeByte(npack,SActivityPopup)
DataPack.writeUInt(npack,atvId)
DataPack.broadcasetWorld(npack, lv, zsLv)
DataPack.freePacketEx(npack)
end
end
--------------------------------------------------------------------
-- CPP回调
--------------------------------------------------------------------
function CheckInitActivity(atvType, atvId, pActor)
local globalData = GetGlobalData(atvId)
local actorData = GetActorData(pActor, atvId)
if globalData.openTimes ~= actorData.openTimes then
local callbacks = dispatcher[ActivityEvent.OnInit]
if callbacks[atvType] then
local func = callbacks[atvType]
func(atvId, pActor)
end
actorData.openTimes = globalData.openTimes
print("[全局活动id"..atvId.."初始化] 重置开启次数:"..(globalData.openTimes or 0).." 玩家:"..Actor.getName(pActor))
end
end
function CheckReqData(func, atvType, atvId, pActor, outPack)
--print("[Activity"..atvType.."."..atvId.."] "..Actor.getName(pActor).." 请求活动数据!")
-- 红点值
local val = 0
local callbacks = dispatcher[ActivityEvent.OnGetRedPoint]
if callbacks and (callbacks[atvType] ~= nil) then
local result = callbacks[atvType](atvId, pActor)
val = result or 0
end
DataPack.writeByte(outPack, val)
-- 活动详细数据
if func then
func(atvId, pActor, outPack)
end
end
function OnEvent(evId, atvType, atvId, ...)
--获取回调
local callbacks = dispatcher[evId]
--回调调用
if evId == ActivityEvent.OnLoad then --活动加载(数据库来的)
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnStart then --活动开启
-- 周循环活动,需要记录开启次数
if ActivitiesConf[atvId] then
local globalData = GetGlobalData(atvId)
if globalData.openTimes == nil then
local currentId = System.getCurrMiniTime();
globalData.openTimes = currentId
else
globalData.openTimes = globalData.openTimes + 1
end
print("[全局活动id"..atvId.."开始] 记录开启次数:"..globalData.openTimes)
end
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnEnd then --活动结束
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnUpdate then --活动帧更新
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnReqData then --请求活动数据
if ActivitiesConf[atvId] then
CheckInitActivity(atvType, atvId, ...)
end
local func = nil
if callbacks and (callbacks[atvType] ~= nil) then
func = callbacks[atvType];
end
CheckReqData(func, atvType, atvId, ...)
elseif evId == ActivityEvent.OnOperator then --通用操作
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnEnterFuben then --玩家进入活动副本
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnExitFuben then --玩家退出活动副本
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnEntityDeath then --副本实体死亡
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnEnterArea then --进入活动区域
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnExitArea then --离开活动区域
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnEntityAttacked then --活动副本实体受击
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnFubenFinish then --活动副本结束
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnAtvAreaDeath then --普通场景活动区域死亡
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnAtvAreaAtk then --普通场景活动区域死亡
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnLoginGame then --登录相关
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnUpdateActivity then --更新
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnCombineSrv then --合服
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnGPStart then --全局个人的开始
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnGPEnd then --全局个人的结束
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnOnAtvRank then --全局个人的结束
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
elseif evId == ActivityEvent.OnAtvGG then --全局个人的结束
if callbacks and (callbacks[atvType] ~= nil) then
local func = callbacks[atvType];
func(atvId, ...)
end
end
return true
end
--------------------------------------------------------------------
-- 活动副本回调
--------------------------------------------------------------------
function CheckEnterFuben(atvType, atvId, pFuben, pEntity, pOwner)
-- 玩家指针(个人活动判断需要一个玩家指针)
local pActor = nil
if Actor.getEntityType(pOwner) == enActor then
pActor = pOwner
elseif Actor.getEntityType(pEntity) == enActor then
pActor = pEntity
elseif Actor.getEntityType(pEntity) == enPet then
pActor = Actor.getMaster(pEntity)
else
return
end
-- 触发玩家进入活动副本事件
if Actor.isActivityRunning(pActor,atvId) then
if Actor.getEntityType(pEntity) == enActor then
print("[Activity"..atvType.."."..atvId.."] [FbId="..Fuben.getFubenIdByPtr(pFuben).."]"..Actor.getName(pEntity).." 进入活动副本!")
OnEvent(ActivityEvent.OnEnterFuben, atvType, atvId, pEntity, pFuben, pOwner)
end
end
end
function CheckExitFuben(atvType, atvId, pFuben, pEntity, pOwner)
-- 玩家指针(个人活动判断需要一个玩家指针)
local pActor = nil
if Actor.getEntityType(pOwner) == enActor then
pActor = pOwner
elseif Actor.getEntityType(pEntity) == enActor then
pActor = pEntity
elseif Actor.getEntityType(pEntity) == enPet then
pActor = Actor.getMaster(pEntity)
else
return
end
-- 触发玩家退出活动副本事件
if Actor.isActivityRunning(pActor,atvId) then
if Actor.getEntityType(pEntity) == enActor then
print("[Activity"..atvType.."."..atvId.."] [FbId="..Fuben.getFubenIdByPtr(pFuben).."]"..Actor.getName(pEntity).." 退出活动副本!")
OnEvent(ActivityEvent.OnExitFuben, atvType, atvId, pEntity, pFuben, pOwner)
end
end
end
function CheckFubenEntityDeath(atvType, atvId, pFuben, pEntity, pKiller, pOwner)
-- 玩家指针(个人活动判断需要一个玩家指针)
local pActor = nil
if Actor.getEntityType(pOwner) == enActor then
pActor = pOwner
elseif Actor.getEntityType(pEntity) == enActor then
pActor = pEntity
elseif Actor.getEntityType(pKiller) == enActor then
pActor = pKiller
elseif Actor.getEntityType(pEntity) == enPet then
pActor = Actor.getMaster(pEntity)
elseif Actor.getEntityType(pKiller) == enPet then
pActor = Actor.getMaster(pKiller)
else
return
end
-- 触发活动副本实体死亡事件
if Actor.isActivityRunning(pActor,atvId) then
-- if pFuben and pEntity and pKiller then
-- print("[Activity"..atvType.."."..atvId.."] [FbId="..Fuben.getFubenIdByPtr(pFuben).."]"..Actor.getName(pEntity).." 被 "..Actor.getName(pKiller).." 杀死!")
-- end
OnEvent(ActivityEvent.OnEntityDeath, atvType, atvId, pEntity, pKiller, pFuben, pOwner)
end
end
function CheckFubenEntityAttacked(atvType, atvId, pFuben, pEntity, pAttacker, pOwner)
-- 玩家指针(个人活动判断需要一个玩家指针)
local pActor = nil
if Actor.getEntityType(pOwner) == enActor then
pActor = pOwner
elseif Actor.getEntityType(pEntity) == enActor then
pActor = pEntity
elseif Actor.getEntityType(pAttacker) == enActor then
pActor = pAttacker
elseif Actor.getEntityType(pEntity) == enPet then
pActor = Actor.getMaster(pEntity)
elseif Actor.getEntityType(pAttacker) == enPet then
pActor = Actor.getMaster(pAttacker)
else
return
end
-- 触发活动副本实体受击事件
if Actor.isActivityRunning(pActor,atvId) then
--print("[Activity"..atvType.."."..atvId.."] [FbId="..Fuben.getFubenIdByPtr(pFuben).."]"..Actor.getName(pEntity).." 受到 "..Actor.getName(pAttacker).." 攻击!")
OnEvent(ActivityEvent.OnEntityAttacked, atvType, atvId, pEntity, pAttacker, pFuben, pOwner)
end
end
function CheckFubenFinish(atvType, atvId, pFuben, result, pOwner)
-- 玩家指针(个人活动判断需要一个玩家指针)
local pActor = nil
if Actor.getEntityType(pOwner) == enActor then
pActor = pOwner
end
-- 触发活动副本结束事件
if Actor.isActivityRunning(pActor,atvId) then
print("[Activity"..atvType.."."..atvId.."] [FbId="..Fuben.getFubenIdByPtr(pFuben).."]"..(Actor.getName(pOwner) or "").." 活动副本结束,结果为("..(result or 0)..")")
OnEvent(ActivityEvent.OnFubenFinish, atvType, atvId, pFuben, result, pOwner)
end
end
function CheckFubenAward(atvType, atvId, pFuben, pActor, pOwner)
-- 触发活动副本结算事件
if Actor.isActivityRunning(pActor,atvId) then
print("[Activity"..atvType.."."..atvId.."] [FbId="..Fuben.getFubenIdByPtr(pFuben).."]"..Actor.getName(pActor).." 请求副本结算!")
OnEvent(ActivityEvent.OnReqFubenAward, atvType, atvId, pFuben, result, pOwner)
end
end

View File

@@ -0,0 +1,71 @@
module("ActorEventDispatcher", package.seeall)
local dispatcher = {}
-- @brief 注册事件分发器
-- @param evId 事件id
-- @param func 回调
function Reg(evId, func, file)
--必须有参数
if evId == nil or func == nil or file == nil then
print( debug.traceback() )
print( file )
assert(false)
end
--玩家事件
if evId >= aeMaxEventCount or evId <= aeNoEvent then
print("[ERROR][EventDispatcher] evId("..evId..") error!")
assert(false)
else
if dispatcher[evId] == nil then
dispatcher[evId] = {}
end
table.insert(dispatcher[evId], func)
System.regScriptEvent(enType, evId)
end
print("[TIP][EventDispatcher] Add Actor Event("..evId..") In File("..file.."), And Index="..table.maxn(dispatcher[evId]))
return true
end
function OnEvent(nIndex, evId, pActor, ...)
local func = dispatcher[evId][nIndex]
if func then
return func(pActor, ...)
end
return false
end
--[[ 详细见ActorEventDef.h
enum tagActorEventID
{
aeNoEvent = 0, //未定义事件
aeLevel = 1, //角色升级 参数1当前等级数
aeUserLogin = 2, //玩家登陆 参数1是否第一次登录
aeUserLogout = 3, //玩家登出 参数1人物id
aeOnActorDeath = 4, //人物死亡
aeReliveTimeOut = 5, //判断复活时间是否超时用户超过5分钟没有选择回城复活还是原地复活如果到达脚本处理送回主城复活. 参数1人物指针
aeNewDayArrive = 6, //跨天或在线期间0点整[角色指针,天数]
aeOnActorBeKilled = 7, //被玩家杀死 [角色指针,杀人者指针]
aeWithDrawYuanBao = 8, //提取元宝 [角色指针,提取的元宝数量]
aeConsumeYb = 9, //消费元宝 [角色指针,消耗元宝数量]
aeOnEnterFuben = 10, //玩家请求进入副本 [角色指针进入的副本id]
aeOnExitFuben = 11, //玩家请求退出副本 [角色指针退出的副本id]
aeGuild = 12, //帮派相关
aeEquipComposite = 13, //装备合成 [角色指针目标装备ItemID]
aeBuffRemoved = 14, //buff被删除事件
aeLeaveTeam = 15, //离开队伍
aeCircle = 16, //角色转生 [角色指针,当前等级数]
aeChangeName = 17, //改名
aeAsyncOpResult = 18, //异步操作结果 参数1类型 参数2结果 参数3操作方式 参数4错误码 参数5卡号 参数6增值类型 参数7Sub类型
aeHero = 19, //英雄系统
aeHurtMonster = 20, //对怪物造成伤害
};
]]
--return EventDispatcher

View File

@@ -0,0 +1,30 @@
module("AsyncWorkDispatcher", package.seeall)
local CallBackList = {}
-- @brief 添加异步工作
-- @param asyncWork 异步工作内容 => { 'function', arg1, arg2 ... }
-- @param callback 完成回调 格式: callback(paramPack,retParam...) => paramPack为传入参数包retParam为异步工作返回值
-- @param paramPack 回调参数包
-- @note asyncWork.function 在异步线程中调用,且应函数应定义在 AsyncWorkerFunction.txt
function Add(asyncWork,callback,paramPack)
local cbid = System.addAsyncWorker(asyncWork)
if cbid ~= nil and cbid ~= 0 and callback ~= nil then
CallBackList[cbid] = {callback, paramPack}
end
end
--------------------------------------------------------------------
-- 提供给CPP的回调
--------------------------------------------------------------------
function OnWorkFinish(cbid, empty, ...)
if not cbid then return end
local callback = CallBackList[cbid]
if callback ~= nil then
func = callback[1]
paramPack = callback[2]
func(paramPack, ...)
CallBackList[cbid] = nil
end
end

View File

@@ -0,0 +1,349 @@
--刷选职业性别奖励
--sex表示玩家的性别-1 不限 0表示男的1表示女的
--job -1,0 表示任何职业 1 - 3 战法道
function SelectAwards(sysarg,awards)
local tab = {}
local job = Actor.getIntProperty( sysarg, PROP_ACTOR_VOCATION)
local sex = Actor.getIntProperty( sysarg, PROP_ACTOR_SEX)
for k,v in ipairs(awards) do
if ((v.sex == -1) or (v.sex == sex) or (v.sex == nil) ) and ((v.job == -1) or (v.job == 0) or (v.job == job) or (v.job == nil)) then
table.insert(tab,v)
end
end
return tab
end
--系统加成通用函数
function GetSysAddCfg()
return 0,0
--[[
local day = System.getDaysSinceOpenServer()
local length = #OpenServerConfig.SysAdd.AddRate
if day < OpenServerConfig.SysAdd.day then
return 0,0
else
local i = day % length + 1
return i, OpenServerConfig.SysAdd.AddRate[i] or 0
end
--]]
end
--给玩家发送物品
function MailItemsToPlayer(actorId, Items, sTitle, sContent)
local nType1, nID1, nCount1, nType2, nID2, nCount2, nType3, nID3, nCount3, nType4, nID4, nCount4,
nType5, nID5, nCount5, nType6, nID6, nCount6 = GetActivityAnswerAwards(Items)
System.sendSysMail(actorId, sTitle, sContent, nType1, nID1, nCount1, nType2, nID2, nCount2,
nType3, nID3, nCount3, nType4, nID4, nCount4, nType5, nID5, nCount5, nType6, nID6, nCount6,1) --默认是非绑定的1-绑定
end
--校验背包物品是否足够
--Item格式{{id1, count1},{id2,count2}}
function CheckBagItems(sysarg, Items)
for _, item in pairs(Items) do
local id = item[1]
local count = item[2]
--print("CheckBagItems, id="..id..", count="..count)
if id > 3 then --物品
if Actor.getItemCount(sysarg, id) < count then
return false
end
else --金钱
if Actor.getMoneyCount(sysarg, id) < count then
return false
end
end
end
return true
end
--检查物品所占格子的数量
-- item为{ type = 0, id=258, count = 5, strong = 0, quality = 0, bind = 0,} 类型
function GetItemGrid(sysarg, item)
return Item.getAddItemNeedGridCount( sysarg, item.id, item.count, item.quality, item.strong)
end
--[[给奖励
使用commonFunc.txt的方法
function GiveCommonAward(sysarg, Awards, logId, LogDesc)
for _, v in ipairs(Awards) do
if v.qualityDataIndex then
Actor.giveAward(sysarg, v.type, v.id, v.count, v.quality or 0, v.strong or 0, v.bind or 0, 0, logId, LogDesc,
v.qualityDataIndex)
else
Actor.giveAward(sysarg, v.type, v.id, v.count, v.quality or 0, v.strong or 0, v.bind or 0, 0, logId, LogDesc)
end
end
end
]]
--检查背包格子是否足够,返回需要空闲的格子数量,
--0-不缺
function CheckBagGridForAwards(sysarg, Awards)
local needGirds = 0
for _, v in ipairs( Awards ) do
if v.type == 0 then
needGirds = needGirds + Item.getAddItemNeedGridCount( sysarg, v.id, v.count, v.quality, v.strong)
end
end
--local hasEmptyIdxs = Item.getBagEmptyGridCount( sysarg )
local hasEmptyIdxs = Item.getAllBagMinEmptyGridCount( sysarg )
if hasEmptyIdxs >= needGirds then
return 0
else
return needGirds
end
end
function GetCommonAwardByRange( diffAwards, diff )
--print("GetCommonAwardByRange, diff="..diff)
for i,diffAward in ipairs(diffAwards) do
if diffAward.range[1] <= diff and diff <= diffAward.range[2] then
return diffAward
end
end
return nil
end
function GetElemByRange( elems, value )
for i,elem in ipairs(elems) do
if elem.range[1] <= value and value <= elem.range[2] then
return elem
end
end
return nil
end
--------------------------------常用公共接口-------------------------------
-- 从a~b范围内随机出N个不重复的数
BaseFuc_Random = function( nMin, nMax, nRandCount )
local nRange = nMax + 1 - nMin
if nRange <= 1 or nRandCount > nRange then
--local szError = string.format( "Error: can't from %d to %d random %d times", nMin, nMax, nRandCount )
--BaseFuc_Print( szError )
return {}
end
local tabRet ={}
local tabTemp = {}
local nTop = nMax
for i = 1, nRandCount do
local nRandResult = math.random( nMin, nTop )
local nResult = tabTemp[nRandResult] or nRandResult
table.insert( tabRet, nResult )
if nRandResult ~= nTop then
tabTemp[nRandResult] = tabTemp[nTop] or nTop
end
nTop = nTop - 1
end
return tabRet
end
--自动拼接打印参数
BaseFuc_Print = function(...)
local strContent=""
for i=1,arg.n,1 do
strContent = tostring(strContent)..tostring(arg[i])
if i ~= arg.n then
strContent = strContent.."\t"
end
end
print(strContent)
end
--table to string
BaseFuc_serialize = function( obj )
local lua = ""
local t = type( obj )
if t == "number" then
lua = lua .. obj
elseif t == "boolean" then
lua = lua .. tostring( obj )
elseif t == "string" then
lua = lua .. string.format( "%q", obj )
elseif t == "table" then
lua = lua .. "{"
for k, v in pairs( obj ) do
lua = lua .. "[" .. BaseFuc_serialize( k ) .. "]=" .. BaseFuc_serialize( v ) .. ","
end
local metatable = getmetatable( obj )
if metatable ~= nil and type( metatable.__index ) == "table" then
for k, v in pairs( metatable.__index ) do
lua = lua .. "[" .. BaseFuc_serialize( k ) .. "]=" .. BaseFuc_serialize( v ) .. ","
end
end
lua = lua .. "}"
elseif t == "nil" then
return nil
else
error( "can not BaseFuc_serialize a " .. t .. " type." )
end
return lua
end
--string to table
BaseFuc_unserialize = function( lua )
local t = type( lua )
if t == "nil" or lua == "" then
return nil
elseif t == "number" or t == "string" or t == "boolean" then
lua = tostring( lua )
else
error( "can not unserialize a " .. t .. " type." )
end
lua = "return " .. lua
local func = loadstring( lua )
if func == nil then
return nil
end
return func()
end
--获取元素列表长度(支持离散列表)
function GetElemsLen( elems )
local num = 0
for k,elem in pairs(elems) do
num = num + 1
end
return num
end
--检查物品是否足够(包括金钱)
function CheckSingleEnoughByType(sysarg, nType, nId , nCount)
if(sysarg == nil or type(nType)~='number' or type(nId)~='number' or type(nCount)~='number')then
print("CheckSingleEnoughByType Error")
return false
end
if(nType == 0)then -- 道具
if (Actor.getItemCount(sysarg, nId, -1, -1) < nCount) then --不足
local strName = Item.getItemName(nId)
local strNotice = string.format(OldLang.Script.ir103,strName)
Actor.sendTipmsg(sysarg, strNotice, ttFlyTip)
return false
end
elseif(nType == 3)then -- 金币
if (Actor.getMoneyCount(sysarg,0) < nCount)then
Actor.sendTipmsg(sysarg, OldLang.Script.ir105, ttFlyTip)
return false
end
elseif(nType == 5)then -- 绑定元宝
if (Actor.getMoneyCount(sysarg,2) < nCount)then
Actor.sendTipmsg(sysarg, OldLang.Script.ir106, ttFlyTip)
return false
end
elseif(nType == 10)then -- 元宝
if (Actor.getMoneyCount(sysarg,3) < nCount)then
Actor.sendTipmsg(sysarg, OldLang.Script.ir107, ttFlyTip)
return false
end
elseif(nType == 27)then -- 羽魂
local myWingSoul = Actor.getMoneyCount(sysarg, mtWingSoul)
if ( myWingSoul < nCount)then
--Actor.sendTipmsg(sysarg, OldLang.Script.ir108, ttFlyTip)
Actor.sendNotEnoughMoney(sysarg, mtWingSoul, nCount)
return false
end
else
return false
end
return true
end
--扣除物品(包括金钱)
function SubSingleItemByType(sysarg, nType, nId , nCount, logId, logStr)
if(nCount == 0)then
return true
end
if(sysarg == nil or type(nType)~='number' or type(nId)~='number' or type(nCount)~='number')then
print("SubSingleItemByType Error")
return false
end
if(type(logId) ~= 'number' or type(logStr)~='string')then
print("SubSingleItemByType Error")
return false
end
if(nType == 0)then --道具
if Actor.getItemCount(sysarg, nId, -1, -1) < nCount then
return false
end
if not Actor.removeItem(sysarg, nId, nCount,-1, -1, -1, logStr, logId)then
return false
end
elseif(nType == 3)then -- 金币
if (Actor.changeMoney(sysarg,0, -nCount, logId, logStr) == false)then
return false
end
elseif(nType == 5)then -- 礼券
if (Actor.changeMoney(sysarg,2, -nCount, logId, logStr) == false)then
return false
end
elseif(nType == 10)then -- 元宝
if (Actor.changeMoney(sysarg,3, -nCount, logId, logStr) == false)then
return false
end
elseif(nType == 27)then
if (Actor.changeMoney(sysarg,6, -nCount, logId, logStr) == false)then
return false
end
else
return false
end
return true
end
--批量扣除物品(包括金钱)
function SubBatchItemByType(sysarg, ItemList, logId, logStr)
if(sysarg == nil or type(ItemList)~='table' or type(logId)~='number' or type(logStr)~='string')then
print("SubBatchItemByType Error")
return false
end
for k,v in pairs(ItemList)do --先判断够不够
if(v.type == nil or v.id == nil or v.count == nil)then
BaseFuc_Print("SubBatchItemByType ItemList Error",v.type,v.id,v.count)
return false
end
if(CheckSingleEnoughByType(sysarg, v.type, v.id , v.count) ~= true)then
return false
end
end
for k,v in pairs(ItemList)do --再批量扣除物品(包括金钱)
if(SubSingleItemByType(sysarg, v.type, v.id , v.count, logId, logStr) ~= true)then
return false
end
end
return true
end
--扣除货币
--nCount:必须 >= 0
function SubSingleMoneyByType(sysarg, nType, nCount, logId, logStr)
--print("SubSingleMoneyByType, nType="..nType..", nCount="..nCount)
if(sysarg == nil or type(nType)~='number' or type(nCount)~='number')then
print("SubSingleMoneyByType type Error")
return false
end
if(type(logId) ~= 'number' or type(logStr)~='string')then
print("SubSingleMoneyByType log Error")
return false
end
if nCount < 0 then
return false
end
if(nType == 0)then -- 金币
if (Actor.changeMoney(sysarg,0, -nCount, logId, logStr) == false)then
return false
end
elseif(nType == 5)then -- 礼券
if (Actor.changeMoney(sysarg,2, -nCount, logId, logStr) == false)then
return false
end
elseif(nType == 10)then -- 元宝
if (Actor.changeMoney(sysarg,3, -nCount, logId, logStr) == false)then
return false
end
else
return false
end
return true
end

View File

@@ -0,0 +1,103 @@
module("CrossServerDispatcher", package.seeall)
--[[
actorData[AtvId]
{
mCrossActorId, --原服玩家id
mRawSrvId --原服跨服serverid
}
]]--
----------------------------------------------------------
---跨服角色处理
----------------------------------------------------------
--获取玩家数据
function GetGlobalData(nActorId)
if nActorId == nil then
assert(false)
end
local var = System.getStaticVar();
if var.globalCsData == nil then
var.globalCsData = {}
end
if var.globalCsData[nActorId] == nil then
var.globalCsData[nActorId] = {}
end
return var.globalCsData[nActorId]
end
-- 初始化
function InitActor(nActorId, nCrossActorId, nRawSrvId)
local globalData = GetGlobalData(nActorId);
if globalData.actorData == nil then
globalData.actorData = {}
end
print("InitActor.."..nActorId.."..nCrossActorId.."..nCrossActorId.."..nRawSrvId.."..nRawSrvId)
globalData.actorData.mCrossActorId = nCrossActorId;
globalData.actorData.mRawSrvId = nRawSrvId;
end
-- 初始化
function GetCrossServerActor(nActorId)
local globalData = GetGlobalData(nActorId);
if globalData.actorData == nil then
return 0, 0
end
local data = globalData.actorData;
print("mCrossActorId.."..data.mCrossActorId.."..mRawSrvId.."..data.mRawSrvId)
return data.mCrossActorId,data.mRawSrvId;
end
----------------------------------------------------------
---跨服账号处理
----------------------------------------------------------
--获取玩家数据
-- @brief 获取某个活动的缓存数据(这个数据,不存储仅缓存)
-- @param fbId 活动id
function GetCenterCacheData(atvId)
if atvId == nil then
assert(false)
end
local var = System.getDyanmicVar();
if var.centerAccountData == nil then
var.centerAccountData = {}
end
if var.centerAccountData[atvId] == nil then
var.centerAccountData[atvId] = {}
end
return var.centerAccountData[atvId]
end
-- 初始化
function InitCSAccount(nAcouuntId, nRawSrvId, pActor)
local nKey = string.format("%d%d", nAcouuntId,nRawSrvId);
print("InitCSAccount nAcouuntId.."..nAcouuntId.."..nAcouuntId.."..nRawSrvId.."..nKey.."..nKey)
local globalData = GetCenterCacheData(nKey);
local handle = Actor.getHandle(pActor)
globalData[nKey] = handle
end
-- 初始化
function DeleteCSAccount(nAcouuntId, nRawSrvId)
local nKey = string.format("%d%d", nAcouuntId,nRawSrvId);
print("DeleteCSAccount nAcouuntId.."..nAcouuntId.."..nAcouuntId.."..nRawSrvId.."..nKey.."..nKey)
local globalData = GetCenterCacheData(nKey);
local pActor = Actor.getEntity(globalData[nKey] or 0)
if pActor then
Actor.KickUserAccount(pActor)
end
globalData[nKey] = nil
end
-- function CheckCSAccount(nAcouuntId, nRawSrvId)
-- local nKey = string.format("%d%d", nAcouuntId,nRawSrvId);
-- print("CheckCSAccount nAcouuntId.."..nAcouuntId.."..nAcouuntId.."..nRawSrvId.."..nKey.."..nKey)
-- local globalData = GetCenterCacheData(nKey);
-- return (globalData[nKey] or 0)
-- end

View File

@@ -0,0 +1,709 @@
module("FubenDispatcher", package.seeall)
--[[
缓存数据CacheData[fbId]
{
atvId, 建立 活动副本 与 活动id 的对应关系
atvType, 副本类型到活动类型列表的映射,用以建立副本类型跟活动类型的对应关系
ownerId, 单人副本的归属者id
timeFlag, 超时设置标志
kickFlag, 超时后踢出标志
result, 副本结果 1成功0失败nil则未知超时后若未设置1则设置为0
relive[aid] = -1~n 对应玩家的复活次数
}
]]--
local campType_Blue = 1
local campType_Red = 2
local dispatcher = {}
_G.FubenEnterType =
{
Single = 0, --单人进入类副本
Team = 1, --队伍进入类副本
All = 2, --多人进入类副本
}
_G.FubenEvent =
{
OnCheckEnter = 1, --进入检查 [副本id进入类型玩家指针] 注意需要返回值true/false
OnCreate = 2, --副本创建 [副本id进入类型副本指针]
OnEnter = 3, --实体进入副本 [副本id进入类型副本指针场景id实体指针]
OnExit = 4, --实体退出副本 [副本id进入类型副本指针场景id实体指针]
OnUpdate = 5, --副本帧更新 [副本id进入类型副本指针当前时间]
OnDeath = 6, --实体死亡 [副本id进入类型副本指针场景id实体指针]
OnGetAward = 7, --获取副本奖励 [副本id进入类型副本指针场景id玩家指针]
OnTimeout = 8, --副本超时 [副本id进入类型副本指针]
OnAttacked = 9, --实体收到攻击 [副本id进入类型副本指针场景id受击者攻击者] 注意:怪物攻击怪物不触发
Count = 10,
}
--------------------------------------------------------------------
-- Lua接口
--------------------------------------------------------------------
-- @brief 注册事件分发器
-- @param evId 事件id
-- @param fbType 副本类型
-- @param func 回调
function Reg(evId, fbType, func, file)
--参数检查
if fbType == nil or evId == nil or func == nil or file == nil then
print( debug.traceback() )
assert(false)
end
--事件范围检查
if evId <= 0 or evId >= FubenEvent.Count then
assert(false)
end
--回调表初始化
if dispatcher[evId] == nil then
dispatcher[evId] = {}
end
if dispatcher[evId][fbType] ~= nil then
assert(false) -- 重复注册了
end
--注册
dispatcher[evId][fbType] = func
print("[TIP][FubenDispatcher] Add Fuben(Type:"..fbType..") Event("..evId..") In File("..file.."), And Index="..table.maxn(dispatcher[evId]))
end
-- @brief 获取某个副本的全局数据(这个数据,是存文件的)
-- @param fbId 副本id
function GetGlobalData(fbId)
if fbId == nil then
assert(false)
end
local var = System.getStaticVar();
if var.Fubens == nil then
var.Fubens = {}
end
if var.Fubens[fbId] == nil then
var.Fubens[fbId] = {}
end
return var.Fubens[fbId]
end
-- @brief 清空某个副本的全局数据(这个数据,是存文件的)
-- @param fbId 副本id
function ClearGlobalData(fbId)
if fbId == nil then
assert(false)
end
local var = System.getStaticVar();
if var.Fubens == nil then
var.Fubens = {}
end
if var.Fubens[fbId] then
var.Fubens[fbId] = nil
end
end
-- @brief 获取某个副本的缓存数据(这个数据,不存储仅缓存)
-- @param pFuben 副本指针
function GetCacheData(pFuben)
if pFuben == nil then
assert(false)
end
return Fuben.getDyanmicVar(pFuben)
end
-- @brief 清空某个副本的缓存数据(这个数据,不存储仅缓存)
-- @param pFuben 副本指针
function ClearCacheData(pFuben)
if pFuben == nil then
assert(false)
end
Fuben.clearDynamicVar(pFuben)
end
-- @brief 获取某个副本的个人数据(这个数据,是存数据库的)
-- @param pActor 玩家指针
-- @param fbId 副本id
function GetActorData(pActor, fbId)
if fbId == nil or Actor.getEntityType(pActor) ~= enActor then
assert(false)
end
local var = Actor.getStaticVar(pActor);
if var.Fubens == nil then
var.Fubens = {}
end
if var.Fubens[fbId] == nil then
var.Fubens[fbId] = {}
end
return var.Fubens[fbId]
end
-- @brief 清空某个副本的个人数据(这个数据,是存数据库的)
-- @param pActor 玩家指针
-- @param fbId 副本id
function ClearActorData(pActor, fbId)
if fbId == nil or Actor.getEntityType(pActor) ~= enActor then
assert(false)
end
local var = Actor.getStaticVar(pActor);
if var.Fubens == nil then
var.Fubens = {}
end
if var.Fubens[fbId] then
var.Fubens[fbId] = nil
end
end
-- @brief 设置复活剩余次数
-- @param pActor 玩家指针
-- @param fbId 副本id
-- @param idx 复活选项索引0为自动复活的大于1的为复活选项卡的索引
-- @param count 次数限制若设置为nil则自动应用配置的相当于重置-1为无限制
function SetReliveCount(pActor, fbId, idx, count)
local actorData = GetActorData(pActor, fbId)
if actorData.relive == nil then
actorData.relive = {}
end
if count == nil then
local ConfId = (StaticFubens[fbId] and StaticFubens[fbId].reliveConfId) or 1
local ReliveConf = ReliveConfig[ConfId] or ReliveConfig[1]
if idx == 0 then
actorData.relive[idx] = ReliveConf.limit
else
actorData.relive[idx] = ReliveConf.selectInfo[idx].limit or -1
end
else
actorData.relive[idx] = count
end
end
-- @brief 设置副本结果(有结果后,再次设置无效)
-- @param pFuben 副本指针
-- @param result 1为成功0为失败
function SetResult(pFuben, result)
local cacheData = GetCacheData(pFuben)
if not cacheData.result then
cacheData.result = result
end
CheckActivityFubenFinish(pFuben)
end
-- @brief 获取副本结果
-- @param pFuben 副本指针
-- @return 1为成功0为失败nil为未知
function GetReault(pFuben)
local cacheData = GetCacheData(pFuben)
return cacheData.result
end
-- @brief 判断是否为活动副本
-- @param pFuben 副本指针
function IsActivityFuben(pFuben)
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
return fbCacheData.atvType ~= nil
end
-- @brief 判断是否为Mon副本
-- @param pFuben 副本指针
function IsMonFuben(pFuben)
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
return fbCacheData.nMonType ~= nil
end
-- @brief 获取副本对应的活动id
-- @param pFuben 副本指针
-- @return 若非活动副本则返回nil
function GetActivityId(pFuben)
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
return fbCacheData.atvId
end
-- @brief 获取副本对应的活动Type
-- @param pFuben 副本指针
-- @return 若非活动副本则返回nil
function GetActivityType(pFuben)
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
return fbCacheData.atvType
end
-- @brief 获取副本对应的活动,超时后踢出标志
-- @param pFuben 副本指针
-- @return 若非活动副本则返回nil
function GetActivityKickFlag(pFuben)
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
return fbCacheData.kickFlag
end
-- @brief 是否为单人副本
-- @param pFuben 副本指针
function IsSingleFuben(pFuben)
local fbId = Fuben.getFubenIdByPtr(pFuben)
if StaticFubens[fbId].enterType == FubenEnterType.Single then
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
if fbCacheData.ownerId then
return true
end
end
end
-- @brief 获取副本所有者(目前仅对单人副本)
-- @param pFuben 副本指针
-- @return 玩家指针若非单人副本则返回nil
function GetOwner(pFuben)
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
return Actor.getActorPtrById(fbCacheData.ownerId)
end
-- @brief 延迟踢出
-- @param pFuben 副本指针
-- @param timeout 超时时间默认10秒
function KictoutAfter(pFuben, timeout)
local cacheData = GetCacheData(pFuben)
cacheData.kickFlag = 1
Fuben.setFbTime(pFuben, timeout or 10)
end
-- @brief 设置复活次数
-- @param pFuben 副本指针
-- @param pActor 玩家指针
-- @param count 次数
function SetReliveCount(pFuben, pActor, count)
if (not pFuben) or (not pActor) then
return
end
local aid = Actor.getActorId(pActor)
local cacheData = GetCacheData(pFuben)
if not cacheData.relive then cacheData.relive = {} end
cacheData.relive[aid] = count
end
-- @brief 获取复活次数
-- @param pFuben 副本指针
-- @param pActor 玩家指针
-- @return -1为不限次数nil为异常
function GetReliveCount(pFuben, pActor)
if (not pFuben) or (not pActor) then
return nil
end
local aid = Actor.getActorId(pActor)
local cacheData = GetCacheData(pFuben)
if not cacheData.relive then cacheData.relive = {} end
return cacheData.relive[aid] or -1
end
-- @brief 分配一个广播包需要外部自己调用FreePacketEx释放包
function AllocPacketEx(systemId, cmdId)
local npack = DataPack.allocPacketEx()
if npack then
DataPack.writeByte(npack,systemId)
DataPack.writeByte(npack,cmdId)
end
return npack
end
-- @brief 释放一个通用回复(注意:这是广播包)
function FreePacketEx(npack)
if npack then
DataPack.freePacketEx(npack)
end
end
--------------------------------------------------------------------
-- CPP回调
--------------------------------------------------------------------
function OnCreateEvent(fbId, fbEnterType, pFuben)
-- 设置副本超时,如果需要的话
local FubenConf = StaticFubens[fbId]
if FubenConf and FubenConf.timeOut then
local cacheData = GetCacheData(pFuben)
if not cacheData.timeFlag then
Fuben.setFbTime(pFuben, FubenConf.timeOut)
cacheData.timeFlag = 1
end
end
end
function OnEnterEvent(fbId, fbEnterType, pFuben, scenId, pEntity)
-- 记录单人副本归属
if fbEnterType == FubenEnterType.Single then
if Actor.getEntityType(pEntity) == enActor then
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
fbCacheData.ownerId = Actor.getActorId(pEntity)
end
end
-- 进入新场景时,发送剩余时间,如果需要的话
local FubenConf = StaticFubens[fbId]
if FubenConf and FubenConf.timeOut then
if Actor.getEntityType(pEntity) == enActor then
local netPack = DataPack.allocPacket(pEntity, enFubenSystemID, sFubenRestTime)
if netPack then
DataPack.writeInt(netPack, Fuben.getFbTime(pFuben))
DataPack.flush(netPack)
end
end
end
-- 进入活动场景检测
if IsActivityFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
ActivityDispatcher.CheckEnterFuben(cacheData.atvType, cacheData.atvId, pFuben, pEntity, Actor.getActorById(cacheData.ownerId))
end
if IsMonFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
MonDispatcher.CheckEnterFuben(cacheData.nMonType, fbId,scenId,pEntity)
end
end
function OnExitEvent(fbId, fbEnterType, pFuben, scenId, pEntity)
-- 离开活动场景检测
if IsActivityFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
ActivityDispatcher.CheckExitFuben(cacheData.atvType, cacheData.atvId, pFuben, pEntity, Actor.getActorById(cacheData.ownerId))
end
if IsMonFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
MonDispatcher.CheckExitFuben(cacheData.nMonType, fbId,scenId,pFuben, pEntity)
end
end
function OnEntityDeathEvent(fbId, fbEnterType, pFuben, scenId, pEntity)
-- 检查活动副本内实体死亡
if IsActivityFuben(pFuben) then
local killerHandle = Actor.getKillHandle(pEntity)
local pKiller = Actor.getEntity(killerHandle)
local cacheData = GetCacheData(pFuben)
ActivityDispatcher.CheckFubenEntityDeath(cacheData.atvType, cacheData.atvId, pFuben, pEntity, pKiller, Actor.getActorById(cacheData.ownerId))
end
if IsMonFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
local killerHandle = Actor.getKillHandle(pEntity)
local pKiller = Actor.getEntity(killerHandle)
MonDispatcher.CheckFubenEntityDeath(cacheData.nMonType, fbId, scenId,pFuben, pEntity, pKiller)
end
end
function OnAttackedEvent(fbId, fbEnterType, pFuben, scenId, pEntity, pAttacker)
-- 检查活动副本内实体收到攻击
if IsActivityFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
ActivityDispatcher.CheckFubenEntityAttacked(cacheData.atvType, cacheData.atvId, pFuben, pEntity, pAttacker, Actor.getActorById(cacheData.ownerId))
end
if IsMonFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
MonDispatcher.CheckFubenEntityAttacked(cacheData.nMonType, fbId, scenId, pFuben,pEntity, pAttacker)
end
end
function OnTimeoutEvent(fbId, fbEnterType, pFuben)
-- 超时设置踢出时间,如果需要的话
local FubenConf = StaticFubens[fbId]
if FubenConf then
local cacheData = GetCacheData(pFuben)
--第二次超时,则表示踢出了
if not cacheData.kickFlag then
Fuben.setFbTime(pFuben, FubenConf.kickTime or 12)
cacheData.kickFlag = 1
--若副本没成功,超时就表示失败了
if not cacheData.result then
cacheData.result = 0
end
-- 检查活动副本结束
CheckActivityFubenFinish(pFuben)
elseif cacheData.kickFlag then
Fuben.ExitAllFbActor(pFuben)
end
end
end
function SetFubenTimeout(fbId, pFuben)
-- 超时设置踢出时间,如果需要的话
local FubenConf = StaticFubens[fbId]
if FubenConf then
local cacheData = GetCacheData(pFuben)
if not cacheData.kickFlag then
Fuben.setFbTime(pFuben, FubenConf.kickTime or 12)
cacheData.kickFlag = 1
--若副本没成功,超时就表示失败了
if not cacheData.result then
cacheData.result = 0
end
end
end
end
function ClearFubenTimeout(fbId, pFuben)
-- 超时设置踢出时间,如果需要的话
local FubenConf = StaticFubens[fbId]
if FubenConf then
local cacheData = GetCacheData(pFuben)
if cacheData then
Fuben.setFbTime(pFuben,0)
cacheData.kickFlag = nil
cacheData.result = nil
end
end
end
function OnGetAwardEvent(fbId, fbEnterType, pFuben, nSceneId, pActor)
-- 检查活动副本结算请求
if IsActivityFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
ActivityDispatcher.CheckFubenAward(cacheData.atvType, cacheData.atvId, pFuben, pActor, Actor.getActorById(cacheData.ownerId))
end
end
function OnEvent(evId, fbType, fbId, fbEnterType, ...)
if evId == FubenEvent.OnCreate then --副本创建
OnCreateEvent(fbId, fbEnterType, ...)
elseif evId == FubenEvent.OnEnter then --实体进入副本
OnEnterEvent(fbId, fbEnterType, ...)
elseif evId == FubenEvent.OnExit then --实体退出副本
OnExitEvent(fbId, fbEnterType, ...)
elseif evId == FubenEvent.OnDeath then --副本实体死亡
OnEntityDeathEvent(fbId, fbEnterType, ...)
elseif evId == FubenEvent.OnAttacked then --实体收到攻击
OnAttackedEvent(fbId, fbEnterType, ...)
elseif evId == FubenEvent.OnTimeout then --副本超时
OnTimeoutEvent(fbId, fbEnterType, ...)
elseif evId == FubenEvent.OnGetAward then --获取副本奖励
OnGetAwardEvent(fbId, fbEnterType, ...)
end
--获取回调
local callbacks = dispatcher[evId]
if callbacks == nil or callbacks[fbType] == nil then
return true
end
local func = callbacks[fbType];
--回调调用
if evId == FubenEvent.OnCheckEnter then --副本进入检查
return func(fbId, fbEnterType, ...)
else
func(fbId, fbEnterType, ...)
end
return true
end
-- 玩家死亡回调,用以发送复活信息
function OnActorDeath(pActor, pFuben)
--if Actor.getReliveTimeOut(pActor) == 0 then
local fbId = Fuben.getFubenIdByPtr(pFuben)
local ConfId = (StaticFubens[fbId] and StaticFubens[fbId].reliveConfId) or 1
local ReliveConf = ReliveConfig[ConfId] or ReliveConfig[1]
local aid = Actor.getActorId(pActor)
local cacheData = GetCacheData(pFuben)
if not cacheData.relive then cacheData.relive = {} end
if not cacheData.relive[aid] then
cacheData.relive[aid] = ReliveConf.limit or -1
end
local reliveCount = cacheData.relive[aid]
-- 维护次数
if reliveCount > 0 then
cacheData.relive[aid] = reliveCount - 1
elseif reliveCount == 0 then
Actor.clearReliveTimeOut(pActor)
local maxhp = Actor.getIntProperty(pActor,PROP_CREATURE_MAXHP)
Actor.changeHp(pActor, maxhp)
local maxmp = Actor.getIntProperty(pActor,PROP_CREATURE_MAXMP)
Actor.changeMp(pActor, maxmp)
local atvId = GetActivityId(pFuben);
local atvType = GetActivityType(pFuben);
ActivityDispatcher.OnEvent(ActivityEvent.OnAtvGG, atvType, atvId, pActor);
Actor.exitFubenAndBackCity(pActor)
--Actor.addState(pActor, esStateDeath)
--Actor.updateActorEntityProp(pActor)
--Actor.removeState(pActor, esStateDeath)
--Actor.updateActorEntityProp(pActor)
cacheData.relive[aid] = nil
return
end
-- 设置自动复活时间
-- 复活特权
local nCurReviveDuration = Actor.getIntProperty2(pActor, PROP_ACTOR_CURREVIVEDURATION);
if nCurReviveDuration ~= 0 then
Actor.setReliveTimeOut(pActor, (ReliveConf.VipRevive or 5))
else
Actor.setReliveTimeOut(pActor, (ReliveConf.expire or 10))
end
-- 通知死亡复活框
local npack = DataPack.allocPacket(pActor, enDefaultEntitySystemID, sActorReliveInfo)
if npack then
DataPack.writeByte(npack, ConfId)
DataPack.writeByte(npack, reliveCount)
local count = (ReliveConf.selectInfo and #ReliveConf.selectInfo) or 0
DataPack.writeByte(npack, count)
local actorData = GetActorData(pActor, fbId)
if actorData.relive == nil then
actorData.relive = {}
end
if count > 0 then
for i=1,count do
if actorData.relive[i] == nil then
actorData.relive[i] = ReliveConf.selectInfo[i].limit or -1
end
DataPack.writeByte(npack, actorData.relive[i])
end
end
-- 添加击杀者名字
local h_killer = Actor.getKillHandle(pActor)
local pKiller = Actor.getEntity(h_killer)
local name = ""
if pKiller then
name = Actor.getName(pKiller)
end
DataPack.writeString( npack, name )
DataPack.flush(npack)
end
--end
end
-- 复活选项
function OnClickReqRelive (pActor, packet)
local confId = DataPack.readByte(packet)
local idx = DataPack.readByte(packet) + 1
--获取当前副本复活配置
local pFuben = Actor.getFubenPrt(pActor)
local fbId = Fuben.getFubenIdByPtr(pFuben)
local ConfId = (StaticFubens[fbId] and StaticFubens[fbId].reliveConfId) or 1
local ReliveConf = ReliveConfig[ConfId] or ReliveConfig[1]
--配置id验证
if confId ~= ConfId then
return
end
--复活选项配置
local selectInfo = ReliveConf.selectInfo[idx]
if selectInfo then
--消耗检查
local consumes = {}
if selectInfo.consume then
table.insert( consumes, selectInfo.consume )
if CommonFunc.Consumes.Check(pActor, consumes) ~= true then
Actor.sendTipmsg(pActor, "|C:0xf56f00&T:道具或金币元宝不足!|", tstEcomeny)
return
end
end
--次数检查
if selectInfo.limit and selectInfo.limit > 0 then
local actorData = GetActorData(pActor, fbId)
if actorData.relive[idx] == nil then
actorData.relive[idx] = selectInfo.limit
else
if actorData.relive[idx] == 0 then
Actor.sendTipmsg(pActor, "超过次数了!"..actorData.relive[idx].."/"..selectInfo.limit, tstUI)
return
end
actorData.relive[idx] = actorData.relive[idx] - 1
end
end
-- 消耗
if consumes and CommonFunc.Consumes.Remove(pActor, consumes,GameLog.Log_Relive , "复活") ~= true then
return
end
--回血回蓝
local maxhp = Actor.getIntProperty(pActor,PROP_CREATURE_MAXHP)
Actor.changeHp(pActor, maxhp * ((selectInfo.hp or 100)/100))
local maxmp = Actor.getIntProperty(pActor,PROP_CREATURE_MAXMP)
Actor.changeMp(pActor, maxmp * ((selectInfo.mp or 100)/100))
-- 原地复活
if selectInfo.type == 1 then
-- 随机复活
elseif selectInfo.type == 2 then
System.telportRandPos(pActor)
-- 副本固定点复活
elseif selectInfo.type == 3 then
if ReliveConf.FixedPosi then
local sceneId = Actor.getSceneId(pActor)
Actor.enterScene(pActor, sceneId, ReliveConf.FixedPosi.x, ReliveConf.FixedPosi.y)
else
Actor.relive(pActor)
end
-- 回城安全区复活
elseif selectInfo.type == 4 or selectInfo.type == 6 then
if Fuben.isFuben(pFuben) then
Actor.exitFubenAndBackCity(pActor)
else
Actor.relive(pActor)
end
-- 本方阵营复活
elseif selectInfo.type == 5 then
end
--清除复活倒计时
Actor.clearReliveTimeOut(pActor)
Actor.onRelive(pActor)
TranRedActorToRedSceen(pActor)
--Actor.removeState(pActor, esStateDeath)
--Actor.updateActorEntityProp(pActor)
end
end
NetmsgDispatcher.Reg(enDefaultEntitySystemID, cChooseRelive, OnClickReqRelive)
--------------------------------------------------------------------
-- 活动副本回调
--------------------------------------------------------------------
-- 映射副本跟活动的对应关系
function MapToActivity(pFuben, atvType, atvId)
if atvType then
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
if fbCacheData.atvType == nil then
fbCacheData.atvId = atvId
fbCacheData.atvType = atvType
local atvCacheData = ActivityDispatcher.GetCacheData(atvId)
atvCacheData.fbHandle = Fuben.getFubenHandle(pFuben)
end
end
end
-- 映射副本跟Monster的对应关系
function MapToMonster(pFuben, nMonType, nSerial)
if nMonType then
local fbCacheData = FubenDispatcher.GetCacheData(pFuben)
if fbCacheData.nMonType == nil then
fbCacheData.nMonType = nMonType
fbCacheData.nSerial = nSerial
end
end
end
-- 检查活动副本结束
function CheckActivityFubenFinish(pFuben)
if IsActivityFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
ActivityDispatcher.CheckFubenFinish(cacheData.atvType, cacheData.atvId, pFuben, cacheData.result, Actor.getActorById(cacheData.ownerId))
end
if IsMonFuben(pFuben) then
local cacheData = GetCacheData(pFuben)
MonDispatcher.CheckFubenFinish(cacheData.nMonType, pFuben, cacheData.result, Actor.getActorById(cacheData.ownerId))
end
end

View File

@@ -0,0 +1,57 @@
HttpClient = {}
function HttpClient:Start()
if nil == self.requester then
self.requester = HttpRequester:create()
self.requester:retain()
self.requester:setCallback(LUA_CALLBACK(self, self.RequestCallback))
self.request_list = {}
end
end
function HttpClient:Update(dt)
end
function HttpClient:Stop()
if nil ~= self.requester then
self.requester:release()
self.requester = nil
self.request_list = nil
end
end
-- 请求
function HttpClient:Request(url, arg, callback)
if nil == self.requester then return end
local key = self.requester:addRequest(url, arg, 0)
if key < 0 then
print("HttpRequest fail url:" .. url)
return false
end
self.request_list[key] = callback
return true
end
function HttpClient:RequestCallback(url, arg, data, size, key)
if nil == self.requester then return end
local callback = self.request_list[key]
if nil ~= callback then
callback(url, arg, data, size)
self.request_list[key] = nil
end
end
function HttpClient:UrlEncode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
HttpClient:Start()

View File

@@ -0,0 +1,274 @@
--#include "data\config\mail\MailEventConfig.txt" once --触发事件发邮件
--邮件通用接口
--nActorId 玩家Id
--sTitle 标题
--sContent 内容
--awardTable 奖励表
--[[
awardTable =
{
{type = 0, id = 1, count = 1, quality = 1, qualityDataIndex = 1, strong = 1, bind = 1,}
}
]]--
mailAttachCount = 5
function SendMail(nActorId, sTitle,sContent,awardTable)
if nActorId == 0 then
print("SendMail error,nActorId =0")
return
end
if not sTitle or not sContent then
print("SendMail error,sTitle or sContent = nil")
return
end
if not awardTable or type(awardTable) ~= "table" then
System.sendSysMail(nActorId, sTitle, sContent)
--print("SendMail error,awardTable nil or not a table")
return
end
local nAwardCount = #awardTable
local nCurCount = 0
local splitTable = {}
if nAwardCount == 0 or nAwardCount < mailAttachCount then
System.sendSysMail(nActorId, sTitle, sContent, awardTable)
else
for i=1,nAwardCount do
nCurCount = nCurCount + 1
table.insert(splitTable, awardTable[i])
if i == nAwardCount or nCurCount >= mailAttachCount then --超过5个附件分开发
System.sendSysMail(nActorId, sTitle, sContent, splitTable)
nCurCount = 0
splitTable = {}
end
end
end
end
--跨服邮件
function SendCrossServerMail(nActorId,sTitle,sContent,awardTable)
if not sTitle or not sContent then
print("SendMail error,sTitle or sContent = nil")
return
end
if not awardTable or type(awardTable) ~= "table" then
System.sendCrossServerMail(nActorId, sTitle, sContent)
--print("SendMail error,awardTable nil or not a table")
return
end
local nAwardCount = #awardTable
local nCurCount = 0
local splitTable = {}
if nAwardCount == 0 or nAwardCount < mailAttachCount then
System.sendCrossServerMail(nActorId, sTitle, sContent, awardTable)
else
for i=1,nAwardCount do
nCurCount = nCurCount + 1
table.insert(splitTable, awardTable[i])
if i == nAwardCount or nCurCount >= mailAttachCount then --超过5个附件分开发
System.sendCrossServerMail(nActorId, sTitle, sContent, splitTable)
nCurCount = 0
splitTable = {}
end
end
end
end
--在线发邮件,可带职业,性别等筛选条件
function SendMailEx(sysarg, sTitle, sContent, awardTable)
local nActorId = Actor.getActorId(sysarg)
local useAwardTable = {}
for i,v in ipairs(awardTable) do
local isUse = true
if v.sex ~= nil and v.sex ~= -1 and v.sex ~= Actor.getIntProperty(sysarg,PROP_ACTOR_SEX) then --有性别要求
isUse = false
end
if v.job ~= nil and v.job ~= 0 and v.job ~= Actor.getIntProperty(sysarg, PROP_ACTOR_VOCATION) then --有职业要求
isUse = false
end
if isUse then
table.insert(useAwardTable,v)
end
end
SendMail(nActorId, sTitle, sContent, useAwardTable)
end
function TestMail(sysarg,mailCount)
local mailCount = tonumber(mailCount) or 1
local nActorId = Actor.getActorId(sysarg)
local sTitle1 = "标题"
local sContent1 = "内容"
for i=1,mailCount do
local awardTable =
{
{type = 0, id = 281 , count = 1, sex = 0},
{type = 0, id = 281 , count = 2, sex =1},
{type = 11, id = 0 , count = 100*i, job=1 },
{type = 21, id = 0 , count = 100*i, job=2},
{type = 31, id = 0 , count = 100*i, job=3},
}
local sTitle = sTitle1..i
local sContent = sContent1 ..i
SendMailEx(sysarg, sTitle, sContent, awardTable)
end
end
--触发邮件事件
function OnMailEvent( sysarg, mailEventId, value1, value2 )
--print("OnMailEvent, mailEventId="..mailEventId..", value1="..value1..", value2="..value2)
local eventcfg = MailEventCfg[mailEventId]
if not eventcfg then --无此事件的配置
return
end
if not eventcfg.isUse then --此事件不使用了
return
end
local mailCfg = GetElemMatch2Cond(eventcfg.mails, value1, value2) --搜索匹配的事件配置
if mailCfg then
SendMail( Actor.getActorId(sysarg), mailCfg.title, mailCfg.content, mailCfg.awards )
end
end
--[[
离线玩家邮件
GlobalMailData[AtvId]
{
maxId ,--邮件id
offlineMail[1...]
{
sTitle --邮件标题
content -- 邮件内容
awards[]
{
type, --类型
id, --id
count, --数量
}
}
}
]]--
--获取玩家数据
function GetGlobalMailData(nActorId)
if nActorId == nil then
assert(false)
end
local var = System.getStaticVar();
if var.GlobalMailData == nil then
var.GlobalMailData = {}
end
if var.GlobalMailData[nActorId] == nil then
var.GlobalMailData[nActorId] = {}
end
return var.GlobalMailData[nActorId]
end
--发送usedata 类型的奖励
function SendUserDataMail(nActorId, sTitle,sContent,useDataTable)
if nActorId == 0 then
print("SendMail error,nActorId =0")
return
end
if not sTitle or not sContent then
print("SendMail error,sTitle or sContent = nil")
return
end
if not useDataTable then
print("SendMail error,useDataTable = nil")
return
end
local awardTable = {}
for v, _ in Ipairs(useDataTable) do
local mail ={}
mail.type = useDataTable[v].type
mail.id =useDataTable[v].id
mail.count =useDataTable[v].count
table.insert(awardTable, mail)
end
local nAwardCount = #awardTable
local nCurCount = 0
local splitTable = {}
if nAwardCount == 0 or nAwardCount < mailAttachCount then
System.sendSysMail(nActorId, sTitle, sContent, awardTable)
else
for i=1,nAwardCount do
nCurCount = nCurCount + 1
table.insert(splitTable, awardTable[i])
if i == nAwardCount or nCurCount >= mailAttachCount then --超过5个附件分开发
System.sendSysMail(nActorId, sTitle, sContent, splitTable)
nCurCount = 0
splitTable = {}
end
end
end
end
--触发邮件
function LoginCheckMail( sysarg)
local actorid = Actor.getActorId(sysarg);
local maildata = GetGlobalMailData(actorid);
if maildata.offlineMail == nil then
return
end
for v, infos in Ipairs(maildata.offlineMail) do
--print("infos.."..v);
local mail = maildata.offlineMail[v]
if mail then
print("LoginCheckMail, nActorId="..actorid..", title="..(mail.sTitle or 0)..", Content="..(mail.content or 0))
if mail.sTitle and mail.content then
SendUserDataMail( actorid, mail.sTitle, mail.content, mail.awards )
end
end
end
maildata.offlineMail = nil;--清空
end
--触发邮件
function AddOfflineMail( nActorId, title, Content, nCount,...)
print("AddOfflineMail, nActorId="..nActorId..", title="..title..", Content="..Content," nCount="..nCount)
local maildata = GetGlobalMailData(nActorId);
if maildata.offlineMail == nil then
maildata.offlineMail = {}
end
if maildata.offlineMail.maxId == nil then
maildata.offlineMail.maxId = 0
end
maildata.offlineMail.maxId = maildata.offlineMail.maxId + 1
local maxId = maildata.offlineMail.maxId;
maildata.offlineMail[maxId] = {}
--print("maxId"..maxId);
local offline = maildata.offlineMail[maxId];
offline.sTitle = title;
offline.content = Content;
offline.awards = {};
local arg={...}
for i,v in ipairs(arg) do
local index = i % 3;
local inType = math.ceil(i / 3);
if offline.awards[inType] == nil then
offline.awards[inType] = {}
end
--print("vv.."..v.."..inType.."..inType)
if index == 1 then
offline.awards[inType].type = v; --类型
elseif index == 2 then
offline.awards[inType].id = v;
else
offline.awards[inType].count = v;
end
end
end

View File

@@ -0,0 +1,321 @@
module("MonDispatcher", package.seeall)
--[[
个人数据ActorData
{
}
全局数据GlobalData[fdId]
{
}
缓存数据CacheData[fdId]
{
}
]]--
local IniScenes = {}
--注册场景
function InitScene(sceneId)
if IniScenes== nil then
IniScenes = {}
end
if IniScenes[sceneId] then
return
end
IniScenes[sceneId] = sceneId;
end
-- 场景是否注册
function IsInitScene(sceneId)
if IniScenes == nil then
return false;
end
return IniScenes[sceneId] ~= nil;
end
local dispatcher = { }
_G.MonEvent =
{
OnInitialize = 1, --初始化
OnEnterFuben = 2, --玩家进入Boss副本[玩家指针,副本指针, pOwner]
OnExitFuben = 3, --玩家离开Boss副本[玩家指针,副本指针, pOwner]
OnEntityDeath = 4, --副本实体死亡 [被杀者指针,击杀者指针,副本指针, pOwner]
OnEntityAttacked = 5, --副本实体收到伤害[副本指针,受击者,攻击者, pOwner]
OnReqData = 6, --boss数据
OnCancelBL = 7,--取消归属
OnSetBossBL = 8,--设置归属
OnCheckEnterFuben = 9, --boss进入检查
OnFubenFinish = 10, --活动副本结束 [, 副本指针,结果, pOwner] 1为完成0为失败nil则结果未知需要对应副本设置结果
OnReqEnterFuben = 11, --请求进入副本 [玩家指针, bossid]
Count = 12,
}
--------------------------------------------------------------------
-- Lua接口
--------------------------------------------------------------------
-- @brief 注册事件分发器
-- @param evId 事件id
-- @param atvType 活动类型
-- @param func 回调
function Reg(evId, nMonType, func, file)
--参数检查
if evId == nil or func == nil or file == nil or nMonType == nil then
print( debug.traceback() )
assert(false)
end
--事件范围检查
if evId <= 0 or evId >= MonEvent.Count then
assert(false)
end
--回调表初始化
if dispatcher[evId] == nil then
dispatcher[evId] = {}
end
if dispatcher[evId][nMonType] ~= nil then
assert(false) -- 重复注册了
end
--注册
dispatcher[evId][nMonType] = func
print("[TIP][MonDispatcher Add nMonType(Type:"..nMonType..")] Event("..evId..") In File("..file..")")
end
-- @brief 获取副本怪物的全局数据(这个数据,是存文件的)
-- @param fdId 副本id
function GetGlobalData(fdId)
if fdId == nil then
assert(false)
end
local var = System.getStaticVar();
if var.Mon == nil then
var.Mon = {}
end
if var.Mon[fdId] == nil then
var.Mon[fdId] = {}
end
return var.Mon[fdId]
end
-- @brief 清空某个bossId的全局数据这个数据是存文件的
-- @param bossId bossId
function ClearGlobalData(fdId)
if fdId == nil then
assert(false)
end
local var = System.getStaticVar();
if var.Mon == nil then
var.Mon = {}
end
if var.Mon[fdId] then
var.Mon[fdId] = nil
end
end
-- @brief 获取某个活动的缓存数据(这个数据,不存储仅缓存)
-- @param fbId 活动id
function GetCacheData(fdId)
if fdId == nil then
assert(false)
end
local var = System.getDyanmicVar();
if var.Mon == nil then
var.Mon = {}
end
if var.Mon[fdId] == nil then
var.Mon[fdId] = {}
end
return var.Mon[fdId]
end
-- @brief 清空boss副本的缓存数据这个数据不存储仅缓存
-- @param fbId 活动id
function ClearCacheData(fdId)
if fdId == nil then
assert(false)
end
local var = System.getDyanmicVar();
if var.Mon == nil then
var.Mon = {}
end
if var.Mon[fdId] then
var.Mon[fdId] = nil
end
end
-- @brief 获取boss副本的个人数据这个数据是存数据库的
-- @param atvId 活动id
function GetActorData(pActor, fdId)
if fdId == nil or Actor.getEntityType(pActor) ~= enActor then
assert(false)
end
local var = Actor.getStaticVar(pActor);
if var.Mon == nil then
var.Mon = {}
end
if var.Mon[fdId] == nil then
var.Mon[fdId] = {}
end
return var.Mon[fdId]
end
-- @brief 清空某个boss副本的个人数据这个数据是存数据库的
-- @param atvId 活动id
function ClearActorData(pActor, fdId)
if fdId == nil or Actor.getEntityType(pActor) ~= enActor then
assert(false)
end
local var = Actor.getStaticVar(pActor);
if var.Mon == nil then
var.Mon = {}
end
if var.Mon[fdId] then
var.Mon[fdId] = nil
end
end
-- @brief 进入活动副本
function EnterFuben(atvId,pActor,fbId)
-- local result = Actor.reqEnterFuben(pActor, fbId)
-- if result then
-- -- 回复活动id与副本句柄的关联
-- local npack = AllocOperReturn(pActor, atvId, ActivityOperate.sEnterFubenResult)
-- if npack then
-- DataPack.flush(npack)
-- end
-- -- 建立副本类型跟活动类型的对应关系
-- local fbHandle = Actor.getFubenHandle(pActor)
-- local pFuben = Fuben.getFubenPtrByHandle(fbHandle)
-- local atvType = 0
-- if (ActivitiesConf[atvId] and ActivitiesConf[atvId].ActivityType) then
-- atvType = ActivitiesConf[atvId].ActivityType
-- elseif (PActivitiesConf[atvId] and PActivitiesConf[atvId].ActivityType) then
-- atvType = PActivitiesConf[atvId].ActivityType
-- end
-- FubenDispatcher.MapToActivity(pFuben, atvType, atvId)
-- return fbHandle
-- end
-- return nil
end
--------------------------------------------------------------------
-- 活动副本回调
--------------------------------------------------------------------
function CheckEnterFuben(nMonType, nFubenId, nSceneId, pEntity)
-- 玩家指针(个人活动判断需要一个玩家指针)
if Actor.getEntityType(pEntity) ~= enActor then
return
end
-- 触发玩家进入boss副本
-- if IsInitScene(nSceneId) then
OnEvent(nMonType, MonEvent.OnEnterFuben,nFubenId,nSceneId, pEntity)
-- end
end
function CheckExitFuben(nMonType, nFubenId,nSceneId, pFuben, pEntity)
-- 玩家指针
if Actor.getEntityType(pEntity) ~= enActor then
return
end
-- 触发玩家退出Boss副本事件
OnEvent(nMonType, MonEvent.OnExitFuben, nFubenId, pFuben, nSceneId, pEntity)
end
function CheckFubenEntityDeath(nMonType,nFubenId, nSceneId, pFuben, pEntity, pKiller)
-- 暂时只处理boss死亡
if Actor.getEntityType(pEntity) == enPet then
return
end
if Actor.getEntityType(pKiller) == enPet then
pKiller = Actor.getMaster(pKiller)
end
-- 触发Boss副本实体死亡事件
OnEvent(nMonType, MonEvent.OnEntityDeath,pFuben, nFubenId, nSceneId, pEntity, pKiller)
end
function CheckFubenEntityAttacked(nMonType, nFubenId, nSceneId, pFuben, pEntity, pAttacker)
-- 玩家指针(个人活动判断需要一个玩家指针)
local pActor = nil
if Actor.getEntityType(pEntity) == enPet then
return
end
if Actor.getEntityType(pAttacker) == enPet then
pAttacker = Actor.getMaster(pAttacker)
end
-- 触发Boss副本实体受击事件
OnEvent(nMonType, MonEvent.OnEntityAttacked, pFuben, nFubenId, nSceneId, pEntity, pAttacker)
-- end
end
function CheckFubenFinish(nMonType,pFuben, result, pOwner)
-- 玩家指针(个人活动判断需要一个玩家指针)
local pActor = nil
if Actor.getEntityType(pOwner) == enActor then
pActor = pOwner
end
-- print("..nMonType.."..nMonType.."..result.."..result)
-- 触发活动副本结束事件
OnEvent(nMonType, MonEvent.OnFubenFinish, pFuben, result, pOwner)
end
-- @brief 进入Boss副本
function EnterMonFuben(nMonType,pActor,fbId, nSerial)
local result = Actor.reqEnterFuben(pActor, fbId)
if result then
-- 建立副本类型跟活动类型的对应关系
local fbHandle = Actor.getFubenHandle(pActor)
local pFuben = Fuben.getFubenPtrByHandle(fbHandle)
FubenDispatcher.MapToMonster(pFuben, nMonType, nSerial)
return fbHandle
end
return nil
end
--公共副本
function EnterGlobalMonFuben(fbHandle,nMonType, fbId)
-- 建立副本类型跟活动类型的对应关系
local pFuben = Fuben.getFubenPtrByHandle(fbHandle)
FubenDispatcher.MapToMonster(pFuben, nMonType, fbId)
end
function OnEvent(nMonType,evId, ...)
--获取回调
local callbacks = dispatcher[evId]
--回调调用
if callbacks and (callbacks[nMonType] ~= nil) then
local func = callbacks[nMonType];
return func(...)
end
return true;
end

View File

@@ -0,0 +1,37 @@
module("NetmsgDispatcher", package.seeall)
local dispatcher = {}
-- @brief 注册网络包的处理函数
-- @param sysId 系统id
-- @param cmd 系统内的消息号
function Reg(sysId, cmdId, func)
if cmdId == nil or sysId == nil then print( debug.traceback() ) end
if sysId > 256 or cmdId > 256 then
print("[ERROR][NetmsgDispatcher] sysId("..sysId..") or cmdId("..cmdId..") error!")
assert(false)
return
end
dispatcher[sysId] = dispatcher[sysId] or {}
dispatcher[sysId][cmdId] = func
System.regScriptNetMsg(sysId, cmdId)
return true
end
function OnNetMsg(sysId, cmdId, actor, pack)
if not dispatcher[sysId] then return end
local func = dispatcher[sysId][cmdId]
print("玩家:"..Actor.getActorId(actor)..",收到消息请求,系统:"..sysId..",协议:"..cmdId)
if func then
func(actor, pack)
end
end
_G.OnNetMsg=OnNetMsg
--[[ 详细见LogicServerCmd.h
]]

View File

@@ -0,0 +1,466 @@
module("NewCdkey", package.seeall)
--[[
游戏猫激活码功能
个人数据NewCdKeyData
{
lastTime,上次使用时间
codeTimes =
{
[id1], 礼包id1的使用次数
[id2],
}
}
]]--
local CODE_SUCCESS = 0 -- 成功
local CODE_INVALID = 1 -- 已被使用
local CODE_NOTEXIST = 2 -- 不存在
local CODE_USED = 3 -- 已使用过同类型
local CODE_ERR = 4 -- SQL查询错误
local CODE_TIME = 5 -- 未到使用时间
local CODE_TIMEEXPIRE = 6 -- 礼包码过期了
local CODE_HTTP = 11 -- HTTP接口错误
local CODE_PF = 12 -- 非本平台礼包码
local CODE_LIMIT = 13 -- 使用次数超过限制
--local NewCdkeyServiceConf={
-- PfId = "1",
-- host = "fgtest.bigrnet.com",--这里不能带http://
-- port = "80",
-- url = "/H5CQ/develop/Service/CheckGiftCodeYXM.php",
--}
--NewCdkeyAwards = {{type=0,id=261,count=5},{type=0,id=269,count=1},{type=7,id=7,count=20},{type=2,id=2,count=100000},}
local PfId = System.getPfId()
local SrvId = System.getServerId()
local ServiceConf = AutoCdkeyServiceConfig[PfId]
--local ServiceConf = NewCdkeyServiceConf
--配置的服务检测
function OnCheckCanPlatform()
print("[DEBUG] OnCheckCanPlatform")
-- 平台验证
if not PfId then
print("[ERR][CdKey YXM]1 load AutoCdkeyServiceConfig error! ")
return false
end
if ServiceConf == nil then
print("[ERR][CdKey YXM]2 load AutoCdkeyServiceConfig error! ")
return false
end
if ServiceConf.host == nil then
print("[ERR][CdKey YXM]3 load AutoCdkeyServiceConfig error! ")
return false
end
if ServiceConf.port == nil then
print("[ERR][CdKey YXM]4 load AutoCdkeyServiceConfig error! ")
return false
end
if ServiceConf.url == nil then
print("[ERR][CdKey YXM]5 load AutoCdkeyServiceConfig error! ")
return false
end
return true
end
-- 根据 CDKey 获取礼包码id
local function getCodeId(code)
local len = string.byte(string.sub(code, -1)) - 97
local pos = string.byte(string.sub(code, -2,-2)) - 97
local str = string.sub(code, pos + 1, pos + len)
--print("gift code len :"..tostring(len))
---print("gift code pos :"..tostring(pos))
--print("gift code str :"..tostring(str))
local id = 0
for i=1, string.len(str) do
id = id * 10 + (math.abs(string.byte(string.sub(str, i, i)) - 97))
end
return id
end
-- 检测平台号
local function checkPfid(code)
local pos = string.byte(string.sub(code, -2,-2)) - 97
local str = string.sub(code, 1, pos)
return str == PfId
end
--[[
-- 获取玩家的 CDKey 数据
local function getActorData(pActor)
if Actor.getEntityType(pActor) ~= enActor then
assert(false)
end
local var = Actor.getStaticVar(pActor);
if var.CdKeyData == nil then
var.CdKeyData = {}
end
if not var.CdKeyData.codeTimes then
var.CdKeyData.codeTimes = {}
end
return var.CdKeyData
end
-- 获取玩家的 CDKey 数据
function getActorCdkData(pActor)
if Actor.getEntityType(pActor) ~= enActor then
assert(false)
end
local var = Actor.getStaticVar(pActor);
if var.CdKeyData == nil then
var.CdKeyData = {}
end
if not var.CdKeyData.codeTimes then
var.CdKeyData.codeTimes = {}
end
if not var.CdKeyData.codeTypeTimes then
var.CdKeyData.codeTypeTimes = {}
end
return var.CdKeyData
end
--]]
-- 检测完CDKey后的回调
local function AfterCheckCDkeyNew(paramPack, content, result)
print("[DEBUG][CdKey YXM]1 AfterCheckCDkeyNew -------------------------content:"..tostring(content).."result:"..tostring(result))
local res = CODE_SUCCESS
local actid = 0
if (result == 0) then --有反馈
--for mu_id in string.gmatch(content, "(%w+),*") do
-- print('mu_id='..mu_id);
--end
local resPattern = "^(.*)(return_code%s*:%s)([^,]*)(.*)$"
strCapture1, strCapture2, res, strCapture3, strCapture4 = string.match(content, resPattern)
print("[CdKey YXM]1 -------------------------param1:"..tostring(strCapture1).."|param2:"..tostring(strCapture2).."|param3:"..tostring(res).."|param4:"..tostring(strCapture3).."|param5:"..tostring(strCapture4))
local aidPattern = "^(.*)(aid%s*:%s)([^,]*)(.*)$"
strCapture1, strCapture2, actid, strCapture3, strCapture4 = string.match(content, aidPattern)
print("[CdKey YXM]1 -------------------------param1:"..tostring(strCapture1).."|param2:"..tostring(strCapture2).."|param3:"..tostring(actid).."|param4:"..tostring(strCapture3).."|param5:"..tostring(strCapture4))
local cdkPattern = "^(.*)(cdk%s*:%s*)([^,]*)(.*)$"
strCapture1, strCapture2, cdk, strCapture3, strCapture4 = string.match(content, cdkPattern)
print("[CdKey YXM]1 -------------------------param1:"..tostring(strCapture1).."|param2:"..tostring(strCapture2).."|param3:"..tostring(cdk).."|param4:"..tostring(strCapture3).."|param5:"..tostring(strCapture4))
if (res == "0") then --新key
--邮件明不需要传了
--local mailtitlePattern = "^(.*)(mailtitle%s*:%s*)([^,]*)(.*)$"
--strCapture1, strCapture2, mailtitle, strCapture3, strCapture4 = string.match(content, mailtitlePattern)
--print("[CdKey YXM]1 -------------------------param1:"..tostring(strCapture1).."|param2:"..tostring(strCapture2).."|param3:"..tostring(mailtitle).."|param4:"..tostring(strCapture3).."|param5:"..tostring(strCapture4))
local mailtlistPattern = "^(.*)(maillist%s*:%s*[)([^]]*)(.*)$"
strCapture1, strCapture2, maillist, strCapture3, strCapture4 = string.match(content, mailtlistPattern)
print("[CdKey YXM]1 -------------------------param1:"..tostring(strCapture1).."|param2:"..tostring(strCapture2).."|param3:"..tostring(maillist).."|param4:"..tostring(strCapture3).."|param5:"..tostring(strCapture4))
local Awards = {}
local mailcount = 0
for kid, kcount, ktype in string.gmatch(maillist, "{\"id\":\"(%d+)\",\"count\":(%d+),\"type\":(%d+)}") do
local item = {}
item.type = ktype
item.id = kid
item.count = kcount
table.insert(Awards, item)
print("[CdKey YXM]kid, kcount, ktype param1:"..tostring(ktype).."|param2:"..tostring(kid).."|param3:"..tostring(kcount))
mailcount = mailcount + 1
end
if mailcount == 0 then
print("[TIP][CdKey YXM]AfterCheckCDkeyNew load mailconfig error! ---content is:"..tostring(content))
return
end
-- 获取结果
--res,actid,cdk,mailtitle = string.match(content, "(%d+),(%d+),(%a+),(%a+) ")
print("[CdKey YXM]1 AfterCheckCDkeyNew param-------------------------res:"..tostring(res).."|actid:"..tostring(actid).."|cdk:"..tostring(cdk).."|mailtitle:"..tostring(mailtitle)..":maillist:"..tostring(maillist))
res = tonumber(res)
actid = tonumber(actid)
if res ~= nil then
if res == CODE_SUCCESS then
-- 发派奖励
--local conf = CDKeyConf[id]
--SendMail(aid, mailtitle or "兑换码", conf.mailcontent or "兑换码兑换成功!", conf.awards)
SendMail(actid, "系统邮件", "尊敬的玩家:感谢您的支持,请查收您的礼包奖励。", Awards)-- NewCdkeyAwards)
-- 记录使用
--local data = getActorData(pActor)
--data.codeTimes[id] = (data.codeTimes[id] or 0) + 1
--data.codeTypeTimes[giftid] = (data.codeTypeTimes[giftid] or 0) + 1
end
else
res = CODE_HTTP
print("[TIP] AfterCheckCDkeyNew : res("..res.."), content: "..content)
end
elseif(res == "10") then
cdkPattern = "^(.*)(cdk%s*:%s*)([^}]*)(.*)$"
strCapture1, strCapture2, cdk, strCapture3, strCapture4 = string.match(content, cdkPattern)
print("[CdKey YXM]1 -------------------------param1:"..tostring(strCapture1).."|param2:"..tostring(strCapture2).."|param3:"..tostring(cdk).."|param4:"..tostring(strCapture3).."|param5:"..tostring(strCapture4))
-- 发派奖励
local id = getCodeId(cdk)
print("[TIP]1022 check old UseCDKey : id = " .. id)
local conf = CDKeyConf[id]
if conf == nil then
return
end
SendMail(actid, "系统邮件", "尊敬的玩家:感谢您的支持,请查收您的礼包奖励。", conf.awards)
elseif(res == "20") then-- 通码
--print("测试111")
cdkPattern = "^(.*)(cdk%s*:%s*)([^}]*)(.*)$"
strCapture1, strCapture2, cdk, strCapture3, strCapture4 = string.match(content, cdkPattern)
print("[CdKey YXM]1 -------------------------param1:"..tostring(strCapture1).."|param2:"..tostring(strCapture2).."|param3:"..tostring(cdk).."|param4:"..tostring(strCapture3).."|param5:"..tostring(strCapture4))
-- 发派奖励
local conf = CommonCDKeyConf[cdk]
if conf == nil then
return
end
SendMail(actid, "系统邮件", "尊敬的玩家:感谢您的支持,请查收您的礼包奖励。", conf.awards)
elseif(res == "7") then
print("[TIP] AfterCheckCDkeyNew : cdkey已经使用超过使用范围, content: "..content)
elseif(res == "8") then
print("[TIP] AfterCheckCDkeyNew : cdkey不存在, content: "..content)
elseif(res == "9") then
print("[TIP] AfterCheckCDkeyNew : cdkey数量不够, content: "..content)
elseif(res == "2") then
print("[TIP] AfterCheckCDkeyNew : cdkey不存在, content: "..content)
elseif(res == "1") then
print("[TIP] AfterCheckCDkeyNew : cdkey已经使用, content: "..content)
elseif(res == "11") then
print("[TIP] AfterCheckCDkeyNew : 危险账号,短时间访问, content: "..content)
else
print("[TIP] AfterCheckCDkeyNew : cdkey不存在, content: "..content)
end
else
res = CODE_HTTP
print("[ERROR] AfterCheckCDkeyNew : result("..result.."), content: "..content)
end
-- 回复使用结果
--local npack = DataPack.allocPacket(pActor, enMiscSystemID, sUseCdkey)
--if npack then
-- DataPack.writeByte(npack, res)
-- DataPack.flush(npack)
--end
end
--使用激活码
function UseCDKey(pActor, code)
print("[DEBUG] UseCDKey, code="..code)
local id = getCodeId(code)
if CDKeyConf[id] == nil then
print("[ERR][YXM] getCodeId error : code = " .. code.." name="..Actor.getName(pActor))
return 0
end
local limit = CDKeyConf[id].limits or 1 --礼包码限制数量
return limit
end
--使用通码
function UseCommonCDKey(code, actorId)
print("[DEBUG] UseCommonCDKey, code="..code)
local conf = CommonCDKeyConf[code]
if conf == nil then
print("[ERR][YXM] UseCommonCDKey:getCodeId error : code = " .. code)
return
end
local limit = 1 --礼包码限制数量 通码只能使用一次
return limit
--local pActor = Actor.getActorById(actorId)
--if pActor == nil then
-- return
--end
--local data = getActorData(pActor)
--local time = System.getCurrMiniTime()
--if data.lastTime and data.lastTime >= time then
-- Actor.sendTipmsg(pActor,"请求过快!")
-- return
--end
-- 使用次数超过限制
--if data.codeTimes[code] then
-- if data.codeTimes[code] >= 1 then
-- local npack = DataPack.allocPacket(pActor, enMiscSystemID, sUseCdkey)
-- if npack then
-- DataPack.writeByte(npack, CODE_LIMIT)
-- DataPack.flush(npack)
-- end
-- return
-- end
--end
-- 发派奖励
-- local conf = CommonCDKeyConf[code]
-- local aid = Actor.getActorId(pActor)
-- SendMail(aid, conf.mailtitle or "兑换码", conf.mailcontent or "兑换码兑换成功!", conf.awards)
-- 记录使用次数
-- local data = getActorData(pActor)
-- data.codeTimes[code] = (data.codeTimes[code] or 0) + 1
end
--是否是通码
function isCommonKey(code)
if CommonCDKeyConf and CommonCDKeyConf[code] then
return true
end
return false
end
-- 老的 客户端请求使用使用激活码
function OnUseOldCDKey(code, actorId)
print("[DEBUG][Tip]2 check old UseCDKey : code = " .. code)
local limit = 0
if isCommonKey(code) then
limit = 1 --礼包码限制数量 通码只能使用一次
return limit
else
if checkPfid(code) == false then --检测平台号
print("[TIP][YXM] UseCDKey: 不是老码 code = " .. code)
--Actor.sendTipmsg(pActor,"非本平台的礼包码!")
return limit
end
local id = getCodeId(code)
if CDKeyConf[id] == nil then
print("[ERR][YXM] getCodeId error : code = " .. code.." name="..Actor.getName(pActor))
return limit
end
limit = CDKeyConf[id].limits or 1 --礼包码限制数量
return limit
end
return limit
end
function OnCheckOldCDKey(code, actorId)
print("[Tip]1 check old UseCDKey : code = " .. code)
if isCommonKey(code) then
print("[Tip]1 check old111 isCommonKey : code = " .. code)
return 2
else
print("[Tip]1 check old112 isCommonKey : code = " .. code)
if checkPfid(code) == false then --检测平台号
return 0
end
local id = getCodeId(code)
print("[Tip]1022 check old UseCDKey : id = " .. id)
if CDKeyConf[id] == nil then
return 0
end
return 1
end
return 0
end
--------------------------------------------------------------------
-- CPP回调
--------------------------------------------------------------------
function OnCMDBackStageCdKey(packet)
if OnCheckCanPlatform() == false then
return
end
local SrvId = DataPack.readInt(packet)
local actorId = DataPack.readInt(packet)
local sUseCdkey = DataPack.readString(packet)
local sMailTitle = DataPack.readString(packet)
print("[CdKey YXM] OnCMDBackStageCdKey() -------------------------------------"..tostring(actorId).."|"..tostring(SrvId).."|"..sUseCdkey)
local ServiceConf = AutoCdkeyServiceConfig[PfId]
--local ServiceConf = NewCdkeyServiceConf
--配置的服务检测
if ServiceConf == nil then
print("[ERR][CdKey YXM]load AutoCdkeyServiceConfig error! ")
return
end
if ServiceConf.host == nil then
print("[ERR][CdKey YXM]load AutoCdkeyServiceConfig error! ")
return
end
if ServiceConf.port == nil then
print("[ERR][CdKey YXM]load AutoCdkeyServiceConfig error! ")
return
end
if ServiceConf.url == nil then
print("[ERR][CdKey YXM]load AutoCdkeyServiceConfig error! ")
return
end
local ServiceHost = ServiceConf.host
local ServicePort = ServiceConf.port
local ServiceUrl = ServiceConf.url
--local pActor = Actor.getActorById(actorId)
--print("[CdKey YXM] OnCMDBackStageCdKey() -------------------------------------"..Actor.getName(pActor))
local isOld = 0
local limit = 0
local keyType = OnCheckOldCDKey(sUseCdkey, actorId)
if keyType == 2 then
limit = 1
isOld = 2
elseif keyType == 1 then
limit = OnUseOldCDKey(sUseCdkey, actorId)
isOld = 1
print("[TIP][CdKey YXM]load OldCDKey Suc! ".. limit)
end
---local data = getActorData(pActor)
--local time = System.getCurrMiniTime()
--if data.lastTime and data.lastTime >= time then
-- print("[CdKey YXM] 请求过快! "..tostring(actorId).."|"..tostring(SrvId).."|"..sUseCdkey)
-- return
--end
--local req = ServiceUrl..'?pfid='..PfId..'&cdkey='..sUseCdkey..'&aid='..actorId..'&sid='..SrvId..'&mailtitle='..sMailTitle..'&limit='..limit..'&isOld='..isOld
local req = ServiceUrl..'?pfid='..PfId..'&cdkey='..sUseCdkey..'&aid='..actorId..'&sid='..SrvId..'&limit='..limit..'&isOld='..isOld
print("[CdKey YXM] GetHttpContent -------------------------ServiceHost:"..tostring(ServiceHost))
print("[CdKey YXM] GetHttpContent -------------------------ServicePort:"..tostring(ServicePort))
print("[CdKey YXM] GetHttpContent -------------------------req:"..tostring(req))
--加入异步工作
AsyncWorkDispatcher.Add(
{'GetHttpContent', ServiceHost, ServicePort, req},
AfterCheckCDkeyNew,
{SrvId, actorId}
)
--[[
local url111 = "/H5CQ/develop/Service/CheckGiftCodeLimit.php"
ServiceUrl = url111
local req = ServiceUrl..'?pfid='..'wyi2'..'&cdkey='..sUseCdkey..'&aid='..actorId..'&sid='..SrvId..'&account=111'..'&limit='..2
print("[CdKey YXM] GetHttpContent -------------------------ServiceHost:"..tostring(ServiceHost))
print("[CdKey YXM] GetHttpContent -------------------------ServicePort:"..tostring(ServicePort))
print("[CdKey YXM] GetHttpContent -------------------------req:"..tostring(req))
--加入异步工作
AsyncWorkDispatcher.Add(
{'GetHttpContent', ServiceHost, ServicePort, req},
AfterCheckCDkeyNew,
{SrvId, actorId}
)
-- ]]
end
--NetmsgDispatcher.Reg(enMiscSystemID, cUseNewCdkey, OnUseCDKey)

View File

@@ -0,0 +1,59 @@
module("QuestDispatcher", package.seeall)
local dispatcher = {}
_G.QuestEvent =
{
OnCompleteQuest = 1, --任务完成
Count = 1,
}
--------------------------------------------------------------------
-- Lua接口
--------------------------------------------------------------------
-- @brief 注册事件分发器
-- @param evId 事件id
-- @param questType 任务类型
-- @param func 回调
function Reg(evId, func, file)
--参数检查
if evId == nil or func == nil or file == nil then
print( debug.traceback() )
assert(false)
end
--事件范围检查
if evId <= 0 or evId >= QuestEvent.Count then
assert(false)
end
--回调表初始化
-- if dispatcher[evId] == nil then
-- dispatcher[evId] = {}
-- end
--注册
dispatcher[evId] = func
print("[TIP][QuestDispatcher] Event("..evId..") In File("..file.."), And Index="..table.maxn(dispatcher[evId]))
end
--------------------------------------------------------------------
-- CPP回调
--------------------------------------------------------------------
function OnEvent(evId, Qid, ...)
--获取回调
local func = dispatcher[evId]
if func == nil then
return true
end
--回调调用
if evId == FubenEvent.OnCompleteQuest then --任务完成
-- return func(fbId, fbEnterType, ...)
end
return true
end

View File

@@ -0,0 +1,119 @@
--所有排行榜的定义放在这里
--排行榜的ID 2000-2999
RANK_DEFINE_ACTIVITY3 = 1001 --活动类型3 竞技大乱斗排行榜
RANK_DEFINE_ACTIVITY4 = 1002 --活动类型4 世界boss排行榜
RANK_DEFINE_ACTIVITY11 = 1003 --活动类型11 夜战沃玛三排行榜
RANK_DEFINE_ACTIVITY16 = 1004 --活动类型16 捐献排行
RANK_DEFINE_ACTIVITY20 = 10020 --活动类型20 沙巴克玩家积分排行
RANK_DEFINE_ACTIVITY21 = 10021 --活动类型20 沙巴克积分排行
RANK_DEFINE_ACTIVITY17 = 1005 --活动类型17 跨服竞技大乱斗
RANK_DEFINE_ACTIVITY24 = 1006 --活动类型24 跨服首领排行
RANK_DEFINE_ACTIVITY23 = 1007 --活动类型23 跨服夜战沃玛三排行
RANK_DEFINE_ACTIVITY26 = 1008 --活动类型26 跨服逃脱试炼排行
RANK_DEFINE_ACTIVITY10033 = 1009 --活动类型10033 区服冠名
RankList =
{
[RANK_DEFINE_ACTIVITY3] = { --排行榜的Id
nMaxRecord = 100, --最大多少条记录
strName = "Activity3", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY4] = { --排行榜的Id
nMaxRecord = 100, --最大多少条记录
strName = "Activity4", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY11] = { --排行榜的Id
nMaxRecord = 100, --最大多少条记录
strName = "Activity11", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY16] = { --排行榜的Id
nMaxRecord = 10, --最大多少条记录
strName = "Activity16", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY20] = { --排行榜的Id
nMaxRecord = 100, --最大多少条记录
strName = "Activity20", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY21] = { --排行榜的Id
nMaxRecord = 100, --最大多少条记录
strName = "Activity21", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY17] = { --排行榜的Id
nMaxRecord = 10, --最大多少条记录
strName = "Activity17", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY24] = { --跨服首领排行Id
nMaxRecord = 10, --最大多少条记录
strName = "Activity18", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY23] = { --跨服夜战沃玛三排行Id
nMaxRecord = 10, --最大多少条记录
strName = "Activity19", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY26] = { --跨服逃脱试炼排行Id
nMaxRecord = 10, --最大多少条记录
strName = "Activity26", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
[RANK_DEFINE_ACTIVITY10033] = { --区服冠名Id
nMaxRecord = 10, --最大多少条记录
strName = "Activity10033", --排行榜的名字
tabColumn =
{ --列名字(如果没有就留空表{})
{"name"}, --行名字
{0 }, --默认值
},
},
}

View File

@@ -0,0 +1,450 @@
module("RankMgr", package.seeall)
--#include "RankDef.txt" once
--脚本的排行榜统一用ID,因为通过ID可以去拿到默认值
-----------------------------------------------只有一个nPoint的排行榜----------------------------------------------------
--初始化排行榜
function Init(nRankId, numMax)
if(type(nRankId) ~= 'number' or type(numMax) ~= 'number')then
return print(actorId, nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if(ranking ~= nil)then
return false
end
ranking = Ranking.add( nRankId,rankName, numMax, 1, 10 )
if(ranking == nil)then
return false
end
if not Ranking.load(ranking, nil) then
Ranking.addColumn(ranking, "name")
end
Ranking.addRef( ranking )
return true
end
--获取排行榜数据
function GetValue(actorId, nRankId)
if(type(actorId) ~= 'number' or type(nRankId) ~= 'number')then
return print(actorId, nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if ranking then
local item = Ranking.getItemPtrFromId( ranking, actorId)
if item then --已经榜上有名
return Ranking.getPoint(item)
end
end
return 0
end
--设置排行榜数据
function SetRank(actorId, nRankId, newValue )
if(type(actorId) ~= 'number' or type(nRankId) ~= 'number' or type(newValue) ~= 'number')then
return print(actorId, nRankId ,addValue)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return
end
local item = Ranking.getItemPtrFromId( ranking, actorId)
if item then --已经榜上有名
Ranking.setItem(ranking, actorId, newValue)
return true
end
local pActor = System.getEntityPtrByActorID(actorId)
if(pActor == nil)then -- 如果没记录,玩家又没在线,不处理
return false
end
item = Ranking.addItem(ranking, actorId, newValue)
if item then
Ranking.setSub(item, 0, Actor.getName(pActor))
end
end
--增加排行榜数据
function AddValue(actorId, nRankId, addValue)
if(type(actorId) ~= 'number' or type(nRankId) ~= 'number' or type(addValue) ~= 'number')then
return print(actorId, nRankId ,addValue)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return
end
local item = Ranking.getItemPtrFromId( ranking, actorId)
if item then --已经榜上有名
Ranking.updateItem(ranking, actorId, addValue)
return true
end --新加的
local pActor = System.getEntityPtrByActorID(actorId)
if(pActor == nil)then -- 如果没记录,玩家又没在线,不处理
return false
end
item = Ranking.addItem(ranking, actorId, addValue)
if item then
Ranking.setSub(item, 0, Actor.getName(pActor))
end
return true
end
--增加排行榜数据
function AddGuildRankValue(actorId, nRankId, addValue)
if(type(actorId) ~= 'number' or type(nRankId) ~= 'number' or type(addValue) ~= 'number')then
return print(actorId, nRankId ,addValue)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return
end
local item = Ranking.getItemPtrFromId( ranking, actorId)
if item then --已经榜上有名
Ranking.updateItem(ranking, actorId, addValue)
return true
end --新加的
local name = System.getGuildName(actorId)
if(name == nil)then -- 如果没记录,玩家又没在线,不处理
return false
end
item = Ranking.addItem(ranking, actorId, addValue)
if item then
Ranking.setSub(item, 0, name)
end
return true
end
--发送排行榜前num名
function SendToClient(pActor, nRankId, num, rankLimit, systemId, msgId)
if(type(nRankId) ~= 'number' or type(num) ~= 'number' or type(systemId) ~= 'number' or type(msgId) ~= 'number')then
return print(actorId, nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return
end
local itemNum = Ranking.getRankItemCount(ranking)
if num < Ranking.getRankItemCount(ranking) then
itemNum = num
end
local pack = DataPack.allocPacket(pActor, systemId, msgId)
if (pack == nil) then
return
end
DataPack.writeByte(pack, itemNum)
for idx=1,itemNum do
local rankItem = Ranking.getItemFromIndex(ranking, idx-1)
if rankItem then
local playerId = Ranking.getId(rankItem)
local value = Ranking.getPoint(rankItem)
local name = Ranking.getSub(rankItem, 0)
DataPack.writeUInt(pack, playerId)
DataPack.writeUInt(pack, value)
DataPack.writeString(pack, name)
end
end
--我的数据
local myId = Actor.getActorId(pActor)
local myStar = 0
local myIdx = 0
local item = Ranking.getItemPtrFromId( ranking, myId)
if item then
myStar = Ranking.getPoint(item) or 0
if myStar < rankLimit then --未上榜
myIdx = 0
else
myIdx = Ranking.getIndexFromPtr(item) + 1
end
end
DataPack.writeUInt(pack, myStar)
DataPack.writeWord(pack, myIdx)
DataPack.flush(pack)
end
--将排行榜前num名放入数据包不包括自己的排名
function PushToPack(nRankId, num, pack)
if(type(nRankId) ~= 'number' or type(num) ~= 'number')then
return print(actorId, nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return
end
local itemNum = Ranking.getRankItemCount(ranking)
if num < itemNum then
itemNum = num
end
if (pack == nil) then
return
end
DataPack.writeByte(pack, itemNum)
for idx=1,itemNum do
local rankItem = Ranking.getItemFromIndex(ranking, idx-1)
if rankItem then
local playerId = Ranking.getId(rankItem)
local value = Ranking.getPoint(rankItem)
local name = Ranking.getSub(rankItem, 0)
DataPack.writeUInt(pack, playerId)
DataPack.writeUInt(pack, value)
DataPack.writeString(pack, name)
local pActor = Actor.getActorById(playerId);
local handle = Actor.getHandle(pActor);
DataPack.writeUint64(pack, handle)
end
end
end
--获取我的排名
function GetMyRank(pActor, nRankId)
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return 0
end
local myId = Actor.getActorId(pActor)
local item = Ranking.getItemPtrFromId( ranking, myId)
if item then
return Ranking.getIndexFromPtr(item) + 1
else
return 0
end
end
--获取我的排名
function GetMyGuildRank(id, nRankId)
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return 0
end
local item = Ranking.getItemPtrFromId( ranking, id)
if item then
return Ranking.getIndexFromPtr(item) + 1
else
return 0
end
end
-----------------------------------------------多个value的排行榜----------------------------------------------------
--排行榜初始化函数
--RankName:排行榜的名称
--sRankFile:排行榜保存文件
--tbColumn:排行榜列 表 tbColumn = {"column0","column1","column2",}, {标题, 是否客户端显示}...}
--nMax:发给客户端最多的行数
function InitEx(nRankId, tbColumn, nMax)
if(type(nRankId) ~= 'number' or type(nMax) ~= 'number')then
return print(nRankId, nMax)
end
rankName = RankList[nRankId].strName
local sRankFile = rankName --默认排行榜的名字就是文件的名字
local ranking = Ranking.getRanking(nRankId) --通过排行名称获取排行对象
if ranking ~= nil then --有排行对象则创建失败
return false
end
ranking = Ranking.add(nRankId,rankName,nMax, 1, 10 ) --创建排行榜
if ranking == nil then
return false
end
local isLoad = Ranking.load(ranking,sRankFile) --读取文件内容
if isLoad == false then --加载排行榜失败,进行标题初始化
for i=1, table.getn(tbColumn) do
Ranking.addColumn(ranking,tbColumn[i]) --添加列名字
end
else
local colCount = Ranking.GetRankColumnCount(ranking)--如果排行榜的文件已经存在
local srcSize= #tbColumn
if colCount < srcSize then
for i = colCount + 1, srcSize do
Ranking.addColumn(ranking, tbColumn[i]) --添加列名字
end
end
end
Ranking.addRef(ranking) --增加对此排行对象的引用计数
end
--设置排行榜的数据
--colIdx从1开始0是name
--在涉及到领取道具的时候,为了避免出现异常,必须判断一下返回值
function SetRankEx(actorId, nRankId, colIdx, newColValue)
if(type(actorId) ~= 'number' or type(nRankId) ~= 'number')then
return print(actorId, nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return false
end
local item = Ranking.getItemPtrFromId( ranking, actorId )
if item then --已经榜上有名
Ranking.setSub(item, colIdx, newColValue) --这里不一定能设置成功
if Ranking.getSub(item, colIdx) ~= tostring(newColValue) then --列没有设置成功
return false
end
return true
end --新加的
local pActor = System.getEntityPtrByActorID(actorId)
if(pActor == nil)then -- 如果没记录,玩家又没在线,不处理
return false
end
item = Ranking.addItem(ranking, actorId, newColValue)
if (item == nil) then
return false
end
Ranking.setSub(item, 0, Actor.getName(pActor))
Ranking.setSub(item, colIdx, newColValue)
if Ranking.getSub(item, colIdx) ~= tostring(newColValue) then --列没有设置成功
return false
end
return true
end
--增加排行榜数据
function AddValueEx(actorId, nRankId, colIdx, addValue)
if(type(actorId) ~= 'number' or type(nRankId) ~= 'number' or type(addValue) ~= 'number')then
return print(actorId, nRankId ,addValue)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return
end
local item = Ranking.getItemPtrFromId( ranking, actorId)
if item then --已经榜上有名
local newColValue = tonumber(Ranking.getSub(item, colIdx)) or 0
newColValue = newColValue + addValue
Ranking.setSub(item, colIdx, newColValue)
return true
end --新加的
local pActor = System.getEntityPtrByActorID(actorId)
if(pActor == nil)then -- 如果没记录,玩家又没在线,不处理
return false
end
item = Ranking.addItem(ranking, actorId, addValue)
if item then
Ranking.setSub(item, 0, Actor.getName(pActor))
end
return true
end
local function _getValueByItem(item, colIdx, nRankId)
if (item == nil) then
return nil
end
if(type(colIdx) ~= 'number' or type(nRankId) ~= 'number')then
return print(colIdx, nRankId)
end
local colValue = Ranking.getSub(item, colIdx)
local Default = RankList[nRankId].tabColumn[2][colIdx] --默认值
if(Default == nil)then
return nil
end
if colValue == "-" then --返回默认值
return Default
end
if(type(Default) == 'string') then
return colValue
end
return tonumber(colValue)
end
-- 获取第colIdx列的数据
--如果排行榜不存在必须返回nil为无效数据避免异常情况
function GetValueById(actorId, nRankId, colIdx)
if(type(actorId) ~= 'number' or type(nRankId) ~= 'number')then
return print(actorId, nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return nil
end
local item = Ranking.getItemPtrFromId( ranking, actorId )
return _getValueByItem(item,colIdx,nRankId)
end
--按名次获取第colIdx列的数据(名次从0开始)
function GetValueByIndx(rankIndx, nRankId, colIdx)
if(type(rankIndx) ~= 'number' or type(nRankId) ~= 'number')then
return print(rankIndx, nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if (ranking == nil) then
return nil
end
local item = Ranking.getItemFromIndex( ranking, rankIndx )
return _getValueByItem(item,rankIndx,nRankId)
end
-----------------------------------所有排行榜共用接口-----------------------------------
function Clear(nRankId)
if(type(nRankId) ~= 'number')then
return print(nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if(ranking == nil)then
return
end
Ranking.clearRanking(ranking)
Ranking.save(ranking, rankName, true)
end
--排行榜销毁函数
function Remove(nRankId)
if(type(nRankId) ~= 'number')then
return print(nRankId)
end
local rankName = RankList[nRankId].strName
local sRankFile = rankName
Ranking.save(ranking,sRankFile)
Ranking.removeRanking(nRankId)
end
function Save(nRankId)
if(type(nRankId) ~= 'number')then
return print(nRankId)
end
local rankName = RankList[nRankId].strName
local ranking = Ranking.getRanking( nRankId )
if ranking then
Ranking.save(ranking, rankName, true)
end
end
--所有排行榜统一初始化
function AutoInit()
--print(" Enter AutoInit")
for RankId,RankInfo in pairs(RankList)do
local tbColumn = RankInfo.tabColumn[1]
local nMax = RankInfo.nMaxRecord
if(0 <#tbColumn)then
InitEx(RankId, tbColumn, nMax)
else
Init(RankId, nMax)
end
end
end
--[[
-- 使用例子
local actorId = Actor.getIntProperty( pActor, PROP_ENTITY_ID )
local colIdx = 1
local newColValue = 99
RankMgr.SetRankEx(actorId, 2001, colIdx, newColValue)
newColValue = RankMgr.GetValueById(actorId, 2001, colIdx)
print(newColValue)
--2001是排行榜的Id,定义在data\functions\Common\RankDef.txt
]]

View File

@@ -0,0 +1,50 @@
--调试脚本用,支持二个参数
--[[功能自定义编号]]
DEBUG_ACTIVITY_AsyncWork = 1000
DEBUG_ACTIVITY_EnterFuBen = 1001
DEBUG_ACTIVITY_ExitFuBen = 1002
DEBUG_ACTIVITY_SendMial = 1003
DEBUG_CDKEY = 1004
function TestAsyncWork(paramPack,ret,str)
local expect = paramPack.expect
if ret == expect then
print("AsyncWorker Test OK!")
print("AsyncWorker ret="..ret.." str="..str)
end
end
function TestCDKEY(paramPack,ret,numb)
print("CDKey Test OK!")
print("CDKey str="..ret)
print("CDKey numb="..numb)
end
-- 例子 @DebugLua 1000 1 1
function DOGMDebugLua(pActor, arg1, arg2, arg3)
if arg1 == DEBUG_ACTIVITY_AsyncWork then
AsyncWorkDispatcher.Add({'Test',arg2,arg3},TestAsyncWork,{expect=arg2+arg3})
elseif arg1 == DEBUG_ACTIVITY_EnterFuBen then
local atvId = tonumber(arg2)
local Conf = Activity1Config[atvId]
ActivityType1.operaEnterFuben(pActor,atvId,Conf)
elseif arg1 == DEBUG_ACTIVITY_ExitFuBen then
local atvId = tonumber(arg2)
local Conf = Activity1Config[atvId]
ActivityType1.operaExitFuben(pActor,atvId,Conf)
elseif arg1 == DEBUG_ACTIVITY_SendMial then
ActivityType3.SendRankAward(4)
elseif arg1 == DEBUG_CDKEY then
-- AsyncWorkDispatcher.Add(
-- {'GetHttpContent','fgtest.biggerking.cn','80','/H5CQ/develop/CheckGiftCode.php?pfid=4399&cdkey=4399baabih4qa2ee&aid=1&sid=11&account=abc'},
-- TestCDKEY,
-- {}
-- )
UseCDKey(pActor,'wyi2baabn7BLa1iiLzcmpXee')
end
end