TalismanLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. --秘宝系统
  2. --[=[
  3. db
  4. human.db.talismanData =
  5. {
  6. [ID1] = level,
  7. [ID2] = level,
  8. }
  9. ]=]--
  10. local Msg = require("core.Msg")
  11. local Grid = require("bag.Grid")
  12. local BagLogic = require("bag.BagLogic")
  13. local Lang = require("common.Lang")
  14. local RoleAttr = require("role.RoleAttr")
  15. local RoleDefine = require("role.RoleDefine")
  16. local ObjHuman = require("core.ObjHuman")
  17. local Broadcast = require("broadcast.Broadcast")
  18. local talismanConfig = require("excel.talisman").talisman
  19. local HeroConfig = require("excel.hero").hero
  20. local HuanJingTowerLogic = require("huanjingTower.HuanjingTowerLogic")
  21. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  22. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  23. local TriggerDefine = require("trigger.TriggerDefine")
  24. local TriggerLogic = require("trigger.TriggerLogic")
  25. local LOGTYPE = "talisman"
  26. local COND_TOWER_LEVEL = 100 --开启本系统需要通关恶魔之塔的层数
  27. --秘宝对挂机钻石/情报等其他方面增益标识
  28. OTHER_EFFECT_TBL = {
  29. ["GJ_QB"] = "GJ_QB", --挂机情报类型
  30. ["GJ_ZS"] = "GJ_ZS", --挂机钻石类型
  31. ["GJ_HERO_EXP"] = "GJ_HERO_EXP", --挂机英雄经验类型
  32. ["GJ_HANG_HOURS"] = "GJ_HANG_HOURS", --挂机最大时间类型
  33. ["GJ_SD_FREE_CNT"] = "GJ_SD_FREE_CNT", --每日扫荡次数类型
  34. ["DJ"] = "DJ", --点金
  35. ["NW_JB"] = "NW_JB", --女巫森林金币类型
  36. ["NW_HERO_EXP"] = "NW_HERO_EXP", --女巫森林英雄经验类型
  37. ["NW_LHS"] = "NW_LHS", --女巫森林龙魂石
  38. ["DRILL_JINBI"] = "DRILL_JINBI", --勇者试炼金币类型
  39. ["ZHANBU_MAX_POINTS"] = "ZHANBU_MAX_POINTS", --占卜最大积分类型
  40. ["JYZH_LOTTERY10"] = "JYZH_LOTTERY10", --精英召唤10连类型
  41. ["NW_FWJH"] = "NW_FWJH", --女巫森林符文精华
  42. ["NW_CHALLENGE_TIMES"] = "NW_CHALLENGE_TIMES", --女巫森林所有类型挑战次数
  43. ["XUANSHANG_QB_MAX"] = "XUANSHANG_QB_MAX", --悬赏情报上限
  44. ["ZHANBU_POS6"] = "ZHANBU_POS6", --占卜解锁格子6
  45. ["ZHANBU_POS7"] = "ZHANBU_POS7", --占卜解锁格子7
  46. ["ZHANBU_FRAGMENT"] = "ZHANBU_FRAGMENT", --占卜获得碎片加成
  47. ["BATTLE_ISQUICKTIME"] = "BATTLE_ISQUICKTIME", --主线闯关跳过战斗
  48. ["YJ_DAILY_SD"] = "YJ_DAILY_SD", -- 遗迹探险每日额外扫荡次数
  49. ["HJ_DAILY_Free"] = "HJ_DAILY_Free", -- 恶魔之塔每日额外免费次数
  50. ["HeroSeed_Attr_Mul"] = "HeroSeed_Attr_Mul", -- 英雄种子系统加成
  51. ["RoleReal_Attr_Mul"] = "RoleReal_Attr_Mul", -- 境界系统加成
  52. ["WinnerRelic_Attr_Mul"] = "WinnerRelic_Attr_Mul", -- 圣遗物系统通用属性加成
  53. ["Elf_Attr_Mul"] = "Elf_Attr_Mul", -- 精灵系统通用属性加成
  54. ["Moshou_LvAttr_Mul"] = "Moshou_LvAttr_Mul", -- 守护凤凰系统等级加成属性的加成
  55. }
  56. --是否开启本系统
  57. local function isOpen(human)
  58. local towerLevel = HuanJingTowerLogic.getTowerLevel(human)
  59. if towerLevel >= COND_TOWER_LEVEL then
  60. return true
  61. end
  62. return false
  63. end
  64. --取对应类型的秘宝配置
  65. local function generateCfgByType(type_m)
  66. local tbl = {}
  67. for id, cfg in pairs(talismanConfig) do
  68. if cfg.type == type_m then
  69. tbl[id] = cfg
  70. tbl[id].id = id
  71. end
  72. end
  73. if not next(tbl) then
  74. return nil
  75. end
  76. return tbl
  77. end
  78. --填充协议的数据
  79. local function populateMsg(config, msgTb, nLevel)
  80. msgTb.id = config.id
  81. msgTb.name = config.name
  82. msgTb.iconId = config.iconId
  83. msgTb.level = nLevel
  84. local descVec = msgTb.descVec
  85. local effectDescCfg = config.effectDesc
  86. descVec[0] = #effectDescCfg
  87. for idx, desc in ipairs(effectDescCfg) do
  88. local singleDesc = descVec[idx]
  89. singleDesc.desc = desc
  90. singleDesc.isActivate = nLevel >= idx and 1 or 0
  91. end
  92. if nLevel < config.maxLevel then
  93. nLevel = nLevel + 1
  94. nLevel = math.ceil(nLevel/3)
  95. else
  96. nLevel = 0
  97. end
  98. Grid.makeItem(msgTb.upGradeCost, config.costItemId, nLevel)
  99. end
  100. --红点判断
  101. local function dotJudgment(human, cfgHtbl)
  102. local talismanData = human.db.talismanData
  103. for id, cfg in pairs(cfgHtbl) do
  104. local nLevel = 0
  105. if talismanData and talismanData[id] then
  106. nLevel = talismanData[id]
  107. end
  108. if nLevel < cfg.maxLevel then
  109. nLevel = nLevel + 1
  110. local costItemCnt = math.ceil(nLevel/3)
  111. if BagLogic.getItemCnt(human, cfg.costItemId) >= costItemCnt then
  112. return true
  113. end
  114. end
  115. end
  116. return false
  117. end
  118. -- 获取秘宝总星数
  119. local function talismanLogic_GetAllStar(human)
  120. local nAllStar = 0
  121. if not human.db.talismanData then
  122. return nAllStar
  123. end
  124. for id, _ in pairs(talismanConfig) do
  125. if human.db.talismanData[id] then
  126. nAllStar = nAllStar + human.db.talismanData[id]
  127. end
  128. end
  129. return nAllStar
  130. end
  131. --GM命令, 设置秘宝等级
  132. function GmSetlevel(human, id, level)
  133. local config = talismanConfig[id]
  134. if not config then
  135. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  136. end
  137. if level > config.maxLevel then
  138. level = config.maxLevel
  139. end
  140. if level < 0 then
  141. level = 0
  142. end
  143. human.db.talismanData = human.db.talismanData or {}
  144. human.db.talismanData[id] = level
  145. end
  146. --秘宝对英雄属性加成
  147. function doCalcHero(human, heroGrid, addAttrs)
  148. if not human or not heroGrid then
  149. return
  150. end
  151. local talismanData = human.db.talismanData
  152. if not talismanData then
  153. return
  154. end
  155. local heroCfg = HeroConfig[heroGrid.id]
  156. for id, level in pairs(talismanData) do
  157. local attrs = talismanConfig[id].attrs
  158. for i=1, level do
  159. local singleAttr = attrs[i]
  160. if #singleAttr == 2 and type(singleAttr[1]) == "number" then --给所有英雄加属性
  161. RoleAttr.updateValue(singleAttr[1], singleAttr[2], addAttrs)
  162. elseif #singleAttr == 3 then --只给某个种族的英雄加属性
  163. if singleAttr[1] == heroCfg.camp then
  164. RoleAttr.updateValue(singleAttr[2], singleAttr[3], addAttrs)
  165. end
  166. end
  167. end
  168. end
  169. end
  170. --红点
  171. function isDot(human, dotConfig)
  172. if not isOpen(human) then
  173. return false
  174. end
  175. --入口处的红点判断
  176. if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2006 then
  177. return dotJudgment(human, talismanConfig)
  178. else
  179. --单个分页的红点
  180. local talismanType = 0
  181. if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2007 then
  182. talismanType = 1
  183. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2008 then
  184. talismanType = 2
  185. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2009 then
  186. talismanType = 3
  187. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2010 then
  188. talismanType = 4
  189. else
  190. talismanType = 5
  191. end
  192. local cfgHtbl = generateCfgByType(talismanType)
  193. if not cfgHtbl then
  194. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  195. end
  196. return dotJudgment(human, cfgHtbl)
  197. end
  198. end
  199. --秘宝对其他方面的加成, 如:挂机钻石
  200. function getTalismanAdd(human, effectType)
  201. local addValue = 0
  202. if not human or not human.db then
  203. return addValue
  204. end
  205. local talismanData = human.db.talismanData
  206. if not talismanData or not effectType then
  207. return addValue
  208. end
  209. for id, level in pairs(talismanData) do
  210. local cfg = talismanConfig[id]
  211. local attrs = cfg.attrs
  212. for i=1,#attrs do
  213. local singleAttr = attrs[i]
  214. local addType = singleAttr[1]
  215. local value = singleAttr[2]
  216. if type(addType) == "string" and level >= i and effectType == addType then
  217. if type(value) == "number" then
  218. addValue = addValue + value
  219. else
  220. addValue = value
  221. end
  222. end
  223. end
  224. end
  225. return addValue
  226. end
  227. --查询
  228. function Query(human, type_m)
  229. if not type_m then
  230. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  231. end
  232. if not isOpen(human) then
  233. return Broadcast.sendErr(human, Lang.COMMOM_NOT_ENABLED)
  234. end
  235. local cfgHtbl = generateCfgByType(type_m)
  236. if not cfgHtbl then
  237. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  238. end
  239. local msgRet = Msg.gc.GC_TALISMAN_QUERY
  240. msgRet.nAllStar = talismanLogic_GetAllStar(human)
  241. msgRet.type = type_m
  242. local talismanVec = msgRet.talismanVec
  243. local len = 0
  244. local talismanData = human.db.talismanData
  245. for id, cfg in pairs(cfgHtbl) do
  246. len = len + 1
  247. local nLevel = 0
  248. if talismanData and talismanData[id] then
  249. nLevel = talismanData[id]
  250. end
  251. populateMsg(cfg, talismanVec[len], nLevel)
  252. end
  253. talismanVec[0] = len
  254. Msg.send(msgRet, human.fd)
  255. end
  256. --升级
  257. function UpGrade(human, id)
  258. if not isOpen(human) then
  259. return Broadcast.sendErr(human, Lang.COMMOM_NOT_ENABLED)
  260. end
  261. local singleCfg = talismanConfig[id]
  262. if not singleCfg then
  263. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  264. end
  265. local nLevel = 0
  266. local type = singleCfg.type
  267. --等级判断
  268. if human.db.talismanData and human.db.talismanData[id] then
  269. nLevel = human.db.talismanData[id]
  270. end
  271. if nLevel >= singleCfg.maxLevel then
  272. return Broadcast.sendErr(human, Lang.COMMON_MAXLEVEL)
  273. end
  274. --道具判断
  275. nLevel = nLevel + 1
  276. local costItemId = singleCfg.costItemId
  277. local costItemCnt = math.ceil(nLevel/3)
  278. if BagLogic.getItemCnt(human, costItemId) < costItemCnt then
  279. return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH)
  280. end
  281. BagLogic.delItem(human, costItemId, costItemCnt, LOGTYPE)
  282. --更新数据
  283. human.db.talismanData = human.db.talismanData or {}
  284. human.db.talismanData[id] = nLevel
  285. --下发数据
  286. local msgRet = Msg.gc.GC_TALISMAN_UPGRADE
  287. msgRet.type = type
  288. populateMsg(singleCfg, msgRet.talismanInfo, nLevel)
  289. Msg.send(msgRet, human.fd)
  290. --重算战力
  291. RoleAttr.cleanHeroAttrCache(human)
  292. RoleAttr.doCalc(human)
  293. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  294. if nLevel == 1 then
  295. -- 激活
  296. TriggerLogic.PublishEvent(TriggerDefine.MIBAO_ACTIVATE, human.db._id, id, 1)
  297. end
  298. -- 总星数
  299. TriggerLogic.PublishEvent(TriggerDefine.MIBAO_ALLSTAR, human.db._id, 1)
  300. --刷新红点
  301. nLevel = nLevel + 1
  302. costItemCnt = math.ceil(nLevel/3)
  303. if nLevel >= singleCfg.maxLevel or BagLogic.getItemCnt(human, costItemId) < costItemCnt then
  304. local dotID = 0
  305. if type == 1 then
  306. dotID = RoleSystemDefine.ROLE_SYS_ID_2007
  307. elseif type == 2 then
  308. dotID = RoleSystemDefine.ROLE_SYS_ID_2008
  309. elseif type == 3 then
  310. dotID = RoleSystemDefine.ROLE_SYS_ID_2009
  311. elseif type == 4 then
  312. dotID = RoleSystemDefine.ROLE_SYS_ID_2010
  313. else
  314. dotID = RoleSystemDefine.ROLE_SYS_ID_2011
  315. end
  316. --刷新单页
  317. RoleSystemLogic.onDot(human, dotID)
  318. --刷新入口处
  319. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2006)
  320. end
  321. Query(human, type)
  322. end