FuwenGrid.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. local FuwenExcel = require("excel.fuwen")
  2. local Util = require("common.Util")
  3. local FuwenLogic = require("fuwen.FuwenLogic")
  4. local PfLogic = require("platform.PfLogic")
  5. local FuwenDefine = require("fuwen.FuwenDefine")
  6. local Broadcast = require("broadcast.Broadcast")
  7. local Lang = require("common.Lang")
  8. FUWEN_SKILL_PRIM = FUWEN_SKILL_PRIM or {} --符文初级技能列表
  9. FUWEN_SKILL_INTE = FUWEN_SKILL_INTE or {} --符文中级技能列表
  10. FUWEN_SKILL_HIGH = FUWEN_SKILL_HIGH or {} --符文高级技能列表
  11. FUWEN_SKILL_TOP = FUWEN_SKILL_TOP or {} --符文顶级技能列表
  12. FUWEN_SKILL_RARE = FUWEN_SKILL_RARE or {} --符文稀有技能列表
  13. function getFuwenSkillMaxCnt(fuwenConfig)
  14. local nowNum, maxNum = 0, 0
  15. for _, skillInfo in ipairs(fuwenConfig.skillRate) do
  16. nowNum = skillInfo[1] + skillInfo[2] + skillInfo[3] + skillInfo[4]
  17. if nowNum > maxNum then
  18. maxNum = nowNum
  19. end
  20. end
  21. return maxNum
  22. end
  23. function initAfterHot()
  24. Util.initTable(FUWEN_SKILL_PRIM)
  25. Util.initTable(FUWEN_SKILL_INTE)
  26. Util.initTable(FUWEN_SKILL_HIGH)
  27. Util.initTable(FUWEN_SKILL_TOP)
  28. Util.initTable(FUWEN_SKILL_RARE)
  29. for fuwenID, config in pairs(FuwenExcel.skill) do
  30. if config.isFuwenSkill == 1 then -- 符文技能
  31. if config.lv == 1 then
  32. FUWEN_SKILL_PRIM[#FUWEN_SKILL_PRIM + 1] = fuwenID
  33. elseif config.lv == 2 then
  34. FUWEN_SKILL_INTE[#FUWEN_SKILL_INTE + 1] = fuwenID
  35. elseif config.lv == 3 then
  36. FUWEN_SKILL_HIGH[#FUWEN_SKILL_HIGH + 1] = fuwenID
  37. elseif config.lv == 4 then
  38. FUWEN_SKILL_TOP[#FUWEN_SKILL_TOP + 1] = fuwenID
  39. end
  40. if config.rare == 1 then
  41. FUWEN_SKILL_RARE[#FUWEN_SKILL_RARE + 1] = fuwenID
  42. end
  43. end
  44. end
  45. end
  46. function create(id)
  47. local tb = {}
  48. tb.id = id
  49. tb.attr = {}
  50. tb.skill = nil
  51. -- 生成随机属性和技能
  52. genFuwenAttr(tb,nil)
  53. tb.attrTemp = {}
  54. tb.skillTemp = nil
  55. return tb
  56. end
  57. function genFuwenAttr(fuwenGrid, luckRefresh)
  58. -- Util.initTable(fuwenGrid.attr)
  59. Util.initTable(fuwenGrid.skill)
  60. local choseSkill = {}
  61. local fuwenConfig = FuwenExcel.fuwen[fuwenGrid.id]
  62. if fuwenConfig == nil then
  63. return
  64. end
  65. -- 绝对值属性抽选 必定有且仅有1条
  66. local cnt = #fuwenConfig.absAttrPool
  67. -- local randIndex = math.random(1, cnt)
  68. -- local attrKey = fuwenConfig.absAttrPool[randIndex][1]
  69. -- local attrVal = fuwenConfig.absAttrPool[randIndex][2]
  70. -- fuwenGrid.attr[1] = {attrKey, attrVal}
  71. if not fuwenGrid.attr[1] or not fuwenGrid.attr[1][3] or fuwenGrid.attr[1][3] ~= 1 then
  72. -- local cnt = #fuwenConfig.absAttrPool
  73. local randIndex = math.random(1, cnt)
  74. local attrKey = fuwenConfig.absAttrPool[randIndex][1]
  75. local attrVal = fuwenConfig.absAttrPool[randIndex][2]
  76. fuwenGrid.attr[1] = {attrKey, attrVal}
  77. end
  78. -- 百分比属性抽选 不一定有
  79. cnt = #fuwenConfig.percentAttrPool
  80. if cnt > 0 then
  81. -- local randIndex = math.random(1, cnt)
  82. -- local attrKey = fuwenConfig.percentAttrPool[randIndex][1]
  83. -- local attrVal = fuwenConfig.percentAttrPool[randIndex][2]
  84. -- fuwenGrid.attr[2] = {attrKey, attrVal}
  85. -- if fuwenGrid.id == 80006 then
  86. -- randIndex = math.random(1, cnt)
  87. -- attrKey = fuwenConfig.percentAttrPool[randIndex][1]
  88. -- attrVal = fuwenConfig.percentAttrPool[randIndex][2]
  89. -- fuwenGrid.attr[3] = {attrKey, attrVal}
  90. -- end
  91. if not fuwenGrid.attr[2] or not fuwenGrid.attr[2][3] or fuwenGrid.attr[2][3] ~= 1 then
  92. local randIndex = math.random(1, cnt)
  93. local attrKey = fuwenConfig.percentAttrPool[randIndex][1]
  94. local attrVal = fuwenConfig.percentAttrPool[randIndex][2]
  95. fuwenGrid.attr[2] = {attrKey, attrVal}
  96. end
  97. if fuwenGrid.id == 80006 and (not fuwenGrid.attr[3] or not fuwenGrid.attr[3][3] or fuwenGrid.attr[3][3] ~= 1) then
  98. local randIndex = math.random(1, cnt)
  99. local attrKey = fuwenConfig.percentAttrPool[randIndex][1]
  100. local attrVal = fuwenConfig.percentAttrPool[randIndex][2]
  101. fuwenGrid.attr[3] = {attrKey, attrVal}
  102. end
  103. end
  104. -- 锁定技能的处理
  105. local allSkillCnt = 0
  106. local subTb = {}
  107. local skillLockList = fuwenGrid.skillLockList
  108. if skillLockList and next(skillLockList) then
  109. fuwenGrid.skill = fuwenGrid.skill or {}
  110. for skillId in pairs(skillLockList) do
  111. allSkillCnt = allSkillCnt + 1
  112. fuwenGrid.skill[allSkillCnt] = skillId
  113. local skillCfg = FuwenExcel.skill[skillId]
  114. subTb[skillCfg.lv] = (subTb[skillCfg.lv] or 0) - 1
  115. choseSkill[skillCfg.groupID] = 1
  116. end
  117. local skillMaxNum = getFuwenSkillMaxCnt(fuwenConfig)
  118. if #fuwenGrid.skill >= skillMaxNum then
  119. for fuwenID, config in pairs(FuwenExcel.skill) do
  120. if config.isFuwenSkill == 1 then -- 符文技能
  121. subTb[config.lv] = -999
  122. end
  123. end
  124. end
  125. end
  126. --幸运重铸技能抽选
  127. if luckRefresh == 1 then
  128. cnt = #fuwenConfig.skillRate
  129. fuwenGrid.skill = fuwenGrid.skill or {}
  130. local skillConfig = FuwenExcel.skill
  131. local total = 0
  132. for i = 1,cnt do
  133. if fuwenConfig.skillRate[i][3] >= 1 or fuwenConfig.skillRate[i][4] >= 1 then
  134. total = total + fuwenConfig.skillRate[i][5]
  135. end
  136. end
  137. local randomNum = math.random(1, total)
  138. local skillGroup = nil
  139. for i = 1,cnt do
  140. if fuwenConfig.skillRate[i][3] >= 1 or fuwenConfig.skillRate[i][4] >= 1 then
  141. if randomNum <= fuwenConfig.skillRate[i][5] then
  142. skillGroup = fuwenConfig.skillRate[i]
  143. break
  144. else
  145. randomNum = randomNum - fuwenConfig.skillRate[i][5]
  146. end
  147. end
  148. end
  149. if skillGroup ~= nil then
  150. local primSkillCnt = (skillGroup[1] or 0) + (subTb[1] or 0)
  151. local inteSkillCnt = (skillGroup[2] or 0) + (subTb[2] or 0)
  152. local highSkillCnt = (skillGroup[3] or 0) + (subTb[3] or 0)
  153. local topSkillCnt = (skillGroup[4] or 0) + (subTb[4] or 0)
  154. --local isHighRare = true
  155. --if highSkillCnt >= 1 and topSkillCnt >= 1 then
  156. -- local randCnt = math.random(1, 2)
  157. -- if randCnt == 2 then
  158. -- isHighRare = false
  159. -- end
  160. --elseif topSkillCnt > 1 then
  161. -- isHighRare = false
  162. --end
  163. -- local allSkillCnt = 0
  164. local skillRandomIndex = 0
  165. for i = 1,primSkillCnt do
  166. local maxPrimSkillCnt = #FUWEN_SKILL_PRIM
  167. while true do
  168. skillRandomIndex = math.random(1,maxPrimSkillCnt)
  169. local newSkill = FUWEN_SKILL_PRIM[skillRandomIndex]
  170. if choseSkill[skillConfig[newSkill].groupID] == nil then
  171. allSkillCnt = allSkillCnt + 1
  172. fuwenGrid.skill[allSkillCnt] = newSkill
  173. choseSkill[skillConfig[newSkill].groupID] = 1
  174. break
  175. end
  176. end
  177. end
  178. for i = 1,inteSkillCnt do
  179. local maxInteSkillCnt = #FUWEN_SKILL_INTE
  180. while true do
  181. skillRandomIndex = math.random(1,maxInteSkillCnt)
  182. local newSkill = FUWEN_SKILL_INTE[skillRandomIndex]
  183. if choseSkill[skillConfig[newSkill].groupID] == nil then
  184. allSkillCnt = allSkillCnt + 1
  185. fuwenGrid.skill[allSkillCnt] = newSkill
  186. choseSkill[skillConfig[newSkill].groupID] = 1
  187. break
  188. end
  189. end
  190. end
  191. for i = 1,highSkillCnt do
  192. local maxHighSkillCnt = 0
  193. --if i == 1 and isHighRare then
  194. -- maxHighSkillCnt = #FUWEN_SKILL_RARE
  195. -- while true do
  196. -- skillRandomIndex = math.random(1,maxHighSkillCnt)
  197. -- local newSkill = FUWEN_SKILL_RARE[skillRandomIndex]
  198. -- if choseSkill[skillConfig[newSkill].groupID] == nil then
  199. -- allSkillCnt = allSkillCnt + 1
  200. -- fuwenGrid.skill[allSkillCnt] = newSkill
  201. -- choseSkill[skillConfig[newSkill].groupID] = 1
  202. -- break
  203. -- end
  204. -- end
  205. --else
  206. maxHighSkillCnt = #FUWEN_SKILL_HIGH
  207. while true do
  208. skillRandomIndex = math.random(1,maxHighSkillCnt)
  209. local newSkill = FUWEN_SKILL_HIGH[skillRandomIndex]
  210. if choseSkill[skillConfig[newSkill].groupID] == nil then
  211. allSkillCnt = allSkillCnt + 1
  212. fuwenGrid.skill[allSkillCnt] = newSkill
  213. choseSkill[skillConfig[newSkill].groupID] = 1
  214. break
  215. end
  216. end
  217. --end
  218. end
  219. for i = 1,topSkillCnt do
  220. local maxTopSkillCnt = 0
  221. if i == 1 and not isHighRare then
  222. maxTopSkillCnt = #FUWEN_SKILL_RARE
  223. while true do
  224. skillRandomIndex = math.random(1,maxTopSkillCnt)
  225. local newSkill = FUWEN_SKILL_RARE[skillRandomIndex]
  226. if choseSkill[skillConfig[newSkill].groupID] == nil then
  227. allSkillCnt = allSkillCnt + 1
  228. fuwenGrid.skill[allSkillCnt] = newSkill
  229. choseSkill[skillConfig[newSkill].groupID] = 1
  230. break
  231. end
  232. end
  233. else
  234. maxTopSkillCnt = #FUWEN_SKILL_TOP
  235. skillRandomIndex = math.random(1,maxTopSkillCnt)
  236. while true do
  237. skillRandomIndex = math.random(1,maxTopSkillCnt)
  238. local newSkill = FUWEN_SKILL_TOP[skillRandomIndex]
  239. if choseSkill[skillConfig[newSkill].groupID] == nil then
  240. allSkillCnt = allSkillCnt + 1
  241. fuwenGrid.skill[allSkillCnt] = newSkill
  242. choseSkill[skillConfig[newSkill].groupID] = 1
  243. break
  244. end
  245. end
  246. end
  247. end
  248. end
  249. return
  250. end
  251. -- 抽选技能组合
  252. cnt = #fuwenConfig.skillRate
  253. if cnt > 0 then
  254. fuwenGrid.skill = fuwenGrid.skill or {}
  255. local skillConfig = FuwenExcel.skill
  256. local total = 0
  257. for i = 1,cnt do
  258. total = total + fuwenConfig.skillRate[i][5]
  259. end
  260. local randomNum = math.random(1, total)
  261. local skillGroup = nil
  262. for i = 1,cnt do
  263. if randomNum <= fuwenConfig.skillRate[i][5] then
  264. skillGroup = fuwenConfig.skillRate[i]
  265. break
  266. else
  267. randomNum = randomNum - fuwenConfig.skillRate[i][5]
  268. end
  269. end
  270. if skillGroup ~= nil then
  271. local primSkillCnt = (skillGroup[1] or 0) + (subTb[1] or 0)
  272. local inteSkillCnt = (skillGroup[2] or 0) + (subTb[2] or 0)
  273. local highSkillCnt = (skillGroup[3] or 0) + (subTb[3] or 0)
  274. local topSkillCnt = (skillGroup[4] or 0) + (subTb[4] or 0)
  275. -- local allSkillCnt = 0
  276. local skillRandomIndex = 0
  277. for i = 1,primSkillCnt do
  278. local maxPrimSkillCnt = #FUWEN_SKILL_PRIM
  279. while true do
  280. skillRandomIndex = math.random(1,maxPrimSkillCnt)
  281. local newSkill = FUWEN_SKILL_PRIM[skillRandomIndex]
  282. if choseSkill[skillConfig[newSkill].groupID] == nil then
  283. allSkillCnt = allSkillCnt + 1
  284. fuwenGrid.skill[allSkillCnt] = newSkill
  285. choseSkill[skillConfig[newSkill].groupID] = 1
  286. break
  287. end
  288. end
  289. end
  290. for i = 1,inteSkillCnt do
  291. local maxInteSkillCnt = #FUWEN_SKILL_INTE
  292. while true do
  293. skillRandomIndex = math.random(1,maxInteSkillCnt)
  294. local newSkill = FUWEN_SKILL_INTE[skillRandomIndex]
  295. if choseSkill[skillConfig[newSkill].groupID] == nil then
  296. allSkillCnt = allSkillCnt + 1
  297. fuwenGrid.skill[allSkillCnt] = newSkill
  298. choseSkill[skillConfig[newSkill].groupID] = 1
  299. break
  300. end
  301. end
  302. end
  303. for i = 1,highSkillCnt do
  304. local maxHighSkillCnt = #FUWEN_SKILL_HIGH
  305. while true do
  306. skillRandomIndex = math.random(1,maxHighSkillCnt)
  307. local newSkill = FUWEN_SKILL_HIGH[skillRandomIndex]
  308. if choseSkill[skillConfig[newSkill].groupID] == nil then
  309. allSkillCnt = allSkillCnt + 1
  310. fuwenGrid.skill[allSkillCnt] = newSkill
  311. choseSkill[skillConfig[newSkill].groupID] = 1
  312. break
  313. end
  314. end
  315. end
  316. for i = 1,topSkillCnt do
  317. local maxTopSkillCnt = #FUWEN_SKILL_TOP
  318. while true do
  319. skillRandomIndex = math.random(1,maxTopSkillCnt)
  320. local newSkill = FUWEN_SKILL_TOP[skillRandomIndex]
  321. if choseSkill[skillConfig[newSkill].groupID] == nil then
  322. allSkillCnt = allSkillCnt + 1
  323. fuwenGrid.skill[allSkillCnt] = newSkill
  324. choseSkill[skillConfig[newSkill].groupID] = 1
  325. break
  326. end
  327. end
  328. end
  329. end
  330. end
  331. end
  332. function setFuwenSkillAttrByGM(human,fuwenID,attr1,val1,attr2,val2,skill1,skill2)
  333. local fuwen = {}
  334. fuwen.id = fuwenID
  335. fuwen.attr = {}
  336. fuwen.skill = {}
  337. fuwen.attr[1] = {attr1,val1}
  338. fuwen.attr[2] = {attr2,val2}
  339. fuwen.skill[1] = skill1
  340. fuwen.skill[2] = skill2
  341. FuwenLogic.addByGrid(human,fuwen,"gm")
  342. end
  343. -- 返回符文背包空余格子数
  344. function getEmptyCnt(human)
  345. local emptyCnt = 0
  346. for i = 1, FuwenDefine.FUWEN_BAG_MAX_CNT do
  347. if human.db.fuwenBag[i] == nil then
  348. emptyCnt = emptyCnt + 1
  349. end
  350. end
  351. return emptyCnt
  352. end
  353. -- 获得符文背包第一个空格子下标
  354. function getEmptyIndex(human)
  355. for index = 1, FuwenDefine.FUWEN_BAG_MAX_CNT do
  356. local grid = human.db.fuwenBag[index]
  357. if grid == nil then
  358. return index
  359. end
  360. end
  361. end
  362. function checkEmptyCnt(human,itemCnt)
  363. if itemCnt > getEmptyCnt(human) then
  364. return Broadcast.sendErr(human,Lang.COMMON_BAG_FULL)
  365. end
  366. return true
  367. end