|
|
@@ -18,10 +18,13 @@ local Json = require("common.Json")
|
|
|
|
|
|
AD_DRAW_REWARD_TYPE = 10 --观看广告领取召唤券
|
|
|
QUERY_MERGE_INFO_TYPE = 11 --获取融合信息
|
|
|
-QUERY_MERGE_BEFORE_INFO_TYPE = 15 --获取融合前信息
|
|
|
HATCH_SCCUESS_TYPE = 12 -- 孵化成功
|
|
|
MERGE_HERO_TYPE = 13 --融合
|
|
|
QUICK_HATCH_TYPE = 14 --加速
|
|
|
+QUERY_MERGE_BEFORE_INFO_TYPE = 15 --获取融合前信息
|
|
|
+WATCH_AD_QUICK_HATCH_TYPE = 16 --观看广告加速孵化 30分钟
|
|
|
+
|
|
|
+AD_HATCH_RESET_FREECNT = 4 --看广告加速孵化次数
|
|
|
|
|
|
function NewProto(human, type, param)
|
|
|
-- print("newProto:",type,param)
|
|
|
@@ -57,6 +60,69 @@ function NewProto(human, type, param)
|
|
|
return
|
|
|
end
|
|
|
|
|
|
+ -- 观看广告增加孵化速度
|
|
|
+ if type == WATCH_AD_QUICK_HATCH_TYPE then
|
|
|
+ human.db.adHatchRewardCnt = human.db.adHatchRewardCnt or 0
|
|
|
+
|
|
|
+ if human.db.adHatchRewardCnt > 4 then
|
|
|
+ Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_LIMIT_ERROR)
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local itemSpeedTime = 30 * 60
|
|
|
+ local nowTime = os.time()
|
|
|
+ local mergeInfo = {}
|
|
|
+ local mergeTime = 0
|
|
|
+ local heroSimple = {}
|
|
|
+ local xLv = human.db.mergeInfo.heroInfo.xLv or 0
|
|
|
+ local heroIndex = 0
|
|
|
+ local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
|
|
|
+ local isHatch = 2
|
|
|
+ local cf = sonHeroID and HeroExcel.hero[sonHeroID]
|
|
|
+ heroSimple.name = cf and cf.name or ""
|
|
|
+
|
|
|
+ --增加今日观看次数
|
|
|
+ human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
|
|
|
+
|
|
|
+ human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_TEST, "human.db.mergeInfo.endTime: " .. human.db.mergeInfo.endTime)
|
|
|
+
|
|
|
+ local hatchTime = human.db.mergeInfo.endTime - nowTime
|
|
|
+
|
|
|
+ if hatchTime < 0 then
|
|
|
+ -- 孵化成功
|
|
|
+ mergeTime = 0
|
|
|
+ isHatch = 3
|
|
|
+ Log.write(Log.LOGID_TEST, "孵化成功: " .. Json.Encode(human.db.mergeInfo))
|
|
|
+ heroIndex = hatchHero(human)
|
|
|
+ end
|
|
|
+
|
|
|
+ if heroIndex ~= 0 then
|
|
|
+ local heroGrid = human.db.heroBag[heroIndex]
|
|
|
+ if not heroGrid then return end
|
|
|
+ heroSimple.general = heroSimple.general or {}
|
|
|
+ HeroGrid.makeHeroSimple(heroSimple, heroGrid, nil, human)
|
|
|
+ else
|
|
|
+ local cf = sonHeroID and HeroExcel.hero[sonHeroID]
|
|
|
+ heroSimple.name = cf and cf.name or ""
|
|
|
+ isHatch = 1
|
|
|
+ end
|
|
|
+
|
|
|
+ mergeInfo.mergeTime = mergeTime
|
|
|
+ mergeInfo.xLv = xLv
|
|
|
+ mergeInfo.heroData = heroSimple
|
|
|
+ mergeInfo.isHatch = isHatch
|
|
|
+ mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_TEST, "看广告 mergeInfo: " .. Json.Encode(mergeInfo))
|
|
|
+
|
|
|
+ msgRet.ret = WATCH_AD_QUICK_HATCH_TYPE
|
|
|
+ msgRet.tip = Json.Encode(mergeInfo)
|
|
|
+ Msg.send(msgRet, human.fd)
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
-- 开始融合
|
|
|
if type == MERGE_HERO_TYPE then
|
|
|
local tb = Util.split(param, "|")
|
|
|
@@ -70,9 +136,6 @@ function NewProto(human, type, param)
|
|
|
local fatherHeroBagIndex = tonumber(tb[1]) or 0
|
|
|
local motherHeroBagIndex = tonumber(tb[2]) or 0
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST,
|
|
|
- "开始融合 fatherHeroBagIndex: " .. fatherHeroBagIndex .. "motherHeroBagIndex: " .. motherHeroBagIndex)
|
|
|
-
|
|
|
local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
|
|
|
if not fatherHeroGrid then
|
|
|
return
|
|
|
@@ -83,15 +146,9 @@ function NewProto(human, type, param)
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST, "motherHeroGrid: " .. Json.Encode(motherHeroGrid))
|
|
|
- Log.write(Log.LOGID_TEST, "fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
|
|
|
-
|
|
|
local fatherHeroAttr = ObjHuman.getHeroAttrs(human, fatherHeroBagIndex)
|
|
|
local motherHeroAttr = ObjHuman.getHeroAttrs(human, motherHeroBagIndex)
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST, "fatherHeroAttr: " .. Json.Encode(fatherHeroAttr))
|
|
|
- Log.write(Log.LOGID_TEST, "motherHeroAttr: " .. Json.Encode(motherHeroAttr))
|
|
|
-
|
|
|
local mergeInfo = {}
|
|
|
local attrs = RoleDefine.PANEL_ATTR_KEY
|
|
|
|
|
|
@@ -100,8 +157,6 @@ function NewProto(human, type, param)
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST, "sonHeroID: " .. sonHeroID)
|
|
|
-
|
|
|
for key, value in pairs(attrs) do
|
|
|
local param1 = fatherHeroAttr[key] or 0
|
|
|
local param2 = motherHeroAttr[key] or 0
|
|
|
@@ -117,17 +172,19 @@ function NewProto(human, type, param)
|
|
|
Log.write(Log.LOGID_TEST, "xLv: " .. xLv)
|
|
|
Log.write(Log.LOGID_TEST, "cnt: " .. cnt)
|
|
|
|
|
|
+ local bagCnt = BagLogic.getItemCnt(human, itemId, true)
|
|
|
+ if bagCnt < cnt then
|
|
|
+ Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
--使用道具
|
|
|
ItemLogic.use(human, itemId, cnt)
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST, "删除开始")
|
|
|
-
|
|
|
-- 删除英雄
|
|
|
HeroLogic.delHeroByIndex(human, fatherHeroBagIndex, "hero_merge")
|
|
|
HeroLogic.delHeroByIndex(human, motherHeroBagIndex, "hero_merge")
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST, "删除结束")
|
|
|
-
|
|
|
-- 记录融合英雄
|
|
|
human.db.mergeInfo.heroInfo.heroID = sonHeroID
|
|
|
human.db.mergeInfo.heroInfo.xLv = xLv
|
|
|
@@ -139,13 +196,15 @@ function NewProto(human, type, param)
|
|
|
|
|
|
Log.write(Log.LOGID_TEST, "human.db.mergeInfo : " .. Json.Encode(human.db.mergeInfo))
|
|
|
|
|
|
- local cf = sonHeroID and HeroExcel.hero[sonHeroID]
|
|
|
- heroSimple.name = cf and cf.name or ""
|
|
|
- mergeInfo.mergeTime = human.db.mergeInfo.hatchTime
|
|
|
- mergeInfo.xLv = xLv
|
|
|
- mergeInfo.heroData = heroSimple
|
|
|
+ local cf = sonHeroID and HeroExcel.hero[sonHeroID]
|
|
|
+ heroSimple.name = cf and cf.name or ""
|
|
|
+ mergeInfo.mergeTime = human.db.mergeInfo.hatchTime
|
|
|
+ mergeInfo.xLv = xLv
|
|
|
+ mergeInfo.heroData = heroSimple
|
|
|
+ mergeInfo.isHatch = 1
|
|
|
+ mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST, "mergeInfo: " .. Json.Encode(mergeInfo))
|
|
|
+ Log.write(Log.LOGID_TEST, "融合 mergeInfo: " .. Json.Encode(mergeInfo))
|
|
|
|
|
|
Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
|
|
|
|
|
|
@@ -200,15 +259,16 @@ function NewProto(human, type, param)
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local cf = sonHeroID and HeroExcel.hero[sonHeroID]
|
|
|
- heroSimple.name = cf and cf.name or ""
|
|
|
- mergeInfo.mergeTime = 0
|
|
|
- mergeInfo.xLv = xLv
|
|
|
- mergeInfo.mergeItem = mergeItem
|
|
|
- mergeInfo.heroData = heroSimple
|
|
|
- mergeInfo.isHatch = isHatch
|
|
|
+ local cf = sonHeroID and HeroExcel.hero[sonHeroID]
|
|
|
+ heroSimple.name = cf and cf.name or ""
|
|
|
+ mergeInfo.mergeTime = 0
|
|
|
+ mergeInfo.xLv = xLv
|
|
|
+ mergeInfo.mergeItem = mergeItem
|
|
|
+ mergeInfo.heroData = heroSimple
|
|
|
+ mergeInfo.isHatch = isHatch
|
|
|
+ mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST, "mergeInfo: " .. Json.Encode(mergeInfo))
|
|
|
+ Log.write(Log.LOGID_TEST, "查询融合前的 mergeInfo: " .. Json.Encode(mergeInfo))
|
|
|
|
|
|
msgRet.ret = QUERY_MERGE_BEFORE_INFO_TYPE
|
|
|
msgRet.tip = Json.Encode(mergeInfo)
|
|
|
@@ -249,6 +309,7 @@ function NewProto(human, type, param)
|
|
|
-- 孵化成功
|
|
|
mergeTime = 0
|
|
|
isHatch = 3
|
|
|
+ Log.write(Log.LOGID_TEST, "孵化成功: " .. Json.Encode(human.db.mergeInfo))
|
|
|
heroIndex = hatchHero(human)
|
|
|
end
|
|
|
|
|
|
@@ -263,11 +324,13 @@ function NewProto(human, type, param)
|
|
|
isHatch = 1
|
|
|
end
|
|
|
|
|
|
- mergeInfo.mergeTime = mergeTime
|
|
|
- mergeInfo.xLv = xLv
|
|
|
- mergeInfo.heroData = heroSimple
|
|
|
- mergeInfo.isHatch = isHatch
|
|
|
- Log.write(Log.LOGID_TEST, "mergeInfo: " .. Json.Encode(mergeInfo))
|
|
|
+ mergeInfo.mergeTime = mergeTime
|
|
|
+ mergeInfo.xLv = xLv
|
|
|
+ mergeInfo.heroData = heroSimple
|
|
|
+ mergeInfo.isHatch = isHatch
|
|
|
+ mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_TEST, "融合中 mergeInfo: " .. Json.Encode(mergeInfo))
|
|
|
|
|
|
msgRet.ret = QUERY_MERGE_INFO_TYPE
|
|
|
msgRet.tip = Json.Encode(mergeInfo)
|
|
|
@@ -301,7 +364,6 @@ function NewProto(human, type, param)
|
|
|
local lastSpeedTime = (60 * 5 * (cnt - 1)) --少一张加速券的加速时间
|
|
|
local itemCnt = 0
|
|
|
|
|
|
- --使用道具
|
|
|
if hatchTime > lastSpeedTime and hatchTime <= speedTime then
|
|
|
itemCnt = cnt
|
|
|
elseif hatchTime > 0 and hatchTime <= lastSpeedTime then
|
|
|
@@ -313,6 +375,13 @@ function NewProto(human, type, param)
|
|
|
end
|
|
|
|
|
|
itemSpeedTime = (60 * 5 * itemCnt)
|
|
|
+
|
|
|
+ local bagCnt = BagLogic.getItemCnt(human, itemId, true)
|
|
|
+ if bagCnt < itemCnt then
|
|
|
+ Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
--使用道具
|
|
|
ItemLogic.use(human, itemId, itemCnt)
|
|
|
else
|
|
|
@@ -341,19 +410,20 @@ function NewProto(human, type, param)
|
|
|
isHatch = 3
|
|
|
end
|
|
|
|
|
|
- Log.write(Log.LOGID_TEST, "加速后 human.db.mergeInfo : " .. Json.Encode(human.db.mergeInfo))
|
|
|
-
|
|
|
Broadcast.sendErr(human, Lang.QUICK_HATCH_SUCCESS)
|
|
|
|
|
|
- local mergeInfo = {}
|
|
|
- local heroSimple = {}
|
|
|
- mergeInfo.mergeTime = hatchTime
|
|
|
- mergeInfo.heroData = heroSimple
|
|
|
- mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
|
|
|
- mergeInfo.isHatch = isHatch
|
|
|
+ local mergeInfo = {}
|
|
|
+ local heroSimple = {}
|
|
|
+ mergeInfo.mergeTime = hatchTime
|
|
|
+ mergeInfo.heroData = heroSimple
|
|
|
+ mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
|
|
|
+ mergeInfo.isHatch = isHatch
|
|
|
+ mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
|
|
|
|
|
|
- msgRet.ret = QUICK_HATCH_TYPE
|
|
|
- msgRet.tip = Json.Encode(mergeInfo)
|
|
|
+ Log.write(Log.LOGID_TEST, "加速孵化 mergeInfo: " .. Json.Encode(mergeInfo))
|
|
|
+
|
|
|
+ msgRet.ret = QUICK_HATCH_TYPE
|
|
|
+ msgRet.tip = Json.Encode(mergeInfo)
|
|
|
Msg.send(msgRet, human.fd)
|
|
|
return
|
|
|
end
|
|
|
@@ -364,9 +434,17 @@ end
|
|
|
-- 孵化英雄
|
|
|
function hatchHero(human)
|
|
|
--添加英雄
|
|
|
- local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
|
|
|
+ local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
|
|
|
"hero_merge")
|
|
|
|
|
|
+ Log.write(Log.LOGID_TEST, "孵化英雄成功 下标" .. heroIndex)
|
|
|
+
|
|
|
+ local attrs = RoleDefine.PANEL_ATTR_KEY
|
|
|
+
|
|
|
+ for key, value in pairs(attrs) do
|
|
|
+ attrs[key] = 1
|
|
|
+ end
|
|
|
+
|
|
|
human.db.mergeInfo.startTime = 0
|
|
|
human.db.mergeInfo.endTime = 0
|
|
|
human.db.mergeInfo.heroInfo = {}
|
|
|
@@ -374,22 +452,9 @@ function hatchHero(human)
|
|
|
human.db.mergeInfo.heroInfo.xLv = 0
|
|
|
human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
|
|
|
human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
|
|
|
- human.db.mergeInfo.heroInfo.heroAttrs = RoleDefine.PANEL_ATTR_KEY
|
|
|
- human.db.heroBag = human.db.heroBag or {}
|
|
|
+ human.db.mergeInfo.heroInfo.heroAttrs = attrs
|
|
|
|
|
|
return heroIndex
|
|
|
- -- local heroGrid = human.db.heroBag[heroIndex]
|
|
|
- -- if type(heroGrid) ~= "table" then return end
|
|
|
-
|
|
|
- -- heroSimple.general = heroSimple.general or {}
|
|
|
- -- HeroGrid.makeHeroSimple(heroSimple, heroGrid, nil, human)
|
|
|
-
|
|
|
- -- data.heroData = heroSimple
|
|
|
- -- data.mergeTime = human.db.mergeInfo.mergeTime
|
|
|
-
|
|
|
- -- msgRet.ret = HATCH_SCCUESS_TYPE
|
|
|
- -- msgRet.tip = Json.Encode(data)
|
|
|
- -- Msg.send(msgRet, human.fd)
|
|
|
end
|
|
|
|
|
|
-- 初始化融合信息
|
|
|
@@ -431,8 +496,13 @@ function getxLv(fatherHeroGrid, motherHeroGrid)
|
|
|
local motherHeroXLv = motherHeroGrid.xLv or 0
|
|
|
local params1 = math.max(fatherHeroXLv, motherHeroXLv)
|
|
|
local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
|
|
|
+ local xLv = params1 + params2
|
|
|
|
|
|
- return params1 + params2
|
|
|
+ if xLv > 50 then
|
|
|
+ return 50
|
|
|
+ end
|
|
|
+
|
|
|
+ return xLv
|
|
|
end
|
|
|
|
|
|
-- 融合获取英雄ID
|
|
|
@@ -466,3 +536,9 @@ function mergeHero(fatherHeroID, motherHeroID)
|
|
|
end
|
|
|
return 0
|
|
|
end
|
|
|
+
|
|
|
+-- 获取剩余融化孵化加速广告观看次数
|
|
|
+function getResetAdHatchCnt(human)
|
|
|
+ local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
|
|
|
+ return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
|
|
|
+end
|