| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- local Msg = require("core.Msg")
- local Broadcast = require("broadcast.Broadcast")
- local Lang = require("common.Lang")
- local Grid = require("bag.Grid")
- local MergeRule = require("excel.mergeConfig").rule
- local BagLogic = require("bag.BagLogic")
- local Log = require("common.Log")
- local Util = require("common.Util")
- local ItemLogic = require("bag.ItemLogic")
- local HeroLogic = require("hero.HeroLogic")
- local HeroExcel = require("excel.hero")
- local RoleDefine = require("role.RoleDefine")
- local ObjHuman = require("core.ObjHuman")
- local HeroGrid = require("hero.HeroGrid")
- local Json = require("common.Json")
- local FenjieLogic = require("hecheng.FenjieLogic")
- local HeroBook = require("hero.HeroBook")
- AD_DRAW_REWARD_TYPE = 10 --观看广告领取召唤券
- QUERY_MERGE_INFO_TYPE = 11 --获取融合信息
- HATCH_SCCUESS_TYPE = 12 -- 孵化成功
- MERGE_HERO_TYPE = 13 --融合
- QUICK_HATCH_TYPE = 14 --加速
- QUERY_MERGE_BEFORE_INFO_TYPE = 15 --获取融合前信息
- GET_MERGE_HERO_TYPE = 16 --获取融合英雄
- QUERY_QUICK_HATCH_ZUANSHI = 17 --查询加速孵化需要的钻石
- AD_HATCH_RESET_FREECNT = 4 --看广告加速孵化次数
- function NewProto(human, type, param)
- -- print("newProto:",type,param)
- -- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
- -- msgRet.ret = type
- -- msgRet.tip = "test data"
- -- Msg.send(msgRet,human.fd)
- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
- -- 观看广告获取召唤券
- if type == AD_DRAW_REWARD_TYPE then
- human.db.adRewardCnt = human.db.adRewardCnt or 0
- if human.db.adRewardCnt > 4 then
- Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_LIMIT_ERROR)
- return
- end
- --增加今日观看次数
- human.db.adRewardCnt = (human.db.adRewardCnt or 0) + 1
- Log.write(Log.LOGID_TEST, "adRewardCnt: " .. human.db.adRewardCnt)
- -- 添加高级召唤卷
- BagLogic.addItem(human, 118, 1, "draw_ad_reward")
- msgRet.ret = AD_DRAW_REWARD_TYPE
- msgRet.tip = Lang.AD_DRAW_REWARD_SUCCESS
- Msg.send(msgRet, human.fd)
- Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_SUCCESS)
- return
- end
- -- 查询加速孵化需要的钻石
- if type == QUERY_QUICK_HATCH_ZUANSHI then
- -- 初始化
- initMergeInfo(human)
- local info = {}
- local nowTime = os.time
- local hatchTime = human.db.mergeInfo.endTime - nowTime
- info.zuanshi = doCalcNeedZuanshi(hatchTime)
- info.isTip = getTodayIsTip(human)
- msgRet.ret = QUERY_QUICK_HATCH_ZUANSHI
- msgRet.tip = Json.Encode(info)
- Msg.send(msgRet, human.fd)
- return
- end
- -- 获取融合前的信息
- if type == QUERY_MERGE_BEFORE_INFO_TYPE then
- local tb = Util.split(param, "|")
- if tb[1] and tb[2] then
- -- 初始化
- initMergeInfo(human)
- human.db.heroBag = human.db.heroBag or {}
- local fatherHeroBagIndex = tonumber(tb[1]) or 0
- local motherHeroBagIndex = tonumber(tb[2]) or 0
- Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroBagIndex: " .. fatherHeroBagIndex)
- Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroBagIndex: " .. motherHeroBagIndex)
- local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
- if not fatherHeroGrid then
- return
- end
- Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
- local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
- if not motherHeroGrid then
- return
- end
- Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroGrid: " .. Json.Encode(motherHeroBagIndex))
- local mergeInfo = {}
- local heroSimple = {}
- local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
- local cnt = math.floor(xLv / 2) + 1
- local isHatch = 2
- local mergeItem = {}
- local itemId = 178
- for k = 1, 1 do
- mergeItem[k] = mergeItem[k] or {}
- mergeItem[k].getway = mergeItem[k].getway or {}
- mergeItem[k].suipian = mergeItem[k].suipian or {}
- mergeItem[k].equip = mergeItem[k].equip or {}
- mergeItem[k].fuwen = mergeItem[k].fuwen or {}
- Grid.makeItem(mergeItem[k], itemId, cnt)
- end
- local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
- local cf = sonHeroID and HeroExcel.hero[sonHeroID]
- heroSimple.name = cf and cf.name or ""
- if cf.grade >= 6 then
- heroSimple.name = "?????"
- end
- mergeInfo.mergeTime = 0
- mergeInfo.xLv = xLv
- mergeInfo.mergeItem = mergeItem
- mergeInfo.heroData = heroSimple
- mergeInfo.isHatch = isHatch
- mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
- mergeInfo.isTip = getTodayIsTip(human)
- Log.write(Log.LOGID_TEST, "查询融合前的 mergeInfo: " .. Json.Encode(mergeInfo))
- msgRet.ret = QUERY_MERGE_BEFORE_INFO_TYPE
- msgRet.tip = Json.Encode(mergeInfo)
- Msg.send(msgRet, human.fd)
- end
- return
- end
- -- 开始融合
- if type == MERGE_HERO_TYPE then
- local tb = Util.split(param, "|")
- if tb[1] and tb[2] then
- -- 初始化
- initMergeInfo(human)
- human.db.heroBag = human.db.heroBag or {}
- local itemId = 178 --生命雨露
- local fatherHeroBagIndex = tonumber(tb[1]) or 0
- local motherHeroBagIndex = tonumber(tb[2]) or 0
- local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
- if not fatherHeroGrid then
- return
- end
- local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
- if not motherHeroGrid then
- return
- end
- local fatherHeroAttr = ObjHuman.getHeroAttrs(human, fatherHeroBagIndex)
- local motherHeroAttr = ObjHuman.getHeroAttrs(human, motherHeroBagIndex)
- local mergeInfo = {}
- local attrs = RoleDefine.PANEL_ATTR_KEY
- local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
- if sonHeroID <= 0 then
- return
- end
- for key, value in pairs(attrs) do
- local param1 = fatherHeroAttr[key] or 0
- local param2 = motherHeroAttr[key] or 0
- attrs[key] = math.floor(((param1 + param2) / 4))
- end
- Log.write(Log.LOGID_TEST, "融合后的属性: " .. Json.Encode(attrs))
- local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
- local cnt = math.floor(xLv / 2) + 1
- local heroSimple = {}
- 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)
- local outItems = {}
- local delHeroList = { [1] = fatherHeroBagIndex, [2] = motherHeroBagIndex }
- for heroIndex in pairs(delHeroList) do
- local heroID = HeroLogic.getHeroIdByIndex(human, heroIndex)
- local inputIDList = { [0] = 1, [1] = heroID }
- local inputIndexList = { [0] = 1, [1] = heroIndex }
- outItems[#outItems + 1] = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_MERGE, inputIDList,
- inputIndexList, nil, "hero_merge")
- end
- BagLogic.sendItemGetList3(human, outItems, "tenStar_displace")
- -- 删除英雄
- -- HeroLogic.delHeroByIndex(human, fatherHeroBagIndex, "hero_merge")
- -- HeroLogic.delHeroByIndex(human, motherHeroBagIndex, "hero_merge")
- -- 记录融合英雄
- human.db.mergeInfo.heroInfo.heroID = sonHeroID
- human.db.mergeInfo.heroInfo.xLv = xLv
- human.db.mergeInfo.heroInfo.heroAttrs = attrs
- human.db.mergeInfo.startTime = os.time()
- human.db.mergeInfo.endTime = os.time() + getHatchTime(xLv)
- human.db.mergeInfo.heroInfo.fatherHeroBagIndex = fatherHeroBagIndex
- human.db.mergeInfo.heroInfo.motherHeroBagIndex = motherHeroBagIndex
- local cf = sonHeroID and HeroExcel.hero[sonHeroID]
- heroSimple.name = cf and cf.name or ""
- if cf.grade >= 6 then
- heroSimple.name = "?????"
- end
- mergeInfo.mergeTime = getHatchTime(xLv)
- mergeInfo.xLv = xLv
- mergeInfo.heroData = heroSimple
- mergeInfo.isHatch = 1
- mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
- mergeInfo.isTip = getTodayIsTip(human)
- Log.write(Log.LOGID_TEST, "融合 mergeInfo: " .. Json.Encode(mergeInfo))
- Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
- msgRet.ret = MERGE_HERO_TYPE
- msgRet.tip = Json.Encode(mergeInfo)
- Msg.send(msgRet, human.fd)
- end
- return
- end
- -- 获取融合中的信息
- if type == QUERY_MERGE_INFO_TYPE then
- -- 初始化
- initMergeInfo(human)
- human.db.heroBag = human.db.heroBag or {}
- local mergeInfo = {}
- local mergeTime = 0
- local heroSimple = {}
- local xLv = human.db.mergeInfo.heroInfo.xLv or 0
- local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
- local isHatch = 2
- if sonHeroID == 0 then
- mergeInfo.mergeTime = mergeTime
- mergeInfo.xLv = xLv
- mergeInfo.heroData = heroSimple
- mergeInfo.isHatch = isHatch
- msgRet.ret = QUERY_MERGE_INFO_TYPE
- msgRet.tip = Json.Encode(mergeInfo)
- Msg.send(msgRet, human.fd)
- return
- end
- local mergeTime = human.db.mergeInfo.endTime - os.time()
- if mergeTime < 0 then
- -- 孵化成功
- mergeTime = 0
- isHatch = 3
- else
- isHatch = 1
- end
- local cf = sonHeroID and HeroExcel.hero[sonHeroID]
- heroSimple.name = cf and cf.name or ""
- if cf.grade >= 6 then
- heroSimple.name = "?????"
- end
- mergeInfo.mergeTime = mergeTime
- mergeInfo.xLv = xLv
- mergeInfo.heroData = heroSimple
- mergeInfo.isHatch = isHatch
- mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
- mergeInfo.isTip = getTodayIsTip(human)
- msgRet.ret = QUERY_MERGE_INFO_TYPE
- msgRet.tip = Json.Encode(mergeInfo)
- Log.write(Log.LOGID_TEST, "融合中 msgRet: " .. Json.Encode(msgRet))
- Msg.send(msgRet, human.fd)
- return
- end
- -- 获取融合英雄
- if type == GET_MERGE_HERO_TYPE then
- local nowTime = os.time()
- local mergeInfo = {}
- local heroSimple = {}
- local xLv = human.db.mergeInfo.heroInfo.xLv or 0
- local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
- local hatchTime = human.db.mergeInfo.endTime - nowTime
- local isHatch = 2
- local heroIndex = 0
- local msgTyep = GET_MERGE_HERO_TYPE
- local heroNiceNet = {}
- if hatchTime <= 0 then
- -- 孵化成功
- hatchTime = 0
- heroIndex = hatchHero(human)
- local heroGrid = human.db.heroBag[heroIndex]
- if not heroGrid then return end
- heroSimple.general = heroSimple.general or {}
- HeroGrid.makeHeroSimple(heroSimple, heroGrid, heroIndex, human)
- for i = 1, 1 do
- local heroID = sonHeroID
- local index = heroIndex
- local heroConfig = HeroExcel[heroID]
- local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
- HeroGrid.makeHeroNice(heroNiceNet, heroID, nil, isNew, index)
- end
- else
- local cf = sonHeroID and HeroExcel.hero[sonHeroID]
- heroSimple.name = cf and cf.name or ""
- if cf.grade >= 6 then
- heroSimple.name = "?????"
- end
- isHatch = 1
- msgTyep = QUERY_MERGE_INFO_TYPE
- end
- mergeInfo.mergeTime = hatchTime
- mergeInfo.xLv = xLv
- mergeInfo.heroData = heroSimple
- mergeInfo.isHatch = isHatch
- mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
- mergeInfo.isTip = getTodayIsTip(human)
- mergeInfo.heroNiceNet = heroNiceNet
- msgRet.ret = msgTyep
- msgRet.tip = Json.Encode(mergeInfo)
- Log.write(Log.LOGID_TEST, "获取英雄 ret: " .. Json.Encode(msgRet))
- Msg.send(msgRet, human.fd)
- return
- end
- -- 加速孵化
- if type == QUICK_HATCH_TYPE then
- local tb = Util.split(param, "|")
- local quickType = tonumber(tb[1]) or 0
- local cnt = tonumber(tb[2]) or 0
- local isHatch = 1
- if tb[1] and tb[2] then
- -- 初始化
- initMergeInfo(human)
- -- 剩余时间
- local nowTime = os.time()
- local hatchTime = human.db.mergeInfo.endTime - nowTime
- if hatchTime <= 0
- then
- Broadcast.sendErr(human, Lang.QUICK_HATCH_TIME_OUT)
- return
- end
- local itemSpeedTime = 0
- if quickType == 1 then
- local speedTime = (60 * 5 * cnt) -- 正常数量加速券的加速时间
- 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
- itemCnt = cnt - 1
- elseif hatchTime >= speedTime then
- itemCnt = cnt
- else
- itemCnt = 0
- end
- itemSpeedTime = (60 * 5 * itemCnt)
- local bagCnt = BagLogic.getItemCnt(human, 179, true)
- if bagCnt < itemCnt then
- Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
- return
- end
- --使用道具
- ItemLogic.use(human, 179, itemCnt)
- elseif quickType == 2 then
- local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
- -- 判断消耗
- if not ObjHuman.checkRMB(human, zuanshiCnt) then
- return
- end
- itemSpeedTime = (30 * zuanshiCnt)
- -- 扣钻石
- ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
- if tb[3] then
- human.db.isTip = human.db.isTip or 1
- human.db.isTip = tonumber(tb[3])
- end
- elseif quickType == 3 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
- --加速30分钟
- itemSpeedTime = 30 * 60
- --增加今日观看次数
- human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
- end
- human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
- local hatchTime = human.db.mergeInfo.endTime - nowTime
- -- 孵化成功
- if hatchTime < 0 then
- hatchTime = 0
- isHatch = 3
- end
- local mergeInfo = {}
- local heroSimple = {}
- local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
- local cf = sonHeroID and HeroExcel.hero[sonHeroID]
- heroSimple.name = cf and cf.name or ""
- if cf.grade >= 6 then
- heroSimple.name = "?????"
- end
- mergeInfo.mergeTime = hatchTime
- mergeInfo.heroData = heroSimple
- mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
- mergeInfo.isHatch = isHatch
- mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
- mergeInfo.isTip = getTodayIsTip(human)
- msgRet.ret = QUICK_HATCH_TYPE
- msgRet.tip = Json.Encode(mergeInfo)
- Log.write(Log.LOGID_TEST, "加速孵化 ret: " .. Json.Encode(msgRet))
- Msg.send(msgRet, human.fd)
- return
- end
- return
- end
- end
- -- 孵化英雄
- function hatchHero(human)
- --添加英雄
- 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 = {}
- human.db.mergeInfo.heroInfo.heroID = 0
- human.db.mergeInfo.heroInfo.xLv = 0
- human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
- human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
- human.db.mergeInfo.heroInfo.heroAttrs = attrs
- Log.write(Log.LOGID_TEST, "孵化重置 mergeInfo: " .. Json.Encode(human.db.mergeInfo))
- return heroIndex
- end
- -- 初始化融合信息
- function initMergeInfo(human)
- human.db.mergeInfo = human.db.mergeInfo or {}
- human.db.mergeInfo.startTime = human.db.mergeInfo.startTime or 0 --融合时间 时间戳
- human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0 --孵化时间 单位s
- human.db.mergeInfo.heroInfo = human.db.mergeInfo.heroInfo or {}
- human.db.mergeInfo.heroInfo.heroID = human.db.mergeInfo.heroInfo.heroID or 0
- human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
- human.db.mergeInfo.heroInfo.fatherHeroBagIndex = human.db.mergeInfo.heroInfo.fatherHeroBagIndex or 0
- human.db.mergeInfo.heroInfo.motherHeroBagIndex = human.db.mergeInfo.heroInfo.motherHeroBagIndex or 0
- human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
- end
- -- 获取孵化时间 单位s
- function getHatchTime(xLv)
- local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
- if time < 0 then
- return 0
- end
- return time * 60
- end
- -- 计算需要钻石数量
- function doCalcNeedZuanshi(hatchTime)
- local cnt = 0
- if hatchTime > 0 then
- cnt = math.ceil(hatchTime / 30)
- end
- return cnt
- end
- -- 获取xlv
- function getxLv(fatherHeroGrid, motherHeroGrid)
- local fatherHeroXLv = fatherHeroGrid.xLv or 0
- 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
- if xLv > 50 then
- return 50
- end
- return xLv
- end
- -- 融合获取英雄ID
- function mergeHero(fatherHeroID, motherHeroID)
- local fatherHeroConfig = HeroExcel.hero[fatherHeroID]
- local motherHeroConfig = HeroExcel.hero[motherHeroID]
- if not fatherHeroConfig or not motherHeroConfig then
- return 0
- end
- --规则3 heroID + heroID
- for _, config in pairs(MergeRule[3].items) do
- if fatherHeroID == config[1] and motherHeroID == config[2] then
- return config[3]
- end
- end
- --规则2 种族 + heroID
- for _, config in pairs(MergeRule[2].items) do
- if fatherHeroConfig.camp == config[1] and motherHeroID == config[2] then
- return config[3]
- end
- end
- --规则1 种族 + 种族
- for _, config in pairs(MergeRule[1].items) do
- if fatherHeroConfig.camp == config[1] and motherHeroConfig.camp == config[2] then
- return config[3]
- end
- end
- return 0
- end
- -- 获取剩余融化孵化加速广告观看次数
- function getResetAdHatchCnt(human)
- local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
- return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
- end
- -- 获取是否今日不再提示
- function getTodayIsTip(human)
- local isTip = human.db.isTip or 1
- return tonumber(isTip)
- end
|