Json = Json or require("common.Json") local Log = require("common.Log") local Msg = require("core.Msg") local Broadcast = require("broadcast.Broadcast") local Grid = require("bag.Grid") local UnionExcel = require("excel.union") local ItemDefine = require("bag.ItemDefine") local BagLogic = require("bag.BagLogic") local ObjHuman = require("core.ObjHuman") local Lang = require("common.Lang") local HeroExcel = require("excel.hero") local RoleAttr = require("role.RoleAttr") local ChengjiuLogic = require("chengjiu.ChengjiuLogic") local UnionDBLogic = require("union.UnionDBLogic") local Util = require("common.Util") local UnionLivenessLogic = require("union.UnionLivenessLogic") local UnionDefine = require("union.UnionDefine") local RoleDefine = require("role.RoleDefine") local TriggerDefine = require("trigger.TriggerDefine") local TriggerLogic = require("trigger.TriggerLogic") TEC_OCCU_CNT = 4 TEC_TIER_CNT = 6 -- 获取科技配置 local function getTechnologyCfg(job, tier) local config = UnionExcel.technology local cfg = nil for i = 1, #config do cfg = config[i] if cfg ~= nil and cfg.occu == job and cfg.tier == tier then return cfg end end end -- 计算科技属性 function doCalcHero(human, grid, attrs) if not human then return end if not human.db.unionUuid or human.db.unionUuid == "" then return end if not human.db.technology then return end local heroConfig = HeroExcel.hero[grid.id] local technology = human.db.technology[heroConfig.job] if technology == nil then return end local techCfg = nil for i = 1,TEC_TIER_CNT do local tech = technology[i] if tech ~= nil and tech.lv ~= nil then techCfg = getTechnologyCfg(heroConfig.job, i) if techCfg ~= nil then for k, v in pairs(techCfg.fortify) do local addValue = v[2] * tech.lv RoleAttr.updateValue(v[1],addValue,attrs) end end end end end function getTechLvByJob(human, job) if not human then return 0 end if not human.db.technology then return 0 end local technology = human.db.technology[job] return technology and technology.lv or 0 end function lvAllUpByGm(human) if human.db.unionUuid == nil then return end human.db.technology = human.db.technology or {} local technology = human.db.technology local config = UnionExcel.technology local len = #config for i = 1, TEC_OCCU_CNT do technology[i] = technology[i] or {} local techOccu = technology[i] for j = 1, TEC_TIER_CNT do techOccu[j] = techOccu[j] or {} for z = 1, len do local v = config[z] if v.occu == i and v.tier == j then techOccu[j].lv = v.lvMax break end end end end end -- 获取其他科技的总等级 function getOtherLv(human, occu) local lv = 9999 if human.db.technology then local technology = human.db.technology for i = 1, TEC_OCCU_CNT do if technology[i] and i ~= occu then local thisLv = technology[i].lv or 0 if lv >= thisLv then lv = thisLv end elseif not technology[i] then lv = 0 end end end lv = lv ~= 9999 and lv or 0 return lv end function getID(occu, tier) local id = 0 for k, v in ipairs(UnionExcel.technology) do if v and v.occu == occu and v.tier == tier then id = k break end end return id end -- 获取该等级所需要的 磨坊等级 和其他 科技等级 function getNeedMillOhter(lv, occu, tier) local needMill = 0 local needOther = 0 local id = getID(occu, tier) local config = UnionExcel.technology[id] for k, v in ipairs(config.needMill) do if v and v[1] <= lv then needMill = v[2] end end local changeLv = config.needSumLv[1] local initLv = config.needSumLv[2] if lv < changeLv then needOther = 0 else needOther = initLv + (lv - changeLv ) * 1 end return needMill,needOther end function techQuery(human, occu) -- 没有加入公会查什么科技 if human.db.unionUuid == nil then return end -- 对不起,你要查的科技这里没得卖,请你出去 if occu == nil then return end if occu < 1 or occu > TEC_OCCU_CNT then return end local union = UnionDBLogic.getUnion(human.db.unionUuid) if not union then return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO) end local millLv = UnionDBLogic.getMillLv(union) local config = UnionExcel.technology local msgRet = Msg.gc.GC_UNION_TECHNOLOGY_QUERY if human.db.technology == nil or human.db.technology[occu] == nil then msgRet.techLv = 1 local consumeConfig = UnionExcel.tecConsume[1] for i = 1,TEC_TIER_CNT do if i == 1 then msgRet.technology[i].canLvUp = 1 else msgRet.technology[i].canLvUp = 3 end local getID = getID(occu, i) local needMillLv, needOther = getNeedMillOhter(0, occu, i) local thisConfig = UnionExcel.technology[getID] msgRet.technology[i].lv = 0 msgRet.technology[i].tier = i msgRet.technology[i].techMsg[0] = 0 msgRet.technology[i].techMsgNext[0] = 0 msgRet.technology[i].name = thisConfig.name msgRet.technology[i].maxLV = thisConfig.lvMax -- msgRet.technology[i].needMillLv = needMillLv -- msgRet.technology[i].otherLv = getOtherLv(human, occu) -- msgRet.technology[i].needOhterLv = needOther msgRet.technology[i].banner = thisConfig.banner for k = 1, #thisConfig.fortify do msgRet.technology[i].techMsg[k].key = thisConfig.fortify[k][1] msgRet.technology[i].techMsg[k].value = thisConfig.fortify[k][2] * msgRet.technology[i].lv -- msgRet.technology[i].techMsg[k].name = thisConfig.techName[k] msgRet.technology[i].techMsg[0] = msgRet.technology[i].techMsg[0] + 1 msgRet.technology[i].techMsgNext[k].key = thisConfig.fortify[k][1] msgRet.technology[i].techMsgNext[k].value = thisConfig.fortify[k][2] * (msgRet.technology[i].lv + 1) -- msgRet.technology[i].techMsgNext[k].name = thisConfig.techName[k] msgRet.technology[i].techMsgNext[0] = msgRet.technology[i].techMsgNext[0] + 1 end msgRet.technology[i].lvUpNeed[0] = 2 msgRet.technology[i].tier = i local jinbiCnt = consumeConfig["location"..i][1][2] local coinCnt = consumeConfig["location"..i][2][2] Grid.makeItem(msgRet.technology[i].lvUpNeed[1], ItemDefine.ITEM_JINBI_ID, jinbiCnt) Grid.makeItem(msgRet.technology[i].lvUpNeed[2], ItemDefine.ITEM_UNION_COIN_ID, coinCnt) -- msgRet.technology[i].needMillLv = 0 end msgRet.technology[0] = TEC_TIER_CNT else msgRet.techLv = 1 if human.db.technology[occu] and human.db.technology[occu].lv then msgRet.techLv = human.db.technology[occu].lv end for i = 1, TEC_TIER_CNT do human.db.technology[occu][i] = human.db.technology[occu][i] or {} human.db.technology[occu][i].lv = human.db.technology[occu][i].lv or 0 if i == 1 then if human.db.technology[occu][i].lv >= config[i].lvMax then msgRet.technology[i].canLvUp = 2 msgRet.techLv = config[i].lvMax else if human.db.technology[occu][i].lv == 0 then msgRet.technology[i].canLvUp = 1 else if human.db.technology[occu][TEC_TIER_CNT] and human.db.technology[occu][TEC_TIER_CNT].lv == human.db.technology[occu][i].lv then msgRet.technology[i].canLvUp = 1 else msgRet.technology[i].canLvUp = 2 end end end else if human.db.technology[occu][i].lv >= config[i].lvMax then msgRet.technology[i].canLvUp = 2 else if human.db.technology[occu][i - 1].lv == human.db.technology[occu][i].lv + 1 then msgRet.technology[i].canLvUp = 1 elseif human.db.technology[occu][i].lv == human.db.technology[occu][1].lv and human.db.technology[occu][1].lv ~= 0 then if human.db.technology[occu].lv == human.db.technology[occu][i].lv then msgRet.technology[i].canLvUp = 3 else msgRet.technology[i].canLvUp = 2 end else msgRet.technology[i].canLvUp = 3 end end end local getID = getID(occu, i) local needMillLv, needOther = getNeedMillOhter(human.db.technology[occu][i].lv , occu, i) local thisConfig = UnionExcel.technology[getID] msgRet.technology[i].lv = human.db.technology[occu][i].lv msgRet.technology[i].tier = i msgRet.technology[i].techMsg[0] = 0 msgRet.technology[i].techMsgNext[0] = 0 -- msgRet.technology[i].needMillLv = needMillLv -- msgRet.technology[i].otherLv = getOtherLv(human, occu) -- msgRet.technology[i].needOhterLv = needOther msgRet.technology[i].maxLV = thisConfig.lvMax msgRet.technology[i].name = thisConfig.name msgRet.technology[i].banner = thisConfig.banner for k = 1, #thisConfig.fortify do msgRet.technology[i].techMsg[k].key = thisConfig.fortify[k][1] msgRet.technology[i].techMsg[k].value = thisConfig.fortify[k][2] * msgRet.technology[i].lv -- msgRet.technology[i].techMsg[k].name = thisConfig.techName[k] msgRet.technology[i].techMsg[0] = msgRet.technology[i].techMsg[0] + 1 if msgRet.technology[i].lv < config[i].lvMax then msgRet.technology[i].techMsgNext[k].key = thisConfig.fortify[k][1] msgRet.technology[i].techMsgNext[k].value = thisConfig.fortify[k][2] * (msgRet.technology[i].lv + 1) -- msgRet.technology[i].techMsgNext[k].name = thisConfig.techName[k] msgRet.technology[i].techMsgNext[0] = msgRet.technology[i].techMsgNext[0] + 1 end end msgRet.technology[i].lvUpNeed[0] = 2 local consumeConfig = UnionExcel.tecConsume[msgRet.technology[i].lv + 1] if consumeConfig then local jinbiCnt = consumeConfig["location"..i][1][2] local coinCnt = consumeConfig["location"..i][2][2] Grid.makeItem(msgRet.technology[i].lvUpNeed[1], ItemDefine.ITEM_JINBI_ID, jinbiCnt) Grid.makeItem(msgRet.technology[i].lvUpNeed[2], ItemDefine.ITEM_UNION_COIN_ID, coinCnt) else msgRet.technology[i].lvUpNeed[0] = 0 end end msgRet.technology[0] = TEC_TIER_CNT end Msg.send(msgRet,human.fd) --Msg.trace(msgRet) end function techLvUp(human,occu,tier) -- 没公会升什么玩意科技 if human.db.unionUuid == nil then return Broadcast.sendErr(human,Lang.UNION_PLAYER_IN_NO) end if occu < 1 or occu >TEC_OCCU_CNT then return end if tier < 1 or tier >TEC_TIER_CNT then return end -- local config = UnionExcel.technology local flag = 1 local isFirst = false if human.db.technology == nil then-- 先升第一层的科技嘛,干啥要跳级呢 if tier ~= 1 then return Broadcast.sendErr(human,Lang.UNION_TECH_LAST_LV_ERR) end local consumeConfig = UnionExcel.tecConsume[1] local jinbiCnt = consumeConfig["location"..tier][1][2] local coinCnt = consumeConfig["location"..tier][2][2] if human.db.jinbi < jinbiCnt or human.db.bag[ItemDefine.ITEM_UNION_COIN_ID] == nil or human.db.bag[ItemDefine.ITEM_UNION_COIN_ID] < coinCnt then return Broadcast.sendErr(human,Lang.UNION_TECH_LV_MATERIALS) end human.db.technology = {} human.db.technology[occu] = {} ObjHuman.updateJinbi(human,-jinbiCnt,"techUp") BagLogic.delItem(human, ItemDefine.ITEM_UNION_COIN_ID,coinCnt, "techUp") human.db.technology[occu][tier] = human.db.technology[occu][tier] or {} human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv or 0 human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv + 1 isFirst = true else -- 不要跳级 if tier ~= 1 then if not human.db.technology or not human.db.technology[occu] or next(human.db.technology[occu]) == nil then return end end local union = UnionDBLogic.getUnion(human.db.unionUuid) if not union then return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO) end human.db.technology[occu] = human.db.technology[occu] or {} human.db.technology[occu][tier] = human.db.technology[occu][tier] or {} human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv or 0 local getID = getID(occu, tier) local thisConfig = UnionExcel.technology[getID] -- 都顶级了还升个锤子 if human.db.technology[occu][tier].lv >= thisConfig.lvMax then return Broadcast.sendErr(human,Lang.UNION_TECH_LV_ERR) end -- 前置科技等级没有达标 if tier~= 1 then if human.db.technology[occu][tier - 1] == nil or human.db.technology[occu][tier - 1].lv == nil or human.db.technology[occu][tier - 1].lv <= human.db.technology[occu][tier].lv then return Broadcast.sendErr(human,Lang.UNION_TECH_LAST_LV_ERR) end else if human.db.technology[occu][tier].lv > 0 and human.db.technology[occu][TEC_TIER_CNT].lv ~= human.db.technology[occu][tier].lv then return Broadcast.sendErr(human,Lang.UNION_TECH_LAST_LV_ERR) end end local millLv = UnionDBLogic.getMillLv(union) local needMillLv, needOther = getNeedMillOhter(human.db.technology[occu][tier].lv, occu, tier) local otherLv = getOtherLv(human, occu) -- 公会聚义堂 等级没有达到需求 if millLv < needMillLv then return Broadcast.sendErr(human, Util.format(Lang.UNION_TECH_MILL_ERR, needMillLv) ) end -- 其他科技没有达标 if otherLv < needOther then return Broadcast.sendErr(human, Util.format(Lang.UNION_TECH_OTHER_ERR, needOther ) ) end local consumeConfig = UnionExcel.tecConsume[human.db.technology[occu][tier].lv + 1] if not consumeConfig then return end local jinbiCnt = consumeConfig["location"..tier][1][2] local coinCnt = consumeConfig["location"..tier][2][2] if human.db.jinbi < jinbiCnt or human.db.bag[ItemDefine.ITEM_UNION_COIN_ID] == nil or human.db.bag[ItemDefine.ITEM_UNION_COIN_ID] < coinCnt then return Broadcast.sendErr(human,Lang.UNION_TECH_LV_MATERIALS) end ObjHuman.updateJinbi(human,-jinbiCnt,"techUp") BagLogic.delItem(human, ItemDefine.ITEM_UNION_COIN_ID,coinCnt, "techUp") human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv or 0 human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv + 1 if tier == TEC_TIER_CNT then human.db.technology[occu].lv = human.db.technology[occu][tier].lv -- 公会科技等级记录 --Log.write(Log.LOGID_OSS_UNION_TECH, human.db._id, human.db.account, human.db.name, occu, human.db.technology[occu].lv or 0) Log.write(Log.LOGID_OSS_UNION_TECH, human.db._id, human.db.newUniqueTag, human.db.name, occu, human.db.technology[occu].lv or 0) end end if isFirst then Broadcast.sendErr(human,Lang.UNION_TECH_LV_UP_OPEN) -- else -- Broadcast.sendErr(human,Lang.UNION_TECH_LV_UP_SUCCESS) end ObjHuman.save(human) techQuery(human,occu) UnionLivenessLogic.touchLiveness(human,UnionDefine.UNION_LIVENESS_TEC,1) RoleAttr.cleanHeroAttrCache(human) RoleAttr.doCalc(human) ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI) TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_UNIONSKILLUP, human.db._id, 1) end function checkisFirstRest(human) local isFirst = true if human.db.technology and human.db.technology.restCnt and human.db.technology.restCnt > 0 then isFirst = false end return isFirst end function getResetNeedZuanshi(human, lv) local config = UnionExcel.techReset[1] if checkisFirstRest(human) then return config.firstRest else local surLv = lv - config.lv surLv = surLv > 0 and surLv or 0 return config.consume + surLv * config.add end end -- 重置 返回道具查询 function techResetQuery(human, occu) -- 没点科技,你重置个锤子 if human.db.technology == nil then return Broadcast.sendErr(human,Lang.UNION_TECH_LV_ZERO_ERR) end if human.db.technology[occu] == nil or human.db.technology[occu][1].lv == 0 then return Broadcast.sendErr(human, Lang.UNION_TECH_LV_ZERO_ERR) end -- 先把消耗计算出来 local jinbiCnt = 0 local coinCnt = 0 local config = UnionExcel.tecConsume local lv = human.db.technology[occu][1].lv for j = 1,#human.db.technology[occu] do for k = 1,human.db.technology[occu][j].lv do jinbiCnt = jinbiCnt + config[k]["location"..j][1][2] coinCnt = coinCnt + config[k]["location"..j][2][2] end end jinbiCnt = math.floor(jinbiCnt * 0.5) local zuanshiCnt = getResetNeedZuanshi(human, human.db.technology[occu][1].lv ) local msgRet = Msg.gc.GC_UNION_TECHNOLOGY_RESET_QUERY Grid.makeItem(msgRet.item[1], ItemDefine.ITEM_JINBI_ID, jinbiCnt) Grid.makeItem(msgRet.item[2], ItemDefine.ITEM_UNION_COIN_ID, coinCnt) msgRet.zuanshiCnt = zuanshiCnt msgRet.item[0] = 2 Msg.send(msgRet,human.fd) end function techReset(human,occu) if occu < 1 or occu >TEC_OCCU_CNT then return end local flag = 1 -- 没点科技,你重置个锤子 if human.db.technology == nil then return Broadcast.sendErr(human,Lang.UNION_TECH_LV_ZERO_ERR) end human.db.technology.restCnt = human.db.technology.restCnt or 0 if human.db.technology[occu] == nil or human.db.technology[occu][1].lv == 0 then return Broadcast.sendErr(human, Lang.UNION_TECH_LV_ZERO_ERR) else local zuanshiCnt = getResetNeedZuanshi(human, human.db.technology[occu][1].lv ) if not ObjHuman.checkRMB(human, zuanshiCnt) then return end ObjHuman.decZuanshi(human, -zuanshiCnt, "reset_technology") end -- 先把消耗计算出来 local jinbiCnt = 0 local coinCnt = 0 local config = UnionExcel.tecConsume for j = 1,#human.db.technology[occu] do for k = 1,human.db.technology[occu][j].lv do jinbiCnt = jinbiCnt + config[k]["location"..j][1][2] coinCnt = coinCnt + config[k]["location"..j][2][2] end end jinbiCnt = math.floor(jinbiCnt * 0.5) human.db.technology.restCnt = human.db.technology.restCnt + 1 human.db.technology[occu] = nil BagLogic.cleanMomentItemList() BagLogic.updateMomentItem(2, ItemDefine.ITEM_JINBI_ID, jinbiCnt) BagLogic.updateMomentItem(2, ItemDefine.ITEM_UNION_COIN_ID, coinCnt) BagLogic.addMomentItemList(human, "reset_technology") Broadcast.sendErr(human,Lang.UNION_TECH_LV_RESET_SUCCESS) techQuery(human,occu) RoleAttr.cleanHeroAttrCache(human) local msgRet = Msg.gc.GC_UNION_TECHNOLOGY_RESET msgRet.flag = 1 Msg.send(msgRet,human.fd) end function getTechnologyLv(human) local lv = 0 if human.db.technology then for k, v in pairs(human.db.technology) do if v then for j, h in pairs(v) do if h and h.lv and h.lv > 0 then lv = lv + h.lv end end end end end return lv end