RoleRealmLogic.lua 5.9 KB

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