RoleHeadLogic.lua 26 KB

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