RoleHeadLogic.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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 ObjHumam = require("core.ObjHuman")
  31. local HuanJingTowerLogic = require("huanjingTower.HuanjingTowerLogic")
  32. local HeroLogic = require("hero.HeroLogic")
  33. local TheStarsDBLogic = require("theStars.TheStarsDBLogic")
  34. HEAD_TYPE_1 = 1 -- 头像
  35. HEAD_TYPE_2 = 2 -- 头像框
  36. HEAD_TYPE_3 = 3 -- 形象
  37. HEAD_TYPE_4 = 4 -- 称号
  38. HEAD_TYPE_5 = 5 -- 立绘
  39. HEAD_TYPE_6 = 6 -- 背景
  40. DEFAULT_FREE_ACTIVE_TYPE = 2 -- 默认激活类型
  41. DEFAULT_HEAD_MALE_ID = 1 -- 默认男性头像id
  42. DEFAULT_HEAD_FEMALE_ID = 2 -- 默认女性头像id
  43. DEFAULT_HEADFREAM_ID = 6000 -- 默认头像框id
  44. DEFAULT_BACKGROUND_ID = 1010 -- 默认背景id
  45. DEFAULT_DEL_TYPE = 99
  46. -- 背景解锁 类型
  47. BACKGROUND_TYPE_4 = 4 -- 战役通关X关
  48. local function getConfig(headType, id)
  49. if headType == HEAD_TYPE_1 then
  50. return RoleExcel.head[id]
  51. elseif headType == HEAD_TYPE_2 then
  52. return RoleExcel.headFrame[id]
  53. elseif headType == HEAD_TYPE_3 then
  54. return RoleExcel.body[id]
  55. elseif headType == HEAD_TYPE_4 then
  56. return RoleExcel.chenghao[id]
  57. elseif headType == HEAD_TYPE_5 then
  58. return RoleExcel.body[id]
  59. elseif headType == HEAD_TYPE_6 then
  60. return RoleExcel.background[id]
  61. end
  62. end
  63. function isActive(human, headType, id)
  64. local config = nil
  65. local checkDB = nil
  66. if headType == HEAD_TYPE_1 then -- 头像
  67. config = RoleExcel.head[id]
  68. if id == DEFAULT_HEAD_MALE_ID or
  69. id == DEFAULT_HEAD_FEMALE_ID or
  70. config.type == DEFAULT_FREE_ACTIVE_TYPE then
  71. return true
  72. end
  73. if not human.db.headList then
  74. return
  75. end
  76. checkDB = human.db.headList[id]
  77. elseif headType == HEAD_TYPE_2 then -- 头像框
  78. config = RoleExcel.headFrame[id]
  79. if id == DEFAULT_HEADFREAM_ID or
  80. config.type == DEFAULT_FREE_ACTIVE_TYPE then
  81. return true
  82. end
  83. if not human.db.headFrameList then
  84. return
  85. end
  86. checkDB = human.db.headFrameList[id]
  87. elseif headType == HEAD_TYPE_3 then -- 形象
  88. config = RoleExcel.body[id]
  89. if config.type == DEFAULT_FREE_ACTIVE_TYPE then
  90. return true
  91. end
  92. if not human.db.bodyList then
  93. return
  94. end
  95. checkDB = human.db.bodyList[id]
  96. elseif headType == HEAD_TYPE_4 then -- 称号
  97. config = RoleExcel.chenghao[id]
  98. if config.type == DEFAULT_FREE_ACTIVE_TYPE then
  99. return true
  100. end
  101. if not human.db.chenghaoList then
  102. return
  103. end
  104. checkDB = human.db.chenghaoList[id]
  105. elseif headType == HEAD_TYPE_5 then -- 立绘
  106. config = RoleExcel.body[id]
  107. if config.type == DEFAULT_FREE_ACTIVE_TYPE then
  108. return true
  109. end
  110. if not human.db.animationList then
  111. return
  112. end
  113. checkDB = human.db.animationList[id]
  114. elseif headType == HEAD_TYPE_6 then -- 背景
  115. config = RoleExcel.background[id]
  116. if config.type == DEFAULT_FREE_ACTIVE_TYPE or
  117. id == DEFAULT_BACKGROUND_ID then
  118. return true
  119. elseif config.type == BACKGROUND_TYPE_4 then
  120. if human.db.battleID >= config.need then
  121. return true
  122. end
  123. end
  124. if not human.db.backgroundList then
  125. return
  126. end
  127. checkDB = human.db.backgroundList[id]
  128. end
  129. if checkDB == nil then
  130. return
  131. end
  132. if checkDB == true then
  133. return true
  134. end
  135. if checkDB.keepTime < 0 or (checkDB.ts + checkDB.keepTime > os.time()) then
  136. return true
  137. else
  138. -- 过期了
  139. unActive(human.db._id, headType, id)
  140. end
  141. end
  142. function active(human, headType, id)
  143. local conf = getConfig(headType, id)
  144. if conf == nil then
  145. return
  146. end
  147. local keepTime = conf.keepTime * 60*60 -- conf.keepTime 为小时数
  148. if isActive(human, headType, id) then
  149. if headType == HEAD_TYPE_4 and keepTime > 0 then
  150. else
  151. return
  152. end
  153. end
  154. if headType == HEAD_TYPE_1 then -- 头像
  155. human.db.headList = human.db.headList or {}
  156. if keepTime == nil then
  157. human.db.headList[id] = true
  158. else
  159. human.db.headList[id] = {ts = os.time(), keepTime = keepTime}
  160. end
  161. elseif headType == HEAD_TYPE_2 then -- 头像框
  162. human.db.headFrameList = human.db.headFrameList or {}
  163. if keepTime == nil then
  164. human.db.headFrameList[id] = true
  165. else
  166. human.db.headFrameList[id] = {ts = os.time(), keepTime = keepTime}
  167. end
  168. elseif headType == HEAD_TYPE_3 then -- 形象
  169. human.db.bodyList = human.db.bodyList or {}
  170. if keepTime == nil then
  171. human.db.bodyList[id] = true
  172. else
  173. human.db.bodyList[id] = {ts = os.time(), keepTime = keepTime}
  174. end
  175. if human.db.body == nil then
  176. human.db.body = id
  177. -- 通知客户端
  178. local msgRet = Msg.gc.GC_ROLE_HEAD_SET
  179. msgRet.headID = id
  180. msgRet.headType = headType
  181. Msg.send(msgRet, human.fd)
  182. end
  183. elseif headType == HEAD_TYPE_4 then -- 称号
  184. if conf.group ~= 0 then
  185. for k, v in pairs(RoleExcel.chenghao) do
  186. if k ~= id and v.group == conf.group then
  187. unActive(human.db._id, HEAD_TYPE_4, k)
  188. end
  189. end
  190. end
  191. human.db.chenghaoList = human.db.chenghaoList or {}
  192. if keepTime == nil then
  193. human.db.chenghaoList[id] = true
  194. else
  195. human.db.chenghaoList[id] = {ts = os.time(), keepTime = keepTime}
  196. end
  197. elseif headType == HEAD_TYPE_5 then -- 立绘
  198. human.db.animationList = human.db.animationList or {}
  199. if keepTime == nil then
  200. human.db.animationList[id] = true
  201. else
  202. human.db.animationList[id] = {ts = os.time(), keepTime = keepTime}
  203. end
  204. if human.db.animation == nil then
  205. human.db.animation = id
  206. -- 通知客户端
  207. local msgRet = Msg.gc.GC_ROLE_HEAD_SET
  208. msgRet.headID = id
  209. msgRet.headType = headType
  210. Msg.send(msgRet, human.fd)
  211. end
  212. elseif headType == HEAD_TYPE_6 then -- 背景
  213. human.db.backgroundList = human.db.backgroundList or {}
  214. if keepTime == nil then
  215. human.db.backgroundList[id] = true
  216. else
  217. human.db.backgroundList[id] = {ts = os.time(), keepTime = keepTime}
  218. end
  219. end
  220. setNewFlag(human, headType, true)
  221. if #conf.attrs > 0 then
  222. ObjHuman.doCalcHero(human)
  223. end
  224. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_101)
  225. end
  226. function unActive(uuid, headType, id)
  227. local changed = nil
  228. local human = ObjHumam.onlineUuid[uuid]
  229. if headType == HEAD_TYPE_1 then -- 头像
  230. local db = RoleDBLogic.getDb(uuid,{head = 1, headList = 1})
  231. if db.headList and db.headList[id] then
  232. db.headList[id] = nil
  233. if db.head == id then
  234. db.head = DEFAULT_HEAD_MALE_ID
  235. if human then
  236. human.db.head = DEFAULT_HEAD_MALE_ID
  237. end
  238. end
  239. RoleDBLogic.saveRoleSset(db)
  240. changed = true
  241. end
  242. elseif headType == HEAD_TYPE_2 then -- 头像框
  243. local db = RoleDBLogic.getDb(uuid,{headFrame = 1, headFrameList = 1})
  244. if db.headFrameList and db.headFrameList[id] then
  245. db.headFrameList[id] = nil
  246. if db.headFrame == id then
  247. db.headFrame = DEFAULT_HEADFREAM_ID
  248. if human then
  249. human.db.headFrame = DEFAULT_HEADFREAM_ID
  250. end
  251. end
  252. RoleDBLogic.saveRoleSset(db)
  253. changed = true
  254. end
  255. elseif headType == HEAD_TYPE_3 then -- 形象
  256. local db = RoleDBLogic.getDb(uuid,{body = 1, bodyList = 1})
  257. if db.bodyList and db.bodyList[id] then
  258. db.bodyList[id] = nil
  259. if db.body == id then
  260. db.body = nil
  261. if human then
  262. human.db.body = nil
  263. end
  264. end
  265. RoleDBLogic.saveRoleSset(db)
  266. changed = true
  267. end
  268. elseif headType == HEAD_TYPE_4 then -- 称号
  269. local db = RoleDBLogic.getDb(uuid,{chenghao = 1, chenghaoList = 1})
  270. if db.chenghaoList and db.chenghaoList[id] then
  271. db.chenghaoList[id] = nil
  272. if db.chenghao == id then
  273. db.chenghao = nil
  274. if human then
  275. human.db.chenghao = nil
  276. end
  277. end
  278. RoleDBLogic.saveRoleSset(db)
  279. changed = true
  280. end
  281. elseif headType == HEAD_TYPE_5 then -- 立绘
  282. local db = RoleDBLogic.getDb(uuid,{body = 1, animationList = 1})
  283. if db.animationList and db.animationList[id] then
  284. db.animationList[id] = nil
  285. if db.animation == id then
  286. db.animation = nil
  287. if human then
  288. human.db.animation = nil
  289. end
  290. end
  291. RoleDBLogic.saveRoleSset(db)
  292. changed = true
  293. end
  294. elseif headType == HEAD_TYPE_6 then -- 背景
  295. local db = RoleDBLogic.getDb(uuid,{chenghao = 1, backgroundList = 1})
  296. if db.backgroundList and db.backgroundList[id] then
  297. db.backgroundList[id] = nil
  298. if db.background == id then
  299. db.background = nil
  300. if human then
  301. human.db.background = nil
  302. end
  303. end
  304. RoleDBLogic.saveRoleSset(db)
  305. changed = true
  306. end
  307. end
  308. if changed then
  309. if human then
  310. RoleAttr.cleanHeroAttrCache(human)
  311. local config = getConfig(headType, id)
  312. if config and #config.attrs > 0 then
  313. ObjHuman.doCalcHero(human)
  314. end
  315. ObjHuman.sendHumanInfo(human)
  316. end
  317. end
  318. end
  319. -- 是否有红点
  320. function isDotByType(human, headType)
  321. if human.db.headHasNewFlag == nil then
  322. return
  323. end
  324. local val = human.db.headHasNewFlag or 0
  325. local bit = Util.getBit(val, headType)
  326. if bit ~= 0 then
  327. return true
  328. end
  329. end
  330. function setNewFlag(human, type, flag)
  331. local val = human.db.headHasNewFlag or 0
  332. if (Util.getBit(val, type) > 0) == flag then
  333. return
  334. end
  335. if flag == true then
  336. val = Util.setBit(val, type)
  337. else
  338. local bit = Util.getBit(val, type)
  339. if bit ~= 0 then
  340. val = val - 2 ^ type
  341. end
  342. end
  343. if val == 0 then
  344. val = nil
  345. end
  346. human.db.headHasNewFlag = val
  347. end
  348. function query(human, headType)
  349. if headType < HEAD_TYPE_1 or headType > HEAD_TYPE_6 then
  350. return
  351. end
  352. local msgRet = Msg.gc.GC_ROLE_HEAD_QUERY
  353. msgRet.type = headType
  354. msgRet.headList[0] = 0
  355. msgRet.isDot[0] = 4
  356. msgRet.isDot[1] = isDotByType(human, HEAD_TYPE_1) and 1 or 0
  357. msgRet.isDot[2] = isDotByType(human, HEAD_TYPE_2) and 1 or 0
  358. msgRet.isDot[3] = isDotByType(human, HEAD_TYPE_3) and 1 or 0
  359. msgRet.isDot[4] = isDotByType(human, HEAD_TYPE_4) and 1 or 0
  360. if headType == HEAD_TYPE_1 then -- 头像
  361. for id, cf in pairs(RoleExcel.head) do
  362. if cf.type ~= DEFAULT_DEL_TYPE then
  363. msgRet.headList[0] = msgRet.headList[0] + 1
  364. local headNet = msgRet.headList[msgRet.headList[0]]
  365. headNet.headID = id
  366. headNet.isActive = isActive(human, HEAD_TYPE_1, id) and 1 or 0
  367. headNet.desc = cf.desc or ""
  368. headNet.keepTime = getKeepTime(human, HEAD_TYPE_1, id)
  369. headNet.name = cf.name or ""
  370. headNet.camp = cf.camp or 0
  371. local len = #cf.attrs
  372. for i = 1,len do
  373. headNet.attr[i].key = cf.attrs[i][1]
  374. headNet.attr[i].value = cf.attrs[i][2]
  375. end
  376. headNet.attr[0] = len
  377. end
  378. end
  379. msgRet.useID = human.db.head or 0
  380. elseif headType == HEAD_TYPE_2 then -- 头像框
  381. for id, cf in pairs(RoleExcel.headFrame) do
  382. if cf.type ~= DEFAULT_DEL_TYPE then
  383. msgRet.headList[0] = msgRet.headList[0] + 1
  384. local headNet = msgRet.headList[msgRet.headList[0]]
  385. headNet.headID = id
  386. headNet.isActive = isActive(human, HEAD_TYPE_2, id) and 1 or 0
  387. headNet.desc = cf.desc or ""
  388. headNet.keepTime = getKeepTime(human, HEAD_TYPE_2, id)
  389. headNet.name = cf.name or ""
  390. headNet.camp = cf.camp or 0
  391. local len = #cf.attrs
  392. for i = 1,len do
  393. headNet.attr[i].key = cf.attrs[i][1]
  394. headNet.attr[i].value = cf.attrs[i][2]
  395. end
  396. headNet.attr[0] = len
  397. end
  398. end
  399. msgRet.useID = human.db.headFrame or 0
  400. elseif headType == HEAD_TYPE_3 then -- 形象
  401. for id, cf in pairs(RoleExcel.body) do
  402. if cf.type ~= DEFAULT_DEL_TYPE then
  403. msgRet.headList[0] = msgRet.headList[0] + 1
  404. local headNet = msgRet.headList[msgRet.headList[0]]
  405. headNet.headID = id
  406. headNet.isActive = isActive(human, HEAD_TYPE_3, id) and 1 or 0
  407. headNet.desc = cf.desc or ""
  408. headNet.keepTime = getKeepTime(human, HEAD_TYPE_3, id)
  409. headNet.name = cf.name or ""
  410. headNet.camp = 0
  411. local len = #cf.attrs
  412. for i = 1,len do
  413. headNet.attr[i].key = cf.attrs[i][1]
  414. headNet.attr[i].value = cf.attrs[i][2]
  415. end
  416. headNet.attr[0] = len
  417. end
  418. end
  419. msgRet.useID = human.db.body or 0
  420. elseif headType == HEAD_TYPE_4 then -- 称号
  421. msgRet.headList[0] = 0
  422. msgRet.useID = 0
  423. ChenghaoImp.query(human)
  424. elseif headType == HEAD_TYPE_5 then -- 立绘
  425. for id, cf in pairs(RoleExcel.body) do
  426. if cf.type ~= DEFAULT_DEL_TYPE then
  427. msgRet.headList[0] = msgRet.headList[0] + 1
  428. local headNet = msgRet.headList[msgRet.headList[0]]
  429. headNet.headID = id
  430. headNet.isActive = isActive(human, HEAD_TYPE_5, id) and 1 or 0
  431. headNet.desc = cf.desc or ""
  432. headNet.keepTime = getKeepTime(human, HEAD_TYPE_5, id)
  433. headNet.name = cf.name or ""
  434. headNet.camp = cf.camp or 0
  435. headNet.attr[0] = 0
  436. end
  437. end
  438. msgRet.useID = human.db.animation or 0
  439. elseif headType == HEAD_TYPE_6 then -- 背景
  440. for id, cf in pairs(RoleExcel.background) do
  441. if cf.type ~= DEFAULT_DEL_TYPE then
  442. msgRet.headList[0] = msgRet.headList[0] + 1
  443. local headNet = msgRet.headList[msgRet.headList[0]]
  444. headNet.headID = id
  445. headNet.isActive = isActive(human, HEAD_TYPE_6, id) and 1 or 0
  446. headNet.desc = cf.desc or ""
  447. headNet.keepTime = getKeepTime(human, HEAD_TYPE_6, id)
  448. headNet.name = cf.name or ""
  449. headNet.camp = cf.camp or 0
  450. headNet.attr[0] = 0
  451. end
  452. end
  453. msgRet.useID = human.db.background or 0
  454. end
  455. setNewFlag(human, headType, nil)
  456. --Msg.trace(msgRet)
  457. Msg.send(msgRet, human.fd)
  458. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_101)
  459. end
  460. -- 背景立绘查询
  461. function bgAndLhQuery(human)
  462. local msgRet = Msg.gc.GC_ROLE_BG_LH_QUERY
  463. msgRet.data[0] = 2
  464. local dataNet = msgRet.data[1]
  465. dataNet.headList[0] = 0
  466. for id, cf in pairs(RoleExcel.body) do
  467. dataNet.headList[0] = dataNet.headList[0] + 1
  468. dataNet.type = HEAD_TYPE_5
  469. local headNet = dataNet.headList[dataNet.headList[0]]
  470. headNet.headID = id
  471. headNet.isActive = isActive(human, HEAD_TYPE_5, id) and 1 or 0
  472. headNet.desc = cf.desc or ""
  473. headNet.keepTime = getKeepTime(human, HEAD_TYPE_5, id)
  474. headNet.name = cf.name or ""
  475. headNet.camp = cf.camp or 0
  476. headNet.attr[0] = 0
  477. dataNet.useID = human.db.animation or 0
  478. end
  479. setNewFlag(human, HEAD_TYPE_5, nil)
  480. dataNet = msgRet.data[2]
  481. dataNet.headList[0] = 0
  482. for id, cf in pairs(RoleExcel.background) do
  483. dataNet.headList[0] = dataNet.headList[0] + 1
  484. local headNet = dataNet.headList[dataNet.headList[0]]
  485. dataNet.type = HEAD_TYPE_6
  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. dataNet.useID = human.db.background or 0
  494. end
  495. setNewFlag(human, HEAD_TYPE_6, nil)
  496. Msg.send(msgRet, human.fd)
  497. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_101)
  498. end
  499. -- 设置头像/头像框/形象
  500. function setHead(human, headID, headType)
  501. if headType < HEAD_TYPE_1 or headType > HEAD_TYPE_6 then
  502. return
  503. end
  504. if isActive(human, headType, headID) ~= true then
  505. return
  506. end
  507. local changed = nil
  508. local useID = nil
  509. if headType == HEAD_TYPE_1 then -- 头像
  510. useID = human.db.head or 0
  511. if useID == headID then
  512. return
  513. end
  514. human.db.head = headID
  515. changed = true
  516. elseif headType == HEAD_TYPE_2 then -- 头像框
  517. useID = human.db.headFrame or 0
  518. if useID == headID then
  519. return
  520. end
  521. human.db.headFrame = headID
  522. changed = true
  523. elseif headType == HEAD_TYPE_3 then -- 形象
  524. useID = human.db.body or 0
  525. if useID == headID then
  526. return
  527. end
  528. human.db.body = headID
  529. changed = true
  530. -- 查询是否有占领王座,如有占领,更改形象
  531. local list = TheStarsDBLogic.getThroneList()
  532. for i, v in ipairs(list) do
  533. if v.uuid ~= nil and v.uuid == human.db._id then
  534. v.body = headID
  535. TheStarsDBLogic.updateThroneDB(v)
  536. break
  537. end
  538. end
  539. elseif headType == HEAD_TYPE_4 then -- 称号
  540. useID = human.db.chenghao or 0
  541. if useID == headID then
  542. return
  543. end
  544. human.db.chenghao = headID
  545. changed = true
  546. elseif headType == HEAD_TYPE_5 then -- 立绘
  547. useID = human.db.animation or 0
  548. if useID == headID then
  549. return
  550. end
  551. human.db.animation = headID
  552. changed = true
  553. elseif headType == HEAD_TYPE_6 then -- 背景
  554. useID = human.db.background or 0
  555. if useID == headID then
  556. return
  557. end
  558. human.db.background = headID
  559. changed = true
  560. end
  561. RoleAttr.cleanHeroAttrCache(human)
  562. if changed == true then
  563. -- 通知客户端
  564. local msgRet = Msg.gc.GC_ROLE_HEAD_SET
  565. msgRet.headID = headID
  566. msgRet.headType = headType
  567. Msg.send(msgRet, human.fd)
  568. --同步头像设置
  569. if headType == HEAD_TYPE_5 or headType == HEAD_TYPE_6 then -- 立绘
  570. bgAndLhQuery(human)
  571. else
  572. query(human, headType)
  573. end
  574. if headType == HEAD_TYPE_1 then -- 头像
  575. HuanJingTowerLogic.changeHeadAfter(human)
  576. end
  577. end
  578. end
  579. function getKeepTime(human, headType, id)
  580. local config = nil
  581. local checkDB = nil
  582. if headType == HEAD_TYPE_1 then -- 头像
  583. if id == DEFAULT_HEAD_MALE_ID or
  584. id == DEFAULT_HEAD_FEMALE_ID then
  585. return -1
  586. end
  587. config = RoleExcel.head[id]
  588. if config == nil then
  589. return 0
  590. end
  591. if not human.db.headList then
  592. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  593. end
  594. checkDB = human.db.headList[id]
  595. elseif headType == HEAD_TYPE_2 then -- 头像框
  596. if id == DEFAULT_HEADFREAM_ID then
  597. return -1
  598. end
  599. config = RoleExcel.headFrame[id]
  600. if config == nil then
  601. return 0
  602. end
  603. if not human.db.headFrameList then
  604. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  605. end
  606. checkDB = human.db.headFrameList[id]
  607. elseif headType == HEAD_TYPE_3 then -- 形象
  608. config = RoleExcel.body[id]
  609. if config == nil then
  610. return 0
  611. end
  612. if not human.db.bodyList then
  613. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  614. end
  615. checkDB = human.db.bodyList[id]
  616. elseif headType == HEAD_TYPE_4 then -- 称号
  617. config = RoleExcel.chenghao[id]
  618. if config == nil then
  619. return 0
  620. end
  621. if not human.db.chenghaoList then
  622. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  623. end
  624. checkDB = human.db.chenghaoList[id]
  625. elseif headType == HEAD_TYPE_5 then -- 立绘
  626. config = RoleExcel.body[id]
  627. if config == nil then
  628. return 0
  629. end
  630. if not human.db.animationList then
  631. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  632. end
  633. checkDB = human.db.animationList[id]
  634. elseif headType == HEAD_TYPE_6 then -- 背景
  635. config = RoleExcel.background[id]
  636. if config == nil then
  637. return 0
  638. end
  639. if not human.db.backgroundList then
  640. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  641. end
  642. checkDB = human.db.backgroundList[id]
  643. end
  644. if checkDB == nil then
  645. return 0
  646. end
  647. if checkDB == true then
  648. return -1
  649. end
  650. if checkDB.keepTime < 0 then
  651. return -1
  652. end
  653. local now = os.time()
  654. if checkDB.ts + checkDB.keepTime <= now then
  655. return 0
  656. else
  657. return checkDB.ts + checkDB.keepTime - now
  658. end
  659. end
  660. -- 获得英雄回调
  661. function onAddHero(human, heroID)
  662. local heroConfig = HeroExcel.hero[heroID]
  663. active(human, HEAD_TYPE_1, heroConfig.head)
  664. active(human, HEAD_TYPE_3, heroConfig.body)
  665. active(human, HEAD_TYPE_5, heroConfig.body)
  666. end
  667. function isDot(human)
  668. if human.db.headHasNewFlag then
  669. return true
  670. end
  671. end
  672. function CG_ROLE_COMBATHERO_QUERY(human, type)
  673. local combatType = type
  674. local combatHero,helpList = CombatPosLogic.getCombatHeros(human, combatType, nil, true)
  675. if not combatHero then return end
  676. local msgRet = Msg.gc.GC_ROLE_COMBATHERO_QUERY
  677. msgRet.combatType = combatType
  678. msgRet.titleId = human.db.chenghao or 0
  679. msgRet.totalcombat = CombatPosLogic.getCombatHeroZDL(human, combatType, true)
  680. --msgRet.bagIndex[0] = CombatDefine.COMBAT_HERO_CNT
  681. local len = 0
  682. for k,v in pairs(combatHero) do
  683. local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
  684. if heroGrid then
  685. len = len + 1
  686. msgRet.bagIndex[len] = heroGrid.bagIndex
  687. end
  688. end
  689. for k,v in pairs(helpList) do
  690. local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
  691. if heroGrid then
  692. len = len + 1
  693. msgRet.bagIndex[len] = heroGrid.bagIndex
  694. end
  695. end
  696. msgRet.bagIndex[0] = len
  697. --Msg.trace(msgRet)
  698. Msg.send(msgRet, human.fd)
  699. end
  700. function doCalcHero(human, attrs)
  701. if not human then return end
  702. if human.db.headList then
  703. for k, v in pairs(human.db.headList) do
  704. if isActive(human, HEAD_TYPE_1, k) and human.db.head == k then
  705. local config = getConfig(HEAD_TYPE_1, k)
  706. for k1,v1 in ipairs(config.attrs) do
  707. RoleAttr.updateValue(v1[1], v1[2], attrs)
  708. end
  709. end
  710. end
  711. end
  712. if human.db.headFrameList then
  713. for k, v in pairs(human.db.headFrameList) do
  714. if isActive(human, HEAD_TYPE_2, k) and human.db.headFrame == k then
  715. local config = getConfig(HEAD_TYPE_2, k)
  716. for k1,v1 in ipairs(config.attrs) do
  717. RoleAttr.updateValue(v1[1], v1[2], attrs)
  718. end
  719. end
  720. end
  721. end
  722. if human.db.bodyList then
  723. for k, v in pairs(human.db.bodyList) do
  724. if isActive(human, HEAD_TYPE_3, k) and human.db.body == k then
  725. local config = getConfig(HEAD_TYPE_3, k)
  726. for k1,v1 in ipairs(config.attrs) do
  727. RoleAttr.updateValue(v1[1], v1[2], attrs)
  728. end
  729. end
  730. end
  731. end
  732. if human.db.chenghaoList then
  733. for k, v in pairs(human.db.chenghaoList) do
  734. if isActive(human, HEAD_TYPE_4, k) then
  735. local config = getConfig(HEAD_TYPE_4, k)
  736. for k1,v1 in ipairs(config.attrs) do
  737. RoleAttr.updateValue(v1[1], v1[2], attrs)
  738. end
  739. end
  740. end
  741. end
  742. if human.db.animationList then
  743. for k, v in pairs(human.db.animationList) do
  744. if isActive(human, HEAD_TYPE_5, k) and human.db.animation == k then
  745. local config = getConfig(HEAD_TYPE_5, k)
  746. for k1,v1 in ipairs(config.attrs) do
  747. RoleAttr.updateValue(v1[1], v1[2], attrs)
  748. end
  749. end
  750. end
  751. end
  752. if human.db.backgroundList then
  753. for k, v in pairs(human.db.backgroundList) do
  754. if isActive(human, HEAD_TYPE_6, k) then
  755. local config = getConfig(HEAD_TYPE_6, k)
  756. for k1,v1 in ipairs(config.attrs) do
  757. RoleAttr.updateValue(v1[1], v1[2], attrs)
  758. end
  759. end
  760. end
  761. end
  762. end