RoleHeadLogic.lua 27 KB

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