RoleHeadLogic.lua 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. -------------------------------------------------------
  2. -- 头像&头像框
  3. -- head = nil, -- 头像
  4. -- headList = nil, -- 已激活头像列表(除默认赠送外)
  5. -- headFrame = nil, -- 头像框
  6. -- headFrameList = nil, -- 已激活头像框列表(除默认赠送外)
  7. -- body = nil, -- 形象
  8. -- bodyList = nil, -- 已激活形象
  9. -- chenghao = nil, -- 称号
  10. -- chenghaoList = nil, -- 已激活称号
  11. -- headHasNewFlag = nil, -- 头像1/头像框2/形象4/称号8有新的flag
  12. --------------------------------------------------------
  13. local Util = require("common.Util")
  14. local Lang = require("common.Lang")
  15. local Log = require("common.Log")
  16. local LogDefine = require("common.LogDefine")
  17. local RoleExcel = require("excel.role")
  18. local HeroExcel = require("excel.hero")
  19. local Msg = require("core.Msg")
  20. local ObjHuman = require("core.ObjHuman")
  21. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  22. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  23. local Broadcast = require("broadcast.Broadcast")
  24. local CombatPosLogic = require("combat.CombatPosLogic")
  25. local CombatDefine = require("combat.CombatDefine")
  26. local ChenghaoImp = require("role.ChenghaoImp")
  27. local RoleDBLogic = require("role.RoleDBLogic")
  28. local RoleDefine = require("role.RoleDefine")
  29. local RoleAttr = require("role.RoleAttr")
  30. local RoleLogic = require("role.RoleLogic")
  31. local ObjHumam = require("core.ObjHuman")
  32. local HuanJingTowerLogic = require("huanjingTower.HuanjingTowerLogic")
  33. local HeroLogic = require("hero.HeroLogic")
  34. local TheStarsDBLogic = require("theStars.TheStarsDBLogic")
  35. local Timer = require("core.Timer")
  36. local TriggerLogic = require("trigger.TriggerLogic")
  37. local TriggerDefine = require("trigger.TriggerDefine")
  38. local Config = require("Config")
  39. local SkinConfig = require("excel.skin").skin
  40. local CommonDefine = require("common.CommonDefine")
  41. HEAD_TYPE_1 = 1 -- 头像
  42. HEAD_TYPE_2 = 2 -- 头像框
  43. HEAD_TYPE_3 = 3 -- 形象
  44. HEAD_TYPE_4 = 4 -- 称号
  45. HEAD_TYPE_5 = 5 -- 立绘
  46. HEAD_TYPE_6 = 6 -- 背景
  47. DEFAULT_FREE_ACTIVE_TYPE = 2 -- 默认激活类型
  48. DEFAULT_HEAD_MALE_ID = 1 -- 默认男性头像id
  49. DEFAULT_HEAD_FEMALE_ID = 2 -- 默认女性头像id
  50. DEFAULT_HEADFREAM_ID = 6000 -- 默认头像框id
  51. DEFAULT_BACKGROUND_ID = 1010 -- 默认背景id
  52. DEFAULT_DEL_TYPE = 99
  53. -- 背景解锁 类型
  54. BACKGROUND_TYPE_4 = 4 -- 战役通关X关
  55. local function getConfig(headType, id)
  56. if headType == HEAD_TYPE_1 then
  57. return RoleExcel.head[id]
  58. elseif headType == HEAD_TYPE_2 then
  59. return RoleExcel.headFrame[id]
  60. elseif headType == HEAD_TYPE_3 then
  61. return RoleExcel.body[id]
  62. elseif headType == HEAD_TYPE_4 then
  63. return RoleExcel.chenghao[id]
  64. elseif headType == HEAD_TYPE_5 then
  65. return RoleExcel.body[id]
  66. elseif headType == HEAD_TYPE_6 then
  67. return RoleExcel.background[id]
  68. end
  69. end
  70. --定时函数,用来检查称号过期
  71. local function timeFunc(human)
  72. -- if not IsOnline then
  73. -- return
  74. -- end
  75. if not ObjHuman.onlineNewUniqueTag[human.db.newUniqueTag] then
  76. return
  77. end
  78. if human and human.db.chenghaoList then
  79. local isContinue = false
  80. for id, data in pairs(human.db.chenghaoList) do
  81. if type(data) == "table" and data.keepTime then
  82. isActive(human, HEAD_TYPE_4, id)
  83. isContinue = true
  84. end
  85. end
  86. if isContinue then
  87. local tag = human.db.newUniqueTag
  88. Timer.addLater(60, function()
  89. local h = ObjHuman.onlineNewUniqueTag[tag]
  90. if not h then return end
  91. timeFunc(h)
  92. end)
  93. end
  94. end
  95. end
  96. function onLogin(human)
  97. timeFunc(human)
  98. RoleLogic.onLogin(human)
  99. end
  100. function isActive(human, headType, id)
  101. local config = nil
  102. local checkDB = nil
  103. if headType == HEAD_TYPE_1 then -- 头像
  104. config = RoleExcel.head[id]
  105. if id == DEFAULT_HEAD_MALE_ID or
  106. id == DEFAULT_HEAD_FEMALE_ID or
  107. config.type == DEFAULT_FREE_ACTIVE_TYPE then
  108. return true
  109. end
  110. if not human.db.headList then
  111. return
  112. end
  113. checkDB = human.db.headList[id]
  114. elseif headType == HEAD_TYPE_2 then -- 头像框
  115. config = RoleExcel.headFrame[id]
  116. if id == DEFAULT_HEADFREAM_ID or
  117. config.type == DEFAULT_FREE_ACTIVE_TYPE then
  118. return true
  119. end
  120. if not human.db.headFrameList then
  121. return
  122. end
  123. checkDB = human.db.headFrameList[id]
  124. elseif headType == HEAD_TYPE_3 then -- 形象
  125. config = RoleExcel.body[id]
  126. if config.type == DEFAULT_FREE_ACTIVE_TYPE then
  127. return true
  128. end
  129. if not human.db.bodyList then
  130. return
  131. end
  132. checkDB = human.db.bodyList[id]
  133. elseif headType == HEAD_TYPE_4 then -- 称号
  134. config = RoleExcel.chenghao[id]
  135. if config.type == DEFAULT_FREE_ACTIVE_TYPE then
  136. return true
  137. end
  138. if not human.db.chenghaoList then
  139. return
  140. end
  141. checkDB = human.db.chenghaoList[id]
  142. elseif headType == HEAD_TYPE_5 then -- 立绘
  143. config = RoleExcel.body[id]
  144. if config.type == DEFAULT_FREE_ACTIVE_TYPE then
  145. return true
  146. end
  147. if not human.db.animationList then
  148. return
  149. end
  150. checkDB = human.db.animationList[id]
  151. elseif headType == HEAD_TYPE_6 then -- 背景
  152. config = RoleExcel.background[id]
  153. if config.type == DEFAULT_FREE_ACTIVE_TYPE or
  154. id == DEFAULT_BACKGROUND_ID then
  155. return true
  156. elseif config.type == BACKGROUND_TYPE_4 then
  157. if human.db.battleID >= config.need then
  158. return true
  159. end
  160. end
  161. if not human.db.backgroundList then
  162. return
  163. end
  164. checkDB = human.db.backgroundList[id]
  165. end
  166. if checkDB == nil then
  167. return
  168. end
  169. if checkDB == true then
  170. return true
  171. end
  172. if checkDB.keepTime < 0 or (checkDB.ts + checkDB.keepTime > os.time()) then
  173. return true
  174. else
  175. -- 过期了
  176. unActive(human.db._id, headType, id)
  177. end
  178. end
  179. function active(human, headType, id)
  180. local conf = getConfig(headType, id)
  181. if conf == nil then
  182. return
  183. end
  184. local keepTime = conf.keepTime * 60*60 -- conf.keepTime 为小时数
  185. if isActive(human, headType, id) then
  186. if headType == HEAD_TYPE_4 and keepTime > 0 then
  187. else
  188. return
  189. end
  190. end
  191. if headType == HEAD_TYPE_1 then -- 头像
  192. human.db.headList = human.db.headList or {}
  193. if keepTime == nil then
  194. human.db.headList[id] = true
  195. else
  196. human.db.headList[id] = {ts = os.time(), keepTime = keepTime}
  197. end
  198. elseif headType == HEAD_TYPE_2 then -- 头像框
  199. human.db.headFrameList = human.db.headFrameList or {}
  200. if keepTime == nil then
  201. human.db.headFrameList[id] = true
  202. else
  203. human.db.headFrameList[id] = {ts = os.time(), keepTime = keepTime}
  204. end
  205. elseif headType == HEAD_TYPE_3 then -- 形象
  206. human.db.bodyList = human.db.bodyList or {}
  207. if keepTime == nil then
  208. human.db.bodyList[id] = true
  209. else
  210. human.db.bodyList[id] = {ts = os.time(), keepTime = keepTime}
  211. end
  212. if human.db.body == nil then
  213. human.db.body = id
  214. -- 通知客户端
  215. local msgRet = Msg.gc.GC_ROLE_HEAD_SET
  216. msgRet.headID = id
  217. msgRet.headType = headType
  218. Msg.send(msgRet, human.fd)
  219. end
  220. elseif headType == HEAD_TYPE_4 then -- 称号
  221. if conf.group ~= 0 then
  222. for k, v in pairs(RoleExcel.chenghao) do
  223. if k ~= id and v.group == conf.group then
  224. unActive(human.db._id, HEAD_TYPE_4, k)
  225. end
  226. end
  227. end
  228. human.db.chenghaoList = human.db.chenghaoList or {}
  229. if keepTime == nil then
  230. human.db.chenghaoList[id] = true
  231. else
  232. human.db.chenghaoList[id] = {ts = os.time(), keepTime = keepTime}
  233. timeFunc(human)
  234. end
  235. elseif headType == HEAD_TYPE_5 then -- 立绘
  236. human.db.animationList = human.db.animationList or {}
  237. if keepTime == nil then
  238. human.db.animationList[id] = true
  239. else
  240. human.db.animationList[id] = {ts = os.time(), keepTime = keepTime}
  241. end
  242. if human.db.animation == nil then
  243. human.db.animation = id
  244. -- 通知客户端
  245. local msgRet = Msg.gc.GC_ROLE_HEAD_SET
  246. msgRet.headID = id
  247. msgRet.headType = headType
  248. msgRet.headID = GetCorrectBodyId(human)
  249. Msg.send(msgRet, human.fd)
  250. end
  251. elseif headType == HEAD_TYPE_6 then -- 背景
  252. human.db.backgroundList = human.db.backgroundList or {}
  253. if keepTime == nil then
  254. human.db.backgroundList[id] = true
  255. else
  256. human.db.backgroundList[id] = {ts = os.time(), keepTime = keepTime}
  257. end
  258. end
  259. setNewFlag(human, headType, true)
  260. if #conf.attrs > 0 then
  261. RoleAttr.cleanHeroAttrCache(human)
  262. ObjHuman.doCalcHero(human)
  263. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  264. end
  265. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_101)
  266. end
  267. function unActive(uuid, headType, id)
  268. local changed = nil
  269. local human = ObjHumam.onlineUuid[uuid]
  270. if headType == HEAD_TYPE_1 then -- 头像
  271. local db = RoleDBLogic.getDb(uuid,{head = 1, headList = 1})
  272. if db.headList and db.headList[id] then
  273. db.headList[id] = nil
  274. if db.head == id then
  275. db.head = DEFAULT_HEAD_MALE_ID
  276. if human then
  277. human.db.head = DEFAULT_HEAD_MALE_ID
  278. end
  279. end
  280. RoleDBLogic.saveRoleSset(db)
  281. changed = true
  282. end
  283. elseif headType == HEAD_TYPE_2 then -- 头像框
  284. local db = RoleDBLogic.getDb(uuid,{headFrame = 1, headFrameList = 1})
  285. if db.headFrameList and db.headFrameList[id] then
  286. db.headFrameList[id] = nil
  287. if db.headFrame == id then
  288. db.headFrame = DEFAULT_HEADFREAM_ID
  289. if human then
  290. human.db.headFrame = DEFAULT_HEADFREAM_ID
  291. end
  292. end
  293. RoleDBLogic.saveRoleSset(db)
  294. changed = true
  295. end
  296. elseif headType == HEAD_TYPE_3 then -- 形象
  297. local db = RoleDBLogic.getDb(uuid,{body = 1, bodyList = 1})
  298. if db.bodyList and db.bodyList[id] then
  299. db.bodyList[id] = nil
  300. if db.body == id then
  301. db.body = nil
  302. if human then
  303. human.db.body = nil
  304. end
  305. end
  306. RoleDBLogic.saveRoleSset(db)
  307. changed = true
  308. end
  309. elseif headType == HEAD_TYPE_4 then -- 称号
  310. local db = RoleDBLogic.getDb(uuid,{chenghao = 1, chenghaoList = 1})
  311. if db.chenghaoList and db.chenghaoList[id] then
  312. db.chenghaoList[id] = nil
  313. if db.chenghao == id then
  314. db.chenghao = nil
  315. if human then
  316. human.db.chenghao = nil
  317. end
  318. end
  319. RoleDBLogic.saveRoleSset(db)
  320. changed = true
  321. end
  322. elseif headType == HEAD_TYPE_5 then -- 立绘
  323. local db = RoleDBLogic.getDb(uuid,{body = 1, animationList = 1})
  324. if db.animationList and db.animationList[id] then
  325. db.animationList[id] = nil
  326. if db.animation == id then
  327. db.animation = nil
  328. if human then
  329. human.db.animation = nil
  330. end
  331. end
  332. RoleDBLogic.saveRoleSset(db)
  333. changed = true
  334. end
  335. elseif headType == HEAD_TYPE_6 then -- 背景
  336. local db = RoleDBLogic.getDb(uuid,{chenghao = 1, backgroundList = 1})
  337. if db.backgroundList and db.backgroundList[id] then
  338. db.backgroundList[id] = nil
  339. if db.background == id then
  340. db.background = nil
  341. if human then
  342. human.db.background = nil
  343. end
  344. end
  345. RoleDBLogic.saveRoleSset(db)
  346. changed = true
  347. end
  348. end
  349. if changed then
  350. if human then
  351. RoleAttr.cleanHeroAttrCache(human)
  352. local config = getConfig(headType, id)
  353. if config and #config.attrs > 0 then
  354. ObjHuman.doCalcHero(human)
  355. end
  356. ObjHuman.sendHumanInfo(human)
  357. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  358. end
  359. end
  360. end
  361. -- 是否有红点
  362. function isDotByType(human, headType)
  363. if human.db.headHasNewFlag == nil then
  364. return
  365. end
  366. local val = human.db.headHasNewFlag or 0
  367. local bit = Util.getBit(val, headType)
  368. if bit ~= 0 then
  369. return true
  370. end
  371. end
  372. function setNewFlag(human, type, flag)
  373. local val = human.db.headHasNewFlag or 0
  374. if (Util.getBit(val, type) > 0) == flag then
  375. return
  376. end
  377. if flag == true then
  378. val = Util.setBit(val, type)
  379. else
  380. local bit = Util.getBit(val, type)
  381. if bit ~= 0 then
  382. val = val - 2 ^ type
  383. end
  384. end
  385. if val == 0 then
  386. val = nil
  387. end
  388. human.db.headHasNewFlag = val
  389. end
  390. function query(human, headType)
  391. if headType < HEAD_TYPE_1 or headType > HEAD_TYPE_6 then
  392. return
  393. end
  394. local msgRet = Msg.gc.GC_ROLE_HEAD_QUERY
  395. msgRet.type = headType
  396. msgRet.headList[0] = 0
  397. msgRet.isDot[0] = 4
  398. msgRet.isDot[1] = isDotByType(human, HEAD_TYPE_1) and 1 or 0
  399. msgRet.isDot[2] = isDotByType(human, HEAD_TYPE_2) and 1 or 0
  400. msgRet.isDot[3] = isDotByType(human, HEAD_TYPE_3) and 1 or 0
  401. msgRet.isDot[4] = isDotByType(human, HEAD_TYPE_4) and 1 or 0
  402. if headType == HEAD_TYPE_1 then -- 头像
  403. for id, cf in pairs(RoleExcel.head) do
  404. if cf.type ~= DEFAULT_DEL_TYPE then
  405. msgRet.headList[0] = msgRet.headList[0] + 1
  406. local headNet = msgRet.headList[msgRet.headList[0]]
  407. headNet.headID = id
  408. headNet.isActive = isActive(human, HEAD_TYPE_1, id) and 1 or 0
  409. headNet.desc = cf.desc or ""
  410. headNet.keepTime = getKeepTime(human, HEAD_TYPE_1, id)
  411. headNet.name = cf.name or ""
  412. headNet.camp = cf.camp or 0
  413. local len = #cf.attrs
  414. for i = 1,len do
  415. headNet.attr[i].key = cf.attrs[i][1]
  416. headNet.attr[i].value = cf.attrs[i][2]
  417. end
  418. headNet.attr[0] = len
  419. end
  420. end
  421. msgRet.useID = human.db.head or 0
  422. elseif headType == HEAD_TYPE_2 then -- 头像框
  423. for id, cf in pairs(RoleExcel.headFrame) do
  424. if cf.type ~= DEFAULT_DEL_TYPE then
  425. msgRet.headList[0] = msgRet.headList[0] + 1
  426. local headNet = msgRet.headList[msgRet.headList[0]]
  427. headNet.headID = id
  428. headNet.isActive = isActive(human, HEAD_TYPE_2, id) and 1 or 0
  429. headNet.desc = cf.desc or ""
  430. headNet.keepTime = getKeepTime(human, HEAD_TYPE_2, id)
  431. headNet.name = cf.name or ""
  432. headNet.camp = cf.camp or 0
  433. local len = #cf.attrs
  434. for i = 1,len do
  435. headNet.attr[i].key = cf.attrs[i][1]
  436. headNet.attr[i].value = cf.attrs[i][2]
  437. end
  438. headNet.attr[0] = len
  439. end
  440. end
  441. msgRet.useID = human.db.headFrame or 0
  442. elseif headType == HEAD_TYPE_3 then -- 形象
  443. for id, cf in pairs(RoleExcel.body) do
  444. if cf.type ~= DEFAULT_DEL_TYPE then
  445. msgRet.headList[0] = msgRet.headList[0] + 1
  446. local headNet = msgRet.headList[msgRet.headList[0]]
  447. headNet.headID = id
  448. headNet.isActive = isActive(human, HEAD_TYPE_3, id) and 1 or 0
  449. headNet.desc = cf.desc or ""
  450. headNet.keepTime = getKeepTime(human, HEAD_TYPE_3, id)
  451. headNet.name = cf.name or ""
  452. headNet.camp = 0
  453. local len = #cf.attrs
  454. for i = 1,len do
  455. headNet.attr[i].key = cf.attrs[i][1]
  456. headNet.attr[i].value = cf.attrs[i][2]
  457. end
  458. headNet.attr[0] = len
  459. end
  460. end
  461. msgRet.useID = human.db.body or 0
  462. elseif headType == HEAD_TYPE_4 then -- 称号
  463. msgRet.headList[0] = 0
  464. msgRet.useID = 0
  465. ChenghaoImp.query(human)
  466. elseif headType == HEAD_TYPE_5 then -- 立绘
  467. for id, cf in pairs(RoleExcel.body) do
  468. if cf.type ~= DEFAULT_DEL_TYPE then
  469. msgRet.headList[0] = msgRet.headList[0] + 1
  470. local headNet = msgRet.headList[msgRet.headList[0]]
  471. headNet.headID = id
  472. headNet.isActive = isActive(human, HEAD_TYPE_5, id) and 1 or 0
  473. headNet.desc = cf.desc or ""
  474. headNet.keepTime = getKeepTime(human, HEAD_TYPE_5, id)
  475. headNet.name = cf.name or ""
  476. headNet.camp = cf.camp or 0
  477. headNet.attr[0] = 0
  478. end
  479. end
  480. msgRet.useID = GetCorrectBodyId(human)
  481. elseif headType == HEAD_TYPE_6 then -- 背景
  482. for id, cf in pairs(RoleExcel.background) do
  483. if cf.type ~= DEFAULT_DEL_TYPE then
  484. msgRet.headList[0] = msgRet.headList[0] + 1
  485. local headNet = msgRet.headList[msgRet.headList[0]]
  486. headNet.headID = id
  487. headNet.isActive = isActive(human, HEAD_TYPE_6, id) and 1 or 0
  488. headNet.desc = cf.desc or ""
  489. headNet.keepTime = getKeepTime(human, HEAD_TYPE_6, id)
  490. headNet.name = cf.name or ""
  491. headNet.camp = cf.camp or 0
  492. headNet.attr[0] = 0
  493. end
  494. end
  495. msgRet.useID = human.db.background or 0
  496. end
  497. setNewFlag(human, headType, nil)
  498. --Msg.trace(msgRet)
  499. Msg.send(msgRet, human.fd)
  500. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_101)
  501. end
  502. -- 背景立绘查询
  503. function bgAndLhQuery(human)
  504. local msgRet = Msg.gc.GC_ROLE_BG_LH_QUERY
  505. msgRet.data[0] = 2
  506. local dataNet = msgRet.data[1]
  507. dataNet.headList[0] = 0
  508. for id, cf in pairs(RoleExcel.body) do
  509. dataNet.headList[0] = dataNet.headList[0] + 1
  510. dataNet.type = HEAD_TYPE_5
  511. local headNet = dataNet.headList[dataNet.headList[0]]
  512. headNet.headID = id
  513. headNet.isActive = isActive(human, HEAD_TYPE_5, id) and 1 or 0
  514. headNet.desc = cf.desc or ""
  515. headNet.keepTime = getKeepTime(human, HEAD_TYPE_5, id)
  516. headNet.name = cf.name or ""
  517. headNet.camp = cf.camp or 0
  518. headNet.attr[0] = 0
  519. dataNet.useID = GetCorrectBodyId(human)
  520. end
  521. setNewFlag(human, HEAD_TYPE_5, nil)
  522. dataNet = msgRet.data[2]
  523. dataNet.headList[0] = 0
  524. local bl = true
  525. for id, cf in pairs(RoleExcel.background) do
  526. bl = true
  527. if cf.type == 5 and not isActive(human, HEAD_TYPE_3, id) then -- 皮肤新增的背景图,只发已经激活的
  528. bl = false
  529. end
  530. if bl then
  531. dataNet.headList[0] = dataNet.headList[0] + 1
  532. local headNet = dataNet.headList[dataNet.headList[0]]
  533. dataNet.type = HEAD_TYPE_6
  534. headNet.headID = id
  535. -- headNet.isActive = isActive(human, HEAD_TYPE_6, id) and 1 or 0
  536. headNet.desc = cf.desc or ""
  537. -- headNet.keepTime = getKeepTime(human, HEAD_TYPE_6, id)
  538. headNet.name = cf.name or ""
  539. headNet.camp = cf.camp or 0
  540. headNet.attr[0] = 0
  541. if cf.type == 5 then -- 皮肤新增的背景图
  542. -- 根据皮肤的body值来判断
  543. headNet.isActive = 1
  544. headNet.keepTime = getKeepTime(human, HEAD_TYPE_3, id)
  545. else
  546. headNet.isActive = isActive(human, HEAD_TYPE_6, id) and 1 or 0
  547. headNet.keepTime = getKeepTime(human, HEAD_TYPE_6, id)
  548. end
  549. dataNet.useID = human.db.background or 0
  550. end
  551. end
  552. setNewFlag(human, HEAD_TYPE_6, nil)
  553. Msg.send(msgRet, human.fd)
  554. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_101)
  555. end
  556. --获取角色当前形象数据,如:头像,形象。。。
  557. function getRoleAppearance(human, type)
  558. if not type or type < HEAD_TYPE_1 or type > HEAD_TYPE_6 then
  559. return
  560. end
  561. local adornId = 0
  562. if type == HEAD_TYPE_1 then
  563. adornId = human.db.head or 0
  564. elseif type == HEAD_TYPE_2 then
  565. adornId = human.db.headFrame or 0
  566. elseif type == HEAD_TYPE_3 then
  567. adornId = human.db.body or 0
  568. elseif type == HEAD_TYPE_5 then
  569. adornId = GetCorrectBodyId(human)
  570. elseif type == HEAD_TYPE_6 then
  571. adornId = human.db.background or 0
  572. end
  573. return adornId
  574. end
  575. -- 获取当前角色已获得的某类装饰的所有数据
  576. function GetRoleAdornInfo(human, adornType)
  577. if not adornType or adornType < HEAD_TYPE_1 or adornType > HEAD_TYPE_6 then
  578. return
  579. end
  580. if adornType == HEAD_TYPE_1 then
  581. return human.db.headList
  582. elseif adornType == HEAD_TYPE_2 then
  583. return human.db.headFrameList
  584. elseif adornType == HEAD_TYPE_3 then
  585. return human.db.bodyList
  586. elseif adornType == HEAD_TYPE_4 then
  587. return human.db.chenghaoList
  588. elseif adornType == HEAD_TYPE_5 then
  589. return human.db.animationList
  590. elseif adornType == HEAD_TYPE_6 then
  591. return human.db.backgroundList
  592. end
  593. end
  594. -- 设置头像/头像框/形象
  595. function setHead(human, headID, headType)
  596. if headType < HEAD_TYPE_1 or headType > HEAD_TYPE_6 then
  597. return
  598. end
  599. local finalType = headType
  600. if headType == HEAD_TYPE_6 then
  601. local backgroundCfg = RoleExcel.background[headID]
  602. if backgroundCfg and backgroundCfg.type == 5 then
  603. finalType = HEAD_TYPE_3
  604. end
  605. end
  606. if isActive(human, finalType, headID) ~= true then
  607. return
  608. end
  609. local changed = nil
  610. local useID = nil
  611. if headType == HEAD_TYPE_1 then -- 头像
  612. useID = human.db.head or 0
  613. if useID == headID then
  614. return
  615. end
  616. human.db.head = headID
  617. changed = true
  618. TriggerLogic.PublishEvent(TriggerDefine.SET_HEAD, human.db._id, 1)
  619. elseif headType == HEAD_TYPE_2 then -- 头像框
  620. useID = human.db.headFrame or 0
  621. if useID == headID then
  622. return
  623. end
  624. human.db.headFrame = headID
  625. changed = true
  626. TriggerLogic.PublishEvent(TriggerDefine.SET_HEAD_FRAME, human.db._id, 1)
  627. elseif headType == HEAD_TYPE_3 then -- 形象
  628. useID = human.db.body or 0
  629. if useID == headID then
  630. return
  631. end
  632. human.db.body = headID
  633. changed = true
  634. TriggerLogic.PublishEvent(TriggerDefine.SET_MODELING, human.db._id, 1)
  635. -- 查询是否有占领王座,如有占领,更改形象
  636. local list = TheStarsDBLogic.getThroneList()
  637. for i, v in ipairs(list) do
  638. if v.uuid ~= nil and v.uuid == human.db._id then
  639. v.body = headID
  640. TheStarsDBLogic.updateThroneDB(v)
  641. break
  642. end
  643. end
  644. elseif headType == HEAD_TYPE_4 then -- 称号
  645. useID = human.db.chenghao or 0
  646. if useID == headID then
  647. return
  648. end
  649. human.db.chenghao = headID
  650. changed = true
  651. TriggerLogic.PublishEvent(TriggerDefine.SET_TITLE, human.db._id, 1)
  652. elseif headType == HEAD_TYPE_5 then -- 立绘
  653. useID = human.db.animation or 0
  654. if useID == headID then
  655. return
  656. end
  657. human.db.animation = headID
  658. changed = true
  659. elseif headType == HEAD_TYPE_6 then -- 背景
  660. useID = human.db.background or 0
  661. if useID == headID then
  662. return
  663. end
  664. human.db.background = headID
  665. changed = true
  666. end
  667. RoleAttr.cleanHeroAttrCache(human)
  668. if changed == true then
  669. -- 通知客户端
  670. local msgRet = Msg.gc.GC_ROLE_HEAD_SET
  671. msgRet.headID = headID
  672. msgRet.headType = headType
  673. if headType == HEAD_TYPE_5 then
  674. msgRet.headID = GetCorrectBodyId(human)
  675. end
  676. Msg.send(msgRet, human.fd)
  677. --同步头像设置
  678. if headType == HEAD_TYPE_5 or headType == HEAD_TYPE_6 then -- 立绘
  679. bgAndLhQuery(human)
  680. else
  681. query(human, headType)
  682. end
  683. if headType == HEAD_TYPE_1 then -- 头像
  684. HuanJingTowerLogic.changeHeadAfter(human)
  685. end
  686. if headType == HEAD_TYPE_1 or headType == HEAD_TYPE_2 or headType == HEAD_TYPE_3 then
  687. local showType = 3
  688. if headType == HEAD_TYPE_2 then
  689. showType = 4
  690. elseif headType == HEAD_TYPE_3 then
  691. showType = 5
  692. end
  693. local GodsAreaNS = require("godsArea.GodsAreaNS")
  694. GodsAreaNS.UpdateShowData(human, showType)
  695. end
  696. end
  697. end
  698. function getKeepTime(human, headType, id)
  699. local config = nil
  700. local checkDB = nil
  701. if headType == HEAD_TYPE_1 then -- 头像
  702. if id == DEFAULT_HEAD_MALE_ID or
  703. id == DEFAULT_HEAD_FEMALE_ID then
  704. return -1
  705. end
  706. config = RoleExcel.head[id]
  707. if config == nil then
  708. return 0
  709. end
  710. if not human.db.headList then
  711. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  712. end
  713. checkDB = human.db.headList[id]
  714. elseif headType == HEAD_TYPE_2 then -- 头像框
  715. if id == DEFAULT_HEADFREAM_ID then
  716. return -1
  717. end
  718. config = RoleExcel.headFrame[id]
  719. if config == nil then
  720. return 0
  721. end
  722. if not human.db.headFrameList then
  723. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  724. end
  725. checkDB = human.db.headFrameList[id]
  726. elseif headType == HEAD_TYPE_3 then -- 形象
  727. config = RoleExcel.body[id]
  728. if config == nil then
  729. return 0
  730. end
  731. if not human.db.bodyList then
  732. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  733. end
  734. checkDB = human.db.bodyList[id]
  735. elseif headType == HEAD_TYPE_4 then -- 称号
  736. config = RoleExcel.chenghao[id]
  737. if config == nil then
  738. return 0
  739. end
  740. if not human.db.chenghaoList then
  741. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  742. end
  743. checkDB = human.db.chenghaoList[id]
  744. elseif headType == HEAD_TYPE_5 then -- 立绘
  745. config = RoleExcel.body[id]
  746. if config == nil then
  747. return 0
  748. end
  749. if not human.db.animationList then
  750. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  751. end
  752. checkDB = human.db.animationList[id]
  753. elseif headType == HEAD_TYPE_6 then -- 背景
  754. config = RoleExcel.background[id]
  755. if config == nil then
  756. return 0
  757. end
  758. if not human.db.backgroundList then
  759. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  760. end
  761. checkDB = human.db.backgroundList[id]
  762. end
  763. if checkDB == nil then
  764. return 0
  765. end
  766. if checkDB == true then
  767. return -1
  768. end
  769. if checkDB.keepTime < 0 then
  770. return -1
  771. end
  772. local now = os.time()
  773. if checkDB.ts + checkDB.keepTime <= now then
  774. return 0
  775. else
  776. return checkDB.ts + checkDB.keepTime - now
  777. end
  778. end
  779. -- 获得英雄回调
  780. function onAddHero(human, heroID)
  781. local heroConfig = HeroExcel.hero[heroID]
  782. active(human, HEAD_TYPE_1, heroConfig.head)
  783. active(human, HEAD_TYPE_3, heroConfig.body)
  784. active(human, HEAD_TYPE_5, heroConfig.body)
  785. end
  786. function isDot(human)
  787. if human.db.headHasNewFlag then
  788. return true
  789. end
  790. end
  791. function CG_ROLE_COMBATHERO_QUERY(human, type)
  792. local combatType = type
  793. local combatHero,helpList = CombatPosLogic.getCombatHeros(human, combatType, nil, true)
  794. if not combatHero then return end
  795. local msgRet = Msg.gc.GC_ROLE_COMBATHERO_QUERY
  796. msgRet.combatType = combatType
  797. msgRet.titleId = human.db.chenghao or 0
  798. msgRet.totalcombat = CombatPosLogic.getCombatHeroZDL(human, combatType, true)
  799. --msgRet.bagIndex[0] = CombatDefine.COMBAT_HERO_CNT
  800. local len = 0
  801. for k,v in pairs(combatHero) do
  802. local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
  803. if heroGrid then
  804. len = len + 1
  805. msgRet.bagIndex[len] = heroGrid.bagIndex
  806. end
  807. end
  808. for k,v in pairs(helpList) do
  809. local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
  810. if heroGrid then
  811. len = len + 1
  812. msgRet.bagIndex[len] = heroGrid.bagIndex
  813. end
  814. end
  815. msgRet.bagIndex[0] = len
  816. --Msg.trace(msgRet)
  817. Msg.send(msgRet, human.fd)
  818. end
  819. function doCalcHero(human, attrs)
  820. if not human then return end
  821. if human.db.headList then
  822. for k, v in pairs(human.db.headList) do
  823. if isActive(human, HEAD_TYPE_1, k) and human.db.head == k then
  824. local config = getConfig(HEAD_TYPE_1, k)
  825. for k1,v1 in ipairs(config.attrs) do
  826. RoleAttr.updateValue(v1[1], v1[2], attrs)
  827. end
  828. end
  829. end
  830. end
  831. if human.db.headFrameList then
  832. for k, v in pairs(human.db.headFrameList) do
  833. -- if isActive(human, HEAD_TYPE_2, k) and human.db.headFrame == k then
  834. -- local config = getConfig(HEAD_TYPE_2, k)
  835. -- for k1,v1 in ipairs(config.attrs) do
  836. -- RoleAttr.updateValue(v1[1], v1[2], attrs)
  837. -- end
  838. -- end
  839. -- 改为所有头像框加成属性叠加
  840. if isActive(human, HEAD_TYPE_2, k) then
  841. local config = getConfig(HEAD_TYPE_2, k)
  842. for k1,v1 in ipairs(config.attrs) do
  843. RoleAttr.updateValue(v1[1], v1[2], attrs)
  844. end
  845. end
  846. end
  847. end
  848. if human.db.bodyList then
  849. for k, v in pairs(human.db.bodyList) do
  850. if isActive(human, HEAD_TYPE_3, k) and human.db.body == k then
  851. local config = getConfig(HEAD_TYPE_3, k)
  852. for k1,v1 in ipairs(config.attrs) do
  853. RoleAttr.updateValue(v1[1], v1[2], attrs)
  854. end
  855. end
  856. end
  857. end
  858. if human.db.chenghaoList then
  859. for k, v in pairs(human.db.chenghaoList) do
  860. if isActive(human, HEAD_TYPE_4, k) then
  861. local config = getConfig(HEAD_TYPE_4, k)
  862. for k1,v1 in ipairs(config.attrs) do
  863. RoleAttr.updateValue(v1[1], v1[2], attrs)
  864. end
  865. end
  866. end
  867. end
  868. if human.db.animationList then
  869. for k, v in pairs(human.db.animationList) do
  870. if isActive(human, HEAD_TYPE_5, k) and human.db.animation == k then
  871. local config = getConfig(HEAD_TYPE_5, k)
  872. for k1,v1 in ipairs(config.attrs) do
  873. RoleAttr.updateValue(v1[1], v1[2], attrs)
  874. end
  875. end
  876. end
  877. end
  878. if human.db.backgroundList then
  879. for k, v in pairs(human.db.backgroundList) do
  880. if isActive(human, HEAD_TYPE_6, k) then
  881. local config = getConfig(HEAD_TYPE_6, k)
  882. for k1,v1 in ipairs(config.attrs) do
  883. RoleAttr.updateValue(v1[1], v1[2], attrs)
  884. end
  885. end
  886. end
  887. end
  888. end
  889. function GetCorrectBodyId(human)
  890. local nowBodyId = human.db.animation or 0
  891. if nowBodyId <= 0 then
  892. return nowBodyId
  893. end
  894. local bl = false
  895. for _, channelId in ipairs(Config.SVR_CHANEL or {}) do
  896. if channelId == CommonDefine.CHANNEL_TAG_WX then
  897. bl = true
  898. break
  899. end
  900. end
  901. if not bl then
  902. return nowBodyId
  903. end
  904. local skinCfg = SkinConfig[nowBodyId]
  905. if skinCfg and (skinCfg.body1 or 0) > 0 then
  906. nowBodyId = skinCfg.body1
  907. end
  908. return nowBodyId
  909. end
  910. function GM_Active(human, headType, id)
  911. active(human, headType, id)
  912. end
  913. function GM_UnActive(human, headType, id)
  914. unActive(human.db._id, headType, id)
  915. end