ObjHuman.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. ----------------------------------
  2. -- 角色相关逻辑
  3. ----------------------------------
  4. local Config = require("Config")
  5. local Util = require("common.Util")
  6. local Log = require("common.Log")
  7. local Lang = require("common.Lang")
  8. local LogDefine = require("common.LogDefine")
  9. local CommonDefine = require("common.CommonDefine")
  10. local RoleExcel = require("excel.role")
  11. local Msg = require("core.Msg")
  12. local Obj = require("core.Obj")
  13. local Timer = require("core.Timer")
  14. local RoleAttr = require("role.RoleAttr")
  15. local RoleDBLogic = require("role.RoleDBLogic")
  16. local RoleDefine = require("role.RoleDefine")
  17. local Broadcast = require("broadcast.Broadcast")
  18. local BagLogic = require("bag.BagLogic")
  19. local HeroLogic = require("hero.HeroLogic")
  20. local VipLogic = require("vip.VipLogic")
  21. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  22. local BarTaskLogic = require("bar.BarTaskLogic")
  23. local CombatPosLogic = require("combat.CombatPosLogic")
  24. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  25. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  26. local OnlineRewardLogic = require("onlineReward.OnlineRewardLogic")
  27. local SettingLogic = require("setting.SettingLogic")
  28. local ChatHandler = require("chat.Handler")
  29. local FriendLogic = require("friend.FriendLogic")
  30. local UnionDBLogic = require("union.UnionDBLogic")
  31. local BuyLogic = require("topup.BuyLogic")
  32. local ReportManager = require("platform.ReportManager")
  33. local BattleLogic = require("battle.BattleLogic")
  34. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  35. local RoleLogic = require("role.RoleLogic")
  36. local FuwenLogic = require("fuwen.FuwenLogic")
  37. local EquipLogic = require("equip.EquipLogic")
  38. local TequanLogic = require("qqTequan.TequanLogic")
  39. local ShopLogic = require("shop.ShopLogic")
  40. local MailLogic = require("mail.MailLogic")
  41. local LianyuLogic = require("lianyu.LianyuLogic")
  42. local MiddleLogic = require("middle.MiddleLogic")
  43. local MiddleOption = require("middle.MiddleOption")
  44. local GuideLogic = require("guide.GuideLogic")
  45. local ItemDefine = require("bag.ItemDefine")
  46. local DrillLogic = require("drill.DrillLogic")
  47. local BRoleLogic = require("billboard.BRoleLogic")
  48. local BillboardDefine = require("billboard.BillboardDefine")
  49. local FcmLogic = require("fcm.FcmLogic")
  50. local CombatLogic = require("combat.CombatLogic")
  51. local SceneHandler = require("scene.Handler")
  52. local TuiSongLiBao = require("present.TuiSongLiBao")
  53. local CopyLogic = require("copy.CopyLogic")
  54. local HuanJingTowerLogic = require("huanjingTower.HuanjingTowerLogic")
  55. local UnionLivenessLogic = require("union.UnionLivenessLogic")
  56. local UnionDonateLogic = require("union.UnionDonateLogic")
  57. local RoleStrongLogic = require("role.RoleStrongLogic")
  58. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  59. local LiLianLogic = require("dailyTask.LiLianLogic")
  60. local FirstChargeLogic = require("present.FirstChargeLogic")
  61. local JjcLadderLogic = require("jjcLadder.JjcLadderLogic")
  62. local RelationGiftLogic = require("present.RelationGiftLogic")
  63. local WelfareGiftLogic = require("present.WelfareGiftLogic")
  64. local GlobalWorld = require("core.GlobalWorld")
  65. local ChatRecord = require("chat.ChatRecord")
  66. local WarReportLogic = require("warReport.WarReportLogic")
  67. local ZhuanpanLogic = require("zhuanpan.ZhuanpanLogic")
  68. local UnionRedBagLogic = require("union.UnionRedBagLogic")
  69. local JjcGodWarLogic = require("jjcGodWar.JjcGodWarLogic")
  70. local JibanLogic = require("combat.JibanLogic")
  71. local YunYingLogic = require("yunying.YunYingLogic")
  72. local KingWorldLogic = require("present.KingWorldLogic")
  73. local CommonDB = require("common.CommonDB")
  74. local ZhanbuLogic = require("zhanbu.ZhanbuLogic")
  75. local TopupLogic = require("topup.TopupLogic")
  76. local HeroLogLogic = require("absAct.HeroLogLogic")
  77. local FanliLogic = require("platform.FanliLogic")
  78. local HeroGrowUp = require("absAct.HeroGrowUp")
  79. local MailManager = require("mail.MailManager")
  80. local MailExcel = require("excel.mail")
  81. local PfLogic = require("platform.PfLogic")
  82. local MoshouLogic = require("moshou.MoshouLogic")
  83. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  84. local LostTempleLogic = require("lostTemple.lostTempleLogic")
  85. local DrawCardV2Excel = require("excel.drawCard").drawCardV2
  86. local WarOrder = require("shop.WarOrder")
  87. local Json = require("common.Json")
  88. fds = fds or {} -- fd->obj_id,包括创角中+游戏中
  89. onlineAccount = onlineAccount or {} -- account->human,包括创角中+游戏中
  90. onlineHuman = onlineHuman or {} -- name->human,仅包括游戏中
  91. onlineUuid = onlineUuid or {} -- uuid->human,仅包括游戏中
  92. function create(fd, account, db)
  93. local human = {}
  94. Obj.create(human, Obj.TYPE_HUMAN)
  95. fds[fd] = human.id
  96. human.fd = fd
  97. human.db = db or RoleDBLogic.loadRole(account)
  98. if human.db ~= nil then
  99. initHuman(human)
  100. else
  101. human.account = account
  102. end
  103. return human
  104. end
  105. function initHuman(human)
  106. local now = os.time()
  107. human.preLoginTime = human.db.lastLoginTime -- 上一次登录时间
  108. human.db.lastLoginTime = now -- 记录最近一次登录时间
  109. human.saveDBTime = Timer.now -- 人物数据库保存时间
  110. human.firstEnter = true -- 首次进入场景
  111. -- 角色信息初始化
  112. onlineAccount[human.db.account] = human
  113. onlineHuman[human.db.name] = human
  114. onlineUuid[human.db._id] = human
  115. end
  116. function destroy(human)
  117. local account = human.account or human.db.account
  118. if human.fd then fds[human.fd] = nil end
  119. if human.db then -- 已创角
  120. onlineAccount[account] = nil
  121. onlineHuman[human.db.name] = nil
  122. onlineUuid[human.db._id] = nil
  123. end
  124. Obj.destroy(human)
  125. end
  126. function doDisconnect(human, code)
  127. print("doDisconnect account:", human.account or human.db.account, " code:", code)
  128. if human.db then
  129. local now = os.time()
  130. if human.db.changeNameCnt ~= nil then
  131. Log.write(Log.LOGID_OSS_LOGOUT, human.db._id, human.db.account, human.db.name, human.db.lv, human.db.ip, code, now - human.db.lastLoginTime)
  132. end
  133. if human.fd then
  134. onLogout(human)
  135. end
  136. end
  137. if code ~= CommonDefine.DISCONNECT_NORMAL and code ~= CommonDefine.DISCONNECT_NORMAL_AFTER then
  138. if _G.is_middle ~= true then
  139. local mm = Msg.gc.GC_DISCONNECT
  140. mm.code = code
  141. mm.msg = CommonDefine.DISCONNECT_MSG[code] or ""
  142. Msg.send(mm, human.fd)
  143. end
  144. end
  145. if human.db then
  146. if code ~= CommonDefine.DISCONNECT_NORMAL then -- 正常断线先不销毁
  147. if code ~= CommonDefine.DISCONNECT_DUPLICATE then
  148. CombatLogic.forceFinish(human)
  149. end
  150. ReportManager.quit(human,code)
  151. destroy(human)
  152. if code == CommonDefine.DISCONNECT_DUPLICATE then
  153. else
  154. if _G.is_middle == true then
  155. -- 数据销毁 要把db数据发回给正常服
  156. MiddleLogic.sendWL_DB_BACK(human)
  157. else
  158. local ret, err = pcall(save, human)
  159. if not ret then
  160. Log.write(Log.LOGID_ERR_PCALL, "destroy account=" .. human.db.account, err)
  161. end
  162. end
  163. end
  164. return
  165. end
  166. else
  167. destroy(human) -- 未创角,立刻销毁对象
  168. return
  169. end
  170. if not human.fd then
  171. assert()
  172. end
  173. fds[human.fd] = nil
  174. human.fd = nil
  175. human.f5 = Timer.now
  176. end
  177. -- 下线回调
  178. function onLogout(human)
  179. local nowTime = os.time()
  180. human.db.lastLogoutTime = os.time() -- 记录最近登出时间
  181. local time = math.max(nowTime - human.db.lastLoginTime, 0)
  182. human.db.onlineTime = (human.db.onlineTime or 0) + time -- 记录在线时长
  183. local time2 = nowTime - math.max(human.db.lastLoginTime, Util.getDayStartTime(nowTime))
  184. human.db.onlineTimeDay = (human.db.onlineTimeDay or 0) + math.max(time2, 0) -- 记录本日在线时长
  185. LianyuLogic.onLogout(human)
  186. OnlineRewardLogic.onLogout(human, time)
  187. YunYingLogic.onCallBack(human, "onLogout")
  188. end
  189. function saveCharDB()
  190. local now = Timer.now
  191. local minn
  192. local ans
  193. for _, human in pairs(onlineUuid) do
  194. if human.fd then
  195. local t = human.saveDBTime
  196. if 300000 <= now - t and (not minn or t < minn) then
  197. minn = t
  198. ans = human
  199. end
  200. end
  201. end
  202. if not ans then
  203. return
  204. end
  205. ans.saveDBTime = now
  206. local ret, err = pcall(save, ans)
  207. if not ret then
  208. Log.write(Log.LOGID_ERR_PCALL, "saveCharDB rolename="..ans.db.name, err)
  209. end
  210. end
  211. function humanOfflineCheck()
  212. if _G.is_middle == true then
  213. local now = os.time()
  214. for account, human in pairs(onlineAccount) do
  215. if human.fd == nil then
  216. if human.f5 == nil or Timer.now - human.f5 > 30000 then
  217. doDisconnect(human, CommonDefine.DISCONNECT_NORMAL_AFTER, "")
  218. end
  219. end
  220. end
  221. for account, humanTempInfo in pairs(MiddleLogic.TRY_LOGIN_HUMAN) do
  222. if now - humanTempInfo.tsForMiddle > 30 then
  223. MiddleLogic.TRY_LOGIN_HUMAN[account] = nil
  224. end
  225. end
  226. else
  227. for uuid, human in pairs(onlineUuid) do
  228. -- 暂时不检测 不主动结束战斗 方便客户端调试 dxzeng debug
  229. if CombatLogic.COMBAT_CACHE[uuid] and not Config.IS_DEBUG then -- reyes test
  230. CombatLogic.checkFinish(human)
  231. else
  232. if human.fd == nil then
  233. if human.f5 == nil or Timer.now - human.f5 > 32000 then
  234. doDisconnect(human, CommonDefine.DISCONNECT_NORMAL_AFTER)
  235. end
  236. end
  237. end
  238. end
  239. end
  240. end
  241. function save(human)
  242. RoleDBLogic.saveRole(human.db)
  243. end
  244. -- 获得在线人数(包含停留在创角页)
  245. function getOnlineCnt()
  246. local onlineCnt = 0
  247. for _ in pairs(onlineAccount) do
  248. onlineCnt = onlineCnt + 1
  249. end
  250. return onlineCnt
  251. end
  252. function onZhandouliUpdate(human)
  253. -- 更新排行榜
  254. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID22,human.db.zhandouli,nil,nil,true)
  255. YunYingLogic.onCallBack(human, "onZhandouli", human.db.zhandouli)
  256. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_203)
  257. end
  258. local old_attr = {}
  259. function doCalc(human)
  260. for k in pairs(old_attr) do
  261. old_attr[k] = nil
  262. end
  263. if human.attr then
  264. for k, v in pairs(human.attr) do
  265. old_attr[k] = v
  266. end
  267. end
  268. RoleAttr.doCalc(human)
  269. onZhandouliUpdate(human)
  270. local mm = Msg.gc.GC_ROLE_ATTR
  271. local len = 0
  272. local left = mm.attrs
  273. for k,v in pairs(human.attr) do
  274. if v ~= old_attr[k] then
  275. len = len + 1
  276. left[len].key = k
  277. left[len].value = v
  278. end
  279. end
  280. if 0 < len then
  281. left[0] = len
  282. Msg.send(mm, human.fd)
  283. --Msg.trace(mm)
  284. end
  285. end
  286. function sendAttr(human,key)
  287. if human.db.middleFlag and _G.is_middle ~= true then
  288. -- 这个时候的属性改变由跨服服计算
  289. return
  290. end
  291. if not human.attr[key] then return end
  292. local msgRet = Msg.gc.GC_ROLE_ATTR
  293. msgRet.attrs[0] = 1
  294. local attr = msgRet.attrs[1]
  295. attr.key = key
  296. attr.value = human.attr[key]
  297. Msg.send(msgRet, human.fd)
  298. --Msg.trace(msgRet)
  299. end
  300. function doCalcHero(human, bagIndex)
  301. RoleAttr.doCalcHero(human, bagIndex)
  302. doCalc(human)
  303. end
  304. function getHeroAttrs(human, bagIndex)
  305. if not human.heroAttrs or not human.heroAttrs[bagIndex] then
  306. RoleAttr.doCalcHero(human, bagIndex)
  307. end
  308. return human.heroAttrs[bagIndex]
  309. end
  310. function checkLevelUp(human)
  311. if human.db.lv > #RoleExcel.exp then
  312. return 0
  313. end
  314. local levelUp = 0
  315. while human.db.exp > 0 do
  316. local needExp = 0
  317. if human.db.lv < 200 then
  318. needExp = RoleExcel.exp[human.db.lv + 1].exp
  319. end
  320. if needExp <= human.db.exp then
  321. if human.db.lv >= #RoleExcel.exp then
  322. if human.db.exp > needExp then
  323. human.db.exp = needExp
  324. end
  325. break
  326. else
  327. human.db.exp = human.db.exp - needExp
  328. human.db.lv = human.db.lv + 1
  329. levelUp = 1
  330. JibanLogic.onCallback(human,4,human.db.lv)
  331. end
  332. else
  333. break
  334. end
  335. end
  336. return levelUp
  337. end
  338. function onLvUpCB(human, oldLv, newLv)
  339. doCalc(human)
  340. --升级判断钻石基金是否返钻
  341. --FundLogic.onLvUp(human, oldLv, newLv)
  342. GuideLogic.onLvUpCB(human, oldLv, newLv)
  343. RoleSystemLogic.onLvUp(human)
  344. YunYingLogic.onLevelUp(human, oldLv, newLv)
  345. TuiSongLiBao.tuiSongLiBaoOnTask(human,TuiSongLiBao.TUISONGLIBAOTASK_LV, newLv, oldLv)
  346. CombatPosLogic.onLvUp(human, oldLv, newLv)
  347. ChengjiuLogic.onLvUp(human)
  348. -- 更新等级排名数据
  349. if BRoleLogic.updateData(BillboardDefine.TYPE_LV, human.db) then
  350. -- 计算世界等级
  351. GlobalWorld.doCalcWorldLv()
  352. end
  353. -- 开服邮件
  354. local subDay = CommonDB.getServerOpenDay()
  355. human.db.sendPfEmail = human.db.sendPfEmail or {}
  356. for k, config in ipairs(MailExcel.openMail) do
  357. if subDay and
  358. subDay >= config.openDay[1] and
  359. subDay <= config.openDay[2] and
  360. PfLogic.isServerIndex(config.svrIndex) then
  361. if newLv >= config.lv and
  362. human.db.sendPfEmail[k] == nil then
  363. human.db.sendPfEmail[k] = 1
  364. local title = MailExcel.mail[config.mailID].title
  365. local content = MailExcel.mail[config.mailID].content
  366. local senderName = MailExcel.mail[config.mailID].senderName
  367. if #config.items > 0 then
  368. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, config.items, senderName)
  369. else
  370. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, nil, senderName)
  371. end
  372. end
  373. end
  374. end
  375. --升级日志
  376. Log.write(Log.LOGID_OSS_LEVELUP, human.db._id, human.db.account, human.db.name, oldLv, newLv)
  377. end
  378. function addExp(human, addExp)
  379. if human.db.lv > #RoleExcel.exp then return end
  380. if not addExp then return end
  381. addExp = math.floor(addExp)
  382. if addExp == 0 then return end
  383. local total = human.db.exp + addExp
  384. total = math.max(0, total)
  385. total = math.floor(total)
  386. if total == human.db.exp then
  387. return
  388. end
  389. local oldLv = human.db.lv
  390. human.db.exp = total
  391. local levelUp = checkLevelUp(human)
  392. if levelUp == 1 then
  393. onLvUpCB(human, oldLv, human.db.lv)
  394. else
  395. human.attr[RoleDefine.EXP] = human.db.exp
  396. sendAttr(human,RoleDefine.EXP)
  397. end
  398. end
  399. function canAddJinbi(human, d)
  400. if human.db.jinbi + d > ItemDefine.BAG_ITEM_MAX_JINBI then
  401. return Broadcast.sendErr(human, Lang.COMMON_ADD_JINBI_LIMIT)
  402. else
  403. return true
  404. end
  405. end
  406. function updateJinbi(human, d, logType,item_id, num)
  407. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["jinbi"] then
  408. assert()
  409. end
  410. d = math.floor(d)
  411. if d == 0 then
  412. return
  413. end
  414. local val = human.db.jinbi + d
  415. if val < 0 then
  416. assert()
  417. end
  418. if val > ItemDefine.BAG_ITEM_MAX_JINBI then
  419. val = ItemDefine.BAG_ITEM_MAX_JINBI
  420. Broadcast.sendErr(human, Lang.COMMON_ADD_JINBI_LIMIT)
  421. end
  422. --金币使用日志
  423. if item_id == nil then item_id = 0 end
  424. if num == nil then num = 0 end
  425. Log.write(Log.LOGID_OSS_JINBI, human.db._id, human.db.account, human.db.name, human.db.lv, d, LogDefine.DEFINE[logType] + LogDefine.TYPE["jinbi"], item_id or 0, num or 0, val)
  426. human.db.jinbi = val
  427. if human.fd then
  428. human.attr[RoleDefine.JINBI] = human.db.jinbi
  429. sendAttr(human,RoleDefine.JINBI)
  430. end
  431. MiddleOption.updateYinliang(human, d, logType)
  432. if d < 0 then
  433. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE4, -d)
  434. end
  435. return true
  436. end
  437. function addZuanshi(human, d, logType, item_id, num)
  438. d = math.floor(d)
  439. if d < 0 then assert(nil) end
  440. if d == 0 then return end
  441. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["zuanshi"] then
  442. assert()
  443. end
  444. local val = human.db.zuanshi + d
  445. --钻石使用日志
  446. Log.write(Log.LOGID_OSS_GOLD, human.db._id, human.db.account, human.db.name, human.db.lv, d, LogDefine.DEFINE[logType] + LogDefine.TYPE["zuanshi"] , item_id or 0, num or 0, val)
  447. human.db.zuanshi = val
  448. if human.fd then
  449. human.attr[RoleDefine.ZUANSHI] = human.db.zuanshi
  450. sendAttr(human, RoleDefine.ZUANSHI)
  451. end
  452. MiddleOption.updateYuanbao(human, d, logType)
  453. return true
  454. end
  455. function decZuanshi(human, d, logType, item_id, num, noSend)
  456. d = math.floor(d)
  457. if d > 0 then assert(nil) end
  458. if d == 0 then return end
  459. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["zuanshi"] then
  460. assert()
  461. end
  462. local val = human.db.zuanshi + d
  463. if val < 0 then
  464. assert()
  465. end
  466. human.db.zuanshi = val
  467. Log.write(Log.LOGID_OSS_GOLD, human.db._id, human.db.account, human.db.name, human.db.lv, d, LogDefine.DEFINE[logType] + LogDefine.TYPE["zuanshi"] , item_id or 0, num or 0, val)
  468. if human.fd then
  469. human.attr[RoleDefine.ZUANSHI] = human.db.zuanshi
  470. sendAttr(human, RoleDefine.ZUANSHI)
  471. end
  472. HeroLogLogic.finishTaskCB(human,HeroLogLogic.HERO_LOG_TYPE_6,-d)
  473. MiddleOption.updateYuanbao(human, d, logType)
  474. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE5, -d)
  475. YunYingLogic.onCallBack(human, "onDecZuanshi",-d)
  476. return true
  477. end
  478. -- 钻石不足时候的处理
  479. function checkRMB(human, need)
  480. local sum = human.db.zuanshi
  481. if sum < need then
  482. if _G.is_middle == true then
  483. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  484. else
  485. if not SceneHandler.canCharge(human) then
  486. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  487. else
  488. local msgRet = Msg.gc.GC_BAG_NORMB
  489. Msg.send(msgRet,human.fd)
  490. end
  491. end
  492. return false
  493. else
  494. return true
  495. end
  496. end
  497. function updateFriendHeart(human, d, logType,item_id, num)
  498. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["friendheart"] then
  499. assert()
  500. end
  501. d = math.floor(d)
  502. if d == 0 then
  503. return
  504. end
  505. local val = human.db.friendHeart + d
  506. if val < 0 then
  507. assert()
  508. end
  509. --好友爱心使用日志
  510. if item_id == nil then item_id = 0 end
  511. if num == nil then num = 0 end
  512. Log.write(Log.LOGID_OSS_FRIENDHEART, human.db._id, human.db.account, human.db.name, human.db.lv, d, LogDefine.DEFINE[logType] + LogDefine.TYPE["friendheart"], item_id or 0, num or 0, val)
  513. human.db.friendHeart = val
  514. if human.fd then
  515. human.attr[RoleDefine.FRIENDHEART] = human.db.friendHeart
  516. sendAttr(human,RoleDefine.FRIENDHEART)
  517. end
  518. return true
  519. end
  520. function sendHumanInfo(human,isNew)
  521. -- 处理称号被销毁的
  522. if human.db.chenghao then
  523. if not human.db.chenghaoList[human.db.chenghao] then
  524. human.db.chenghao = nil
  525. end
  526. end
  527. local subDay = CommonDB.getServerOpenDay()
  528. local mm = Msg.gc.GC_ZZ_HUMAN_INFO
  529. RoleLogic.getRoleBase(human, mm.roleBase)
  530. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  531. mm.unionName = union and union.name or ""
  532. mm.unionIdentity = union and union.id or ""
  533. mm.bannerID = union and union.bannerID or 0
  534. mm.unionFrame = union and union.headFrame or 0
  535. mm.identity = human.db.identity
  536. mm.vipLv = VipLogic.getVipLv(human)
  537. mm.animation = human.db.animation or 0
  538. mm.background = human.db.background or 0
  539. mm.debug = Config.IS_USE_GM_CMD and 1 or 0
  540. mm.worldLv = GlobalWorld.getWorldLv()
  541. mm.openDay = subDay or 0
  542. mm.guideState= GuideLogic.checkAllFinish(human)
  543. mm.isFrist = isNew and 1 or 0
  544. for i = 1,#mm.warOrder do
  545. mm.warOrder[0] = i
  546. WarOrder.getWarOrderInfo(human,i,mm.warOrder[i] )
  547. end
  548. local drawCardRateList = {}
  549. local drawCardV2Confs = DrawCardV2Excel
  550. local num = drawCardV2Confs and (#drawCardV2Confs) or 0
  551. for i = 0 , num do
  552. local drawCardV2Conf = drawCardV2Confs[i]
  553. drawCardRateList[i] = drawCardRateList[i] or {}
  554. for weightIndex = 1 , #drawCardV2Conf.weight do
  555. drawCardRateList[i][weightIndex] = drawCardRateList[i][weightIndex] or {}
  556. drawCardRateList[i][weightIndex] = drawCardV2Conf.weight[weightIndex][2]
  557. end
  558. end
  559. mm.drawCardRateList = Json.Encode(drawCardRateList)
  560. Msg.send(mm, human.fd)
  561. end
  562. function enterCity(human)
  563. Msg.send(Msg.gc.GC_ENTER_CITY, human.fd)
  564. end
  565. -- 上线回调
  566. function onLogin(human, isNew)
  567. human.db.ip = human.ip
  568. human.db.phpChanelID = human.phpChanelID
  569. if human.db.changeNameCnt ~= nil then
  570. Log.write(Log.LOGID_OSS_LOGIN, human.db._id, human.db.account, human.db.name, human.db.lv, human.db.ip)
  571. end
  572. updateDaily(human)
  573. if not FcmLogic.checkFcm(human) then
  574. return -- 防沉迷 踢下线
  575. end
  576. TequanLogic.jihuopt(human)
  577. TequanLogic.setHumanTequan(human,human.pf_info)
  578. doCalc(human)
  579. sendHumanInfo(human,isNew)
  580. BagLogic.sendBagList(human)
  581. FuwenLogic.sendFuwenBagList(human)
  582. EquipLogic.sendEquipBagList(human)
  583. HeroLogic.sendHeroBagCap(human)
  584. HeroLogic.sendHeroBagList(human)
  585. CombatPosLogic.onLogin(human)
  586. VipLogic.onLogin(human)
  587. FriendLogic.onLogin(human)
  588. DailyTaskLogic.onLogin(human)
  589. OnlineRewardLogic.onLogin(human)
  590. SettingLogic.query(human)
  591. ChatHandler.onLogin(human)
  592. BattleLogic.onLogin(human)
  593. ChatPaoMaLogic.onLogin(human)
  594. MailLogic.cleanNilContent(human)
  595. YunYingLogic.onLogin(human)
  596. RoleStrongLogic.onLogin(human)
  597. RelationGiftLogic.onLogin(human)
  598. ChatRecord.sendAllNotRead(human)
  599. JjcGodWarLogic.onLogin(human)
  600. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE1, 1)
  601. if not isNew then
  602. ReportManager.login(human)
  603. end
  604. LostTempleLogic.onLogin(human)
  605. SettingLogic.onLogin(human)
  606. GuideLogic.onLogin(human)
  607. CombatLogic.onLogin(human) -- reyes test
  608. LianyuLogic.onLogin(human)
  609. MoshouLogic.onLogin(human)
  610. TopupLogic.checkKf(human)
  611. -- 最后执行离线发货
  612. BuyLogic.onLogin(human)
  613. HeroLogLogic.finishTaskCB(human,HeroLogLogic.HERO_LOG_TYPE_1,1)
  614. -- 红点 检测 需要放在通用的onLogin 后面 保持数据的正确性 再检测红点
  615. local pcallRet, pcallErr = pcall(RoleSystemLogic.onLogin, human)
  616. if not pcallRet then
  617. Log.write(Log.LOGID_ERR_PCALL, "RoleSystemLogic.onLogin err=" .. human.db.account, pcallErr)
  618. end
  619. enterCity(human)
  620. local day = Util.diffDay(human.db.createTime)
  621. if day == 2 or day == 7 then
  622. local msgRet = Msg.gc.GC_NOTICE_DADIAN
  623. msgRet.type = 2
  624. msgRet.param = day
  625. msgRet.param2 = 0
  626. Msg.send(msgRet,human.fd)
  627. end
  628. -- 注意 这个函数写在doLogin的最后
  629. MiddleLogic.onLogin(human)
  630. end
  631. -- 这里有个潜规则,凡是使用每天都需更新的数据时,都必须先调用这个方法。by cc
  632. function updateDaily(human, isGm)
  633. if not isGm then
  634. if human.db.update_daily_time and Util.isSameDay(human.db.update_daily_time) then
  635. return true
  636. end
  637. end
  638. -- 跨月
  639. if human.db.update_daily_time and Util.isSameMonth(human.db.update_daily_time) ~= true then
  640. human.db.topupAccountMonth = nil
  641. end
  642. YunYingLogic.updateDaily(human)
  643. BattleLogic.updateDaily(human)
  644. BarTaskLogic.refreshDailyTask(human)
  645. FriendLogic.refreshDailyTask(human)
  646. TequanLogic.cleanDaily(human)
  647. CopyLogic.updateDaily(human)
  648. HuanJingTowerLogic.updateDaily(human)
  649. VipLogic.updateDaily(human)
  650. WelfareGiftLogic.updateDaily(human)
  651. WarReportLogic.updateDaily(human)
  652. ZhanbuLogic.updateDaily(human)
  653. ZhuanpanLogic.updateDaily(human)
  654. LostTempleLogic.updateDaily(human)
  655. human.db.update_daily_time = os.time()
  656. human.db.dailyTask = nil
  657. human.db.dailyShareTask = nil
  658. human.db.jjcDailyFight = nil
  659. human.db.jjcWorship = nil
  660. human.db.personMail = nil
  661. human.db.topupAcountDaily = nil
  662. human.db.dailyLeiChong = nil
  663. human.db.onlineTimeDay = nil
  664. human.db.onlineTimeDayReport = nil
  665. human.db.heroResetCnt = nil
  666. human.db.dailyLibao = nil
  667. human.db.ectypeLike = nil
  668. human.db.ectypHurt = nil
  669. human.db.ectypeCnt = nil
  670. human.db.ectypLikeUuid = nil
  671. human.db.adRewardCnt = nil
  672. human.db.adHatchRewardCnt = nil
  673. human.db.isTip = nil
  674. ShopLogic.updateDaily(human)
  675. LianyuLogic.updateDaily(human)
  676. DrillLogic.updateDaily(human)
  677. UnionLivenessLogic.updateDaily(human)
  678. UnionDonateLogic.updateDaily(human)
  679. FirstChargeLogic.updateDaily(human)
  680. JjcLadderLogic.updateDaily(human)
  681. UnionRedBagLogic.updateDaily(human)
  682. JjcGodWarLogic.updateDaily(human)
  683. -- 红点 发送 理论放最后
  684. RoleSystemLogic.onLogin(human)
  685. end
  686. -- 角色心跳
  687. function refresh()
  688. for _, human in pairs(onlineHuman) do
  689. --活动开启邮件提示
  690. RoleSystemLogic.checkMailTips(human)
  691. end
  692. end