ObjHuman.lua 23 KB

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