local EventSystem = require('Event/EventSystem')
local Player_Controller = {}
local private = {}
local energyTimeHandle = nil
local ENERGYID = 2 --体力id
local MaxEnergy = DataSheetManager.ConstData:GetDataByID("MaxEnergy").IntValue
local JSON = require("cjson")
local EmojiSex =
{
"
", --"[male]",
"
",
}
local common_pb = require "Proto.common_pb"
--region -- **************** 数据部分 ******************* --
--endregion 数据部分
function Player_Controller.OnStartup()
EventSystem.Regist(EventID.FunctionUnlockUpdate, Player_Controller.ShowEnergyHint)
EventSystem.Regist(EventID.UI_Energy_Refresh, Player_Controller.ShowEnergyHint)
end
function Player_Controller.GetNobilityTeamLevelStr(level)
local teamLevelData = DataSheetManager.TeamLevelData:GetDataByTeamLevel(level)
local teamLevelLocStr = string.FormatByIdsId(Const_IDS[teamLevelData.TeamLevelName], UTL.Item.GetNobilityByTeamLevel(teamLevelData.TeamLevel))
return teamLevelLocStr
end
function Player_Controller.OperateGenderImage(imageState, gender)
if gender > 0 then
imageState:SetState(gender - 1)
UIUtils.SetActive(imageState, true)
else
UIUtils.SetActive(imageState, false)
end
end
function Player_Controller.UpdateRoleInfo(roleInfo)
local level = MDL.Player.GetRoleLevel()
local exp = MDL.Player.GetRoleLevelExp()
local rankId = MDL.Player.GetRoleRankID()
MDL.Player.SetRoleInfo(roleInfo.TeamLevel,roleInfo.TeamLevelExp,roleInfo.TeamRankID,roleInfo.attr,roleInfo.Gs)
if roleInfo.TeamLevel>level then
private.TeamLevelUp(level,roleInfo.TeamLevel)
EventSystem.Dispatch(EventID.BI_ReachLevel, roleInfo.TeamLevel)
end
if exp~=roleInfo.TeamLevelExp and BattleDataGetter.IsOnlineTownLevel() then
EventSystem.Dispatch(EventID.UI_RefreshExp)
end
EventSystem.Dispatch(EventID.UI_UpdateRoleInfo)
end
function Player_Controller.AddEnergy(info)
if energyTimeHandle then
TimerUtil.Remove(energyTimeHandle)
end
if MDL.Player.GetEnergyValue() < MaxEnergy then
if MDL.Player.GetNextEnergyTime() <= 0 then
private.CalculateEnergy()
else
energyTimeHandle = TimerUtil.Interval(private.CalculateEnergy,MDL.Player.GetNextEnergyTime(), 1)
end
else
Player_Controller.ShowEnergyHint()
end
end
function Player_Controller.ShowEnergyHint(fucId, isComplete)
if fucId and isComplete then
if MDL.Player.GetEnergyValue() >= MaxEnergy then
if fucId == MDL.Unlock.FunctionType.EnergyMaxHint then
CTL.HomeMain.AddMainNotice(CTL.HomeMain.NoticeType.FullEnergy, private.OpenFullEnergyPanel)
end
else
CTL.HomeMain.RemoveMainNotice(CTL.HomeMain.NoticeType.FullEnergy)
end
else
if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.EnergyMaxHint) then
if MDL.Player.GetEnergyValue() >= MaxEnergy then
CTL.HomeMain.AddMainNotice(CTL.HomeMain.NoticeType.FullEnergy, private.OpenFullEnergyPanel)
else
CTL.HomeMain.RemoveMainNotice(CTL.HomeMain.NoticeType.FullEnergy)
end
end
end
end
function Player_Controller.GetSexEmojiKey(sex)
return EmojiSex[sex]
end
function private.OpenFullEnergyPanel()
UIManager.OpenView(Const_UI_Lua.UIEnum.UIEnergyFullPanel)
end
function private.CalculateEnergy()
local info = MDL.Player.GetEnergyInfo()
info.Count = info.Count + 1
info.energyRestoreTime = UTL.Time.GetServerTimestamp()
MDL.Player.SetEnergyInfo(info)
end
function private.TeamLevelUp(preLevel,curlevel)
if not GameAppInfo.IsVietnamPackage() then
SDKUtil.RoleLevelUp(curlevel)
end
if BattleDataGetter.IsOnlineTownLevel() then
private.ShowLevelUpEffect()
else
CTL.HomeMain.AddTownHomeDelayFuncNoUI(private.ShowLevelUpEffect)
end
EventSystem.Dispatch(EventID.TeamLevelUpdate)
EventSystem.Dispatch(EventID.OnConditionChangeFunctionUpdate, LuaConst.UnlockConditionType.TeamLevel)
end
function private.ShowLevelUpEffect()--中文播特效 其它语言ui界面显示加特效
if Localization.IsChinese() then
NotSyncBattleSetter.MainPlayerPlayEffectByType(LuaConst.EffectType.TeamLevelUp)
else
EventSystem.Dispatch(EventID.UI_TeamLevelUpdate)
NotSyncBattleSetter.MainPlayerPlayEffectByType(LuaConst.EffectType.OtherLanguageTeamLevelUp)
end
end
function Player_Controller.SetNetSecProtectData()
if DEF.USE_YIDUN_PROTECT then
local accid = PlayerInfoManager.AcID
local playerId = MDL.Player.GetRoleId()
local roleName = PlayerInfoManager.PlayerName
local serverID = MDL.Login.GetServerId()
local serverName = MDL.Login.GetServerShowId()
local extraData = {}
extraData.GameVersion = AppInfo.marketVersion
extraData.AssetVersion = MDL.HotFix.GetVersionInfo()
if GameAppInfo.IsPCPackage() then
if GameAppInfo.IsChinesePackage() then
AuxUtil.SetNetSecProtectRoleInfo(playerId, roleName, accid, serverName, serverID, JSON.encode(extraData), "W003441873")
end
elseif GameAppInfo.IsOverseaPackage() and GameAppInfo.IsVersionGreaterThan17000() then
if GameAppInfo.IsVersionGreaterThan113400() then
--新版本易盾修复卡死问题
AuxUtil.SetNetSecProtectRoleInfo(playerId, roleName, accid, serverName, serverID, JSON.encode(extraData), "")
end
elseif GameAppInfo.IsChinesePackage() and GameAppInfo.IsVersionGreaterThan16000() then
AuxUtil.SetNetSecProtectRoleInfo(playerId, roleName, accid, serverName, serverID, JSON.encode(extraData), "")
elseif GameAppInfo.IsJapanesePackage() and GameAppInfo.IsVersionGreaterThan16000() then
-- 日本先不分版本关闭易盾功能
-- AuxUtil.SetNetSecProtectRoleInfo(playerId, roleName, accid, serverName, serverID, JSON.encode(extraData), "")
elseif GameAppInfo.IsVietnamPackage() and GameAppInfo.IsVersionGreaterThan112000() then
AuxUtil.SetNetSecProtectRoleInfo(playerId, roleName, accid, serverName, serverID, JSON.encode(extraData), "")
else
AuxUtil.SetNetSecProtectRoleInfo(playerId, roleName, accid, serverName, serverID, JSON.encode(extraData))
end
end
end
--场景协议角色结构RoleSceneBasic转系统角色协议结构CommonShowRoleHeadInfo
--这里没有全部转 如果需要 自己补充
function Player_Controller.RoleSceneBasicToCommonRoleInfo(basicInfo)
local commonRoleInfo = {
acid = basicInfo.accid,
HeroID = basicInfo.HeroId,
level = basicInfo.level,
name = basicInfo.Name,
HeroAppearanceID = basicInfo.heroAppearanceId,
IsActiveMagicWeapon = basicInfo.isActiveMagicWeapon,
MagicWeaponBreak = basicInfo.weaponBreak,
HeroBreakNums = basicInfo.heroBreakNums,
ShowServerId = basicInfo.serverShowId,
WeaponAppearanceID = basicInfo.weaponAppearanceId,
EmblemContent = basicInfo.guildShow.emblemContent,
EmblemFrame = basicInfo.guildShow.emblemFrame,
guildName = basicInfo.guildShow.guildName,
guildId = basicInfo.guildShow.guildId,
JobTitle = basicInfo.guildShow.jobTitle,
weaponSoulInfo = basicInfo.weaponSoulInfo,
dyeCurPartList = basicInfo.dyeCurPartList,
}
return commonRoleInfo
end
--场景协议角色结构CommonShowRoleHeadInfo转系统角色协议结构RoleSceneBasic
--这里没有全部转 如果需要 自己补充
function Player_Controller.CommonRoleInfoToRoleSceneBasic(commonRoleInfo)
local basicInfo = {
accid = commonRoleInfo.acid,
HeroId = commonRoleInfo.HeroID,
level = commonRoleInfo.level,
Name = commonRoleInfo.name,
heroAppearanceId = commonRoleInfo.HeroAppearanceID,
isActiveMagicWeapon = commonRoleInfo.IsActiveMagicWeapon,
weaponBreak = commonRoleInfo.MagicWeaponBreak,
heroBreakNums = commonRoleInfo.HeroBreakNums,
weaponAppearanceId = commonRoleInfo.WeaponAppearanceID,
guildShow = {
emblemContent = commonRoleInfo.EmblemContent,
emblemFrame = commonRoleInfo.EmblemFrame,
guildId = commonRoleInfo.guildName,
guildName = commonRoleInfo.guildId,
jobTitle = commonRoleInfo.JobTitle,
},
countryInfo = {
countryId = commonRoleInfo.CountryId,
countryJobId = commonRoleInfo.CountryOfficial,
}
}
return basicInfo
end
--队员详细信息转换成通用外显信息CommonShowRoleHeadInfo
function Player_Controller.TeamMemberDetailInfoToCommonRoleInfo(teamMemberDetailInfo)
local commonRoleInfo = {
HeroID = teamMemberDetailInfo.mainHeroId,
HeroAppearanceID = teamMemberDetailInfo.heroAppearanceId,
IsActiveMagicWeapon = teamMemberDetailInfo.isActiveMagicWeapon,
MagicWeaponBreak = teamMemberDetailInfo.weaponBreak,
HeroBreakNums = teamMemberDetailInfo.heroBreakNums,
WeaponAppearanceID = teamMemberDetailInfo.weaponAppearanceId,
lightEffectIds = teamMemberDetailInfo.lightEffectIds,
dyeCurPartList = teamMemberDetailInfo.dyeCurPartList,
}
return commonRoleInfo
end
return Player_Controller