using System.Collections.Generic;
|
using UnityEngine;
|
using LitJson;
|
using System;
|
|
//方案预设:流派设定
|
// 这里存储的是流派id设定; 功能预设在各个功能里如命格的是存在命格背包对应,武将是另外通知使用的格子索引
|
public class FuncPresetManager : GameSystemManager<FuncPresetManager>
|
{
|
//预设方案:功能类型(含全局和子功能,配表)-子方案ID-预设方案解锁名称信息
|
Dictionary<int, Dictionary<int, FuncPreset>> m_FuncPresetDict = new Dictionary<int, Dictionary<int, FuncPreset>>();
|
|
//对应 BattlePreSetType 战斗类型 : 全局方案ID
|
Dictionary<int, int> battlePreSetDict = new Dictionary<int, int>();
|
|
//所有预设方案的保存信息 全局方案ID :子功能类型(配表):子方案ID
|
Dictionary<int, Dictionary<int, int>> m_FuncPresetSaveDict = new Dictionary<int, Dictionary<int, int>>();
|
public Action<int> OnFuncPresetUseDataEvent; //0 更换子方案,1 更换全局方案,2 解锁/更改名
|
|
public const int GlobalDefaultPresetID = 1; //默认全局方案ID
|
public const int FuncDefaultPresetID = 1; //默认子功能方案ID
|
|
public int[] openConditions; //流派预设(也叫全局方案/战斗方案) 开启条件【开服第N天,主线通关X-Y,定军阁达到N层】
|
|
public Action<int, int, int, bool> OnSelectPresetEvent; //选择功能预设方案事件 功能类型 方案ID 是否展开
|
|
public override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;
|
ParseConfig();
|
}
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
|
}
|
|
|
void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("FuncPreset");
|
openConditions = JsonMapper.ToObject<int[]>(config.Numerical1);
|
}
|
|
private void OnBeforePlayerDataInitialize()
|
{
|
battlePreSetDict.Clear();
|
m_FuncPresetSaveDict.Clear();
|
InitFuncPreset();
|
}
|
|
//流派解锁
|
public bool IsOpen()
|
{
|
//特殊约定
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.FuncPreset))
|
return false;
|
|
if (TimeUtility.OpenDay < openConditions[0] - 1)
|
{
|
return false;
|
}
|
if (PlayerDatas.Instance.baseData.ExAttr1 / 100 <= openConditions[1])
|
{
|
return false;
|
}
|
if (!WarlordPavilionManager.Instance.TryGetHistoryMaxFinishProgress(out int layerNum, out int levelNum))
|
return false;
|
|
if (layerNum*100 + levelNum < openConditions[2])
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
//提前显示
|
public bool IsPreShow()
|
{
|
return FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.FuncPreset);
|
}
|
|
void InitFuncPreset()
|
{
|
m_FuncPresetDict.Clear();
|
// if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Mingge))
|
// {
|
// return;
|
// }
|
var keys = PresetUnlockConfig.GetKeys();
|
for (int i = 0; i < keys.Count; i++)
|
{
|
var config = PresetUnlockConfig.Get(keys[i]);
|
if (!m_FuncPresetDict.ContainsKey(config.PresetType))
|
{
|
m_FuncPresetDict[config.PresetType] = new Dictionary<int, FuncPreset>();
|
}
|
m_FuncPresetDict[config.PresetType][config.PresetID] = new FuncPreset()
|
{
|
unLock = config.UnlockType == 0,
|
PresetName = Language.Get(config.PresetType == 1 ? "FuncPreset10" : "Mingge13", config.PresetID)
|
};
|
}
|
}
|
|
public void UpdateFuncPresetInfoList(HB161_tagSCFuncPresetInfoList vNetData)
|
{
|
for (int i = 0; i < vNetData.FuncCnt; i++)
|
{
|
var funcPresetInfo = vNetData.FuncPresetList[i];
|
if (!m_FuncPresetDict.ContainsKey(funcPresetInfo.FuncPresetType))
|
{
|
m_FuncPresetDict[funcPresetInfo.FuncPresetType] = new Dictionary<int, FuncPreset>();
|
}
|
for (int j = 0; j < funcPresetInfo.PresetCnt; j++)
|
{
|
var preset = funcPresetInfo.PresetList[j];
|
//该功能预设解锁状态,按预设ID二进制位运算记录是否已解锁
|
bool _unlock = (funcPresetInfo.UnlockState & (1 << preset.PresetID)) != 0;
|
m_FuncPresetDict[funcPresetInfo.FuncPresetType][preset.PresetID] = new FuncPreset()
|
{
|
unLock = _unlock,
|
PresetName = string.IsNullOrEmpty(preset.PresetName) ?
|
Language.Get(funcPresetInfo.FuncPresetType == 1 ? "FuncPreset10" : "Mingge13", preset.PresetID) : preset.PresetName,
|
};
|
}
|
}
|
|
OnFuncPresetUseDataEvent?.Invoke(2);
|
}
|
|
//每个全局方案的存储信息
|
public void UpdateFuncPresetUseData(HB162_tagSCFuncPresetSwitchInfo vNetData)
|
{
|
for (int i = 0; i < vNetData.BatPresetCnt; i++)
|
{
|
var batPreset = vNetData.BatPresetList[i];
|
if (!m_FuncPresetSaveDict.ContainsKey(batPreset.BatPresetID))
|
{
|
m_FuncPresetSaveDict[batPreset.BatPresetID] = new Dictionary<int, int>();
|
}
|
for (int j = 0; j < batPreset.FuncCnt; j++)
|
{
|
var funcPreset = batPreset.FuncPresetList[j];
|
m_FuncPresetSaveDict[batPreset.BatPresetID][funcPreset.FuncPresetType] = funcPreset.FuncPresetID;
|
}
|
}
|
OnFuncPresetUseDataEvent?.Invoke(0);
|
}
|
|
//当前战斗功能的全局方案ID使用情况
|
public void UpdateBatPresetNowUseInfo(HB163_tagSCBatPresetSwitchInfo netPack)
|
{
|
for (int i = 0; i < netPack.BatFuncCnt; i++)
|
{
|
battlePreSetDict[netPack.BatPresetList[i].BatPresetType] = netPack.BatPresetList[i].BatPresetID;
|
}
|
OnFuncPresetUseDataEvent?.Invoke(1);
|
}
|
|
//根据战斗获取全局方案ID,如果取不到默认方案1
|
public int GetGlobalPresetID(int battlePresetType)
|
{
|
if (battlePreSetDict.ContainsKey(battlePresetType))
|
{
|
return battlePreSetDict[battlePresetType];
|
}
|
return 1;
|
}
|
|
//指定战斗模式下获取子功能方案ID,如果取不到默认方案1
|
public int GetFuncPresetIDByBattleType(int battlePresetType, int funcType)
|
{
|
int globalPresetID = GetGlobalPresetID(battlePresetType);
|
if (m_FuncPresetSaveDict.ContainsKey(globalPresetID) && m_FuncPresetSaveDict[globalPresetID].ContainsKey(funcType))
|
{
|
return m_FuncPresetSaveDict[globalPresetID][funcType];
|
}
|
return 1;
|
}
|
|
//指定流派获取子功能方案ID,如果取不到默认方案1
|
public int GetFuncPresetID(int globalPresetID, int funcType)
|
{
|
if (m_FuncPresetSaveDict.ContainsKey(globalPresetID) && m_FuncPresetSaveDict[globalPresetID].ContainsKey(funcType))
|
{
|
return m_FuncPresetSaveDict[globalPresetID][funcType];
|
}
|
return 1;
|
}
|
|
//获取当前流派下的子功能的方案ID,如果取不到默认方案1
|
public int GetFuncPresetID(int funcType)
|
{
|
int globalPresetID = GetGlobalPresetID((int)BattlePreSetType.Story);
|
if (m_FuncPresetSaveDict.ContainsKey(globalPresetID) && m_FuncPresetSaveDict[globalPresetID].ContainsKey(funcType))
|
{
|
return m_FuncPresetSaveDict[globalPresetID][funcType];
|
}
|
return 1;
|
}
|
|
//指定预设信息
|
public FuncPreset GetFuncPreset(int funcType, int presetID)
|
{
|
if (m_FuncPresetDict.ContainsKey(funcType) && m_FuncPresetDict[funcType].ContainsKey(presetID))
|
{
|
return m_FuncPresetDict[funcType][presetID];
|
}
|
return null;
|
}
|
|
// 这里虽然传的是 battleType,但是实际还是根据全局方案ID做对应修改;如果这个全局方案其他地方有使用也是同步变化
|
public void SaveFuncPresetID(int battleType, int funcType, int presetID)
|
{
|
if (funcType == 1)
|
{
|
SaveBattlePresetID(battleType, presetID);
|
return;
|
}
|
var pack = new CB262_tagCSFuncPresetSwitch();
|
pack.FuncPresetType = (byte)funcType;
|
pack.PresetID = (byte)presetID;
|
pack.BatPresetID = (byte)GetGlobalPresetID(battleType);
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void SaveBattlePresetID(int battleType, int globalPresetID)
|
{
|
var pack = new CB263_tagCSBatPresetSwitch();
|
pack.BatPresetID = (byte)globalPresetID;
|
pack.BatPresetType = (byte)battleType;
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void UnLockPreset(int funcType, int presetID)
|
{
|
var pack = new CB260_tagCSFuncPresetUnlock();
|
pack.FuncPresetType = (byte)funcType;
|
pack.PresetID = (byte)presetID;
|
GameNetSystem.Instance.SendInfo(pack);
|
SysNotifyMgr.Instance.ShowTip("FuncPreset2");
|
}
|
|
//要显示的方案数量; 根据情况会包含未解锁
|
//a. 按元宝解锁的为逐一开启,默认开启x个,第x+1个显示条件需要【流派预设】功能开启, 可解锁后逐一保留一个锁住的(直到全开启);
|
//b. 按功能条件开启的,如果默认只开其一个方案的情况不显示,达到下一个方案的条件满足后全显示;默认大于1个的情况直接全显示
|
public int GetShowFuncPresetCount(int funcType)
|
{
|
var unlockCnt = GetUnlockCnt(funcType);
|
var maxCount = PresetUnlockConfig.GetFuncPresetMaxCount(funcType);
|
var unlockType = PresetUnlockConfig.GetUnlockType(funcType);
|
if (unlockType == 2)
|
{
|
//命格按推演境界解锁
|
//只有1个方案则不显示,大于1个则全显示
|
if (unlockCnt == 1)
|
{
|
var config = PresetUnlockConfig.GetPresetUnlockConfig(funcType, 2);
|
if (MinggeManager.Instance.m_GanwuLV >= config.UnlockValue)
|
{
|
return maxCount;
|
}
|
return 0;
|
}
|
return maxCount;
|
}
|
if (!IsOpen())
|
{
|
//未开启时,默认大于1则显示
|
return unlockCnt == 1 ? 0 : unlockCnt;
|
}
|
|
return unlockCnt == maxCount ? unlockCnt : unlockCnt + 1;
|
}
|
|
public int GetUnlockCnt(int funcType)
|
{
|
int count = 0;
|
if (m_FuncPresetDict.ContainsKey(funcType))
|
{
|
for (int i = 0; i < m_FuncPresetDict[funcType].Count; i++)
|
{
|
if (m_FuncPresetDict[funcType][i + 1].unLock)
|
{
|
count++;
|
}
|
}
|
}
|
return count;
|
}
|
|
//选择方案:解锁或选中
|
// 选择方案返回true,否则返回false
|
public bool ClickFuncPreset(int battleType, int funcType, int id)
|
{
|
var config = PresetUnlockConfig.GetPresetUnlockConfig(funcType, id);
|
var data = GetFuncPreset(funcType, id);
|
if (!data.unLock)
|
{
|
// 未解锁 则购买
|
if (config.UnlockType == 1)
|
{
|
ConfirmCancel.MoneyIconToggleConfirmByType(ToggleCheckType.FuncPreset, config.UnlockValue, 1,
|
Language.Get("FuncPreset12", UIHelper.GetIconNameWithMoneyType(1), config.UnlockValue), () =>
|
{
|
if (!UIHelper.CheckMoneyCount(1, config.UnlockValue, 2))
|
return;
|
|
UnLockPreset(funcType, id);
|
});
|
}
|
else if (config.UnlockType == 2)
|
{
|
|
if (MinggeManager.Instance.m_GanwuLV < config.UnlockValue)
|
{
|
SysNotifyMgr.Instance.ShowTip("FuncPreset1", config.UnlockValue);
|
return false;
|
}
|
UnLockPreset(funcType, id);
|
}
|
return false;
|
}
|
|
SaveFuncPresetID(battleType, funcType, id);
|
return true;
|
}
|
|
// 点击流派/防守预设按钮
|
public void ClickBattlePreset(int battleType)
|
{
|
if (battleType > 1)
|
{
|
UIManager.Instance.OpenWindow<FuncPresetWin>(battleType);
|
return;
|
}
|
|
if (!IsOpen())
|
{
|
UIManager.Instance.OpenWindow<FuncPresetUnLockWin>(battleType);
|
}
|
else
|
{
|
UIManager.Instance.OpenWindow<FuncPresetWin>(battleType);
|
}
|
}
|
|
//功能类的满足条件后,提示红点手动解锁
|
// 某个方案是否要红点提示
|
public bool ShowRed(int funcType, int id)
|
{
|
if (funcType == (int)FuncPresetType.Mingge)
|
{
|
var presetData = GetFuncPreset(funcType, id);
|
if (presetData.unLock)
|
{
|
return false;
|
}
|
var config = PresetUnlockConfig.GetPresetUnlockConfig(funcType, id);
|
if (config != null && config.UnlockType == 2 && MinggeManager.Instance.m_GanwuLV < config.UnlockValue)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
return false;
|
}
|
|
public int GetNeedShowRedID(int funcType)
|
{
|
if (funcType == (int)FuncPresetType.Mingge)
|
{
|
var maxCnt = PresetUnlockConfig.GetFuncPresetMaxCount(funcType); ;
|
for (int i = 1; i <= maxCnt; i++)
|
{
|
if (ShowRed(funcType, i))
|
{
|
return i;
|
}
|
}
|
}
|
return 0;
|
}
|
|
|
}
|
|
|
public class FuncPreset
|
{
|
public bool unLock; //是否解锁
|
public string PresetName; //预设名称
|
}
|
|
|
|
//战斗功能区分对应存储全局方案ID,如演武场防守用哪个全局方案ID的分类
|
public enum BattlePreSetType
|
{
|
None = 0,
|
Story = 1, //主线
|
Arena = 2, //演武场防守
|
|
}
|
|
//功能预设类型 1-全局战斗;2-阵容;3-命格;
|
public enum FuncPresetType
|
{
|
Global = 1,
|
Team = 2,
|
Mingge = 3,
|
}
|