ObjHuman.lua 29 KB

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