|
|
@@ -0,0 +1,190 @@
|
|
|
+--境界系统
|
|
|
+--[=[
|
|
|
+ 数据库存储数据: human.db.realmLv
|
|
|
+ 只存境界等级,境界的属性加成等则是实时计算
|
|
|
+]=]--
|
|
|
+
|
|
|
+local Msg = require("core.Msg")
|
|
|
+local BagLogic = require("bag.BagLogic")
|
|
|
+local realmConfig = require("excel.realm").Sheet1
|
|
|
+local Grid = require("bag.Grid")
|
|
|
+local RoleAttr = require("role.RoleAttr")
|
|
|
+local RoleDefine = require("role.RoleDefine")
|
|
|
+local ObjHuman = require("core.ObjHuman")
|
|
|
+local Util = require("common.Util")
|
|
|
+local REALM_UPGRADE_LOG = "realmUpgrade"
|
|
|
+
|
|
|
+
|
|
|
+--加万分比的属性
|
|
|
+local sp_attr = {
|
|
|
+ [201] = 1,
|
|
|
+ [202] = 1,
|
|
|
+ [203] = 1,
|
|
|
+ [204] = 1
|
|
|
+}
|
|
|
+
|
|
|
+local function calAttrSum(tbl, lv)
|
|
|
+ for i = 1, lv do
|
|
|
+ local cfg = realmConfig[i]
|
|
|
+ if cfg and cfg.attrs then
|
|
|
+ for k,v in ipairs(cfg.attrs) do
|
|
|
+ local id = v[1]
|
|
|
+ local value = v[2]
|
|
|
+ tbl[k] = tbl[k] or {}
|
|
|
+ tbl[k].key = id
|
|
|
+ if sp_attr[id] then
|
|
|
+ tbl[k].value = (tbl[k].value or 0) + (value / 100)
|
|
|
+ else
|
|
|
+ tbl[k].value = (tbl[k].value or 0) + value
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+local function sendToclient(human)
|
|
|
+ local realmLv = human.db and human.db.realmLv or 0
|
|
|
+ local msgRet = Util.copyTable(Msg.gc.GC_ROLE_REALM_QUERY)
|
|
|
+
|
|
|
+ local bl = false
|
|
|
+ if realmLv <= 0 then
|
|
|
+ bl = true
|
|
|
+ msgRet.nowRealmName = ""
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ local nowRealmCfg = bl and realmConfig[1] or realmConfig[realmLv]
|
|
|
+ if not nowRealmCfg then
|
|
|
+ return
|
|
|
+ end
|
|
|
+ if not bl then
|
|
|
+ msgRet.nowRealmName = nowRealmCfg.name
|
|
|
+ end
|
|
|
+
|
|
|
+ local attrsCfg = nowRealmCfg.attrs
|
|
|
+ msgRet.nowAttrs[0] = #attrsCfg
|
|
|
+
|
|
|
+ if bl then
|
|
|
+ for k,v in ipairs(attrsCfg) do
|
|
|
+ msgRet.nowAttrs[k] = msgRet.nowAttrs[k] or {}
|
|
|
+ msgRet.nowAttrs[k].key = v[1] or 0
|
|
|
+ msgRet.nowAttrs[k].value = 0
|
|
|
+ end
|
|
|
+ else
|
|
|
+ calAttrSum(msgRet.nowAttrs, realmLv)
|
|
|
+ end
|
|
|
+
|
|
|
+ local itemId, itemCnt, nextRealmCfg
|
|
|
+ if realmLv < #realmConfig then
|
|
|
+ nextRealmCfg = realmConfig[realmLv + 1]
|
|
|
+ if not nextRealmCfg then
|
|
|
+ return
|
|
|
+ end
|
|
|
+ itemCnt = nextRealmCfg.itemCnt
|
|
|
+ calAttrSum(msgRet.nextAttrs, realmLv+1)
|
|
|
+ else
|
|
|
+ nextRealmCfg = realmConfig[realmLv]
|
|
|
+ itemCnt = 0
|
|
|
+ calAttrSum(msgRet.nextAttrs, realmLv)
|
|
|
+ end
|
|
|
+ itemId = nextRealmCfg.itemId
|
|
|
+ Grid.makeItem(msgRet.itemData, itemId, itemCnt)
|
|
|
+
|
|
|
+ msgRet.nextRealmName = nextRealmCfg.name
|
|
|
+
|
|
|
+ msgRet.nextAttrs[0] = #nextRealmCfg.attrs
|
|
|
+
|
|
|
+ Msg.send(msgRet, human.fd)
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+--境界对属性加成
|
|
|
+function doCalcHero(human, attrs)
|
|
|
+ if not human then
|
|
|
+ return
|
|
|
+ end
|
|
|
+ local realmLv = human.db and human.db.realmLv or 0
|
|
|
+ if realmLv <= 0 then
|
|
|
+ return
|
|
|
+ end
|
|
|
+ for i=1, realmLv do
|
|
|
+ local singleCfg = realmConfig[i]
|
|
|
+ if singleCfg and singleCfg.attrs then
|
|
|
+ for _, v in ipairs(singleCfg.attrs) do
|
|
|
+ if v[2] > 0 then
|
|
|
+ RoleAttr.updateValue(v[1], v[2], attrs)
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+--获取境界名字
|
|
|
+function getRealmName(human)
|
|
|
+ local name = ""
|
|
|
+ if human.db and human.db.realmLv then
|
|
|
+ local singleCfg = realmConfig[human.db.realmLv]
|
|
|
+ if singleCfg and singleCfg.name then
|
|
|
+ name = singleCfg.name
|
|
|
+ end
|
|
|
+ end
|
|
|
+ return name
|
|
|
+end
|
|
|
+
|
|
|
+--红点判断
|
|
|
+function isDot(human)
|
|
|
+ local realmLv = human.db.realmLv or 0
|
|
|
+ if realmLv >= #realmConfig then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local singleCfg = realmConfig[1]
|
|
|
+ if realmLv > 0 then
|
|
|
+ singleCfg = realmConfig[realmLv + 1]
|
|
|
+ end
|
|
|
+ if not singleCfg then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+ local itemId = singleCfg.itemId
|
|
|
+ local itemCnt = singleCfg.itemCnt
|
|
|
+ if BagLogic.getItemCnt(human, itemId) < itemCnt then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+ return true
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+--查询
|
|
|
+function query(human)
|
|
|
+ sendToclient(human)
|
|
|
+end
|
|
|
+
|
|
|
+--提升境界
|
|
|
+function realmUpgrade(human)
|
|
|
+ local realmLv = human.db.realmLv or 0
|
|
|
+
|
|
|
+ if realmLv >= #realmConfig then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ realmLv = realmLv + 1
|
|
|
+ local singleCfg = realmConfig[realmLv]
|
|
|
+ if not singleCfg then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local itemId = singleCfg.itemId
|
|
|
+ local itemCnt = singleCfg.itemCnt
|
|
|
+ if not BagLogic.checkItemCnt(human, itemId, itemCnt) then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ BagLogic.delItem(human, itemId, itemCnt, REALM_UPGRADE_LOG)
|
|
|
+ human.db.realmLv = realmLv
|
|
|
+ sendToclient(human)
|
|
|
+ RoleAttr.cleanHeroAttrCache(human)
|
|
|
+ RoleAttr.doCalc(human)
|
|
|
+ ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
|
|
|
+end
|