ObjHuman.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  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 OnlineAwardLogic = require("present.OnlineAwardLogic")
  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. --升级日志
  383. Log.write(Log.LOGID_OSS_LEVELUP, human.db._id, human.db.account, human.db.name, oldLv, newLv)
  384. end
  385. function addExp(human, addExp)
  386. if human.db.lv > #RoleExcel.exp then return end
  387. if not addExp then return end
  388. addExp = math.floor(addExp)
  389. if addExp == 0 then return end
  390. local total = human.db.exp + addExp
  391. total = math.max(0, total)
  392. total = math.floor(total)
  393. if total == human.db.exp then
  394. return
  395. end
  396. local oldLv = human.db.lv
  397. human.db.exp = total
  398. local levelUp = checkLevelUp(human)
  399. if levelUp == 1 then
  400. onLvUpCB(human, oldLv, human.db.lv)
  401. else
  402. human.attr[RoleDefine.EXP] = human.db.exp
  403. sendAttr(human,RoleDefine.EXP)
  404. end
  405. end
  406. function canAddJinbi(human, d)
  407. if human.db.jinbi + d > ItemDefine.BAG_ITEM_MAX_JINBI then
  408. return Broadcast.sendErr(human, Lang.COMMON_ADD_JINBI_LIMIT)
  409. else
  410. return true
  411. end
  412. end
  413. function updateJinbi(human, d, logType,item_id, num)
  414. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["jinbi"] then
  415. assert()
  416. end
  417. d = math.floor(d)
  418. if d == 0 then
  419. return
  420. end
  421. local val = human.db.jinbi + d
  422. if val < 0 then
  423. assert()
  424. end
  425. if val > ItemDefine.BAG_ITEM_MAX_JINBI then
  426. val = ItemDefine.BAG_ITEM_MAX_JINBI
  427. Broadcast.sendErr(human, Lang.COMMON_ADD_JINBI_LIMIT)
  428. end
  429. --金币使用日志
  430. if item_id == nil then item_id = 0 end
  431. if num == nil then num = 0 end
  432. 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)
  433. human.db.jinbi = val
  434. if human.fd then
  435. human.attr[RoleDefine.JINBI] = human.db.jinbi
  436. sendAttr(human,RoleDefine.JINBI)
  437. end
  438. MiddleOption.updateYinliang(human, d, logType)
  439. if d < 0 then
  440. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE4, -d)
  441. end
  442. return true
  443. end
  444. function addZuanshi(human, d, logType, item_id, num)
  445. d = math.floor(d)
  446. if d < 0 then assert(nil) end
  447. if d == 0 then return end
  448. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["zuanshi"] then
  449. assert()
  450. end
  451. local val = human.db.zuanshi + d
  452. --钻石使用日志
  453. 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)
  454. human.db.zuanshi = val
  455. if human.fd then
  456. human.attr[RoleDefine.ZUANSHI] = human.db.zuanshi
  457. sendAttr(human, RoleDefine.ZUANSHI)
  458. end
  459. MiddleOption.updateYuanbao(human, d, logType)
  460. return true
  461. end
  462. function decZuanshi(human, d, logType, item_id, num, noSend)
  463. d = math.floor(d)
  464. if d > 0 then assert(nil) end
  465. if d == 0 then return end
  466. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["zuanshi"] then
  467. assert()
  468. end
  469. local val = human.db.zuanshi + d
  470. if val < 0 then
  471. assert()
  472. end
  473. human.db.zuanshi = val
  474. 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)
  475. if human.fd then
  476. human.attr[RoleDefine.ZUANSHI] = human.db.zuanshi
  477. sendAttr(human, RoleDefine.ZUANSHI)
  478. end
  479. HeroLogLogic.finishTaskCB(human,HeroLogLogic.HERO_LOG_TYPE_6,-d)
  480. MiddleOption.updateYuanbao(human, d, logType)
  481. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE5, -d)
  482. YunYingLogic.onCallBack(human, "onDecZuanshi",-d)
  483. return true
  484. end
  485. -- 钻石不足时候的处理
  486. function checkRMB(human, need)
  487. local sum = human.db.zuanshi
  488. if sum < need then
  489. if _G.is_middle == true then
  490. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  491. else
  492. if not SceneHandler.canCharge(human) then
  493. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  494. else
  495. local msgRet = Msg.gc.GC_BAG_NORMB
  496. Msg.send(msgRet,human.fd)
  497. end
  498. end
  499. return false
  500. else
  501. return true
  502. end
  503. end
  504. function updateFriendHeart(human, d, logType,item_id, num)
  505. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["friendheart"] then
  506. assert()
  507. end
  508. d = math.floor(d)
  509. if d == 0 then
  510. return
  511. end
  512. local val = human.db.friendHeart + d
  513. if val < 0 then
  514. assert()
  515. end
  516. --好友爱心使用日志
  517. if item_id == nil then item_id = 0 end
  518. if num == nil then num = 0 end
  519. 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)
  520. human.db.friendHeart = val
  521. if human.fd then
  522. human.attr[RoleDefine.FRIENDHEART] = human.db.friendHeart
  523. sendAttr(human,RoleDefine.FRIENDHEART)
  524. end
  525. return true
  526. end
  527. function sendHumanInfo(human,isNew)
  528. -- 处理称号被销毁的
  529. if human.db.chenghao then
  530. if not human.db.chenghaoList[human.db.chenghao] then
  531. human.db.chenghao = nil
  532. end
  533. end
  534. local subDay = CommonDB.getServerOpenDay()
  535. local mm = Msg.gc.GC_ZZ_HUMAN_INFO
  536. RoleLogic.getRoleBase(human, mm.roleBase)
  537. local union = UnionDBLogic.getUnion(human.db.unionUuid)
  538. mm.unionName = union and union.name or ""
  539. mm.unionIdentity = union and union.id or ""
  540. mm.bannerID = union and union.bannerID or 0
  541. mm.unionFrame = union and union.headFrame or 0
  542. mm.identity = human.db.identity
  543. mm.vipLv = VipLogic.getVipLv(human)
  544. mm.animation = human.db.animation or 0
  545. mm.background = human.db.background or 0
  546. mm.debug = Config.IS_USE_GM_CMD and 1 or 0
  547. mm.worldLv = GlobalWorld.getWorldLv()
  548. mm.openDay = subDay or 0
  549. mm.guideState= GuideLogic.checkAllFinish(human)
  550. mm.isFrist = isNew and 1 or 0
  551. for i = 1,#mm.warOrder do
  552. mm.warOrder[0] = i
  553. WarOrder.getWarOrderInfo(human,i,mm.warOrder[i] )
  554. end
  555. local drawCardRateList = {}
  556. -- if nil ~= DrawCardV2Excel then
  557. -- local drawCardV2Confs = DrawCardV2Excel
  558. -- local num = drawCardV2Confs and (#drawCardV2Confs) or 0
  559. -- for i = 0 , num do
  560. -- local drawCardV2Conf = drawCardV2Confs[i]
  561. -- drawCardRateList[i] = drawCardRateList[i] or {}
  562. -- for weightIndex = 1 , #drawCardV2Conf.weight do
  563. -- drawCardRateList[i][weightIndex] = drawCardRateList[i][weightIndex] or {}
  564. -- drawCardRateList[i][weightIndex] = drawCardV2Conf.weight[weightIndex][2]
  565. -- end
  566. -- end
  567. -- end
  568. mm.drawCardRateList = Json.Encode(drawCardRateList)
  569. mm.nSpeed[0] = 3
  570. mm.nSpeed[1] = 0
  571. mm.nSpeed[2] = 0
  572. mm.nSpeed[3] = 0
  573. if human.db.nSpeed then
  574. mm.nSpeed[1] = human.db.nSpeed[1] and human.db.nSpeed[1] or 0
  575. mm.nSpeed[2] = human.db.nSpeed[2] and human.db.nSpeed[2] or 0
  576. mm.nSpeed[3] = human.db.nSpeed[3] and human.db.nSpeed[3] or 0
  577. end
  578. mm.nServerIndex = Config.SVR_INDEX
  579. Msg.send(mm, human.fd)
  580. end
  581. function enterCity(human)
  582. Msg.send(Msg.gc.GC_ENTER_CITY, human.fd)
  583. end
  584. -- 上线回调
  585. function onLogin(human, isNew)
  586. human.db.ip = human.ip
  587. human.db.phpChanelID = human.phpChanelID
  588. if human.db.changeNameCnt ~= nil then
  589. Log.write(Log.LOGID_OSS_LOGIN, human.db._id, human.db.account, human.db.name, human.db.lv, human.db.ip)
  590. end
  591. updateDaily(human)
  592. if not FcmLogic.checkFcm(human) then
  593. return -- 防沉迷 踢下线
  594. end
  595. TequanLogic.jihuopt(human)
  596. TequanLogic.setHumanTequan(human,human.pf_info)
  597. doCalc(human)
  598. sendHumanInfo(human,isNew)
  599. BagLogic.sendBagList(human)
  600. FuwenLogic.sendFuwenBagList(human)
  601. EquipLogic.sendEquipBagList(human)
  602. HeroLogic.sendHeroBagCap(human)
  603. HeroLogic.sendHeroBagList(human)
  604. CombatPosLogic.onLogin(human)
  605. VipLogic.onLogin(human)
  606. FriendLogic.onLogin(human)
  607. DailyTaskLogic.onLogin(human)
  608. OnlineRewardLogic.onLogin(human)
  609. SettingLogic.query(human)
  610. ChatHandler.onLogin(human)
  611. BattleLogic.onLogin(human)
  612. ChatPaoMaLogic.onLogin(human)
  613. MailLogic.cleanNilContent(human)
  614. YunYingLogic.onLogin(human)
  615. RoleStrongLogic.onLogin(human)
  616. RelationGiftLogic.onLogin(human)
  617. ChatRecord.sendAllNotRead(human)
  618. JjcGodWarLogic.onLogin(human)
  619. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE1, 1)
  620. if not isNew then
  621. ReportManager.login(human)
  622. end
  623. LostTempleLogic.onLogin(human)
  624. HuanJingTowerLogic.onLogin(human)
  625. SettingLogic.onLogin(human)
  626. GuideLogic.onLogin(human)
  627. CombatLogic.onLogin(human) -- reyes test
  628. LianyuLogic.onLogin(human)
  629. MoshouLogic.onLogin(human)
  630. TopupLogic.checkKf(human)
  631. VoucherShopLogic.onLogin(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. -- 角色心跳
  713. function refresh()
  714. for _, human in pairs(onlineHuman) do
  715. --活动开启邮件提示
  716. RoleSystemLogic.checkMailTips(human)
  717. end
  718. end