| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- 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")
- 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 --加速
- 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)
- -- 观看广告获取召唤券
- 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
- -- 添加高级召唤卷
- BagLogic.addItem(human, 118, 1, "draw_ad_reward")
- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
- 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)
- 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
- Log.write(Log.LOGID_TEST,
- "开始融合 fatherHeroBagIndex: " .. fatherHeroBagIndex .. "motherHeroBagIndex: " .. motherHeroBagIndex)
- local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
- if not heroGrid then
- return
- end
- local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
- if not heroGrid then
- 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
- local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
- if sonHeroID <= 0 then
- 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
- 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)
- --使用道具
- 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, "删除结束")
- -- for heroIndex = 1, human.db.heroBag[0] do
- -- local heroGrid = human.db.heroBag[heroIndex]
- -- if heroGrid.id == fatherHeroID or heroGrid.id == motherHeroID then
- -- end
- -- end
- -- 记录融合英雄
- human.db.mergeInfo.heroInfo.heroID = sonHeroID
- human.db.mergeInfo.heroInfo.xLv = xLv
- human.db.mergeInfo.heroInfo.heroAttrs = attrs
- human.db.mergeInfo.mergeStartTime = os.time()
- human.db.mergeInfo.mergeEndTime = os.time() + getHatchTime(xLv)
- human.db.mergeInfo.mergeTime = 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.mergeTime
- mergeInfo.xLv = xLv
- mergeInfo.heroData = heroSimple
- Log.write(Log.LOGID_TEST, "mergeInfo: " .. Json.Encode(mergeInfo))
- Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
- 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 heroGrid then
- return
- end
- local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
- if not heroGrid then
- return
- end
- local mergeInfo = {}
- local heroSimple = {}
- local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
- local cnt = math.floor(xLv / 2) + 1
- 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 = human.db.mergeInfo.mergeTime
- mergeInfo.xLv = xLv
- mergeInfo.heroData = heroSimple
- Log.write(Log.LOGID_TEST, "mergeInfo: " .. Json.Encode(mergeInfo))
- local msgRet = Msg.gc.QUERY_MERGE_BEFORE_INFO_TYPE
- msgRet.ret = QUERY_MERGE_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 nowTime = os.time()
- local mergeTime = 0
- local heroSimple = {}
- local xLv = human.db.mergeInfo.heroInfo.xLv
- local sonHeroID = human.db.mergeInfo.heroInfo.heroID
- if sonHeroID <= 0 then
- return
- end
- if human.db.mergeInfo.mergeEndTime ~= 0 then
- mergeTime = human.db.mergeInfo.mergeEndTime - nowTime
- -- 孵化成功
- if mergeTime <= 0 then
- hatchHero(human)
- return
- end
- end
- local cf = sonHeroID and HeroExcel.hero[sonHeroID]
- heroSimple.name = cf and cf.name or ""
- mergeInfo.mergeTime = human.db.mergeInfo.mergeTime
- mergeInfo.xLv = xLv
- mergeInfo.heroData = heroSimple
- Log.write(Log.LOGID_TEST, "mergeInfo: " .. Json.Encode(mergeInfo))
- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
- 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
- if tb[1] and tb[2] then
- -- 初始化
- initMergeInfo(human)
- --使用道具
- ItemLogic.use(human, itemId, cnt)
- local remainingTime = human.db.mergeInfo.mergeTime - (60 * cnt)
- Log.write(Log.LOGID_TEST, "remainingTime: " .. remainingTime)
- -- 孵化成功
- if remainingTime <= 0 then
- hatchHero(human)
- -- return
- 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 = {}
- -- heroSimple.general = heroSimple.general or {}
- -- HeroGrid.makeHeroSimpleByID(heroSimple, human.db.mergeInfo.heroId, nil, nil, human)
- mergeInfo.mergeTime = human.db.mergeInfo.mergeTime
- mergeInfo.heroData = heroSimple
- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
- 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")
- local data = {}
- local heroSimple = {}
- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
- human.db.mergeInfo.mergeStartTime = 0
- human.db.mergeInfo.mergeEndTime = 0
- human.db.mergeInfo.mergeTime = 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 = RoleDefine.PANEL_ATTR_KEY
- human.db.heroBag = human.db.heroBag or {}
- 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
- -- 初始化融合信息
- function initMergeInfo(human)
- human.db.mergeInfo = human.db.mergeInfo or {}
- human.db.mergeInfo.mergeStartTime = human.db.mergeInfo.mergeStartTime or 0
- human.db.mergeInfo.mergeEndTime = human.db.mergeInfo.mergeEndTime or 0
- human.db.mergeInfo.mergeTime = human.db.mergeInfo.mergeTime or 0
- 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(human, xLv)
- local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
- if time < 0 then
- return 0
- end
- return time * 60
- end
- -- 获取xlv
- function getxLv(fatherHeroGrid, motherHeroGrid)
- local params1 = math.max(fatherHeroGrid.xLv, motherHeroGrid.xLv)
- local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
- return params1 + params2
- 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
|