RoleHeadLogic.lua 26 KB

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