ObjHuman.lua 29 KB

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