ObjHuman.lua 28 KB

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