| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- local Msg = require("core.Msg")
- local Broadcast = require("broadcast.Broadcast")
- local Lang = require("common.Lang")
- local ItemDefine = require("bag.ItemDefine")
- local Grid = require("bag.Grid")
- local DrawCardLogic = require("drawCard.DrawCardLogic")
- 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")
- 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 --获取融合前信息
- WATCH_AD_QUICK_HATCH_TYPE = 16 --观看广告加速孵化 30分钟
- 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 == 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, "|")
- 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)
- -- 删除英雄
- 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
- 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
- mergeInfo.isHatch = 1
- mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(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_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
- 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 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)
- if sonHeroID <= 0 then
- 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
- mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(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 == 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 heroIndex = 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
- 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 = QUERY_MERGE_INFO_TYPE
- msgRet.tip = Json.Encode(mergeInfo)
- Msg.send(msgRet, human.fd)
- return
- end
- -- 加速孵化
- if type == QUICK_HATCH_TYPE then
- local tb = Util.split(param, "|")
- local itemId = tonumber(tb[1]) or 0
- local cnt = tonumber(tb[2]) or 0
- local isHatch = 2
- if tb[1] and tb[2] then
- -- 初始化
- initMergeInfo(human)
- -- 剩余时间
- local nowTime = os.time()
- local hatchTime = human.db.mergeInfo.endTime - nowTime
- if hatchTime <= 0
- then
- return
- end
- local itemSpeedTime = 0
- if itemId == 179 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, itemId, true)
- if bagCnt < itemCnt then
- Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
- return
- end
- --使用道具
- ItemLogic.use(human, itemId, itemCnt)
- else
- local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
- -- 判断消耗
- if not ObjHuman.checkRMB(human, zuanshiCnt) then
- return
- end
- itemSpeedTime = (30 * zuanshiCnt)
- -- 扣钻石
- ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
- end
- 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
- hatchTime = 0
- isHatch = 3
- end
- 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
- mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
- 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
- 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
- return heroIndex
- end
- -- 初始化融合信息
- function initMergeInfo(human)
- human.db.mergeInfo = human.db.mergeInfo or {}
- human.db.mergeInfo.mergeTime = human.db.mergeInfo.mergeTime or 0 --融合时间 时间戳
- human.db.mergeInfo.hatchTime = human.db.mergeInfo.hatchTime 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
|