ObjHuman.lua 24 KB

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