RoleHeadLogic.lua 26 KB

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