RoleHeadLogic.lua 25 KB

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