ObjHuman.lua 29 KB

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