lcy
2026-02-04 e80cb92bf4b84cab4d87bf3a23bbf21da311cd03
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class HeroGiftRoleListCell : CellView
{
    [SerializeField] Button addHeroBtn;
    [SerializeField] HeroShowBaseCell addHeroShow;
    [SerializeField] GiftBaseCell[] addGiftCells;
    [SerializeField] Image onTeamImg;
    [SerializeField] Toggle selectToggle;
 
    public void Display(int index)
    {
        addHeroBtn.AddListener(()=> { AddHero(index); });
 
        var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroEatList[index]);
        addHeroShow.Init(hero.heroId, hero.SkinID, hero.breakLevel, hero.heroStar, hero.awakeLevel, hero.heroLevel, hero.isLock);
        HeroUIManager.Instance.RefreshGiftCell(addGiftCells, hero);
 
        onTeamImg.SetActive(hero.IsInAnyTeam());
        int girdIndex = hero.itemHero.gridIndex;
        selectToggle.isOn = HeroUIManager.Instance.selectEatHeroIndexList.Contains(girdIndex);
 
    }
 
    void AddHero(int index)
    {
        var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroEatList[index]);
        //上阵 锁定 觉醒 的情况
        if (hero.awakeLevel > 0)
        {
            SysNotifyMgr.Instance.ShowTip("HeroReborn1");
            return;
        }
 
        if (hero.IsInAnyTeamJustOne())
        {
            //阵容至少要有一个武将上阵
            SysNotifyMgr.Instance.ShowTip("HeroFunc3");
            return;
        }
 
        if (hero.isLock)
        {
            ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
            Language.Get("herocard66"), (bool isOK) =>
                {
                    if (isOK)
                    {
                        hero.ChangeLockState();
                    }
                });
            return;
        }
 
        if (hero.IsInAnyTeam())
        {
            ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
            Language.Get("herocard65"), (bool isOK) =>
                {
                    if (isOK)
                    {
                        hero.LeaveAllTeam();
                    }
                });
            return;
        }
 
        if (hero.heroLevel > 1)
        {
            HeroUIManager.Instance.ResetBtnClick(hero);
            return;
        }
 
        int maxStarCnt = HeroUIManager.Instance.GetMaxStarCount(hero.heroId, hero.Quality);
        int girdIndex = hero.itemHero.gridIndex;
        if (hero.heroStar > 0 && !selectToggle.isOn)
        {
            ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
            Language.Get("HeroGift13"), (bool isOK) =>
                {
                    if (isOK)
                    {
                        SelectHero(girdIndex, maxStarCnt);
                    }
                });
            return;
        }
 
        SelectHero(girdIndex, maxStarCnt);
        
    }
 
    void SelectHero(int girdIndex, int maxStarCnt)
    {
        if (!selectToggle.isOn)
        {
 
            //需要统计被吞噬的武将星数
            int eatStar = 0;
            for (int i = 0; i < HeroUIManager.Instance.selectEatHeroIndexList.Count; i++)
            {
                var hero = HeroManager.Instance.GetHero(HeroUIManager.Instance.heroEatList[i]);
                if (hero == null)
                    continue;
                eatStar += hero.heroStar + 1;  //本体也算可增加1星
            }
            // 需增加待选这只的星级
            var selectStar = HeroManager.Instance.GetHeroByIndex(girdIndex).heroStar + 1; //本体也算可增加1星
 
            // 主武将星级
            var star = HeroManager.Instance.GetHero(HeroUIManager.Instance.selectHeroGuidForGiftFunc)?.heroStar;
 
            // 只选1只的情况下,如果 39星 + 5星超过了也让可选,其他情况的话需判断星上限
            if (!(HeroUIManager.Instance.selectEatHeroIndexList.Count == 0 && selectStar > 1))
            {
                if (eatStar + selectStar + star > maxStarCnt)
                {
                    SysNotifyMgr.Instance.ShowTip("HeroGiftEat1");
                    return;
                }
            }
 
            if (!HeroUIManager.Instance.selectEatHeroIndexList.Contains(girdIndex))
            {
                HeroUIManager.Instance.selectEatHeroIndexList.Add(girdIndex);
                selectToggle.isOn = true;
                
            }
        }
        else
        {
            if (HeroUIManager.Instance.selectEatHeroIndexList.Contains(girdIndex))
            {
                HeroUIManager.Instance.selectEatHeroIndexList.Remove(girdIndex);
                selectToggle.isOn = false;
            }
        }
    }
}