ObjHuman.lua 24 KB

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