ObjHuman.lua 28 KB

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