RoleHeadLogic.lua 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  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 adornId = 0
  540. if type == HEAD_TYPE_1 then
  541. adornId = human.db.head or 0
  542. elseif type == HEAD_TYPE_2 then
  543. adornId = human.db.headFrame or 0
  544. elseif type == HEAD_TYPE_3 then
  545. adornId = human.db.body or 0
  546. elseif type == HEAD_TYPE_5 then
  547. adornId = human.db.animation or 0
  548. elseif type == HEAD_TYPE_6 then
  549. adornId = human.db.background or 0
  550. end
  551. return adornId
  552. end
  553. -- 获取当前角色已获得的某类装饰的所有数据
  554. function GetRoleAdornInfo(human, adornType)
  555. if not adornType or adornType < HEAD_TYPE_1 or adornType > HEAD_TYPE_6 then
  556. return
  557. end
  558. if adornType == HEAD_TYPE_1 then
  559. return human.db.headList
  560. elseif adornType == HEAD_TYPE_2 then
  561. return human.db.headFrameList
  562. elseif adornType == HEAD_TYPE_3 then
  563. return human.db.bodyList
  564. elseif adornType == HEAD_TYPE_4 then
  565. return human.db.chenghaoList
  566. elseif adornType == HEAD_TYPE_5 then
  567. return human.db.animationList
  568. elseif adornType == HEAD_TYPE_6 then
  569. return human.db.backgroundList
  570. end
  571. end
  572. -- 设置头像/头像框/形象
  573. function setHead(human, headID, headType)
  574. if headType < HEAD_TYPE_1 or headType > HEAD_TYPE_6 then
  575. return
  576. end
  577. if isActive(human, headType, headID) ~= true then
  578. return
  579. end
  580. local changed = nil
  581. local useID = nil
  582. if headType == HEAD_TYPE_1 then -- 头像
  583. useID = human.db.head or 0
  584. if useID == headID then
  585. return
  586. end
  587. human.db.head = headID
  588. changed = true
  589. TriggerLogic.PublishEvent(TriggerDefine.SET_HEAD, human.db._id, 1)
  590. elseif headType == HEAD_TYPE_2 then -- 头像框
  591. useID = human.db.headFrame or 0
  592. if useID == headID then
  593. return
  594. end
  595. human.db.headFrame = headID
  596. changed = true
  597. TriggerLogic.PublishEvent(TriggerDefine.SET_HEAD_FRAME, human.db._id, 1)
  598. elseif headType == HEAD_TYPE_3 then -- 形象
  599. useID = human.db.body or 0
  600. if useID == headID then
  601. return
  602. end
  603. human.db.body = headID
  604. changed = true
  605. TriggerLogic.PublishEvent(TriggerDefine.SET_MODELING, human.db._id, 1)
  606. -- 查询是否有占领王座,如有占领,更改形象
  607. local list = TheStarsDBLogic.getThroneList()
  608. for i, v in ipairs(list) do
  609. if v.uuid ~= nil and v.uuid == human.db._id then
  610. v.body = headID
  611. TheStarsDBLogic.updateThroneDB(v)
  612. break
  613. end
  614. end
  615. elseif headType == HEAD_TYPE_4 then -- 称号
  616. useID = human.db.chenghao or 0
  617. if useID == headID then
  618. return
  619. end
  620. human.db.chenghao = headID
  621. changed = true
  622. TriggerLogic.PublishEvent(TriggerDefine.SET_TITLE, human.db._id, 1)
  623. elseif headType == HEAD_TYPE_5 then -- 立绘
  624. useID = human.db.animation or 0
  625. if useID == headID then
  626. return
  627. end
  628. human.db.animation = headID
  629. changed = true
  630. elseif headType == HEAD_TYPE_6 then -- 背景
  631. useID = human.db.background or 0
  632. if useID == headID then
  633. return
  634. end
  635. human.db.background = headID
  636. changed = true
  637. end
  638. RoleAttr.cleanHeroAttrCache(human)
  639. if changed == true then
  640. -- 通知客户端
  641. local msgRet = Msg.gc.GC_ROLE_HEAD_SET
  642. msgRet.headID = headID
  643. msgRet.headType = headType
  644. Msg.send(msgRet, human.fd)
  645. --同步头像设置
  646. if headType == HEAD_TYPE_5 or headType == HEAD_TYPE_6 then -- 立绘
  647. bgAndLhQuery(human)
  648. else
  649. query(human, headType)
  650. end
  651. if headType == HEAD_TYPE_1 then -- 头像
  652. HuanJingTowerLogic.changeHeadAfter(human)
  653. end
  654. if headType == HEAD_TYPE_1 or headType == HEAD_TYPE_2 or headType == HEAD_TYPE_3 then
  655. local showType = 3
  656. if headType == HEAD_TYPE_2 then
  657. showType = 4
  658. elseif headType == HEAD_TYPE_3 then
  659. showType = 5
  660. end
  661. local GodsAreaNS = require("godsArea.GodsAreaNS")
  662. GodsAreaNS.UpdateShowData(human, showType)
  663. end
  664. end
  665. end
  666. function getKeepTime(human, headType, id)
  667. local config = nil
  668. local checkDB = nil
  669. if headType == HEAD_TYPE_1 then -- 头像
  670. if id == DEFAULT_HEAD_MALE_ID or
  671. id == DEFAULT_HEAD_FEMALE_ID then
  672. return -1
  673. end
  674. config = RoleExcel.head[id]
  675. if config == nil then
  676. return 0
  677. end
  678. if not human.db.headList then
  679. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  680. end
  681. checkDB = human.db.headList[id]
  682. elseif headType == HEAD_TYPE_2 then -- 头像框
  683. if id == DEFAULT_HEADFREAM_ID then
  684. return -1
  685. end
  686. config = RoleExcel.headFrame[id]
  687. if config == nil then
  688. return 0
  689. end
  690. if not human.db.headFrameList then
  691. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  692. end
  693. checkDB = human.db.headFrameList[id]
  694. elseif headType == HEAD_TYPE_3 then -- 形象
  695. config = RoleExcel.body[id]
  696. if config == nil then
  697. return 0
  698. end
  699. if not human.db.bodyList then
  700. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  701. end
  702. checkDB = human.db.bodyList[id]
  703. elseif headType == HEAD_TYPE_4 then -- 称号
  704. config = RoleExcel.chenghao[id]
  705. if config == nil then
  706. return 0
  707. end
  708. if not human.db.chenghaoList then
  709. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  710. end
  711. checkDB = human.db.chenghaoList[id]
  712. elseif headType == HEAD_TYPE_5 then -- 立绘
  713. config = RoleExcel.body[id]
  714. if config == nil then
  715. return 0
  716. end
  717. if not human.db.animationList then
  718. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  719. end
  720. checkDB = human.db.animationList[id]
  721. elseif headType == HEAD_TYPE_6 then -- 背景
  722. config = RoleExcel.background[id]
  723. if config == nil then
  724. return 0
  725. end
  726. if not human.db.backgroundList then
  727. return config.keepTime == -1 and config.keepTime or config.keepTime*60*60
  728. end
  729. checkDB = human.db.backgroundList[id]
  730. end
  731. if checkDB == nil then
  732. return 0
  733. end
  734. if checkDB == true then
  735. return -1
  736. end
  737. if checkDB.keepTime < 0 then
  738. return -1
  739. end
  740. local now = os.time()
  741. if checkDB.ts + checkDB.keepTime <= now then
  742. return 0
  743. else
  744. return checkDB.ts + checkDB.keepTime - now
  745. end
  746. end
  747. -- 获得英雄回调
  748. function onAddHero(human, heroID)
  749. local heroConfig = HeroExcel.hero[heroID]
  750. active(human, HEAD_TYPE_1, heroConfig.head)
  751. active(human, HEAD_TYPE_3, heroConfig.body)
  752. active(human, HEAD_TYPE_5, heroConfig.body)
  753. end
  754. function isDot(human)
  755. if human.db.headHasNewFlag then
  756. return true
  757. end
  758. end
  759. function CG_ROLE_COMBATHERO_QUERY(human, type)
  760. local combatType = type
  761. local combatHero,helpList = CombatPosLogic.getCombatHeros(human, combatType, nil, true)
  762. if not combatHero then return end
  763. local msgRet = Msg.gc.GC_ROLE_COMBATHERO_QUERY
  764. msgRet.combatType = combatType
  765. msgRet.titleId = human.db.chenghao or 0
  766. msgRet.totalcombat = CombatPosLogic.getCombatHeroZDL(human, combatType, true)
  767. --msgRet.bagIndex[0] = CombatDefine.COMBAT_HERO_CNT
  768. local len = 0
  769. for k,v in pairs(combatHero) do
  770. local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
  771. if heroGrid then
  772. len = len + 1
  773. msgRet.bagIndex[len] = heroGrid.bagIndex
  774. end
  775. end
  776. for k,v in pairs(helpList) do
  777. local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
  778. if heroGrid then
  779. len = len + 1
  780. msgRet.bagIndex[len] = heroGrid.bagIndex
  781. end
  782. end
  783. msgRet.bagIndex[0] = len
  784. --Msg.trace(msgRet)
  785. Msg.send(msgRet, human.fd)
  786. end
  787. function doCalcHero(human, attrs)
  788. if not human then return end
  789. if human.db.headList then
  790. for k, v in pairs(human.db.headList) do
  791. if isActive(human, HEAD_TYPE_1, k) and human.db.head == k then
  792. local config = getConfig(HEAD_TYPE_1, 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.headFrameList then
  800. for k, v in pairs(human.db.headFrameList) do
  801. -- if isActive(human, HEAD_TYPE_2, k) and human.db.headFrame == k then
  802. -- local config = getConfig(HEAD_TYPE_2, k)
  803. -- for k1,v1 in ipairs(config.attrs) do
  804. -- RoleAttr.updateValue(v1[1], v1[2], attrs)
  805. -- end
  806. -- end
  807. -- 改为所有头像框加成属性叠加
  808. if isActive(human, HEAD_TYPE_2, k) then
  809. local config = getConfig(HEAD_TYPE_2, k)
  810. for k1,v1 in ipairs(config.attrs) do
  811. RoleAttr.updateValue(v1[1], v1[2], attrs)
  812. end
  813. end
  814. end
  815. end
  816. if human.db.bodyList then
  817. for k, v in pairs(human.db.bodyList) do
  818. if isActive(human, HEAD_TYPE_3, k) and human.db.body == k then
  819. local config = getConfig(HEAD_TYPE_3, k)
  820. for k1,v1 in ipairs(config.attrs) do
  821. RoleAttr.updateValue(v1[1], v1[2], attrs)
  822. end
  823. end
  824. end
  825. end
  826. if human.db.chenghaoList then
  827. for k, v in pairs(human.db.chenghaoList) do
  828. if isActive(human, HEAD_TYPE_4, k) then
  829. local config = getConfig(HEAD_TYPE_4, k)
  830. for k1,v1 in ipairs(config.attrs) do
  831. RoleAttr.updateValue(v1[1], v1[2], attrs)
  832. end
  833. end
  834. end
  835. end
  836. if human.db.animationList then
  837. for k, v in pairs(human.db.animationList) do
  838. if isActive(human, HEAD_TYPE_5, k) and human.db.animation == k then
  839. local config = getConfig(HEAD_TYPE_5, k)
  840. for k1,v1 in ipairs(config.attrs) do
  841. RoleAttr.updateValue(v1[1], v1[2], attrs)
  842. end
  843. end
  844. end
  845. end
  846. if human.db.backgroundList then
  847. for k, v in pairs(human.db.backgroundList) do
  848. if isActive(human, HEAD_TYPE_6, k) then
  849. local config = getConfig(HEAD_TYPE_6, k)
  850. for k1,v1 in ipairs(config.attrs) do
  851. RoleAttr.updateValue(v1[1], v1[2], attrs)
  852. end
  853. end
  854. end
  855. end
  856. end