ObjHuman.lua 24 KB

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