RoleDBLogic.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. ----------------------------------
  2. -- 角色DB相关逻辑
  3. -- isNameExistInDB 角色名是否存在
  4. -- getDb 根据uuid取角色信息(优先取内存)
  5. -- getDbByName 根据名字取角色信息(优先取内存)
  6. -- getDbByAccount 根据账号取角色信息(优先取内存)
  7. -- loadRole 根据账号取db
  8. -- saveRole 保存角色整个db
  9. -- saveRoleSset 仅对角色db某些字段进行修改
  10. -- createDefaultRole 初始化角色db信息
  11. ----------------------------------
  12. local LuaMongo = _G.lua_mongo
  13. local Config = require("Config")
  14. local DB = require("common.DB")
  15. local ObjHuman = require("core.ObjHuman")
  16. local HeroDefine = require("hero.HeroDefine")
  17. local CreateRole = require("role.CreateRole")
  18. local CombatDefine = require("combat.CombatDefine")
  19. local RoleLogic = require("role.RoleLogic")
  20. local RoleHeadLogic = require("role.RoleHeadLogic")
  21. local Util = require("common.Util")
  22. local QueryByAccount = {} --按帐号查询
  23. local QueryByName = {} --按角色名查询
  24. local QueryByUuid = {} --按uuid查询
  25. local QueryByIdentity = {} --按identity查询
  26. local QueryUpdateChar = {}
  27. local QueryByNewUniqueTag = {} --根据新的唯一标识查询
  28. local FieldName = {name = 1}
  29. local FieldAccount = {account = 1}
  30. local FieldNewUniqueTag = {newUniqueTag = 1}
  31. local tempData = {}
  32. --木子渠道ID, 特殊处理下老账号
  33. local MUZI_CHANNEL_ID = 2
  34. --功夫熊猫渠道ID, 特殊处理下老账号
  35. local GONGFUXIONGMAOCHANNEL_ID = 3
  36. function Generateuuid(channelID, account, serverTag)
  37. if not channelID or not account or not serverTag then
  38. assert(false, string.format("data Error! channelID: %s, account:%s, svrIndex:%s", channelID, account, serverTag))
  39. end
  40. return string.format("%s|%s|%s", channelID, serverTag, account)
  41. end
  42. function isNameExistInDB(name)
  43. QueryByName.name = name
  44. tempData.name = nil
  45. LuaMongo.find(DB.db_char, QueryByName, FieldName)
  46. return LuaMongo.next(tempData) and tempData
  47. end
  48. -- function isAccountExistInDB(account)
  49. -- QueryByAccount.account = account
  50. -- tempData.account = nil
  51. -- LuaMongo.find(DB.db_char, QueryByAccount, FieldAccount)
  52. -- return LuaMongo.next(tempData) and tempData
  53. -- end
  54. function isNewUniqueTagExistInDB(channelID, account, serverTag)
  55. QueryByNewUniqueTag.newUniqueTag = Generateuuid(channelID, account, serverTag)
  56. tempData.newUniqueTag = nil
  57. LuaMongo.find(DB.db_char, QueryByNewUniqueTag, FieldNewUniqueTag)
  58. return LuaMongo.next(tempData) and tempData
  59. end
  60. --没有用到的地方
  61. -- function isUuidExistInDB(uuid)
  62. -- QueryByUuid._id = uuid
  63. -- tempData.newUniqueTag = nil
  64. -- LuaMongo.find(DB.db_char, QueryByUuid, FieldAccount)
  65. -- return LuaMongo.next(tempData) and tempData
  66. -- end
  67. local f = {}
  68. function getDb(uuid, fields)
  69. local t = ObjHuman.onlineUuid[uuid]
  70. if t then
  71. return t.db, t.fd ~= nil
  72. end
  73. QueryByUuid._id = uuid
  74. local data = {}
  75. if type(fields) == "string" then
  76. local k = next(f)
  77. if k then f[k] = nil end
  78. f[fields] = 1
  79. fields = f
  80. end
  81. LuaMongo.find(DB.db_char, QueryByUuid, fields)
  82. return LuaMongo.next(data) and data, nil
  83. end
  84. function getDbByName(name, fields)
  85. if not name then
  86. assert()
  87. end
  88. local t = ObjHuman.onlineHuman[name]
  89. if t then
  90. return t.db, t.fd ~= nil
  91. end
  92. QueryByName.name = name
  93. local data = {}
  94. if type(fields) == "string" then
  95. local k = next(f)
  96. if k then f[k] = nil end
  97. f[fields] = 1
  98. fields = f
  99. end
  100. LuaMongo.find(DB.db_char, QueryByName, fields)
  101. return LuaMongo.next(data) and data, nil
  102. end
  103. function getDbByNameRegex(name, fields)
  104. QueryByName.name = {["$regex"] = name}
  105. local data = {}
  106. if type(fields) == "string" then
  107. local k = next(f)
  108. if k then f[k] = nil end
  109. f[fields] = 1
  110. fields = f
  111. end
  112. RoleLogic.makeRoleBaseFields(fields)
  113. LuaMongo.find(DB.db_char, QueryByName, fields,50)
  114. local userList = {}
  115. local len = 0
  116. while true do
  117. local data = {}
  118. if not LuaMongo.next(data) then
  119. break
  120. end
  121. len = len + 1
  122. userList[len] = {}
  123. userList[len].name = data.name
  124. userList[len].uuid = data._id
  125. userList[len].account = data.account
  126. userList[len].identity = data.identity
  127. userList[len].lv = data.lv
  128. userList[len].head = data.head
  129. userList[len].headFrame = data.headFrame
  130. userList[len].unionUuid = data.unionUuid
  131. userList[len].blue = data.blue
  132. userList[len].yellow = data.yellow
  133. userList[len].zhandouli = data.zhandouli
  134. end
  135. return userList,#userList
  136. end
  137. --弃用
  138. function getDbByAccount(account, fields)
  139. do return end --直接返回
  140. local t = ObjHuman.onlineAccount[account]
  141. if t then
  142. return t.db, t.fd ~= nil
  143. end
  144. QueryByAccount.account = account
  145. local data = {}
  146. if type(fields) == "string" then
  147. local k = next(f)
  148. if k then f[k] = nil end
  149. f[fields] = 1
  150. fields = f
  151. end
  152. LuaMongo.find(DB.db_char, QueryByAccount, fields)
  153. return LuaMongo.next(data) and data, nil
  154. end
  155. -- function loadRole(account)
  156. -- QueryByAccount.account = account
  157. -- local data = {}
  158. -- LuaMongo.find(DB.db_char, QueryByAccount)
  159. -- if LuaMongo.next(data) then
  160. -- return data
  161. -- end
  162. -- end
  163. --根据渠道标识, account, 区服标识组成的 唯一值来读取
  164. function loadRole(newUniqueTag)
  165. QueryByNewUniqueTag.newUniqueTag = newUniqueTag
  166. local data = {}
  167. LuaMongo.find(DB.db_char, QueryByNewUniqueTag)
  168. if LuaMongo.next(data) then
  169. return data
  170. end
  171. end
  172. function getDbByIdentity(identity,fields)
  173. QueryByIdentity.identity = identity
  174. local data = {}
  175. if type(fields) == "string" then
  176. local k = next(f)
  177. if k then f[k] = nil end
  178. f[fields] = 1
  179. fields = f
  180. end
  181. LuaMongo.find(DB.db_char, QueryByIdentity, fields)
  182. return LuaMongo.next(data) and data, nil
  183. end
  184. function saveRole(db)
  185. QueryUpdateChar._id = db._id
  186. LuaMongo.update(DB.db_char, QueryUpdateChar, db)
  187. end
  188. local tempTb = {}
  189. function saveRoleSset(db, sunset)
  190. QueryUpdateChar._id = db._id
  191. db._id = nil
  192. tempTb["$set"] = db
  193. tempTb["$unset"] = sunset
  194. LuaMongo.update(DB.db_char, QueryUpdateChar, tempTb)
  195. db._id = QueryUpdateChar._id
  196. end
  197. -------------------- humandb 初始化 start ----------------------
  198. function createDefaultRole(channelID, account, serverTag)
  199. local db = {
  200. svrIndex = Config.SVR_INDEX,
  201. newUniqueTag = Generateuuid(channelID, account, serverTag),
  202. identity = nil, -- 11位全局不重复的数字id
  203. account = account, -- 帐号名
  204. name = nil, -- 角色名
  205. changeNameCnt = nil, -- 修改名字次数
  206. changeBase = nil, -- 修改基础信息次数
  207. birthDay = nil, -- 生日
  208. signature = nil, -- 个性签名
  209. lv = 1, -- 等级
  210. exp = 0,
  211. zuanshi = 0, -- 钻石
  212. jinbi = 0, -- 金币
  213. createTime = nil, -- 角色创建时间
  214. lastLoginTime = nil, -- 上一次登录时间
  215. lastLogoutTime = nil, -- 最近登出时间
  216. update_daily_time = nil, -- 每天更新时间
  217. onlineTime = nil, -- 在线时长
  218. onlineTimeDay = nil, -- 本日在线时长
  219. onlineTimeDayReport = nil,
  220. heroBag = {[0] = HeroDefine.HERO_BAG_CNT}, -- 英雄背包[index] ={id,lv等级,quality品阶}
  221. heroLevelUpgrade = 0, -- 英雄手动升级最大值
  222. bag = {}, -- 道具背包 {itemID->itemCnt}
  223. fuwenBag = {}, -- 符文背包 [index] = {id, 属性, 技能}
  224. equipBag = {}, -- 装备背包 [index] = {id, 属性, 技能}
  225. combatHero = {}, -- 出战英雄[type] = {[pos] = uuid}
  226. buyCapCnt = nil, -- 购买背包容量次数
  227. heroBook = nil, -- 获得过的图鉴英雄[id]= true
  228. shop = nil, -- 商店购买物品次数记录 shop[shopType][itemID] = cnt
  229. battleGameTimes = nil, -- 普通闯关的获得的游戏次数
  230. eliteBattleGameTimes = nil, -- 精英闯关的获得的游戏次数
  231. hardBattleGameTimes = nil, -- 困难闯关的获得的游戏次数
  232. normalBattleAttrData = nil, -- 普通闯关的属性数据
  233. eliteBattleAttrData = nil, -- 精英闯关的属性数据
  234. hardBattleAttrData = nil, -- 困难闯关的属性数据
  235. battleType = 1, -- 战役类型(1、普通,2、精英,3、困难)
  236. maxBattleTime = nil, -- 最新关卡通关时间
  237. guajiID = 0, -- 已通关关卡/挂机关卡
  238. guajiID_elite = 0, -- 精英- 已通关关卡/挂机关卡
  239. guajiID_hard = 0, -- 困难- 已通关关卡/挂机关卡
  240. battleID = 1, -- 战役即将战斗id
  241. battleID_elite = 1, -- 精英-战役即将战斗id
  242. battleID_hard = 1, -- 困难-战役即将战斗id
  243. battleHis = nil, -- 战役历史记录(用于新手任务第五关特殊处理)
  244. battleRewards = nil, -- 征战奖励领取记录
  245. battleRewards_elite = nil, -- 精英征战奖励领取记录
  246. battleRewards_hard = nil, -- 困难征战奖励领取记录
  247. battleOut = nil, -- 挂机收益{expTs1--经验开始产出时间戳,expTs2--经验产出结算时间戳,itemTs1--道具产出时间戳,itemTs2--道具产出结算时间戳,exp,jinbi,greenExp,items,itemsHalf}
  248. battleadopt = 0, -- 普通战役是否通关
  249. battleadopt_elite = 0, -- 精英战役是否通关
  250. battleadopt_haed = 0, -- 困难战役是否通关
  251. copy = nil, -- 活动副本 [1] ={cnt今日已挑战次数,buyCnt已购买次数}
  252. dailyTask = nil, -- 每日任务
  253. weekTask = nil, -- 每周任务
  254. bar = nil, -- [taskID] = {isLock是否锁定, star任务星级, nameID阿辛多, actionID委托, itemID, itemCnt, ts开始做任务时间戳, hero={index}上阵英雄, camp = {1,2}任务要求, job = {1}任务要求}
  255. zhuanpan = nil, -- [type] = {ts1[强制刷新时间戳],ts2[免费刷新时间戳],[1] = {id抽奖id, itemID奖品ID,itemCnt奖品数量,getCnt = nil抽到次数[该抽奖有次数限制才记录]
  256. tower = nil, -- 幻境之塔{当前关卡lv, 恢复时间ts, 当前体力值tili}
  257. drawCard = {jifen=0,list={[1]={},[2]={},[3]={},[4]={},[8]={}}},--召唤法阵
  258. combatSpeed = nil, -- 战斗速度
  259. jinbiExchange = nil, -- {[1][2][3]对应档位是否领取 ts刷新时间戳}
  260. vipLv = nil, -- vip等级
  261. vipExp = nil, -- vip经验(注意这个经验是累计的 升级不会清0)
  262. vipLibao = nil, -- vip礼包标识
  263. vipYueka = nil, -- vip月卡额外奖励
  264. jjcBestRank = nil, -- 个人竞技场最佳排名
  265. jjcDailyFight = nil, -- 个人竞技场每日战斗次数
  266. chengjiu = {}, -- 成就
  267. onlineReward = nil, -- 在线奖励 {id, ts}
  268. combatQuick = {}, -- 快速战斗
  269. systemSet = nil, -- 系统设置 位与操作 第4位 不展示vip 第5位 屏蔽私聊
  270. chatBan = nil, -- 屏蔽聊天的玩家
  271. actMonthEndTime = nil, -- 月度活动结束时间
  272. actMonthTask = nil, -- 月度活动进度
  273. -- jifen hzz竞技积分 trial hzz皇家试炼积分 buyNum 破碎徽章购买 drunkery = {[id] = num} 酒馆活动 hecheng={[id] = num}
  274. fundFlag = nil, -- 钻石基金标志 nil未购买 1已购买未领完 2已购买已领完
  275. friendHeart = 0, -- 友情值
  276. sendHeart = nil, -- 每日赠送红心好友列表{uuid->1}
  277. getHeartCnt = nil, -- 每日领取红心次数
  278. sendHeartCnt = nil, -- 每日赠送红心次数
  279. friendBlack = nil, -- 黑名单
  280. buy = {}, -- 购买记录
  281. absAct = {}, -- 绝对时间活动数据
  282. loginGiveTime = nil, -- 登录赠送 (限时活动) 记录获得赠送时间
  283. signInCnt = nil, -- 登陆奖励次数
  284. signIn = nil, -- 登陆奖励状态,0 未登录,1,已登录未领取,2已登录已领取
  285. signInTime = nil, -- 登陆时间,用于判断是否是同一天登陆
  286. unionUuid = nil, -- 工会标志 如果玩家不属于任何工会,unionUuid为nil,否则unionUuid为工会唯一id
  287. ectypeCnt = nil, -- 公会副本每日通关次数
  288. ectypeLike = nil , -- 公会副本点赞次数
  289. ectypLikeUuid = nil, -- 公会副本点赞人
  290. ectypHurt = nil, -- 公会副本每日伤害记录
  291. combatVideos = nil, -- 战斗记录列表
  292. technology = nil, -- 公会科技信息
  293. ip = nil, -- 登录IP
  294. killEctype = nil, -- 参与击杀Boss等级
  295. phpChanelID = nil, -- 渠道导入id
  296. dailyShareTask = nil, -- 每日公共任务
  297. openServerGift = nil, -- 开服有礼
  298. mopupDoCnt = nil, -- 战役已扫荡次数
  299. mopupFreeCnt = nil, -- 战役已免费扫荡次数
  300. mopupAddFreeCnt = nil, -- 战役额外增加扫荡次数
  301. topupAcount = nil, -- 玩家充值总额
  302. topupAcountDaily = nil, -- 玩家每日充值总额
  303. topupAccountMonth = nil, -- 玩家每月充值总额
  304. firstCharge = nil, -- 超值首充 6元 100元
  305. newFirstCharge = nil, -- 新首充
  306. godDailyTopup = nil, -- 成神之路每日礼包
  307. kingworld = nil, -- 国王君临
  308. superFund = nil, -- 超值基金 大小基金 [type] = {}
  309. sex = 1, -- 性别 1男2女
  310. head = RoleHeadLogic.DEFAULT_HEAD_MALE_ID, -- 头像
  311. headList = nil, -- 已激活头像列表(除默认赠送外)
  312. headFrame = RoleHeadLogic.DEFAULT_HEADFREAM_ID, -- 头像框
  313. headFrameList = nil, -- 已激活头像框列表(除默认赠送外)
  314. body = nil, -- 形象
  315. bodyList = nil, -- 已激活形象
  316. chenghao = nil, -- 称号
  317. chenghaoList = nil, -- 已激活称号
  318. headHasNewFlag = nil, -- 头像1/头像框2/形象4/称号8有新的flag
  319. animation = nil, -- 立绘
  320. animationList = nil, -- 已激活的立绘列表
  321. background = RoleHeadLogic.DEFAULT_BACKGROUND_ID, -- 背景
  322. backgroundList = nil, -- 已激活的背景列表
  323. throneTime = nil, -- 挑战失败记录时间
  324. banSay = nil, -- 被举报
  325. yellow = nil, -- 黄钻贵族
  326. blue = nil, -- 蓝钻贵族
  327. txHall = nil, -- 腾讯大厅
  328. qqZone = nil, -- QQ空间
  329. qqBigShot = nil, -- QQ大咖
  330. fuwenRefreshCnt = nil, -- 符文刷新次数
  331. helpCnt = nil, -- 公会秘境助战次数
  332. personMail = nil, -- 私人郵件次數
  333. skinBag = {[0] = HeroDefine.HERO_SKIN_CNT},
  334. mailtips = {}, -- 邮件提醒
  335. skinLog = {}, --皮肤获取记录
  336. lookGl = nil, -- 是否看过攻略
  337. tujianCP = nil, -- 图鉴CP
  338. personalrecord = nil, -- 炼狱个人记录
  339. middleFlag = nil, -- 跨服游戏中
  340. middleOptions = nil, -- 跨服操作事件
  341. leichongHaoli = nil, -- 累充好礼
  342. dailyLeiChong = nil, -- 每日累充 奖励发放 dailyLeiChong[1] = true
  343. battleExtraReward = nil, -- 征战关卡额外奖励
  344. plShare = nil, -- 微信小程序分享
  345. tuiSongLiBao = nil, -- 推送礼包
  346. heroResetCnt = nil, -- 英雄每日重置次数
  347. moshou = nil, -- 魔兽
  348. equipLogs = nil, -- 装备合成日志
  349. jjcGodWar = nil, -- 众神之战
  350. unionLive = nil, -- 公会活跃
  351. moShouPingFen = nil, -- 魔兽评分
  352. unionDonate = nil, -- 公会捐献
  353. dailyBanggong = nil, -- 每日帮贡
  354. totalBanggong = nil, -- 总帮贡
  355. donateReward = nil, -- 公会捐献达标奖励
  356. combatBackup = nil, -- 援军激活条件
  357. liLian = nil, -- 历练
  358. billboard = nil, -- 排行榜-上榜时间
  359. billboardAim = nil, -- 排行榜-进度奖励
  360. lianyu = nil, -- 绝望深渊
  361. lianyuCache = nil, -- 绝望深渊战斗信息
  362. battleVideoUuid = nil, -- 战役挂机Uuid
  363. chatRead = nil, -- 聊天记录阅读到第几条
  364. dailyLibao = nil, -- 充值-每日礼包
  365. richangLibao = nil, -- 充值-每周/每月礼包
  366. tequanShop = nil, -- 充值-特权商店
  367. tequanMopup = nil, -- 扫荡特权 截止时间
  368. weekendFuli = nil, -- 周末福利
  369. unionWar = nil, -- 玩家 公会战 相关数据
  370. jjcLadder = nil, -- 天梯争霸 相关数据
  371. valleyTask = nil, -- 荣耀峡谷(龙族战场)目标
  372. jjcNewestRecord = nil, -- 个人竞技场最新战斗记录时间
  373. jjcWorship = nil, -- 个人竞技场每日膜拜
  374. jjcBeWorship = nil, -- 个人竞技场总被膜拜次数
  375. relationKey = nil, -- 推广码
  376. relationBind= {}, -- 推广关系
  377. relationId = nil, -- 推广人
  378. relationRew = {}, -- 奖励领取状态
  379. warReport = {}, -- 战报收藏列表
  380. warAdmire = nil, -- 战报点赞
  381. drill = nil, -- 勇者试炼
  382. welfareGift = {}, -- 超值礼包
  383. redBagCnt = nil, -- 公会红包次数
  384. monthCard = nil, -- 贵族月卡,王者月卡
  385. limitBuy = nil, -- 限时抢购
  386. leijiChongzhi = nil, -- 累计充值
  387. giftPack = nil, -- 成长礼包
  388. heroRise = nil, -- 英雄崛起
  389. leaveUnionLimit = nil, -- 离开公会后,加入或创建公会时间限制
  390. roleDot = nil, -- 红点
  391. chongJi = nil, -- 创角冲级活动
  392. cdkFix = nil, -- 固定兑换码
  393. cdk = {},
  394. roleSys = nil, -- 系统开放标识
  395. roleSysOpen = nil, -- 系统点击标识
  396. xingYaoGongMing = nil, -- 星耀之门-星耀共鸣
  397. guide = nil, -- 指引
  398. lvGuide = nil, -- 等级指引
  399. sendPfEmail = nil, --开服邮件
  400. limitMangHe = nil, -- 开服 -限时幸运盲盒
  401. fpsTb = nil, -- fps信息
  402. systemSound = nil, -- 系统设置
  403. relic = {}, -- 圣器
  404. adRewardCnt = nil , --每日广告观看次数
  405. adHatchRewardCnt = nil , --每日广告观看加速孵化次数
  406. isTip = nil , --钻石加速孵化今日是否提示
  407. nWeekLoopEndTime = nil, -- 周循环活动结束时间戳
  408. nWeekLoopEndMail = nil, -- 周循环活动结束处理奖励标识
  409. nWeekHeroID = nil, -- 周活动-升星英雄ID
  410. tWeekHeroPrize = nil, -- 周活动-升星奖励信息
  411. nWeekUseGuYu = nil, -- 周活动消耗古玉数量
  412. tWeekGuYuPrize = nil, -- 周活动-古玉奖励信息
  413. nWeekCardType = nil, -- 周活动-抽卡当前类型
  414. nWeekCardNum = nil, -- 周活动-抽卡数量
  415. tWeekCardPrize = nil, -- 周活动-抽卡奖励信息
  416. realmLv = nil, --境界
  417. RacialTrial = nil, --种族试炼
  418. nFirstBuy = nil, --第一次购买
  419. talismanData = nil, --秘宝
  420. OnlineRewardData = nil, --在线奖励
  421. nSpeed = nil, -- 特权战斗速度
  422. tBuyVoucherInflate = nil, -- 代金券 - 膨胀记录(nStatus = 0,nil 未购买,1已购买, nTime = 购买时间)
  423. relicListData = {}, -- {圣者遗物}
  424. HonorJourney = {}, -- {荣耀历程}
  425. mergeInfo = {}, --融合信息 {mergeStartTime: 0 , mergeTime: 0, mergeEndTime: 0, heroId: 0}
  426. gift = {
  427. unlock = {},
  428. online = {}
  429. }, -- 弹窗礼包
  430. warOrder = { -- 战令相关
  431. battleOrder = {
  432. exp = 0,
  433. finish = {},
  434. unlock = 0,
  435. upgradeFinish = {}
  436. },
  437. devilOrder = {
  438. exp = 0,
  439. finish = {},
  440. unlock = 0,
  441. upgradeFinish = {}
  442. },
  443. clanOrder = {
  444. exp = 0,
  445. finish = {},
  446. unlock = 0,
  447. upgradeFinish = {}
  448. },
  449. arenaOrder = {
  450. exp = 0,
  451. finish = {},
  452. unlock = 0,
  453. upgradeFinish = {}
  454. },
  455. tiantiOrder = {
  456. exp = 0,
  457. finish = {},
  458. unlock = 0,
  459. upgradeFinish = {}
  460. },
  461. },
  462. -- 注意 以后再加字段如初始化为非nil 要在下面的newAddDBData同步加,否则老号会报错。
  463. }
  464. db.createTime = os.time()
  465. LuaMongo.insert(DB.db_char, db)
  466. return db
  467. end
  468. local newAddDBData = {
  469. heroLevelUpgrade = 0, -- 英雄手动升级最大值
  470. gift = {
  471. unlock = {},
  472. online = {}
  473. }, -- 弹窗礼包
  474. warOrder = {
  475. battleOrder = {
  476. exp = 0,
  477. finish = {},
  478. unlock = 0,
  479. upgradeFinish = {}
  480. },
  481. devilOrder = {
  482. exp = 0,
  483. finish = {},
  484. unlock = 0,
  485. upgradeFinish = {}
  486. },
  487. clanOrder = {
  488. exp = 0,
  489. finish = {},
  490. unlock = 0,
  491. upgradeFinish = {}
  492. },
  493. arenaOrder = {
  494. exp = 0,
  495. finish = {},
  496. unlock = 0,
  497. upgradeFinish = {}
  498. },
  499. tiantiOrder = {
  500. exp = 0,
  501. finish = {},
  502. unlock = 0,
  503. upgradeFinish = {}
  504. },
  505. }, -- 战令相关
  506. adRewardCnt = nil,
  507. adHatchRewardCnt = nil,
  508. mergeInfo = {},
  509. cdk = {},
  510. isTip = nil,
  511. battleType = 1, -- 战役类型(1、普通,2、精英,3、困难)
  512. guajiID_elite = 0, -- 精英- 已通关关卡/挂机关卡
  513. guajiID_hard = 0, -- 困难- 已通关关卡/挂机关卡
  514. battleID_elite = 1, -- 精英-战役即将战斗id
  515. battleID_hard = 1, -- 困难-战役即将战斗id
  516. battleRewards_elite = nil, -- 精英征战奖励领取记录
  517. battleRewards_hard = nil, -- 困难征战奖励领取记录
  518. battleadopt = 0, -- 普通战役是否通关
  519. battleadopt_elite = 0, -- 精英战役是否通关
  520. battleadopt_haed = 0, -- 困难战役是否通关
  521. }
  522. local roleDBchanged
  523. local function handleNew(orgDB, newTable)
  524. for k, v in pairs(newTable) do
  525. if not orgDB[k] then
  526. orgDB[k] = v
  527. roleDBchanged = true
  528. elseif type(v) == "table" then
  529. handleNew(orgDB[k],v)
  530. end
  531. end
  532. end
  533. function roleDBInit()
  534. _G.collectgarbage("step", 1000000)
  535. LuaMongo.find(DB.db_char)
  536. local list = {}
  537. local all = 0
  538. while true do
  539. local data = {}
  540. if not LuaMongo.next(data) then
  541. break
  542. end
  543. all = all + 1
  544. roleDBchanged = nil
  545. handleNew(data, newAddDBData)
  546. if roleDBchanged then
  547. list[#list + 1] = data._id
  548. end
  549. end
  550. print(#list, "/", all)
  551. _G.collectgarbage("step", 1000000)
  552. local query = {}
  553. for _, v in ipairs(list) do
  554. query._id = v
  555. LuaMongo.find(DB.db_char, query)
  556. local data = {}
  557. if not LuaMongo.next(data) then
  558. assert()
  559. end
  560. roleDBchanged = nil
  561. handleNew(data, newAddDBData)
  562. if not roleDBchanged then
  563. assert()
  564. end
  565. LuaMongo.update(DB.db_char, query, data)
  566. end
  567. end
  568. -------------------- humandb 初始化 end ----------------------