RoleRealmLogic.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. --境界系统
  2. --[=[
  3. 数据库存储数据: human.db.realmLv
  4. 只存境界等级,境界的属性加成等则是实时计算
  5. ]=]--
  6. local Msg = require("core.Msg")
  7. local BagLogic = require("bag.BagLogic")
  8. local realmConfig = require("excel.realm").Sheet1
  9. local Grid = require("bag.Grid")
  10. local RoleAttr = require("role.RoleAttr")
  11. local RoleDefine = require("role.RoleDefine")
  12. local ObjHuman = require("core.ObjHuman")
  13. local Util = require("common.Util")
  14. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  15. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  16. local TriggerLogic = require("trigger.TriggerLogic")
  17. local TriggerDefine = require("trigger.TriggerDefine")
  18. local REALM_UPGRADE_LOG = "realmUpgrade"
  19. --加万分比的属性
  20. local sp_attr = {
  21. [201] = 1,
  22. [202] = 1,
  23. [203] = 1,
  24. [204] = 1
  25. }
  26. local function calAttrSum(tbl, lv)
  27. for i = 1, lv do
  28. local cfg = realmConfig[i]
  29. if cfg and cfg.attrs then
  30. for k,v in ipairs(cfg.attrs) do
  31. local id = v[1]
  32. local value = v[2]
  33. tbl[k] = tbl[k] or {}
  34. tbl[k].key = id
  35. if sp_attr[id] then
  36. tbl[k].value = (tbl[k].value or 0) + (value / 100)
  37. else
  38. tbl[k].value = (tbl[k].value or 0) + value
  39. end
  40. end
  41. end
  42. end
  43. end
  44. local function sendToclient(human)
  45. local realmLv = human.db and human.db.realmLv or 0
  46. local msgRet = Util.copyTable(Msg.gc.GC_ROLE_REALM_QUERY)
  47. local bl = false
  48. if realmLv <= 0 then
  49. bl = true
  50. msgRet.nowRealmName = ""
  51. end
  52. local nowRealmCfg = bl and realmConfig[1] or realmConfig[realmLv]
  53. if not nowRealmCfg then
  54. return
  55. end
  56. if not bl then
  57. msgRet.nowRealmName = nowRealmCfg.name
  58. end
  59. local attrsCfg = nowRealmCfg.attrs
  60. msgRet.nowAttrs[0] = #attrsCfg
  61. if bl then
  62. for k,v in ipairs(attrsCfg) do
  63. msgRet.nowAttrs[k] = msgRet.nowAttrs[k] or {}
  64. msgRet.nowAttrs[k].key = v[1] or 0
  65. msgRet.nowAttrs[k].value = 0
  66. end
  67. else
  68. calAttrSum(msgRet.nowAttrs, realmLv)
  69. end
  70. local itemId, itemCnt, nextRealmCfg
  71. if realmLv < #realmConfig then
  72. nextRealmCfg = realmConfig[realmLv + 1]
  73. if not nextRealmCfg then
  74. return
  75. end
  76. itemCnt = nextRealmCfg.itemCnt
  77. calAttrSum(msgRet.nextAttrs, realmLv+1)
  78. else
  79. nextRealmCfg = realmConfig[realmLv]
  80. itemCnt = 0
  81. calAttrSum(msgRet.nextAttrs, realmLv)
  82. end
  83. itemId = nextRealmCfg.itemId
  84. Grid.makeItem(msgRet.itemData, itemId, itemCnt)
  85. msgRet.nextRealmName = nextRealmCfg.name
  86. msgRet.nextAttrs[0] = #nextRealmCfg.attrs
  87. Msg.send(msgRet, human.fd)
  88. if BagLogic.getItemCnt(human, itemId) < itemCnt then
  89. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_303)
  90. end
  91. end
  92. --境界对属性加成
  93. function doCalcHero(human, attrs)
  94. if not human then
  95. return
  96. end
  97. local realmLv = human.db and human.db.realmLv or 0
  98. if realmLv <= 0 then
  99. return
  100. end
  101. for i=1, realmLv do
  102. local singleCfg = realmConfig[i]
  103. if singleCfg and singleCfg.attrs then
  104. for _, v in ipairs(singleCfg.attrs) do
  105. if v[2] > 0 then
  106. RoleAttr.updateValue(v[1], v[2], attrs)
  107. end
  108. end
  109. end
  110. end
  111. end
  112. --获取境界名字
  113. function getRealmName(human)
  114. local name = ""
  115. if human.db and human.db.realmLv then
  116. local singleCfg = realmConfig[human.db.realmLv]
  117. if singleCfg and singleCfg.name then
  118. name = singleCfg.name
  119. end
  120. end
  121. return name
  122. end
  123. --获取当前境界
  124. function GetNowRealmLv(human)
  125. local realmLv = human.db.realmLv or 0
  126. return realmLv
  127. end
  128. --红点判断
  129. function isDot(human)
  130. local realmLv = human.db.realmLv or 0
  131. if realmLv >= #realmConfig then
  132. return false
  133. end
  134. local singleCfg = realmConfig[1]
  135. if realmLv > 0 then
  136. singleCfg = realmConfig[realmLv + 1]
  137. end
  138. if not singleCfg then
  139. return false
  140. end
  141. local itemId = singleCfg.itemId
  142. local itemCnt = singleCfg.itemCnt
  143. if BagLogic.getItemCnt(human, itemId) < itemCnt then
  144. return false
  145. end
  146. return true
  147. end
  148. --查询
  149. function query(human)
  150. sendToclient(human)
  151. end
  152. --提升境界
  153. function realmUpgrade(human)
  154. local realmLv = human.db.realmLv or 0
  155. if realmLv >= #realmConfig then
  156. return
  157. end
  158. realmLv = realmLv + 1
  159. local singleCfg = realmConfig[realmLv]
  160. if not singleCfg then
  161. return
  162. end
  163. local itemId = singleCfg.itemId
  164. local itemCnt = singleCfg.itemCnt
  165. if not BagLogic.checkItemCnt(human, itemId, itemCnt) then
  166. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_303)
  167. return
  168. end
  169. BagLogic.delItem(human, itemId, itemCnt, REALM_UPGRADE_LOG)
  170. human.db.realmLv = realmLv
  171. sendToclient(human)
  172. RoleAttr.cleanHeroAttrCache(human)
  173. RoleAttr.doCalc(human)
  174. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  175. ObjHuman.doCalc(human)
  176. TriggerLogic.PublishEvent(TriggerDefine.REALM_UPGRADE, human.db._id, 1, realmLv)
  177. end