RoleLogic.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 Msg = require("core.Msg")
  24. local RoleHeadLogic = require("role.RoleHeadLogic")
  25. local UnionExcel = require("excel.union")
  26. local FilterUtil = require("common.FilterUtil")
  27. local Broadcast = require("broadcast.Broadcast")
  28. local RoleRealmLogic = require("roleSystem.RoleRealmLogic")
  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)
  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. combatType = CombatDefine.COMBAT_TYPE1
  131. local combatHero = CombatPosLogic.getCombatHeros(FAKE_HUMAN, combatType)
  132. local union = UnionDBLogic.getUnion(db.unionUuid)
  133. getRoleBase(FAKE_HUMAN, net.roleBase,combatType)
  134. net.moshouBody = MoshouLogic.getCombatMoshouBody(FAKE_HUMAN,combatType)
  135. net.defenceList[0] = 0
  136. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  137. local uuid = combatHero and combatHero[i]
  138. local heroGrid = HeroLogic.getHeroGridByUuid(FAKE_HUMAN, uuid)
  139. if heroGrid then
  140. net.defenceList[0] = net.defenceList[0] + 1
  141. local defenceNet = net.defenceList[net.defenceList[0]]
  142. HeroGrid.makeHeroSimple(defenceNet, heroGrid, heroGrid.bagIndex, FAKE_HUMAN)
  143. if i == CombatDefine.COMBAT_HERO_CNT then
  144. net.yjUuid = uuid
  145. end
  146. end
  147. end
  148. net.vipLv = db.vipLv or 0
  149. -- vip 大于14 不管是否屏蔽 客户端都显示 王者VIP
  150. if SettingLogic.isNoShowVip(FAKE_HUMAN) == true and net.vipLv ~= 0 and net.vipLv < 14 then
  151. net.vipLv = -1
  152. end
  153. net.unionName = union and union.name or ""
  154. net.svrName = Config.SVR_NAME
  155. net.isFriend = 0
  156. if FriendDBLogic.isBlackFriend(FAKE_HUMAN.db._id,uuid) then
  157. net.isFriend = 2
  158. elseif FriendDBLogic.isFriend(FAKE_HUMAN.db._id,uuid) then
  159. net.isFriend = 1
  160. end
  161. return true
  162. end
  163. -- 获取玩家公会旗帜
  164. function getUnionBannerID(db)
  165. if db then
  166. local union = UnionDBLogic.getUnion(db.unionUuid)
  167. if union then
  168. return union.bannerID
  169. end
  170. end
  171. return 0
  172. end
  173. function makeOtherPlayInfo(net,jjcData)
  174. if not jjcData then return end
  175. local monsterOutID = jjcData.monsterOutID
  176. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  177. FAKE_HUMAN.db = jjcData
  178. getRoleBase(FAKE_HUMAN, net.roleBase)
  179. net.moshouBody = 0
  180. net.defenceList[0] = 0
  181. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  182. local monsterConfig = monsterOutConfig.member[i]
  183. local monsterID = monsterConfig and monsterConfig[1]
  184. if monsterID and monsterID > 0 then
  185. local monsterLv = monsterConfig and monsterConfig[2]
  186. local others = HeroGrid.createOthers(monsterLv)
  187. net.defenceList[0] = net.defenceList[0] + 1
  188. local defenceNet = net.defenceList[net.defenceList[0]]
  189. HeroGrid.makeHeroSimpleByMonsterID(defenceNet, monsterID, others)
  190. net.defenceList[i].index = i
  191. end
  192. end
  193. end
  194. function makePlayInfoByOther(net, uuid)
  195. local jjcData = JjcDB.getJjcData(uuid)
  196. if not jjcData then return end
  197. makeOtherPlayInfo(net,jjcData)
  198. net.vipLv = 0
  199. net.isFriend = 0
  200. net.unionName = ""
  201. net.svrName = Config.SVR_NAME
  202. return true
  203. end
  204. CHANGE_BASEINFO_FAIL = 0
  205. CHANGE_BASEINFO_SUCCESS = 1
  206. -- 更改基础信息查询
  207. function changeBaseInfoQuery(human,type)
  208. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO_QUERY
  209. msgRet.price = RoleExcel.define[type].zuanshi
  210. if human.db.changeBase == nil or human.db.changeBase[type] == nil then
  211. msgRet.price = 0
  212. end
  213. Msg.send(msgRet,human.fd)
  214. end
  215. -- 更改基础信息
  216. function changeBaseInfo(human,type,param)
  217. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  218. msgRet.ret = CHANGE_BASEINFO_FAIL
  219. if human.db.changeBase ~= nil and human.db.changeBase[type] ~= nil then
  220. -- 不是免费,且钻石不够
  221. if RoleExcel.define[type].zuanshi ~= 0 and human.db.zuanshi < RoleExcel.define[type].zuanshi then
  222. msgRet.tip = Lang.COMMON_NO_ZUANSHI
  223. Msg.send(msgRet,human.fd)
  224. return
  225. end
  226. human.db.changeBase[type] = human.db.changeBase[type] + 1
  227. ObjHuman.decZuanshi(human, -RoleExcel.define[type].zuanshi, "change_baseinfo")
  228. else
  229. -- 首次免费
  230. human.db.changeBase = human.db.changeBase or {}
  231. human.db.changeBase[type] = 1
  232. end
  233. if type == BIRTHDAY_TYPE then
  234. -- 改生日
  235. local tb = Util.split(param, "|")
  236. if tb[1] and tb[2] and tb[3] then
  237. local tbTemp = {}
  238. tbTemp.year = tonumber(tb[1])
  239. tbTemp.month = tonumber(tb[2])
  240. tbTemp.day = tonumber(tb[3])
  241. local time = os.time(tbTemp)
  242. local now = os.time()
  243. -- time == nil 意味着时间小于1970.01.01 时间合法
  244. if time ~= nil and time >= now then
  245. msgRet.tip = Lang.CHANGE_BASEINFO_TIME_ERR
  246. Msg.send(msgRet,human.fd)
  247. return
  248. end
  249. human.db.birthDay = {}
  250. human.db.birthDay.year = tbTemp.year
  251. human.db.birthDay.month = tbTemp.month
  252. human.db.birthDay.day = tbTemp.day
  253. msgRet.ret = CHANGE_BASEINFO_SUCCESS
  254. msgRet.tip = Lang.CHANGE_BASEINFO_TIP
  255. Msg.send(msgRet,human.fd)
  256. return
  257. end
  258. msgRet.tip = Lang.CHANGE_BASEINFO_TIME_ERR
  259. Msg.send(msgRet,human.fd)
  260. return
  261. elseif type == SEX_TYPE then
  262. -- 改性别
  263. if param == human.db.sex then
  264. msgRet.tip = Lang.CHANGE_BASEINFO_NO_EFFECT_ERR
  265. Msg.send(msgRet,human.fd)
  266. return
  267. end
  268. human.db.sex = tonumber(param)
  269. msgRet.ret = CHANGE_BASEINFO_SUCCESS
  270. msgRet.tip = Lang.CHANGE_BASEINFO_TIP
  271. Msg.send(msgRet,human.fd)
  272. return
  273. elseif type == SIGNATURE_TYPE then
  274. -- 改个性签名
  275. local strLen = string.len(param)
  276. if strLen > 150 then
  277. msgRet.tip = Lang.CHANGE_BASEINFO_STR_LEN_ERR
  278. Msg.send(msgRet,human.fd)
  279. return
  280. end
  281. local newParam = FilterUtil.filter(param)
  282. if param ~= newParam then
  283. return Broadcast.sendErr(human, Lang.ROLE_SINGATURE_DESC_FILTER)
  284. end
  285. human.db.signature = newParam
  286. msgRet.ret = CHANGE_BASEINFO_SUCCESS
  287. msgRet.tip = Lang.CHANGE_BASEINFO_TIP
  288. Msg.send(msgRet,human.fd)
  289. else
  290. end
  291. end
  292. function roleInfoIconQuery(human,type,param)
  293. if type == 1 then
  294. -- 公会查询
  295. local msgRet = Msg.gc.GC_ROLE_INFO_ICON_UNION
  296. local union = UnionDBLogic.getUnion(param)
  297. if not union then
  298. return
  299. end
  300. local lv = math.min(union.lv, #UnionExcel.union)
  301. local config = UnionExcel.union[lv]
  302. msgRet.unionUuid = union._id
  303. msgRet.name = union.name or ""
  304. msgRet.maxCnt = config.maxCnt
  305. msgRet.curCnt = union.curCnt
  306. msgRet.bannerID = union.bannerID
  307. msgRet.needLv = union.needLv or 0
  308. msgRet.notice = union.notice
  309. msgRet.lv = lv
  310. local presidentDB = RoleDBLogic.getDb(union.presidentUuid, "name")
  311. msgRet.presidentName = presidentDB and presidentDB.name or ""
  312. Msg.send(msgRet,human.fd)
  313. elseif type == 2 then
  314. local id = tonumber(param)
  315. local isActive = RoleHeadLogic.isActive(human, RoleHeadLogic.HEAD_TYPE_4, id)
  316. local msgRet = Msg.gc.GC_ROLE_INFO_ICON_CHENGHAO
  317. local config = RoleExcel.chenghao[id]
  318. msgRet.chenghao.id = id
  319. msgRet.chenghao.name = config.name
  320. msgRet.chenghao.desc = config.desc
  321. local len = 0
  322. for k,v in ipairs(config.attrs) do
  323. len = len + 1
  324. msgRet.chenghao.attrs[len].key = v[1]
  325. msgRet.chenghao.attrs[len].value = v[2]
  326. end
  327. msgRet.chenghao.attrs[0] = len
  328. msgRet.chenghao.isActive = isActive and 1 or 0
  329. msgRet.panelID = config.panelID
  330. Msg.send(msgRet,human.fd)
  331. end
  332. end