RoleHeadLogic.lua 30 KB

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