ObjHuman.lua 24 KB

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