ObjHuman.lua 24 KB

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