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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
 
/// <summary>
/// 内政 - 基本用于淘金
/// </summary>
public class AffairBaseWin : UIBase
{
    [SerializeField] Button bagBtn;
 
    //淘金相关
    [SerializeField] GameObject fullGoldRush;
    [SerializeField] Image goldRushIcon;
    [SerializeField] Text goldRushCountText;
    [SerializeField] Button goldRushItemBtn;
    [SerializeField] Image goldRushItemProcess;
    [SerializeField] Text autoText;
    [SerializeField] GameObject flowAutoEffect;
    [SerializeField] Button autoBtn;
 
    //NPC对话相关
 
    [SerializeField] HeroSkinModel[] funcNPCs;
    [SerializeField] Transform[] talkRects;
    [SerializeField] Text[] talkTexts;
    [SerializeField] UIEffectPlayer autoMGEffect;
 
    protected override void InitComponent()
    {
        bagBtn.AddListener(() =>
            {
                UIManager.Instance.OpenWindow<RolePackWin>();
            }
        );
 
        goldRushIcon.SetIconWithMoneyType(52);
        goldRushItemBtn.AddListener(() =>
            {
                ItemTipUtility.ShowMoneyTip(52, false);
            }
        );
        autoBtn.AddListener(() =>
            {
                if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.GoldRush, true))
                {
                    UIManager.Instance.OpenWindow<GoldRushAutoWin>();
                }
            }
        );
    }
 
    protected override void OnPreOpen()
    {
        GoldRushManager.Instance.OnGoldRushInfoEvent += OnGoldRushInfoEvent;
        GoldRushManager.Instance.OnAutoWorkingEvent += OnAutoWorkingEvent;
        GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
        PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
        GlobalTimeEvent.Instance.fiveSecondEvent += OnFiveSecondEvent;
        MinggeManager.Instance.ChangeAutoEvent += ChangeAutoEvent;
        
        Display();
        if (GoldRushManager.Instance.openAutoGoldRush)
        {
            GoldRushManager.Instance.GetAllAward();
        }
        ChangeAutoEvent();
    }
 
    protected override void OnPreClose()
    {
        GoldRushManager.Instance.OnGoldRushInfoEvent -= OnGoldRushInfoEvent;
        GoldRushManager.Instance.OnAutoWorkingEvent -= OnAutoWorkingEvent;
        GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
        PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
        GlobalTimeEvent.Instance.fiveSecondEvent -= OnFiveSecondEvent;
        MinggeManager.Instance.ChangeAutoEvent -= ChangeAutoEvent;
    }
 
    void ChangeAutoEvent()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Mingge))
        {
            return;
        }
        if (MinggeManager.Instance.isStartAuto)
        {
            autoMGEffect.Play();
            funcNPCs[5].GetModel().PlayAnimation("suanming", true);
        }
        else
        {
            autoMGEffect.Stop();
            funcNPCs[5].GetModel().PlayAnimation("idle", true);
        }
    }
 
 
    protected override void OnOpen()
    {
        GoldRushManager.Instance.ResumeAutoWorking();
    }
 
    void Display()
    {
        fullGoldRush.SetActive(GoldRushManager.Instance.GetFinishGoldRushCount() >= GoldRushManager.Instance.warehouseMaxCnt);
        RefreshGoldRushMoney();
        autoText.text = Language.Get(GoldRushManager.Instance.isAutoWorking ? "GoldRush34" : "GoldRush24");
 
        if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.GoldRush))
        {
            autoBtn.SetActive(true);
            goldRushItemBtn.SetActive(true);
        }
        else
        {
            autoBtn.SetActive(false);
            goldRushItemBtn.SetActive(false);
        }
 
 
        foreach (var npc in funcNPCs)
        {
            var key = npc.heroSkinID;
            if (!FuncOpen.Instance.IsFuncOpen(FuncNPCManager.Instance.funcNPCToFuncID[key]))
            {
                npc.SetActive(false);
            }
            else
            {
                npc.SetActive(true);
            }
        }
    }
 
 
    void OnGoldRushInfoEvent()
    {
        fullGoldRush.SetActive(GoldRushManager.Instance.GetFinishGoldRushCount() >= GoldRushManager.Instance.warehouseMaxCnt);
    }
 
    void OnSecondEvent()
    {
        RefreshGoldRushMoney();
    }
 
    void OnAutoWorkingEvent()
    {
        if (GoldRushManager.Instance.isAutoWorking)
        {
            autoText.text = Language.Get("GoldRush34");
            flowAutoEffect.SetActive(true);
 
        }
        else
        {
            autoText.text = Language.Get("GoldRush24");
            flowAutoEffect.SetActive(false);
        }
    }
 
    void RefreshGoldRushMoney()
    {
        var count = UIHelper.GetMoneyCnt(52);
        if (count > 0)
        {
            goldRushCountText.text = count + "/" + GoldRushManager.Instance.goldRushMissionMaxCnt;
        }
        else
        {
            //倒计时
            goldRushCountText.text = TimeUtility.SecondsToMS(GoldRushManager.Instance.restoreMissionSeconds - (TimeUtility.AllSeconds - GoldRushManager.Instance.lastRecoverTime));
        }
        goldRushItemProcess.fillAmount = (float)count / GoldRushManager.Instance.goldRushMissionMaxCnt;
    }
 
    void PlayerDataRefreshEvent(PlayerDataType type)
    {
        if (type == PlayerDataType.GoldRush)
        {
            RefreshGoldRushMoney();
        }
    }
 
    void OnFiveSecondEvent()
    {
        var skinID = FuncNPCManager.Instance.GetRandomAffairNpcTalk();
        var talk = FuncNPCManager.Instance.GetAffairTalk(skinID);
        var index = 0;
        for (int i = 0; i < funcNPCs.Length; i++)
        {
            if (funcNPCs[i].heroSkinID == skinID)
            {
                index = i;
                break;
            }
        }
        if (talk != null)
        {
            talkTexts[index].text = Language.Get(talk);
            talkRects[index].SetActive(true);
        }
 
        var npc = funcNPCs[index].GetModel();
        npc.PlayAnimation("hanhua", true);
        Talk(index).Forget();
    }
 
    async UniTask Talk(int index)
    {
        await UniTask.Delay(5000);
        talkRects[index].SetActive(false);
        var npc = funcNPCs[index].GetModel();
        npc.PlayAnimation("idle", true);
    }
}