using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; /// /// 武将遣散界面 /// public class HeroDeleteWin : UIBase { [SerializeField] Button storeBtn; [SerializeField] ScrollerController scroller; [SerializeField] Transform heroSelectBehaviour; HeroSelectBehaviour fiterManager; //武将筛选 [SerializeField] GameObject noHeroObj; [SerializeField] Button quickSelectBtn; [SerializeField] Button deleteBtn; protected override void InitComponent() { storeBtn.AddListener(() => { StoreModel.Instance.selectStoreFuncType = StoreFunc.Hero; UIManager.Instance.OpenWindow(); }); quickSelectBtn.AddListener(QuickSelect); deleteBtn.AddListener(DeleteHero); fiterManager = HeroSelectBehaviour.Create(heroSelectBehaviour); } protected override void OnPreOpen() { scroller.OnRefreshCell += OnRefreshCell; TeamManager.Instance.OnTeamChange += OnTeamChange; PackManager.Instance.RefreshItemLockEvent += RefreshItemLockEvent; ItemLogicUtility.Instance.OnGetItemShowEvent += OnGetItemShowEvent; HeroUIManager.Instance.SortHeroDeleteList(); //外部选中 if (!string.IsNullOrEmpty(HeroUIManager.Instance.jumpDeleteHeroGuid)) { HeroUIManager.Instance.SelectDeleteHero(HeroManager.Instance.GetHero(HeroUIManager.Instance.jumpDeleteHeroGuid)); } fiterManager.Display(0, SelectJobCountry); RefreshEmptyTip(); // CreateScroller(); } protected override void OnPreClose() { scroller.OnRefreshCell -= OnRefreshCell; TeamManager.Instance.OnTeamChange -= OnTeamChange; PackManager.Instance.RefreshItemLockEvent -= RefreshItemLockEvent; ItemLogicUtility.Instance.OnGetItemShowEvent -= OnGetItemShowEvent; HeroUIManager.Instance.selectDeleteHeroList.Clear(); HeroUIManager.Instance.jumpDeleteHeroGuid = ""; } void CreateScroller() { scroller.Refresh(); for (int i = 0; i < HeroUIManager.Instance.heroDeleteSortList.Count; i++) { if (i % 5 == 0) { scroller.AddCell(ScrollerDataType.Header, i); } } scroller.Restart(); scroller.JumpIndex(FindJumpIndexByHero(HeroUIManager.Instance.jumpDeleteHeroGuid)); } void OnRefreshCell(ScrollerDataType type, CellView cell) { var _cell = cell as HeroDeleteLineCell; _cell.Display(cell.index); } /// 回调参数: 职业,国家,伤害类型,6大战斗属性,特殊属性 void SelectJobCountry(List selects) { HeroUIManager.Instance.selectHeroDeleteList = selects; HeroUIManager.Instance.SortHeroDeleteList(); CreateScroller(); RefreshEmptyTip(); } void RefreshEmptyTip() { if (HeroUIManager.Instance.heroDeleteSortList.Count <= 0) { noHeroObj.SetActive(true); scroller.SetActive(false); } else { noHeroObj.SetActive(false); scroller.SetActive(true); } } void OnTeamChange(int type) { scroller.m_Scorller.RefreshActiveCellViews(); } void RefreshItemLockEvent(PackType type, string guid, bool lockState) { scroller.m_Scorller.RefreshActiveCellViews(); } void QuickSelect() { //先遍历一遍找出品质最低的 int minQuality = 100; for (int i = 0; i < HeroUIManager.Instance.heroDeleteSortList.Count; i++) { HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroDeleteSortList[i]); if (hero == null) continue; if (hero.Quality < minQuality) { minQuality = hero.Quality; } if (minQuality == 1) { //已经找到了最低品质的,就不用再找了 break; } } if (minQuality == 100 || minQuality > 2) { //只有低品质的才有快速选择 minQuality = 1; } //只选精英以下 for (int i = 0; i < HeroUIManager.Instance.heroDeleteSortList.Count; i++) { HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroDeleteSortList[i]); if (hero == null) continue; if (hero.Quality != minQuality) continue; if (hero.awakeLevel > 0) continue; if (hero.isLock) continue; if (hero.IsInAnyTeam()) continue; if (HeroUIManager.Instance.selectDeleteHeroList.Contains(hero.itemHero.guid)) continue; HeroUIManager.Instance.selectDeleteHeroList.Add(hero.itemHero.guid); } if (HeroUIManager.Instance.selectDeleteHeroList.Count == 0) { SysNotifyMgr.Instance.ShowTip("HeroReborn2"); return; } scroller.m_Scorller.RefreshActiveCellViews(); } void DeleteHero() { if (HeroUIManager.Instance.selectDeleteHeroList.Count == 0) { SysNotifyMgr.Instance.ShowTip("HeroReborn3"); return; } bool hasStarHero = false; for (int i = 0; i < HeroUIManager.Instance.selectDeleteHeroList.Count; i++) { HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectDeleteHeroList[i]); if (hero == null) continue; if (hero.heroStarMaxBefore > 0) { hasStarHero = true; break; } } if (hasStarHero) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("herocard67"), (bool isOK) => { if (isOK) { ShowDeleteItems(); } }); return; } ShowDeleteItems(); } void ShowDeleteItems() { Dictionary allItemDict = new Dictionary(); for (int i = 0; i < HeroUIManager.Instance.selectDeleteHeroList.Count; i++) { HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectDeleteHeroList[i]); if (hero == null) continue; allItemDict = CommonFunc.AddDict(allItemDict, CommonFunc.AddDict(HeroUIManager.Instance.GetHeroLVPayBack(hero.Quality, hero.heroLevel), HeroUIManager.Instance.GetHeroBreakPayBack(hero.Quality, hero.breakLevel))); Dictionary tmpDict = new Dictionary(); foreach (var itemInfo in hero.qualityConfig.DismissReturnItems) { if (!tmpDict.ContainsKey(itemInfo[0])) { tmpDict.Add(itemInfo[0], itemInfo[1] * (1 + hero.heroStarMaxBefore)); } else { tmpDict[itemInfo[0]] += itemInfo[1] * (1 + hero.heroStarMaxBefore); } } allItemDict = CommonFunc.AddDict(allItemDict, tmpDict); } //计算返还比例 var _list = allItemDict.Keys.ToList(); foreach (var key in _list) { allItemDict[key] = Math.Max((long)(allItemDict[key] * HeroUIManager.Instance.deletePayBackPer / 100.0), 1); } List items = new List(); foreach (var data in allItemDict) { items.Add(new Item(data.Key, data.Value, _dataEx:$"( {HeroUIManager.Instance.deletePayBackPer}% )")); } Dictionary moreMMItemDict = new Dictionary(); Dictionary moreTitleItemDict = new Dictionary(); int beautyEffectPer = BeautyMMManager.Instance.GetTalentEffectByType(TalentEffectType.HeroDelete); int titleEffect = PhantasmPavilionManager.Instance.GetTotalTalentValue(PhantasmPavilionType.Title, 3); //红颜和称号额外获得 if (beautyEffectPer > 0) { for (int i = 0; i < HeroUIManager.Instance.selectDeleteHeroList.Count; i++) { HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectDeleteHeroList[i]); if (hero == null) continue; foreach (var tmp in hero.qualityConfig.TitleReturnItems) { if (!moreMMItemDict.ContainsKey(tmp[0])) { moreMMItemDict.Add(tmp[0], (long)Math.Ceiling(tmp[1] * beautyEffectPer / 100.0f)); } else { moreMMItemDict[tmp[0]] += (long)Math.Ceiling(tmp[1] * beautyEffectPer / 100.0f); } } } foreach (var key in moreMMItemDict.Keys) { items.Add(new Item(key, moreMMItemDict[key], 20, _dataEx: $"( {beautyEffectPer}% )")); } } if (titleEffect > 0) { for (int i = 0; i < HeroUIManager.Instance.selectDeleteHeroList.Count; i++) { HeroInfo hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectDeleteHeroList[i]); if (hero == null) continue; foreach (var tmp in hero.qualityConfig.TitleReturnItems) { if (!moreTitleItemDict.ContainsKey(tmp[0])) { moreTitleItemDict.Add(tmp[0], (long)Math.Ceiling(tmp[1] * titleEffect / 100.0f)); } else { moreTitleItemDict[tmp[0]] += (long)Math.Ceiling(tmp[1] * titleEffect / 100.0f); } } } foreach (var key in moreTitleItemDict.Keys) { items.Add(new Item(key, moreTitleItemDict[key], 30, _dataEx: $"( {titleEffect}% )")); } } ConfirmCancel.ShowItemsConfirm(items, Language.Get("herocard25"), Language.Get("herocard26"), (bool isOk) => { if (isOk) { //发包 var pack = new CB240_tagCSHeroDismiss(); List indexList = new List(); for (int i = 0; i < HeroUIManager.Instance.selectDeleteHeroList.Count; i++) { indexList.Add((ushort)HeroManager.Instance.GetHero(HeroUIManager.Instance.selectDeleteHeroList[i]).itemHero.gridIndex); } pack.ItemIndexList = indexList.ToArray(); pack.Count = (ushort)pack.ItemIndexList.Length; GameNetSystem.Instance.SendInfo(pack); HeroUIManager.Instance.selectDeleteHeroList.Clear(); } }); } void OnGetItemShowEvent() { HeroUIManager.Instance.SortHeroDeleteList(); CreateScroller(); } int FindJumpIndexByHero(string guid) { if (string.IsNullOrEmpty(guid)) { return 0; } var hero = HeroManager.Instance.GetHero(guid); if (hero == null) return -1; if (hero.Quality > HeroUIManager.Instance.jumpDeleteHeroQuality && !HeroUIManager.Instance.isJumpDeleteHero) { return -1; } return HeroUIManager.Instance.heroDeleteSortList.IndexOf(guid) / 5 - 1; } }