RoleLogic.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. -- 玩家 功能函数模块
  2. local Config = require("Config")
  3. local Json = require("common.Json")
  4. local Msg = require("core.Msg")
  5. local MonsterExcel = require("excel.monster")
  6. local ObjHuman = require("core.ObjHuman")
  7. local CombatPosLogic = require("combat.CombatPosLogic")
  8. local CombatLogic = require("combat.CombatLogic")
  9. local CombatDefine = require("combat.CombatDefine")
  10. local JjcDB = require("jjc.JjcDB")
  11. local HeroGrid = require("hero.HeroGrid")
  12. local RoleDefine = require("role.RoleDefine")
  13. local RoleDBLogic = require("role.RoleDBLogic")
  14. local UnionDBLogic = require("union.UnionDBLogic")
  15. local MoshouLogic = require("moshou.MoshouLogic")
  16. local SettingLogic = require("setting.SettingLogic")
  17. local RoleExcel = require("excel.role")
  18. local Lang = require("common.Lang")
  19. local Util = require("common.Util")
  20. local FriendDBLogic = require("friend.FriendDBLogic")
  21. local HeroLogic = require("hero.HeroLogic")
  22. local UnionLogic = require("union.UnionLogic")
  23. local RoleHeadLogic = require("role.RoleHeadLogic")
  24. local UnionExcel = require("excel.union")
  25. local FilterUtil = require("common.FilterUtil")
  26. local Broadcast = require("broadcast.Broadcast")
  27. local RoleRealmLogic = require("roleSystem.RoleRealmLogic")
  28. local Timer = require("core.Timer")
  29. FieldRoleBase = {identity=1, name=1, lv=1, vipLv=1, systemSet=1, head=1, headFrame=1, body=1, chenghao=1, unionUuid=1, zhandouli=1, blue=1, yellow=1,birthday = 1,sex = 1,signature = 1}
  30. local FAKE_HUMAN = {db = nil}
  31. BIRTHDAY_TYPE = 1
  32. SEX_TYPE = 2
  33. SIGNATURE_TYPE = 4
  34. function makeRoleBaseFields(fields)
  35. fields._id = "1"
  36. for key in pairs(FieldRoleBase) do
  37. fields[key] = 1
  38. end
  39. end
  40. local TEMP_COMBAT_FIELD = nil
  41. function getCombatField()
  42. if not TEMP_COMBAT_FIELD then
  43. TEMP_COMBAT_FIELD = {}
  44. for k in pairs(CombatLogic.FieldsCombat) do
  45. TEMP_COMBAT_FIELD[k] = 1
  46. end
  47. makeRoleBaseFields(TEMP_COMBAT_FIELD)
  48. end
  49. return TEMP_COMBAT_FIELD
  50. end
  51. -- 删除多余的数据
  52. function clear2MinNet(db, net)
  53. for key in pairs(FieldRoleBase) do
  54. if net[key] and (not db or not db[key]) then
  55. net[key] = nil
  56. end
  57. end
  58. end
  59. -- 构造rolebase 结构体
  60. function getRoleBase(human, net, combatType, isMinNet)
  61. local db = human and human.db
  62. net.uuid = db and (db._id or db.uuid) or ""
  63. net.name = tostring(db and db.name or "")
  64. net.lv = db and db.lv or 0
  65. net.identity = db and db.identity or ""
  66. net.head = db and db.head or 0
  67. net.headFrame = db and db.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  68. net.body = db and db.body or 0
  69. net.createTime = db and db.createTime or 0
  70. if db and db.signIn then
  71. net.signInCnt = (db.signIn.cnt or 0) + 1
  72. else
  73. net.signInCnt = 1
  74. end
  75. net.birthday = net.birthday or {}
  76. net.birthday.year = (db and db.birthDay) and db.birthDay.year or 1970
  77. net.birthday.month = (db and db.birthDay) and db.birthDay.month or 1
  78. net.birthday.day = (db and db.birthDay) and db.birthDay.day or 1
  79. net.sex = db and db.sex or 1
  80. net.signature = db and db.signature or ""
  81. net.chenghaoID = db and db.chenghao or 0
  82. net.chenghaoName = ""
  83. if db and db.chenghao and RoleExcel.chenghao[db.chenghao] then
  84. net.chenghaoName = RoleExcel.chenghao[db.chenghao].name
  85. end
  86. net.unionUuid = db and db.unionUuid or ""
  87. net.bannerID = getUnionBannerID(db)
  88. net.zhandouli = db and db.zhandouli or 0
  89. net.serverName = Config.SVR_NAME
  90. if combatType and db and db.combatHero then
  91. net.zhandouli = CombatPosLogic.getCombatHeroZDL(human, combatType)
  92. end
  93. net.blue = net.blue or {}
  94. net.blue.lv = (db and db.blue) and db.blue.lv or 0
  95. net.blue.year = (db and db.blue and db.blue.year) and 1 or 0
  96. net.blue.lux = (db and db.blue and db.blue.lux) and 1 or 0
  97. net.yellow = net.yellow or {}
  98. net.yellow.lv = (db and db.yellow) and db.yellow.lv or 0
  99. net.yellow.year = (db and db.yellow and db.yellow.year) and 1 or 0
  100. net.yellow.lux = (db and db.yellow and db.yellow.lux) and 1 or 0
  101. net.realmName = RoleRealmLogic.getRealmName(human)
  102. net.nServerIndex = Config.SVR_INDEX
  103. if isMinNet then
  104. clear2MinNet(db, net)
  105. end
  106. return (db ~= nil)
  107. end
  108. function getRoleBaseByUuid(uuid, net, combatType, isMinNet)
  109. FAKE_HUMAN.db = nil
  110. if uuid and uuid ~= "" then
  111. local fields = getCombatField()
  112. FAKE_HUMAN.db = RoleDBLogic.getDb(uuid, fields)
  113. end
  114. return getRoleBase(FAKE_HUMAN, net, combatType, isMinNet), FAKE_HUMAN
  115. end
  116. function makeRoleBase(data, net, combatType, isMinNet)
  117. FAKE_HUMAN.db = data
  118. return getRoleBase(FAKE_HUMAN, net, combatType, isMinNet)
  119. end
  120. function makePlayInfo(net, uuid, nCombatType)
  121. if not uuid or uuid == "" then return end
  122. net.yjUuid = ""
  123. local fields = getCombatField()
  124. local db = RoleDBLogic.getDb(uuid, fields)
  125. if not db then
  126. return makePlayInfoByOther(net, uuid) -- 假人
  127. end
  128. FAKE_HUMAN.db = db
  129. -- 真人
  130. local combatType = nCombatType or CombatDefine.COMBAT_TYPE1
  131. local combatHero = CombatPosLogic.getCombatHeros(FAKE_HUMAN, combatType)
  132. if nil == _G.next(combatHero) then
  133. print("'[makePlayInfo] 获取不到对应的英雄数据, 取默认阵容 combatType = "..combatType)
  134. combatHero = CombatPosLogic.getCombatHeros(FAKE_HUMAN, CombatDefine.COMBAT_TYPE1)
  135. end
  136. local union = UnionDBLogic.getUnion(db.unionUuid)
  137. getRoleBase(FAKE_HUMAN, net.roleBase,combatType)
  138. net.moshouBody = MoshouLogic.getCombatMoshouBody(FAKE_HUMAN,combatType)
  139. net.defenceList[0] = 0
  140. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  141. local uuid = combatHero and combatHero[i]
  142. local heroGrid = HeroLogic.getHeroGridByUuid(FAKE_HUMAN, uuid)
  143. if heroGrid then
  144. net.defenceList[0] = net.defenceList[0] + 1
  145. local defenceNet = net.defenceList[net.defenceList[0]]
  146. HeroGrid.makeHeroSimple(defenceNet, heroGrid, heroGrid.bagIndex, FAKE_HUMAN)
  147. if i == CombatDefine.COMBAT_HERO_CNT then
  148. net.yjUuid = uuid
  149. end
  150. end
  151. end
  152. net.vipLv = db.vipLv or 0
  153. -- vip 大于14 不管是否屏蔽 客户端都显示 王者VIP
  154. if SettingLogic.isNoShowVip(FAKE_HUMAN) == true and net.vipLv ~= 0 and net.vipLv < 14 then
  155. net.vipLv = -1
  156. end
  157. net.unionName = union and union.name or ""
  158. net.svrName = Config.SVR_NAME
  159. net.isFriend = 0
  160. if FriendDBLogic.isBlackFriend(FAKE_HUMAN.db._id,uuid) then
  161. net.isFriend = 2
  162. elseif FriendDBLogic.isFriend(FAKE_HUMAN.db._id,uuid) then
  163. net.isFriend = 1
  164. end
  165. return true
  166. end
  167. -- 获取玩家公会旗帜
  168. function getUnionBannerID(db)
  169. if db then
  170. local union = UnionDBLogic.getUnion(db.unionUuid)
  171. if union then
  172. return union.bannerID
  173. end
  174. end
  175. return 0
  176. end
  177. function makeOtherPlayInfo(net,jjcData)
  178. if not jjcData then return end
  179. local monsterOutID = jjcData.monsterOutID
  180. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  181. FAKE_HUMAN.db = jjcData
  182. getRoleBase(FAKE_HUMAN, net.roleBase)
  183. if net.moshouBody then
  184. net.moshouBody = 0
  185. end
  186. net.defenceList[0] = 0
  187. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  188. local monsterConfig = monsterOutConfig.member[i]
  189. local monsterID = monsterConfig and monsterConfig[1]
  190. if monsterID and monsterID > 0 then
  191. local monsterLv = monsterConfig and monsterConfig[2]
  192. local others = HeroGrid.createOthers(monsterLv)
  193. net.defenceList[0] = net.defenceList[0] + 1
  194. local defenceNet = net.defenceList[net.defenceList[0]]
  195. HeroGrid.makeHeroSimpleByMonsterID(defenceNet, monsterID, others)
  196. net.defenceList[i].index = i
  197. end
  198. end
  199. end
  200. function makePlayInfoByOther(net, uuid)
  201. local jjcData = JjcDB.getJjcData(uuid)
  202. if not jjcData then return end
  203. makeOtherPlayInfo(net,jjcData)
  204. net.vipLv = 0
  205. net.isFriend = 0
  206. net.unionName = ""
  207. net.svrName = Config.SVR_NAME
  208. return true
  209. end
  210. CHANGE_BASEINFO_FAIL = 0
  211. CHANGE_BASEINFO_SUCCESS = 1
  212. -- 更改基础信息查询
  213. function changeBaseInfoQuery(human,type)
  214. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO_QUERY
  215. msgRet.price = RoleExcel.define[type].zuanshi
  216. if human.db.changeBase == nil or human.db.changeBase[type] == nil then
  217. msgRet.price = 0
  218. end
  219. Msg.send(msgRet,human.fd)
  220. end
  221. -- 更改基础信息
  222. function changeBaseInfo(human,type,param)
  223. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  224. msgRet.ret = CHANGE_BASEINFO_FAIL
  225. if human.db.changeBase ~= nil and human.db.changeBase[type] ~= nil then
  226. -- 不是免费,且钻石不够
  227. if RoleExcel.define[type].zuanshi ~= 0 and human.db.zuanshi < RoleExcel.define[type].zuanshi then
  228. msgRet.tip = Lang.COMMON_NO_ZUANSHI
  229. Msg.send(msgRet,human.fd)
  230. return
  231. end
  232. human.db.changeBase[type] = human.db.changeBase[type] + 1
  233. ObjHuman.decZuanshi(human, -RoleExcel.define[type].zuanshi, "change_baseinfo")
  234. else
  235. -- 首次免费
  236. human.db.changeBase = human.db.changeBase or {}
  237. human.db.changeBase[type] = 1
  238. end
  239. if type == BIRTHDAY_TYPE then
  240. -- 改生日
  241. local tb = Util.split(param, "|")
  242. if tb[1] and tb[2] and tb[3] then
  243. local tbTemp = {}
  244. tbTemp.year = tonumber(tb[1])
  245. tbTemp.month = tonumber(tb[2])
  246. tbTemp.day = tonumber(tb[3])
  247. local time = os.time(tbTemp)
  248. local now = os.time()
  249. -- time == nil 意味着时间小于1970.01.01 时间合法
  250. if time ~= nil and time >= now then
  251. msgRet.tip = Lang.CHANGE_BASEINFO_TIME_ERR
  252. Msg.send(msgRet,human.fd)
  253. return
  254. end
  255. human.db.birthDay = {}
  256. human.db.birthDay.year = tbTemp.year
  257. human.db.birthDay.month = tbTemp.month
  258. human.db.birthDay.day = tbTemp.day
  259. msgRet.ret = CHANGE_BASEINFO_SUCCESS
  260. msgRet.tip = Lang.CHANGE_BASEINFO_TIP
  261. Msg.send(msgRet,human.fd)
  262. return
  263. end
  264. msgRet.tip = Lang.CHANGE_BASEINFO_TIME_ERR
  265. Msg.send(msgRet,human.fd)
  266. return
  267. elseif type == SEX_TYPE then
  268. -- 改性别
  269. if param == human.db.sex then
  270. msgRet.tip = Lang.CHANGE_BASEINFO_NO_EFFECT_ERR
  271. Msg.send(msgRet,human.fd)
  272. return
  273. end
  274. human.db.sex = tonumber(param)
  275. msgRet.ret = CHANGE_BASEINFO_SUCCESS
  276. msgRet.tip = Lang.CHANGE_BASEINFO_TIP
  277. Msg.send(msgRet,human.fd)
  278. return
  279. elseif type == SIGNATURE_TYPE then
  280. -- 改个性签名
  281. local strLen = string.len(param)
  282. if strLen > 150 then
  283. msgRet.tip = Lang.CHANGE_BASEINFO_STR_LEN_ERR
  284. Msg.send(msgRet,human.fd)
  285. return
  286. end
  287. local newParam = FilterUtil.filter(param)
  288. if param ~= newParam then
  289. return Broadcast.sendErr(human, Lang.ROLE_SINGATURE_DESC_FILTER)
  290. end
  291. human.db.signature = newParam
  292. msgRet.ret = CHANGE_BASEINFO_SUCCESS
  293. msgRet.tip = Lang.CHANGE_BASEINFO_TIP
  294. Msg.send(msgRet,human.fd)
  295. else
  296. end
  297. end
  298. function roleInfoIconQuery(human,type,param)
  299. if type == 1 then
  300. -- 公会查询
  301. local msgRet = Msg.gc.GC_ROLE_INFO_ICON_UNION
  302. local union = UnionDBLogic.getUnion(param)
  303. if not union then
  304. return
  305. end
  306. local lv = math.min(union.lv, #UnionExcel.union)
  307. local config = UnionExcel.union[lv]
  308. msgRet.unionUuid = union._id
  309. msgRet.name = union.name or ""
  310. msgRet.maxCnt = config.maxCnt
  311. msgRet.curCnt = union.curCnt
  312. msgRet.bannerID = union.bannerID
  313. msgRet.needLv = union.needLv or 0
  314. msgRet.notice = union.notice
  315. msgRet.lv = lv
  316. local presidentDB = RoleDBLogic.getDb(union.presidentUuid, "name")
  317. msgRet.presidentName = presidentDB and presidentDB.name or ""
  318. Msg.send(msgRet,human.fd)
  319. elseif type == 2 then
  320. local id = tonumber(param)
  321. local isActive = RoleHeadLogic.isActive(human, RoleHeadLogic.HEAD_TYPE_4, id)
  322. local msgRet = Msg.gc.GC_ROLE_INFO_ICON_CHENGHAO
  323. local config = RoleExcel.chenghao[id]
  324. msgRet.chenghao.id = id
  325. msgRet.chenghao.name = config.name
  326. msgRet.chenghao.desc = config.desc
  327. local len = 0
  328. for k,v in ipairs(config.attrs) do
  329. len = len + 1
  330. msgRet.chenghao.attrs[len].key = v[1]
  331. msgRet.chenghao.attrs[len].value = v[2]
  332. end
  333. msgRet.chenghao.attrs[0] = len
  334. msgRet.chenghao.isActive = isActive and 1 or 0
  335. msgRet.panelID = config.panelID
  336. Msg.send(msgRet,human.fd)
  337. end
  338. end
  339. function RoleLogic_GetOnlineTime(human, nType)
  340. if not human.db.onlineTimeDayReport then
  341. human.db.onlineTimeDayReport = os.time()
  342. end
  343. local tMsgData = Msg.gc.GC_ONLINETIME_REPORT
  344. local nNowTime = os.time()
  345. tMsgData.time = nNowTime - human.db.onlineTimeDayReport
  346. tMsgData.nType = nType
  347. Msg.send(tMsgData, human.fd)
  348. print("[RoleLogic_GetOnlineTime] 下发协议结束")
  349. end
  350. function RoleLogic_CreateTime(uuid)
  351. Timer.addLater(5400, RoleLogic_OnTime, uuid)
  352. end
  353. function RoleLogic_OnTime(uuid)
  354. local human = ObjHuman.onlineUuid[uuid]
  355. if not human then
  356. return
  357. end
  358. RoleLogic_GetOnlineTime(human, 1)
  359. RoleLogic_CreateTime(human.db._id)
  360. end
  361. function onLogin(human)
  362. RoleLogic_CreateTime(human.db._id)
  363. end
  364. local function isChange(human)
  365. if not human.db.topupAcount or human.db.topupAcount <= 0 then
  366. return false
  367. end
  368. return true
  369. end
  370. function RoleLogic_QueryHumanInfo(human)
  371. local tMsgData = Msg.gc.GC_COMMON_HUMAN_INFO
  372. tMsgData.bChange = isChange(human) and 1 or 0
  373. Msg.send(tMsgData, human.fd)
  374. end