123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- RoleAttr = {}
- local this = {}
- ---@class RoleAttrProgrammeData
- ---@field current number 当前方案
- ---@field freeSwitchAttrPointData table<number,FreeSwitchAttrPointData>
- ---@class FreeSwitchAttrPointData
- ---@field id number
- ---@field attr table
- ---@field name string
- this.ROLE_ATTR_CHANGE_LINE_KEY = "T$_ROLE_ATTR_CHANGE_LINE_KEY"
- RoleAttrKey = {
- UNION_ARMBAND_LEVEL = "roleunionarmbandlevelattrkey", -- 战盟臂章等级属性
- UNION_ARMBAND_STRONG = "roleunionarmbandstrongattrkey", -- 战盟臂章强化属性
- PRIVILEGE_MONTH_DROP_RATE = "privilegemonthdroprateattrpointkey", -- 月卡特权增加爆率
- EXP_BOOST_ITEM_USE = "roleexpboostitemuseattrpointkey", -- 经验药水使用增加杀怪经验提升
- VIP_GIFT_PACK = "rolevipgiftpackprivilegekey", -- VIP特权增加属性
- ANGEL_MAJOR_EQUIPMENT = "roleangelmajorattrkey_%s", -- 大天使装备属性
- ANGEL_MAJOR_TALENT = "roleangelmajorattrkey", -- 大天使天赋属性
- ANGEL_GRAIL = "roleangelgrailattrkey_%s", -- 大天使圣杯属性
- PRIVILEGE_EXP_BOOST = "roleexpboostprivilegekey", -- 经验提升特权
- ANGEL_GRAIL_SUIT = "roleangelgrailsuitattrkey", -- 大天使圣杯套装属性
- }
- function RoleAttr.levelup(actor, level, oldlevel)
- this.addAttrPointByCareer(actor, level, oldlevel)
- end
- -- 添加属性,并把属性保存起来,下次添加属性自动叠加
- function RoleAttr.addAndSaveRoleAttr(actor, key, attr_map)
- this.addAndSaveRoleAttr(actor, key, attr_map)
- end
- -- 减少属性,并把属性保存起来,下次添加属性自动相减
- function RoleAttr.reduceAndSaveRoleAttr(actor, key, attr_map)
- this.reduceAndSaveRoleAttr(actor, key, attr_map)
- end
- -- 清空指定Key的属性和保存的数据
- function RoleAttr.clearRoleAttrAndDB(actor, key)
- this.clearRoleAttrAndDB(actor, key)
- end
- function RoleAttr.createrole(actor)
- -- this.createRoleAddAttrPointByCareer(actor)
- end
- function RoleAttr.setPrivilegeAttrPointProgramme(actor, data)
- this.setPrivilegeAttrPointProgramme(actor, data)
- end
- function RoleAttr.getPrivilegeAttrPointProgramme(actor)
- local data = this.getPrivilegeData(actor)
- this.jprint("--- 获取属性点方案数据 ---")
- this.jprint(data)
- sendluamsg(actor, LuaMessageIdToClient.RES_GET_ROLE_ATTR_POINT_PROGRAMME, data)
- end
- function RoleAttr.changePrivilegeAttrPointProgramme(actor, key)
- this.changePrivilegeAttrPointProgramme(actor, key)
- end
- -----------------------------------
- function this.createRoleAddAttrPointByCareer(actor)
- --local level = getbaseinfo(actor, "level")
- --this.addAttrPointByCareer(actor, level, 0)
- end
- function this.setPrivilegeAttrPointProgramme(actor, param)
- local data = this.getPrivilegeData(actor)
- if table.isEmpty(data) then
- data = {}
- data.current = 1
- end
- this.jprint("--- param ---")
- this.jprint(param)
- if table.isEmpty(data.freeSwitchAttrPointData) then
- data.freeSwitchAttrPointData = {}
- end
- data.freeSwitchAttrPointData[param.id] = param
- this.setPrivilegeData(actor, data)
- RoleAttr.getPrivilegeAttrPointProgramme(actor)
- end
- ---@return RoleAttrProgrammeData
- function this.getPrivilegeData(actor)
- return getplaydef(actor, this.ROLE_ATTR_CHANGE_LINE_KEY)
- end
- function this.setPrivilegeData(actor, data)
- setplaydef(actor, this.ROLE_ATTR_CHANGE_LINE_KEY, data)
- end
- function this.changePrivilegeAttrPointProgramme(actor, key)
- local is_has = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.SWITCHING_POINT_SCHEME)
- if not is_has then
- this.jprint("玩家没有权限")
- return
- end
- local data = this.getPrivilegeData(actor)
- if table.isEmpty(data) then
- sendluamsg(actor, LuaMessageIdToClient.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME, key)
- return
- end
- this.jprint("key")
- this.jprint(key)
- this.jprint("--- data ---")
- this.jprint(data)
- if data.current == key then
- this.jprint("当前方案和要切换的方案一样,无需切换")
- return
- end
- data.current = key
- this.setPrivilegeData(actor, data)
- resetattrpoint(actor, 1, 0)
- local programme_data = data.freeSwitchAttrPointData[key]
- if table.isEmpty(programme_data) then
- sendluamsg(actor, LuaMessageIdToClient.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME, key)
- return
- end
- this.jprint("-- programme_data --")
- this.jprint(programme_data)
- if not table.isEmpty(programme_data.attr) then
- attr_map = {}
- for _, v in pairs(programme_data.attr) do
- attr_map[v.type] = v.num
- end
- this.jprint("-- attr_map --")
- this.jprint(attr_map)
- deployattrpoint(actor, attr_map, 1)
- end
- sendluamsg(actor, LuaMessageIdToClient.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME, key)
- end
- function this.addAttrPointByCareer(actor, level, oldlevel)
- this.jprint(oldlevel)
- this.jprint(level)
- local career = getbaseinfo(actor, "getbasecareer")
- career = tonumber(career)
- this.jprint("职业:" .. career)
- local key = "";
- if career == 1 then
- key = "swordsmanAttribute"
- end
- if career == 2 then
- key = "magicianAttribute"
- end
- if career == 3 then
- key = "archerAttributes"
- end
- if career == 4 then
- key = "magicSwordsmanAttribute"
- end
- if career == 5 then
- key = "saintMentorAttribute"
- end
- if career == 6 then
- key = "summonerAttribute"
- end
- if key == "" then
- this.jprint("职业错误")
- return
- end
- local attr_map = this.getAttrMap(actor)
- for i = oldlevel + 1, level do
- this.calculAttr(actor, i, key, attr_map)
- end
- if next(attr_map) == nil then
- return
- end
- this.jprint("添加属性点")
- this.jprint(attr_map)
- this.setAttrMap(actor, attr_map)
- addrolekmlattributes(actor, "luaaddattrpointbycareer", attr_map)
- end
- function this.getAttrMap(actor)
- local data = getplaydef(actor, "T$_luaaddattrpointbycareer")
- if data == nil then
- data = {}
- end
- return data
- end
- function this.setAttrMap(actor, attr_map)
- setplaydef(actor, "T$_luaaddattrpointbycareer", attr_map)
- end
- function this.calculAttr(actor, level, key, attr_map)
- local attr_map_str = ConfigDataManager.getTableValue("cfg_level", key, "id", level)
- if attr_map_str == nil or attr_map_str == "" then
- return
- end
- local map = string.toIntIntMap(attr_map_str, "#", "|")
- this.jprint("map")
- for attr_id, value in pairs(map) do
- this.jprint(attr_id)
- this.jprint(value)
- local attr_value = attr_map[attr_id]
- this.jprint("attr_value")
- this.jprint(attr_value)
- if attr_value ~= nil and tonumber(attr_value) > 0 then
- attr_value = attr_value + value
- else
- attr_value = value
- end
- attr_map[attr_id] = attr_value
- end
- end
- function this.addAndSaveRoleAttr(actor, key, attr_map)
- if table.isEmpty(attr_map) then
- return
- end
- local db_key = "T$_" .. key
- local data = getplaydef(actor, db_key)
- if table.isEmpty(data) then
- data = attr_map
- else
- for attr_id, value in pairs(attr_map) do
- if data[attr_id] == nil then
- data[attr_id] = value
- else
- data[attr_id] = data[attr_id] + value
- end
- end
- end
- setplaydef(actor, db_key, data)
- addrolekmlattributes(actor, key, data)
- this.jprint("---- 添加属性 ----")
- this.jprint("key")
- this.jprint(key)
- this.jprint("data")
- this.jprint(data)
- end
- function this.reduceAndSaveRoleAttr(actor, key, attr_map)
- if table.isEmpty(attr_map) then
- return
- end
- local db_key = "T$_" .. key
- local data = getplaydef(actor, db_key)
- if table.isEmpty(data) then
- data = {}
- end
- for attr_id, value in pairs(attr_map) do
- if data[attr_id] ~= nil then
- data[attr_id] = math.max(0, data[attr_id] - value)
- end
- end
- setplaydef(actor, db_key, data)
- addrolekmlattributes(actor, key, data)
- end
- function this.clearRoleAttrAndDB(actor, key)
- local db_key = "T$_" .. key
- setplaydef(actor, db_key, {})
- addrolekmlattributes(actor, key, {})
- end
- ---------------------------- 日志打印 -----------------------------
- this.log_open = false
- function this.jprint(param)
- if not this.log_open then
- return
- end
- if param == nil then
- param = "error! 输出内容为空. nil"
- end
- jprint(param)
- end
- function this.loginfo(actor, param)
- if not this.log_open then
- return
- end
- if param == nil then
- param = "error! 日志输出内容为空. nil"
- end
- jprint(param)
- info(actor, param)
- end
- -- 设置角色属性加成方式
- function RoleAttr.setRoleAttAddWay(actor, msgData)
- local addAttWay = setroleattaddway(actor, msgData[1])
- sendluamsg(actor, LuaMessageIdToClient.RES_ROLE_ATT_ADD_WAY, addAttWay)
- end
- -- 设置角色属性加成方式
- function RoleAttr.getRoleAttAddWay(actor)
- local addAttWay = getrolefield(actor, "role.RoleAttribute.attrAddWay")
- sendluamsg(actor, LuaMessageIdToClient.RES_ROLE_ATT_ADD_WAY, addAttWay)
- end
- function RoleAttr.transferCareer(actor, careerName)
- local wash = ConfigDataManager.getTableValue("cfg_career", "wash", "name", careerName)
- if tonumber(wash) == 1 then
- resetattrpoint(actor, 1)
- end
- local rec = getplaydef(actor, PlayerDefKey.player.CAREER_REC)
- local msgData = {}
- if not string.isNullOrEmpty(rec) then
- msgData[1] = rec
- setplaydef(actor, PlayerDefKey.player.CAREER_REC, nil)
- else
- local careerRec = ConfigDataManager.getTableValue("cfg_career", "careerRec", "name", careerName)
- local careerRecTable = string.split(careerRec, "|")
- if #careerRecTable ~= 1 then
- msgData[1] = -1
- end
- end
- if not table.isNullOrEmpty(msgData) then
- RoleAttr.setRoleAttAddWay(actor, msgData)
- end
- end
- -- @description 脚本计算角色最终属性
- -- @param 玩家对象
- -- @return
- function RoleAttr.CalcPlayFinalAttr(actor)
- --攻速加成=(1+attackSpeed*攻击速度转换系数)*(AniSpeedBonus)-1
- local aniSpeed = getattrinfo(actor, "attackSpeed")
- local aniSpeedBonus = getattrinfo(actor, "AniSpeedBonus")
- local coefficient = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", 7001))
- if coefficient == nil then
- coefficient = 0.0067
- else
- coefficient = coefficient / 10000
- end
- local atkSpeed = (1 + aniSpeed * coefficient) * aniSpeedBonus - 1
- --jprint(name,"属性计算","aniSpeed",aniSpeed)
- --jprint(name,"属性计算","coefficient",coefficient)
- --jprint(name,"属性计算","aniSpeedBonus",aniSpeedBonus)
- --jprint(name,"属性计算","aniSpeed",aniSpeed)
- --jprint(name,"属性计算","attackSpeedBonus",atkSpeed)
- local id = attrname2id("attackSpeedBonus")
- local remarks = tonumber(ConfigDataManager.getTableValue("cfg_att_info", "remarks", "id", id))
- if remarks == 2 then
- atkSpeed = atkSpeed * 10000
- if atkSpeed < 0 then
- atkSpeed = 0
- end
- end
- local ret = {}
- local innerData = { id = id, value = atkSpeed }
- table.insert(ret, innerData)
- -- 自动恢复魔法
- local mpRecovery = getattrinfo(actor, "MPFullRecoverRate")
- if mpRecovery and mpRecovery ~= "" and mpRecovery > 0 then
- local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO)
- if not table.isEmpty(roleInfo) then
- local exist = false
- for _, v in pairs(roleInfo) do
- if actor:toString() == v["actor"]:toString() then
- exist = true
- end
- end
- if not exist then
- table.insert(roleInfo, {
- actor = actor,
- recovery = mpRecovery
- })
- setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo)
- end
- else
- local temp = {}
- table.insert(temp, {
- actor = actor,
- recovery = mpRecovery
- })
- setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, temp)
- GlobalTimer.setontimerex(TimerIds.AUTO_RECOVERY_MAGIC, TimeUnit.SECOND * 3)
- end
- end
- return ret
- end
- --- 自动恢复魔法
- function RoleAttr.autoRecoveryMagic()
- local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO)
- if not table.isEmpty(roleInfo) then
- for key, actorInfo in pairs(roleInfo) do
- local actor = actorInfo["actor"]
- local mpFullRecoverRate = actorInfo["recovery"]
- if mpFullRecoverRate > 0 then
- local mp = getbaseinfo(actor, "mp")
- local maxMp = getbaseinfo(actor, "maxmp")
- local incrementMp = maxMp * mpFullRecoverRate
- if mp + incrementMp > maxMp then
- setmp(actor, maxMp)
- table.remove(roleInfo, key)
- else
- setmp(actor, mp + incrementMp)
- end
- else
- table.remove(roleInfo, key)
- end
- end
- setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo)
- if table.isEmpty(roleInfo) then
- GlobalTimer.setofftimer(TimerIds.AUTO_RECOVERY_MAGIC)
- end
- end
- end
- --- 切换地图后将actor对象mapId修改
- ---@param actor table 玩家对象
- ---@param mapCfgId number 地图配置id
- function RoleAttr.enterMap(actor, mapCfgId)
- local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO)
- if not table.isEmpty(roleInfo) then
- for k, v in pairs(roleInfo) do
- local player = v["actor"]
- local recovery = v["recovery"]
- if player:toString() == actor:toString() then
- local getActor = getactor(actor, player:toString(), gamemap.getMapKey(mapCfgId, 1))
- table.remove(roleInfo, k)
- table.insert(roleInfo, {
- actor = getActor,
- recovery = recovery
- })
- break
- end
- end
- setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo)
- end
- end
|