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