RoleLogic.lua 12 KB

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