ObjHuman.lua 28 KB

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