//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, March 14, 2018 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using vnxbqy.UI; using System; using LitJson; using System.Collections.Generic; using System.Linq; public class CutTreeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk { //砍树速度 public int cutTreeSpeed = 1; //月卡开启加速, 速度越大越快 public event Action OnSelectMainType; //0:主界面砍树 1:战斗界面 private int m_SelectMainType = 0; public int SelectMainType { get { return m_SelectMainType; } set { if (m_SelectMainType != value) { m_SelectMainType = value; OnSelectMainType?.Invoke(); } } } public event Action OnCutTreeResult; public Action AfterPlayCutTreeAnimEvent; //砍树动画播放完毕后的事件 public List m_ExItemList = new List(); // 砍树获得额外物品奖励(非装备) 存储起来统一展示 public int m_EquipCount; public int[] equipUIEffectLights; //砍树装备掉落特效 public int[] cutTreeAtkEffects; //砍树攻击特效 public int upgradeTreeMoneyType; //升级仙树消耗的货币类型 public int timeUpTreeItemID; //加速仙树升级的道具ID public int timeUpTreeItemSubTime; //减少仙树升级时间的道具减少的时间 public Dictionary taskClickGuide = new Dictionary(); //点击任务引导 任务类型-引导id public Dictionary realmWinClickGuide = new Dictionary(); //点击境界窗口引导 境界类型-引导id public Dictionary defeadWinClickGuide = new Dictionary(); //点击副本战败引导 副本id-引导id public int[] autoGuideList; //小于x级y秒内无任何点击自动引导【等级,秒】 public Dictionary newEquipIDToGuideID = new Dictionary(); //新装备id对应的引导id public ItemModel selectFloorEquip; //选中的地板装备 public bool dontNotifyDecompose = false; // 是否提示更好装备分解警告 public bool dontNotifyExchangeDecompose = false; // 是否提示更好装备替换会被分解警告 public bool waitEquipOPPack = false; //等待装备操作(分解/替换)包返回 public bool waitCutTreePack = false; //等待砍树结果包返回 public event Action OnEquipOPResultAction; public float lastModelAnimateTime = 0; //上次模型最后一次砍树动画时间 public bool isPlayCutTreeAnim = false; //是否正在播放砍树动画,用于重复点击砍树按钮的判断 //仙树信息 int m_TreeLV; // 当前仙树等级 public int m_LVUPState; // 0-非升级中;1-升级中 int m_LVUPRemainTime; // 升级剩余时间,秒;当升级中且倒计时为0时可发送B223执行升级包进行升级 int m_LVPackTime; //收包时间用于计算剩余时间m_LVUPRemainTime public float cutTreeDuration = 0.8f; //砍树动画基础不加速的单次间隔 public event Action UpdateTreeLVEvent; bool loginOKTreePack = false; //登录时是否已经收到仙树信息包,用于判定是否仙树升级 public bool isCreateNewUIModel = true; //砍树界面是否创建新的UI模型,用于换模型功能或者重登时刷新界面模型 //砍树任务 另外一套逻辑 public int m_CutTreeTaskID = 0; public int m_CutTreeTaskValue = 0; public int m_CutTreeTaskState = 0; // 任务状态 1-进行中 2-可领取 public event Action OnCutTreeTaskEvent; public bool clickEquipTipOnMain = false; //主界面点击在身上装备的tip显示 //功能入口 public int[] dongfuFuncArr; public int[] tiaozhanFuncArr; public Dictionary funcIDToDailyIDDic = new Dictionary(); //功能id对应的日常id, 用于进度完成显示 public Dictionary funcShowLVDic = new Dictionary(); //功能显示的最低等级 不是开启功能的等级 public Dictionary funcRedpointDic = new Dictionary(); public int selectFuncArrNum = 0; //选择的功能组序号 0-洞府 1-挑战 PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } EquipModel equipModel { get { return ModelCenter.Instance.GetModel(); } } AutoCutTreeModel autoCutTreeModel { get { return ModelCenter.Instance.GetModel(); } } TaskModel taskModel { get { return ModelCenter.Instance.GetModel(); } } DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel(); } } public override void Init() { DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent += OnEquipResult; GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent; ParseConfig(); } void ParseConfig() { var config = FuncConfigConfig.Get("CutTreeEquip"); equipUIEffectLights = JsonMapper.ToObject(config.Numerical1); var json = JsonMapper.ToObject(config.Numerical2); foreach (var key in json.Keys) { taskClickGuide.Add(int.Parse(key), int.Parse(json[key].ToString())); } autoGuideList = JsonMapper.ToObject(config.Numerical3); json = JsonMapper.ToObject(config.Numerical4); foreach (var key in json.Keys) { newEquipIDToGuideID.Add(int.Parse(key), int.Parse(json[key].ToString())); } cutTreeAtkEffects = JsonMapper.ToObject(config.Numerical5); config = FuncConfigConfig.Get("TreeLVUP"); upgradeTreeMoneyType = int.Parse(config.Numerical1); var arr = config.Numerical2.Split('|'); timeUpTreeItemID = int.Parse(arr[0]); timeUpTreeItemSubTime = int.Parse(arr[1]); config = FuncConfigConfig.Get("CutTreePanel1"); dongfuFuncArr = JsonMapper.ToObject(config.Numerical1); tiaozhanFuncArr = JsonMapper.ToObject(config.Numerical2); json = JsonMapper.ToObject(config.Numerical3); foreach (var key in json.Keys) { funcIDToDailyIDDic.Add(int.Parse(key), int.Parse(json[key].ToString())); } json = JsonMapper.ToObject(config.Numerical4); foreach (var key in json.Keys) { funcShowLVDic.Add(int.Parse(key), int.Parse(json[key].ToString())); } json = JsonMapper.ToObject(config.Numerical5); foreach (var key in json.Keys) { funcRedpointDic.Add(int.Parse(key), int.Parse(json[key].ToString())); } config = FuncConfigConfig.Get("CutTreePanel2"); json = JsonMapper.ToObject(config.Numerical1); foreach (var key in json.Keys) { realmWinClickGuide.Add(int.Parse(key), int.Parse(json[key].ToString())); } json = JsonMapper.ToObject(config.Numerical2); foreach (var key in json.Keys) { defeadWinClickGuide.Add(int.Parse(key), int.Parse(json[key].ToString())); } } public void OnBeforePlayerDataInitialize() { if (WindowCenter.Instance.IsOpen()) WindowCenter.Instance.Close(); selectFloorEquip = null; m_ExItemList.Clear(); dontNotifyDecompose = false; dontNotifyExchangeDecompose = false; waitEquipOPPack = false; waitCutTreePack = false; m_TreeLV = 0; m_LVUPState = 0; m_LVUPRemainTime = 0; m_CutTreeTaskID = 0; m_CutTreeTaskValue = 0; m_CutTreeTaskState = 0; loginOKTreePack = false; isCreateNewUIModel = true; isPlayCutTreeAnim = false; } public void OnPlayerLoginOk() { var _mapConfig = MapConfig.Get(PlayerDatas.Instance.baseData.MapID); if (_mapConfig.MapFBType == (int)MapType.OpenCountry) { SelectMainType = 0; //后续根据具体情况调整 } } public override void UnInit() { DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent -= OnEquipResult; GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent; } //是否休息时间 public bool IsRestTime() { if (Time.realtimeSinceStartup - lastModelAnimateTime > 10) return true; return false; } private void OnEquipResult(H0721_tagMakeItemAnswer info) { if (info.MakeType != (int)MakeType.default1) return; waitEquipOPPack = false; OnEquipOPResultAction?.Invoke(); } public void SendCutTree(int count) { var pack = new CB221_tagCMCutTree(); pack.CutCount = (byte)count; GameNetSystem.Instance.SendInfo(pack); lastModelAnimateTime = Time.realtimeSinceStartup; isPlayCutTreeAnim = true; } public void CutTreeResult(HB122_tagMCCutTreeResult vNetData) { waitCutTreePack = false; lastModelAnimateTime = Time.realtimeSinceStartup; m_EquipCount = vNetData.EquipCount; if (vNetData.ExItemList.Length != 0) { for (int i = 0; i < vNetData.ExItemList.Length; i++) { m_ExItemList.Add(new Item() { id = (int)vNetData.ExItemList[i].ItemID, count = (int)vNetData.ExItemList[i].ItemCount }); } if (SelectMainType == 0) { ItemLogicUtility.Instance.ShowGetItem(m_ExItemList, Language.Get("CutTree1"), func: () => { m_ExItemList.Clear(); }); } } //1.没有界面表现的砍树结果 2.有界面表现的砍树结果 if (SelectMainType == 0 && WindowCenter.Instance.IsOpen()) { OnCutTreeResult?.Invoke(); } else { ProcessEquipOnFloor(); } } //不展示界面的时候按间隔时间处理地板装备 public void ProcessEquipOnFloor() { //时间顺序:砍树动作-掉落-分解/替换 var quality = GetStartEquipQuality(); var betterQuality = GetBetterEquipQuality(quality); var cutCount = betterQuality - quality + 1; float delayTime = Math.Max(cutTreeDuration / cutTreeSpeed * cutCount / (1 + Math.Max(cutCount - 2, 0) * 0.3f), 0.5f); Clock.AlarmAfter(delayTime, () => { if (!autoCutTreeModel.isAutoCutTree) { var betterEquip = GetBetterFloorEquip(); if (betterEquip != null) { OpenEquipExchangeWin(betterEquip); } } else { isPlayCutTreeAnim = false; } }); } //砍树动作对应装备品质的起始表现,最小1 public int GetStartEquipQuality() { var rateList = TreeLVConfig.Get(m_TreeLV).EquipColorRateList; for (int i = 0;i< rateList.Length; i++) { if (rateList[i] != 0) return i + 1; } return 1; } public int GetBetterEquipQuality(int quality = 1) { var items = packModel.GetItems(PackType.EquipOnFloor); if (items == null || items.Count == 0) return quality; for (int i = 0; i < items.Count; i++) { var equip = items[i]; if (equip == null) continue; if (quality < equip.config.ItemColor) quality = equip.config.ItemColor; } return quality; } public ItemModel GetBetterFloorEquip() { var items = packModel.GetItems(PackType.EquipOnFloor); if (items == null || items.Count == 0) return null; ItemModel betterEquip = null; for (int i = 0; i < items.Count; i++) { var equip = items[i]; if (equip == null) continue; var equipOn = equipModel.GetEquipItemModel(new Int2(PlayerDatas.Instance.baseData.suitLevel, equip.config.EquipPlace)); if (equipOn == null) continue; //后续要处理自动功能的战斗属性对比 if (betterEquip.score > equipOn.score) betterEquip = equip; } return betterEquip; } public void SendCutTreeEquipOP(byte[] itemIndexList, byte opType, bool autoDecompose = false) { if (waitEquipOPPack) return; NoteFloorEquip(itemIndexList, opType); var pack = new CB222_tagCMCutTreeEquipOP(); pack.IndexCount = (byte)itemIndexList.Length; pack.ItemIndexList = itemIndexList; pack.OPType = opType; // 操作类型:1-替换;2-分解 pack.AutoDecompose = (byte)(autoDecompose ? 1 : 0); // 替换后是否自动分解原装备:0否1是,仅替换操作下有用 waitEquipOPPack = true; GameNetSystem.Instance.SendInfo(pack); } //equipFloorInfo记录地板装备的最新一次信息,不作清除可能地板上的装备已经消失,用于替换和分解装备的表现 public void NoteFloorEquip(byte[] itemIndexList, int opType) { equipFloorInfo.Clear(); foreach (var girdIndex in itemIndexList) { var equip = packModel.GetItemByIndex(PackType.EquipOnFloor, girdIndex); if (equip == null) continue; equipFloorInfo[girdIndex] = new EquipOnFloorInfo() { equipID = equip.itemId, posX = equipOnFloorBtn[girdIndex].transform.position.x, posY = equipOnFloorBtn[girdIndex].transform.position.y, opType = opType }; } } public void OpenEquipExchangeWin(ItemModel equip) { isPlayCutTreeAnim = false; if (SelectMainType == 1) return; //未回复装备操作结果,否则会显示旧装备 if (waitEquipOPPack) return; if (TurnFightModel.Instance.IsTurnFight()) return; if (WindowCenter.Instance.IsOpen()) return; if (NewBieCenter.Instance.inGuiding) return; selectFloorEquip = equip; WindowCenter.Instance.Open(); } //用于飘动逻辑 public Dictionary equipFloorInfo = new Dictionary(); //真实背包的索引,对应地板装备的信息 public List