UnionTecLogic.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. Json = Json or require("common.Json")
  2. local Log = require("common.Log")
  3. local Msg = require("core.Msg")
  4. local Broadcast = require("broadcast.Broadcast")
  5. local Grid = require("bag.Grid")
  6. local UnionExcel = require("excel.union")
  7. local ItemDefine = require("bag.ItemDefine")
  8. local BagLogic = require("bag.BagLogic")
  9. local ObjHuman = require("core.ObjHuman")
  10. local Lang = require("common.Lang")
  11. local HeroExcel = require("excel.hero")
  12. local RoleAttr = require("role.RoleAttr")
  13. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  14. local UnionDBLogic = require("union.UnionDBLogic")
  15. local Util = require("common.Util")
  16. local UnionLivenessLogic = require("union.UnionLivenessLogic")
  17. local UnionDefine = require("union.UnionDefine")
  18. local RoleDefine = require("role.RoleDefine")
  19. local TriggerDefine = require("trigger.TriggerDefine")
  20. local TriggerLogic = require("trigger.TriggerLogic")
  21. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  22. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  23. TEC_OCCU_CNT = 4
  24. TEC_TIER_CNT = 6
  25. -- 获取科技配置
  26. local function getTechnologyCfg(job, tier)
  27. local config = UnionExcel.technology
  28. local cfg = nil
  29. for i = 1, #config do
  30. cfg = config[i]
  31. if cfg ~= nil and cfg.occu == job and cfg.tier == tier then
  32. return cfg
  33. end
  34. end
  35. end
  36. -- 判断红点数据
  37. local function CheckUnionTecRed(human, occu)
  38. if occu < 1 or occu > TEC_OCCU_CNT then
  39. return 0
  40. end
  41. -- 无公会
  42. if not human.db.unionUuid then
  43. return 0
  44. end
  45. -- 不存在数据 或者不存在对应的类型
  46. if human.db.technology == nil or not human.db.technology[occu] then
  47. -- 判断一级
  48. local tConf = UnionExcel.tecConsume[1]
  49. for i = 1, TEC_TIER_CNT, 1 do
  50. local jinbiCnt = tConf["location"..i][1][2]
  51. local coinCnt = tConf["location"..i][2][2]
  52. if human.db.jinbi and human.db.jinbi >= jinbiCnt
  53. and human.db.bag[ItemDefine.ITEM_UNION_COIN_ID] and human.db.bag[ItemDefine.ITEM_UNION_COIN_ID] >= coinCnt then
  54. return 1
  55. end
  56. end
  57. else
  58. -- 科技类型
  59. local tDBData = human.db.technology[occu]
  60. local nMinLv
  61. for i = 1, TEC_TIER_CNT, 1 do
  62. if tDBData[i] then
  63. if not nMinLv then
  64. nMinLv = tDBData[i].lv
  65. end
  66. nMinLv = math.min(nMinLv, tDBData[i].lv)
  67. else
  68. nMinLv = 0
  69. break
  70. end
  71. end
  72. if not nMinLv then
  73. return 0
  74. end
  75. print("[CheckUnionTecRed] 获取到的最小等级 nMinLv = "..nMinLv)
  76. for i = 1, TEC_TIER_CNT, 1 do
  77. local nID = getID(occu, i)
  78. local thisConfig = UnionExcel.technology[nID]
  79. local nMaxLv = thisConfig.lvMax
  80. local tConf = nil
  81. if tDBData[i] then
  82. local nNowLv = tDBData[i].lv
  83. if nNowLv == nMinLv and nMaxLv > nNowLv then
  84. tConf = UnionExcel.tecConsume[nNowLv + 1]
  85. end
  86. else
  87. tConf = UnionExcel.tecConsume[nMinLv + 1]
  88. end
  89. if tConf then
  90. local jinbiCnt = tConf["location"..i][1][2]
  91. local coinCnt = tConf["location"..i][2][2]
  92. print("[CheckUnionTecRed] jinbiCnt = "..jinbiCnt.." coinCnt = "..coinCnt.." occu = "..occu)
  93. if human.db.jinbi and human.db.jinbi >= jinbiCnt
  94. and human.db.bag[ItemDefine.ITEM_UNION_COIN_ID] and human.db.bag[ItemDefine.ITEM_UNION_COIN_ID] >= coinCnt then
  95. return 1
  96. end
  97. end
  98. end
  99. end
  100. return 0
  101. end
  102. -- 计算科技属性
  103. function doCalcHero(human, grid, attrs)
  104. if not human then return end
  105. if not human.db.unionUuid or human.db.unionUuid == "" then
  106. return
  107. end
  108. if not human.db.technology then return end
  109. local heroConfig = HeroExcel.hero[grid.id]
  110. local technology = human.db.technology[heroConfig.job]
  111. if technology == nil then return end
  112. local techCfg = nil
  113. for i = 1,TEC_TIER_CNT do
  114. local tech = technology[i]
  115. if tech ~= nil and tech.lv ~= nil then
  116. techCfg = getTechnologyCfg(heroConfig.job, i)
  117. if techCfg ~= nil then
  118. for k, v in pairs(techCfg.fortify) do
  119. local addValue = v[2] * tech.lv
  120. RoleAttr.updateValue(v[1],addValue,attrs)
  121. end
  122. end
  123. end
  124. end
  125. end
  126. function getTechLvByJob(human, job)
  127. if not human then return 0 end
  128. if not human.db.technology then return 0 end
  129. local technology = human.db.technology[job]
  130. return technology and technology.lv or 0
  131. end
  132. function lvAllUpByGm(human)
  133. if human.db.unionUuid == nil then
  134. return
  135. end
  136. human.db.technology = human.db.technology or {}
  137. local technology = human.db.technology
  138. local config = UnionExcel.technology
  139. local len = #config
  140. for i = 1, TEC_OCCU_CNT do
  141. technology[i] = technology[i] or {}
  142. local techOccu = technology[i]
  143. for j = 1, TEC_TIER_CNT do
  144. techOccu[j] = techOccu[j] or {}
  145. for z = 1, len do
  146. local v = config[z]
  147. if v.occu == i and v.tier == j then
  148. techOccu[j].lv = v.lvMax
  149. break
  150. end
  151. end
  152. end
  153. end
  154. end
  155. -- 获取其他科技的总等级
  156. function getOtherLv(human, occu)
  157. local lv = 9999
  158. if human.db.technology then
  159. local technology = human.db.technology
  160. for i = 1, TEC_OCCU_CNT do
  161. if technology[i] and i ~= occu then
  162. local thisLv = technology[i].lv or 0
  163. if lv >= thisLv then
  164. lv = thisLv
  165. end
  166. elseif not technology[i] then
  167. lv = 0
  168. end
  169. end
  170. end
  171. lv = lv ~= 9999 and lv or 0
  172. return lv
  173. end
  174. function getID(occu, tier)
  175. local id = 0
  176. for k, v in ipairs(UnionExcel.technology) do
  177. if v and v.occu == occu and v.tier == tier then
  178. id = k
  179. break
  180. end
  181. end
  182. return id
  183. end
  184. -- 获取该等级所需要的 磨坊等级 和其他 科技等级
  185. function getNeedMillOhter(lv, occu, tier)
  186. local needMill = 0
  187. local needOther = 0
  188. local id = getID(occu, tier)
  189. local config = UnionExcel.technology[id]
  190. for k, v in ipairs(config.needMill) do
  191. if v and v[1] <= lv then
  192. needMill = v[2]
  193. end
  194. end
  195. local changeLv = config.needSumLv[1]
  196. local initLv = config.needSumLv[2]
  197. if lv < changeLv then
  198. needOther = 0
  199. else
  200. needOther = initLv + (lv - changeLv ) * 1
  201. end
  202. return needMill,needOther
  203. end
  204. function techQuery(human, occu)
  205. -- 没有加入公会查什么科技
  206. if human.db.unionUuid == nil then
  207. return
  208. end
  209. -- 对不起,你要查的科技这里没得卖,请你出去
  210. if occu == nil then return end
  211. if occu < 1 or occu > TEC_OCCU_CNT then
  212. return
  213. end
  214. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  215. if not union then
  216. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  217. end
  218. local millLv = UnionDBLogic.getMillLv(union)
  219. local config = UnionExcel.technology
  220. local msgRet = Msg.gc.GC_UNION_TECHNOLOGY_QUERY
  221. if human.db.technology == nil or human.db.technology[occu] == nil then
  222. msgRet.techLv = 1
  223. local consumeConfig = UnionExcel.tecConsume[1]
  224. for i = 1,TEC_TIER_CNT do
  225. if i == 1 then
  226. msgRet.technology[i].canLvUp = 1
  227. else
  228. msgRet.technology[i].canLvUp = 3
  229. end
  230. local getID = getID(occu, i)
  231. local needMillLv, needOther = getNeedMillOhter(0, occu, i)
  232. local thisConfig = UnionExcel.technology[getID]
  233. msgRet.technology[i].lv = 0
  234. msgRet.technology[i].tier = i
  235. msgRet.technology[i].techMsg[0] = 0
  236. msgRet.technology[i].techMsgNext[0] = 0
  237. msgRet.technology[i].name = thisConfig.name
  238. msgRet.technology[i].maxLV = thisConfig.lvMax
  239. -- msgRet.technology[i].needMillLv = needMillLv
  240. -- msgRet.technology[i].otherLv = getOtherLv(human, occu)
  241. -- msgRet.technology[i].needOhterLv = needOther
  242. msgRet.technology[i].banner = thisConfig.banner
  243. for k = 1, #thisConfig.fortify do
  244. msgRet.technology[i].techMsg[k].key = thisConfig.fortify[k][1]
  245. msgRet.technology[i].techMsg[k].value = thisConfig.fortify[k][2] * msgRet.technology[i].lv
  246. -- msgRet.technology[i].techMsg[k].name = thisConfig.techName[k]
  247. msgRet.technology[i].techMsg[0] = msgRet.technology[i].techMsg[0] + 1
  248. msgRet.technology[i].techMsgNext[k].key = thisConfig.fortify[k][1]
  249. msgRet.technology[i].techMsgNext[k].value = thisConfig.fortify[k][2] * (msgRet.technology[i].lv + 1)
  250. -- msgRet.technology[i].techMsgNext[k].name = thisConfig.techName[k]
  251. msgRet.technology[i].techMsgNext[0] = msgRet.technology[i].techMsgNext[0] + 1
  252. end
  253. msgRet.technology[i].lvUpNeed[0] = 2
  254. msgRet.technology[i].tier = i
  255. local jinbiCnt = consumeConfig["location"..i][1][2]
  256. local coinCnt = consumeConfig["location"..i][2][2]
  257. Grid.makeItem(msgRet.technology[i].lvUpNeed[1], ItemDefine.ITEM_JINBI_ID, jinbiCnt)
  258. Grid.makeItem(msgRet.technology[i].lvUpNeed[2], ItemDefine.ITEM_UNION_COIN_ID, coinCnt)
  259. -- msgRet.technology[i].needMillLv = 0
  260. end
  261. msgRet.technology[0] = TEC_TIER_CNT
  262. else
  263. msgRet.techLv = 1
  264. if human.db.technology[occu] and human.db.technology[occu].lv then
  265. msgRet.techLv = human.db.technology[occu].lv
  266. end
  267. for i = 1, TEC_TIER_CNT do
  268. human.db.technology[occu][i] = human.db.technology[occu][i] or {}
  269. human.db.technology[occu][i].lv = human.db.technology[occu][i].lv or 0
  270. if i == 1 then
  271. if human.db.technology[occu][i].lv >= config[i].lvMax then
  272. msgRet.technology[i].canLvUp = 2
  273. msgRet.techLv = config[i].lvMax
  274. else
  275. if human.db.technology[occu][i].lv == 0 then
  276. msgRet.technology[i].canLvUp = 1
  277. else
  278. if human.db.technology[occu][TEC_TIER_CNT] and human.db.technology[occu][TEC_TIER_CNT].lv == human.db.technology[occu][i].lv then
  279. msgRet.technology[i].canLvUp = 1
  280. else
  281. msgRet.technology[i].canLvUp = 2
  282. end
  283. end
  284. end
  285. else
  286. if human.db.technology[occu][i].lv >= config[i].lvMax then
  287. msgRet.technology[i].canLvUp = 2
  288. else
  289. if human.db.technology[occu][i - 1].lv == human.db.technology[occu][i].lv + 1 then
  290. msgRet.technology[i].canLvUp = 1
  291. elseif human.db.technology[occu][i].lv == human.db.technology[occu][1].lv and human.db.technology[occu][1].lv ~= 0 then
  292. if human.db.technology[occu].lv == human.db.technology[occu][i].lv then
  293. msgRet.technology[i].canLvUp = 3
  294. else
  295. msgRet.technology[i].canLvUp = 2
  296. end
  297. else
  298. msgRet.technology[i].canLvUp = 3
  299. end
  300. end
  301. end
  302. local getID = getID(occu, i)
  303. local needMillLv, needOther = getNeedMillOhter(human.db.technology[occu][i].lv , occu, i)
  304. local thisConfig = UnionExcel.technology[getID]
  305. msgRet.technology[i].lv = human.db.technology[occu][i].lv
  306. msgRet.technology[i].tier = i
  307. msgRet.technology[i].techMsg[0] = 0
  308. msgRet.technology[i].techMsgNext[0] = 0
  309. -- msgRet.technology[i].needMillLv = needMillLv
  310. -- msgRet.technology[i].otherLv = getOtherLv(human, occu)
  311. -- msgRet.technology[i].needOhterLv = needOther
  312. msgRet.technology[i].maxLV = thisConfig.lvMax
  313. msgRet.technology[i].name = thisConfig.name
  314. msgRet.technology[i].banner = thisConfig.banner
  315. for k = 1, #thisConfig.fortify do
  316. msgRet.technology[i].techMsg[k].key = thisConfig.fortify[k][1]
  317. msgRet.technology[i].techMsg[k].value = thisConfig.fortify[k][2] * msgRet.technology[i].lv
  318. -- msgRet.technology[i].techMsg[k].name = thisConfig.techName[k]
  319. msgRet.technology[i].techMsg[0] = msgRet.technology[i].techMsg[0] + 1
  320. if msgRet.technology[i].lv < config[i].lvMax then
  321. msgRet.technology[i].techMsgNext[k].key = thisConfig.fortify[k][1]
  322. msgRet.technology[i].techMsgNext[k].value = thisConfig.fortify[k][2] * (msgRet.technology[i].lv + 1)
  323. -- msgRet.technology[i].techMsgNext[k].name = thisConfig.techName[k]
  324. msgRet.technology[i].techMsgNext[0] = msgRet.technology[i].techMsgNext[0] + 1
  325. end
  326. end
  327. msgRet.technology[i].lvUpNeed[0] = 2
  328. local consumeConfig = UnionExcel.tecConsume[msgRet.technology[i].lv + 1]
  329. if consumeConfig then
  330. local jinbiCnt = consumeConfig["location"..i][1][2]
  331. local coinCnt = consumeConfig["location"..i][2][2]
  332. Grid.makeItem(msgRet.technology[i].lvUpNeed[1], ItemDefine.ITEM_JINBI_ID, jinbiCnt)
  333. Grid.makeItem(msgRet.technology[i].lvUpNeed[2], ItemDefine.ITEM_UNION_COIN_ID, coinCnt)
  334. else
  335. msgRet.technology[i].lvUpNeed[0] = 0
  336. end
  337. end
  338. msgRet.technology[0] = TEC_TIER_CNT
  339. end
  340. getRedInfo(human, msgRet.tRed)
  341. Msg.send(msgRet,human.fd)
  342. --Msg.trace(msgRet)
  343. end
  344. function techLvUp(human,occu,tier)
  345. -- 没公会升什么玩意科技
  346. if human.db.unionUuid == nil then
  347. return Broadcast.sendErr(human,Lang.UNION_PLAYER_IN_NO)
  348. end
  349. if occu < 1 or occu >TEC_OCCU_CNT then
  350. return
  351. end
  352. if tier < 1 or tier >TEC_TIER_CNT then
  353. return
  354. end
  355. --
  356. local config = UnionExcel.technology
  357. local flag = 1
  358. local isFirst = false
  359. if human.db.technology == nil then-- 先升第一层的科技嘛,干啥要跳级呢
  360. if tier ~= 1 then
  361. return Broadcast.sendErr(human,Lang.UNION_TECH_LAST_LV_ERR)
  362. end
  363. local consumeConfig = UnionExcel.tecConsume[1]
  364. local jinbiCnt = consumeConfig["location"..tier][1][2]
  365. local coinCnt = consumeConfig["location"..tier][2][2]
  366. 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
  367. return Broadcast.sendErr(human,Lang.UNION_TECH_LV_MATERIALS)
  368. end
  369. human.db.technology = {}
  370. human.db.technology[occu] = {}
  371. ObjHuman.updateJinbi(human,-jinbiCnt,"techUp")
  372. BagLogic.delItem(human, ItemDefine.ITEM_UNION_COIN_ID,coinCnt, "techUp")
  373. human.db.technology[occu][tier] = human.db.technology[occu][tier] or {}
  374. human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv or 0
  375. human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv + 1
  376. isFirst = true
  377. else
  378. -- 不要跳级
  379. if tier ~= 1 then
  380. if not human.db.technology or not human.db.technology[occu] or next(human.db.technology[occu]) == nil then
  381. return
  382. end
  383. end
  384. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  385. if not union then
  386. return Broadcast.sendErr(human, Lang.UNION_PLAYER_IN_NO)
  387. end
  388. human.db.technology[occu] = human.db.technology[occu] or {}
  389. human.db.technology[occu][tier] = human.db.technology[occu][tier] or {}
  390. human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv or 0
  391. local getID = getID(occu, tier)
  392. local thisConfig = UnionExcel.technology[getID]
  393. -- 都顶级了还升个锤子
  394. if human.db.technology[occu][tier].lv >= thisConfig.lvMax then
  395. return Broadcast.sendErr(human,Lang.UNION_TECH_LV_ERR)
  396. end
  397. -- 前置科技等级没有达标
  398. if tier~= 1 then
  399. 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
  400. return Broadcast.sendErr(human,Lang.UNION_TECH_LAST_LV_ERR)
  401. end
  402. else
  403. if human.db.technology[occu][tier].lv > 0 and human.db.technology[occu][TEC_TIER_CNT].lv ~= human.db.technology[occu][tier].lv then
  404. return Broadcast.sendErr(human,Lang.UNION_TECH_LAST_LV_ERR)
  405. end
  406. end
  407. local millLv = UnionDBLogic.getMillLv(union)
  408. local needMillLv, needOther = getNeedMillOhter(human.db.technology[occu][tier].lv, occu, tier)
  409. local otherLv = getOtherLv(human, occu)
  410. -- 公会聚义堂 等级没有达到需求
  411. -- if millLv < needMillLv then
  412. -- return Broadcast.sendErr(human, Util.format(Lang.UNION_TECH_MILL_ERR, needMillLv) )
  413. -- end
  414. -- 其他科技没有达标
  415. if otherLv < needOther then
  416. return Broadcast.sendErr(human, Util.format(Lang.UNION_TECH_OTHER_ERR, needOther ) )
  417. end
  418. local consumeConfig = UnionExcel.tecConsume[human.db.technology[occu][tier].lv + 1]
  419. if not consumeConfig then return end
  420. local jinbiCnt = consumeConfig["location"..tier][1][2]
  421. local coinCnt = consumeConfig["location"..tier][2][2]
  422. 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
  423. return Broadcast.sendErr(human,Lang.UNION_TECH_LV_MATERIALS)
  424. end
  425. ObjHuman.updateJinbi(human,-jinbiCnt,"techUp")
  426. BagLogic.delItem(human, ItemDefine.ITEM_UNION_COIN_ID,coinCnt, "techUp")
  427. human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv or 0
  428. human.db.technology[occu][tier].lv = human.db.technology[occu][tier].lv + 1
  429. if tier == TEC_TIER_CNT then
  430. human.db.technology[occu].lv = human.db.technology[occu][tier].lv
  431. -- 公会科技等级记录
  432. --Log.write(Log.LOGID_OSS_UNION_TECH, human.db._id, human.db.account, human.db.name, occu, human.db.technology[occu].lv or 0)
  433. Log.write(Log.LOGID_OSS_UNION_TECH, human.db._id, human.db.newUniqueTag, human.db.name, occu, human.db.technology[occu].lv or 0)
  434. end
  435. end
  436. if isFirst then
  437. Broadcast.sendErr(human,Lang.UNION_TECH_LV_UP_OPEN)
  438. -- else
  439. -- Broadcast.sendErr(human,Lang.UNION_TECH_LV_UP_SUCCESS)
  440. end
  441. ObjHuman.save(human)
  442. techQuery(human,occu)
  443. UnionLivenessLogic.touchLiveness(human,UnionDefine.UNION_LIVENESS_TEC,1)
  444. RoleAttr.cleanHeroAttrCache(human)
  445. RoleAttr.doCalc(human)
  446. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  447. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_UNIONSKILLUP, human.db._id, 1)
  448. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1007)
  449. end
  450. function checkisFirstRest(human)
  451. local isFirst = true
  452. if human.db.technology and human.db.technology.restCnt and human.db.technology.restCnt > 0 then
  453. isFirst = false
  454. end
  455. return isFirst
  456. end
  457. function getResetNeedZuanshi(human, lv)
  458. local config = UnionExcel.techReset[1]
  459. if checkisFirstRest(human) then
  460. return config.firstRest
  461. else
  462. local surLv = lv - config.lv
  463. surLv = surLv > 0 and surLv or 0
  464. return config.consume + surLv * config.add
  465. end
  466. end
  467. -- 重置 返回道具查询
  468. function techResetQuery(human, occu)
  469. -- 没点科技,你重置个锤子
  470. if human.db.technology == nil then
  471. return Broadcast.sendErr(human,Lang.UNION_TECH_LV_ZERO_ERR)
  472. end
  473. if human.db.technology[occu] == nil or human.db.technology[occu][1].lv == 0 then
  474. return Broadcast.sendErr(human, Lang.UNION_TECH_LV_ZERO_ERR)
  475. end
  476. -- 先把消耗计算出来
  477. local jinbiCnt = 0
  478. local coinCnt = 0
  479. local config = UnionExcel.tecConsume
  480. local lv = human.db.technology[occu][1].lv
  481. for j = 1,#human.db.technology[occu] do
  482. for k = 1,human.db.technology[occu][j].lv do
  483. jinbiCnt = jinbiCnt + config[k]["location"..j][1][2]
  484. coinCnt = coinCnt + config[k]["location"..j][2][2]
  485. end
  486. end
  487. jinbiCnt = math.floor(jinbiCnt * 0.5)
  488. local zuanshiCnt = getResetNeedZuanshi(human, human.db.technology[occu][1].lv )
  489. local msgRet = Msg.gc.GC_UNION_TECHNOLOGY_RESET_QUERY
  490. Grid.makeItem(msgRet.item[1], ItemDefine.ITEM_JINBI_ID, jinbiCnt)
  491. Grid.makeItem(msgRet.item[2], ItemDefine.ITEM_UNION_COIN_ID, coinCnt)
  492. msgRet.zuanshiCnt = zuanshiCnt
  493. msgRet.item[0] = 2
  494. Msg.send(msgRet,human.fd)
  495. end
  496. function techReset(human,occu)
  497. if occu < 1 or occu >TEC_OCCU_CNT then
  498. return
  499. end
  500. local flag = 1
  501. -- 没点科技,你重置个锤子
  502. if human.db.technology == nil then
  503. return Broadcast.sendErr(human,Lang.UNION_TECH_LV_ZERO_ERR)
  504. end
  505. human.db.technology.restCnt = human.db.technology.restCnt or 0
  506. if human.db.technology[occu] == nil or human.db.technology[occu][1].lv == 0 then
  507. return Broadcast.sendErr(human, Lang.UNION_TECH_LV_ZERO_ERR)
  508. else
  509. local zuanshiCnt = getResetNeedZuanshi(human, human.db.technology[occu][1].lv )
  510. if not ObjHuman.checkRMB(human, zuanshiCnt) then
  511. return
  512. end
  513. ObjHuman.decZuanshi(human, -zuanshiCnt, "reset_technology")
  514. end
  515. -- 先把消耗计算出来
  516. local jinbiCnt = 0
  517. local coinCnt = 0
  518. local config = UnionExcel.tecConsume
  519. for j = 1,#human.db.technology[occu] do
  520. for k = 1,human.db.technology[occu][j].lv do
  521. jinbiCnt = jinbiCnt + config[k]["location"..j][1][2]
  522. coinCnt = coinCnt + config[k]["location"..j][2][2]
  523. end
  524. end
  525. jinbiCnt = math.floor(jinbiCnt * 0.5)
  526. human.db.technology.restCnt = human.db.technology.restCnt + 1
  527. human.db.technology[occu] = nil
  528. BagLogic.cleanMomentItemList()
  529. BagLogic.updateMomentItem(2, ItemDefine.ITEM_JINBI_ID, jinbiCnt)
  530. BagLogic.updateMomentItem(2, ItemDefine.ITEM_UNION_COIN_ID, coinCnt)
  531. BagLogic.addMomentItemList(human, "reset_technology")
  532. Broadcast.sendErr(human,Lang.UNION_TECH_LV_RESET_SUCCESS)
  533. techQuery(human,occu)
  534. RoleAttr.cleanHeroAttrCache(human)
  535. local msgRet = Msg.gc.GC_UNION_TECHNOLOGY_RESET
  536. msgRet.flag = 1
  537. Msg.send(msgRet,human.fd)
  538. end
  539. function getTechnologyLv(human)
  540. local lv = 0
  541. if human.db.technology then
  542. for k, v in pairs(human.db.technology) do
  543. if v then
  544. for j, h in pairs(v) do
  545. if h and h.lv and h.lv > 0 then
  546. lv = lv + h.lv
  547. end
  548. end
  549. end
  550. end
  551. end
  552. return lv
  553. end
  554. -- 获取红点信息
  555. function getRedInfo(human, net)
  556. net[0] = TEC_OCCU_CNT
  557. for i = 1, TEC_OCCU_CNT, 1 do
  558. net[i] = CheckUnionTecRed(human, i)
  559. end
  560. end
  561. -- 红点
  562. function isDot(human)
  563. for i = 1, TEC_OCCU_CNT, 1 do
  564. if 1 == CheckUnionTecRed(human, i) then
  565. return true
  566. end
  567. end
  568. end