RoleHeadLogic.lua 29 KB

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