TalismanLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. }
  50. --是否开启本系统
  51. local function isOpen(human)
  52. local towerLevel = HuanJingTowerLogic.getTowerLevel(human)
  53. if towerLevel >= COND_TOWER_LEVEL then
  54. return true
  55. end
  56. return false
  57. end
  58. --取对应类型的秘宝配置
  59. local function generateCfgByType(type_m)
  60. local tbl = {}
  61. for id, cfg in pairs(talismanConfig) do
  62. if cfg.type == type_m then
  63. tbl[id] = cfg
  64. tbl[id].id = id
  65. end
  66. end
  67. if not next(tbl) then
  68. return nil
  69. end
  70. return tbl
  71. end
  72. --填充协议的数据
  73. local function populateMsg(config, msgTb, nLevel)
  74. msgTb.id = config.id
  75. msgTb.name = config.name
  76. msgTb.iconId = config.iconId
  77. msgTb.level = nLevel
  78. local descVec = msgTb.descVec
  79. local effectDescCfg = config.effectDesc
  80. descVec[0] = #effectDescCfg
  81. for idx, desc in ipairs(effectDescCfg) do
  82. local singleDesc = descVec[idx]
  83. singleDesc.desc = desc
  84. singleDesc.isActivate = nLevel >= idx and 1 or 0
  85. end
  86. if nLevel < config.maxLevel then
  87. nLevel = nLevel + 1
  88. nLevel = math.ceil(nLevel/3)
  89. else
  90. nLevel = 0
  91. end
  92. Grid.makeItem(msgTb.upGradeCost, config.costItemId, nLevel)
  93. end
  94. --红点判断
  95. local function dotJudgment(human, cfgHtbl)
  96. local talismanData = human.db.talismanData
  97. for id, cfg in pairs(cfgHtbl) do
  98. local nLevel = 0
  99. if talismanData and talismanData[id] then
  100. nLevel = talismanData[id]
  101. end
  102. if nLevel < cfg.maxLevel then
  103. nLevel = nLevel + 1
  104. local costItemCnt = math.ceil(nLevel/3)
  105. if BagLogic.getItemCnt(human, cfg.costItemId) >= costItemCnt then
  106. return true
  107. end
  108. end
  109. end
  110. return false
  111. end
  112. -- 获取秘宝总星数
  113. local function talismanLogic_GetAllStar(human)
  114. local nAllStar = 0
  115. if not human.db.talismanData then
  116. return nAllStar
  117. end
  118. for id, _ in pairs(talismanConfig) do
  119. if human.db.talismanData[id] then
  120. nAllStar = nAllStar + human.db.talismanData[id]
  121. end
  122. end
  123. return nAllStar
  124. end
  125. --GM命令, 设置秘宝等级
  126. function GmSetlevel(human, id, level)
  127. local config = talismanConfig[id]
  128. if not config then
  129. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  130. end
  131. if level > config.maxLevel then
  132. level = config.maxLevel
  133. end
  134. if level < 0 then
  135. level = 0
  136. end
  137. human.db.talismanData = human.db.talismanData or {}
  138. human.db.talismanData[id] = level
  139. end
  140. --秘宝对英雄属性加成
  141. function doCalcHero(human, heroGrid, addAttrs)
  142. if not human or not heroGrid then
  143. return
  144. end
  145. local talismanData = human.db.talismanData
  146. if not talismanData then
  147. return
  148. end
  149. local heroCfg = HeroConfig[heroGrid.id]
  150. for id, level in pairs(talismanData) do
  151. local attrs = talismanConfig[id].attrs
  152. for i=1, level do
  153. local singleAttr = attrs[i]
  154. if #singleAttr == 2 and type(singleAttr[1]) == "number" then --给所有英雄加属性
  155. RoleAttr.updateValue(singleAttr[1], singleAttr[2], addAttrs)
  156. elseif #singleAttr == 3 then --只给某个种族的英雄加属性
  157. if singleAttr[1] == heroCfg.camp then
  158. RoleAttr.updateValue(singleAttr[2], singleAttr[3], addAttrs)
  159. end
  160. end
  161. end
  162. end
  163. end
  164. --红点
  165. function isDot(human, dotConfig)
  166. if not isOpen(human) then
  167. return false
  168. end
  169. --入口处的红点判断
  170. if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2006 then
  171. return dotJudgment(human, talismanConfig)
  172. else
  173. --单个分页的红点
  174. local talismanType = 0
  175. if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2007 then
  176. talismanType = 1
  177. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2008 then
  178. talismanType = 2
  179. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2009 then
  180. talismanType = 3
  181. else
  182. talismanType = 4
  183. end
  184. local cfgHtbl = generateCfgByType(talismanType)
  185. if not cfgHtbl then
  186. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  187. end
  188. return dotJudgment(human, cfgHtbl)
  189. end
  190. end
  191. --秘宝对其他方面的加成, 如:挂机钻石
  192. function getTalismanAdd(human, type_m)
  193. local addValue = 0
  194. local talismanData = human.db.talismanData
  195. if not talismanData or not type_m then
  196. return addValue
  197. end
  198. for id, level in pairs(talismanData) do
  199. local cfg = talismanConfig[id]
  200. local attrs = cfg.attrs
  201. for i=1,#attrs do
  202. local singleAttr = attrs[i]
  203. local addType = singleAttr[1]
  204. local value = singleAttr[2]
  205. if type(addType) == "string" and level >= i and type_m == addType then
  206. if type(value) == "number" then
  207. addValue = addValue + value
  208. else
  209. addValue = value
  210. end
  211. end
  212. end
  213. end
  214. return addValue
  215. end
  216. --查询
  217. function Query(human, type_m)
  218. if not type_m then
  219. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  220. end
  221. if not isOpen(human) then
  222. return Broadcast.sendErr(human, Lang.COMMOM_NOT_ENABLED)
  223. end
  224. local cfgHtbl = generateCfgByType(type_m)
  225. if not cfgHtbl then
  226. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  227. end
  228. local msgRet = Msg.gc.GC_TALISMAN_QUERY
  229. msgRet.nAllStar = talismanLogic_GetAllStar(human)
  230. msgRet.type = type_m
  231. local talismanVec = msgRet.talismanVec
  232. local len = 0
  233. local talismanData = human.db.talismanData
  234. for id, cfg in pairs(cfgHtbl) do
  235. len = len + 1
  236. local nLevel = 0
  237. if talismanData and talismanData[id] then
  238. nLevel = talismanData[id]
  239. end
  240. populateMsg(cfg, talismanVec[len], nLevel)
  241. end
  242. talismanVec[0] = len
  243. Msg.send(msgRet, human.fd)
  244. end
  245. --升级
  246. function UpGrade(human, id)
  247. if not isOpen(human) then
  248. return Broadcast.sendErr(human, Lang.COMMOM_NOT_ENABLED)
  249. end
  250. local singleCfg = talismanConfig[id]
  251. if not singleCfg then
  252. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  253. end
  254. local nLevel = 0
  255. local type = singleCfg.type
  256. --等级判断
  257. if human.db.talismanData and human.db.talismanData[id] then
  258. nLevel = human.db.talismanData[id]
  259. end
  260. if nLevel >= singleCfg.maxLevel then
  261. return Broadcast.sendErr(human, Lang.COMMON_MAXLEVEL)
  262. end
  263. --道具判断
  264. nLevel = nLevel + 1
  265. local costItemId = singleCfg.costItemId
  266. local costItemCnt = math.ceil(nLevel/3)
  267. if BagLogic.getItemCnt(human, costItemId) < costItemCnt then
  268. return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH)
  269. end
  270. BagLogic.delItem(human, costItemId, costItemCnt, LOGTYPE)
  271. --更新数据
  272. human.db.talismanData = human.db.talismanData or {}
  273. human.db.talismanData[id] = nLevel
  274. --下发数据
  275. local msgRet = Msg.gc.GC_TALISMAN_UPGRADE
  276. msgRet.type = type
  277. populateMsg(singleCfg, msgRet.talismanInfo, nLevel)
  278. Msg.send(msgRet, human.fd)
  279. --重算战力
  280. RoleAttr.cleanHeroAttrCache(human)
  281. RoleAttr.doCalc(human)
  282. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  283. if nLevel == 1 then
  284. -- 激活
  285. TriggerLogic.PublishEvent(TriggerDefine.MIBAO_ACTIVATE, human.db._id, id, 1)
  286. end
  287. -- 总星数
  288. TriggerLogic.PublishEvent(TriggerDefine.MIBAO_ALLSTAR, human.db._id, 1)
  289. --刷新红点
  290. nLevel = nLevel + 1
  291. costItemCnt = math.ceil(nLevel/3)
  292. if nLevel >= singleCfg.maxLevel or BagLogic.getItemCnt(human, costItemId) < costItemCnt then
  293. local dotID = 0
  294. if type == 1 then
  295. dotID = RoleSystemDefine.ROLE_SYS_ID_2007
  296. elseif type == 2 then
  297. dotID = RoleSystemDefine.ROLE_SYS_ID_2008
  298. elseif type == 3 then
  299. dotID = RoleSystemDefine.ROLE_SYS_ID_2009
  300. else
  301. dotID = RoleSystemDefine.ROLE_SYS_ID_2010
  302. end
  303. --刷新单页
  304. RoleSystemLogic.onDot(human, dotID)
  305. --刷新入口处
  306. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2006)
  307. end
  308. Query(human, type)
  309. end