ObjHuman.lua 23 KB

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