RoleRealmLogic.lua 4.8 KB

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