local OfficialPrivilege_Controller = {} local private = {} local opt2Interact = { [MDL.OfficialPrivilege.OptType.Inquire] = MDL.PlayerInteract.InteractType.Inquire, [MDL.OfficialPrivilege.OptType.Silence] = MDL.PlayerInteract.InteractType.Silence, [MDL.OfficialPrivilege.OptType.Punishment] = MDL.PlayerInteract.InteractType.Punishment, [MDL.OfficialPrivilege.OptType.Promote] = MDL.PlayerInteract.InteractType.Promote, } local interact2Opt = { [MDL.PlayerInteract.InteractType.Inquire] = MDL.OfficialPrivilege.OptType.Inquire, [MDL.PlayerInteract.InteractType.Silence] = MDL.OfficialPrivilege.OptType.Silence, [MDL.PlayerInteract.InteractType.Punishment] = MDL.OfficialPrivilege.OptType.Punishment, [MDL.PlayerInteract.InteractType.Promote] = MDL.OfficialPrivilege.OptType.Promote, } OfficialPrivilege_Controller.LimitType = { ConsumeOrOwn = 1, -- 消耗/拥有 UseNum = 2, -- 使用次数 BeUseNum = 3, -- 被使用次数 } OfficialPrivilege_Controller.LimitUIType = { NoItem = 0, -- ui中仅文字 HaveItem = 1, -- ui中有item展示 } function OfficialPrivilege_Controller.OnStartup() private.rightsDataList = {} private.rightsBuffContinueTime = {} OfficialPrivilege_Controller.RightsDataListSort() end function OfficialPrivilege_Controller.OnShutdown() end local function SortRights(a, b) if a.GradeID ~= b.GradeID then return a.GradeID > b.GradeID end return a.RightsID < b.RightsID end local function IpairsValue(tab, i) i = i + 1 local data = tab[i] if data then return i, tab[i] else return nil end end function OfficialPrivilege_Controller.RightsDataListSort() local index = 1 for _, v in DataSheetManager.OfficialRights:GetEnumerator() do private.rightsDataList[index] = v index = index + 1 end for i = #private.rightsDataList, index, -1 do table.remove(private.rightsDataList, i) end table.sort(private.rightsDataList, SortRights) end function OfficialPrivilege_Controller.GetSortedRightsDataIterator() return IpairsValue, private.rightsDataList, 0 end function OfficialPrivilege_Controller.GetIsEnableOpt(rightsData, titleId, targetRank) local gradeID = MDL.OfficialPosition.GetCurGradeID() if gradeID == 0 or gradeID > rightsData.GradeID then --自己品阶不满足,没有该特权 return false end local targetTitleData = nil if titleId > 0 then targetTitleData = DataSheetManager.OfficialPosition:GetDataByID(titleId) if targetTitleData == nil then --无官职 return false end else return false end local targetGradeId = targetTitleData.GradeID local scope = rightsData.Scope if targetGradeId > scope[1] or targetGradeId < scope[2] then --目标品阶不在范围内 return false end if rightsData.Lower > 0 and targetGradeId - rightsData.Lower < gradeID then --目标品阶在自己的职权品阶范围之外 return false end if rightsData.RightsID ~= MDL.OfficialPrivilege.OptType.Inquire and targetGradeId < gradeID then --目标品阶高于自己 return false end --如果品阶跟自己一致,需要判断演武排名 if rightsData.RightsID ~= MDL.OfficialPrivilege.OptType.Inquire and targetGradeId == gradeID then local curRank = MDL.SoloFight.GetSelfRankId() or 0 --排名比自己靠前 if targetRank and targetRank > 0 and targetRank < curRank then return false end end return true end function OfficialPrivilege_Controller.AddOptBtn(btnList, titleId, rank, server) if server > 0 and server ~= MDL.Login.GetServerShowId() then --不同服不加 return end for _, v in OfficialPrivilege_Controller.GetSortedRightsDataIterator() do if v.IfUse and OfficialPrivilege_Controller.GetIsEnableOpt(v, titleId, rank) then local type = opt2Interact[v.RightsID] table.insert(btnList, type) end end end function OfficialPrivilege_Controller.ExecuteInteractOptBtn(interactType, acid) local optType = interact2Opt[interactType] MDL.OfficialPrivilege.OfficialPrivilegeOptRequest(optType, acid) end -- 根据rightsData数据返回操作记录的str -- recordData操作记录数据 -- isUse 自身是否是使用者 function OfficialPrivilege_Controller.GetRecordStr(recordData) local isUse = recordData.optAcid == BattleDataGetter.GetAcID() local otherName = isUse and recordData.targetName or recordData.optName local rightsData = DataSheetManager.OfficialRights:GetDataByRightsID(recordData.optType) local showIds = isUse and rightsData.UseRecord or rightsData.UsedRecord if recordData.optType == MDL.OfficialPrivilege.OptType.Inquire then local goodsItem = DataSheetManager.ItemData:GetDataByID(rightsData.ItemID) return string.FormatByIdsKey(showIds, otherName, string.format("%s%s", rightsData.Parm[1], UIUtils.GetLocalizedTxt(Const_IDS[goodsItem.Name]))) elseif recordData.optType == MDL.OfficialPrivilege.OptType.Silence or recordData.optType == MDL.OfficialPrivilege.OptType.Punishment then return string.FormatByIdsKey(showIds, otherName, OfficialPrivilege_Controller.GetRightsBuffContinueTime(rightsData)) else return string.FormatByIdsKey(showIds, otherName) end end function OfficialPrivilege_Controller.GetRightsBuffContinueTime(rightsData) if private.rightsBuffContinueTime[rightsData.RightsID] == nil then local buffID = 0 if rightsData.RightsID == MDL.OfficialPrivilege.OptType.Strengthen then buffID = DataSheetManager.OfficialRightsPower:GetDataByPowerLevel(1).BuffID else buffID = rightsData.BuffID end local townBuffShowData = DataSheetManager.CapitalBuffData:GetDataByRelateID(buffID) private.rightsBuffContinueTime[rightsData.RightsID] = townBuffShowData.BuffDuration / 1000 -- 表中配置为毫秒。此处转换为秒 end return UTL.Time.GetShowTimeBySeconds(private.rightsBuffContinueTime[rightsData.RightsID]) end function OfficialPrivilege_Controller.ShowOfficialPrivilegeSuccess(rightsId) if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIOfficialPrivilegeSuccessPopUp) then if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIRewardGainPanel) then private.isRecoverGainPanel = true UIManager.OpenAndPush(Const_UI_Lua.UIEnum.UIOfficialPrivilegeSuccessPopUp, { RightsID = rightsId }, nil, Const_UI_Lua.UIEnum.UIRewardGainPanel) else private.isRecoverGainPanel = false UIManager.OpenView(Const_UI_Lua.UIEnum.UIOfficialPrivilegeSuccessPopUp, { RightsID = rightsId }) end end end function OfficialPrivilege_Controller.OnOfficialPrivilegeSuccessClose() if private.isRecoverGainPanel then private.isRecoverGainPanel = false UIManager.RecoverView() end end function OfficialPrivilege_Controller.ShowOfficialPrivilegeCostNotEnough(rightsID) local rightsData = DataSheetManager.OfficialRights:GetDataByRightsID(rightsID) UTL.MessageBox.ShowOKCancelBox(UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_InsufficientProps), string.FormatByIdsId(Const_IDS.IDS_OfficialPrivilege_InsufficientPropsDes, UTL.Item.GetItemColorName(rightsData.ItemID)), function() local sourcesList = MDL.ItemSources.GetItemSourcesById(rightsData.ItemID) if #sourcesList > 0 then CTL.ItemSources.ExecuteSourceFunctionById(sourcesList[1].sourceId, rightsData.ItemID) end end, nil, UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_Go)) end function OfficialPrivilege_Controller.CheckOfficialPrivilegeCanUse(rightsData, effectLevel) local rightsID = rightsData.RightsID local infoNum = MDL.OfficialPrivilege.GetPrivilegeInfoNum(rightsID) local offset = rightsData.UseTimes - infoNum if offset <= 0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OfficialPrivilege_UseLimit"..rightsID]) return false end return true end ---------- start 红点逻辑 start ---------- function OfficialPrivilege_Controller.CheckOfficialPrivilegeRedPoint() for _, v in OfficialPrivilege_Controller.GetSortedRightsDataIterator() do if v.RightsID == MDL.OfficialPrivilege.OptType.Inquire then local infoNum, _ = MDL.OfficialPrivilege.GetPrivilegeInfoNum(v.RightsID) local isArriveGrade = CTL.OfficialPosition.CheckIfUnlock(v.GradeID) if isArriveGrade and infoNum < v.UseTimes then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.OfficialPosition_Privilege_Inquire) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.OfficialPosition_Privilege_Inquire) end end end end ---------- end 红点逻辑 end ---------- return OfficialPrivilege_Controller