少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, September 21, 2017
//--------------------------------------------------------
 
using vnxbqy.UI;
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
namespace vnxbqy.UI
{
 
    public class TaskBoxBGMWin : Window
    {
 
        [SerializeField] Text _NpcName;//NPC名
        [SerializeField] Text _TextTaskDescription;//对话内容
        [SerializeField] Text _TextRewards;//按钮内容
        [SerializeField] Button _BtnRewards;//领取奖励按钮
        [SerializeField] Button _Close;//关闭按钮
        [SerializeField] Transform _Grid;//动态创建节点
        [SerializeField] Text _TextTaskName;//任务名称
        [SerializeField] GameObject m_ImageReward;
        [SerializeField] Text m_AutomaticThreadTask_Text;
        private int _TaskId = 0;//获取任务ID
        private int _NpcID = 0;//获取NPCID
        private int _Gold = 0;//获取流动仙玉
        private string StrConversa = null;//对话内容接收
        Dictionary<int, MissionDetailDates> _AllMissionDict;//任务初始化接收字典
        private List<RewardAnalysis.RewardInfo> rewardList = new List<RewardAnalysis.RewardInfo>();
        TaskModel m_TaskModel;
        TaskModel taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<TaskModel>()); } }
 
        PackModel _playerPack;
        PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
 
        VipModel m_Vipmodel;
        VipModel vipmodel { get { return m_Vipmodel ?? (m_Vipmodel = ModelCenter.Instance.GetModel<VipModel>()); } }
 
        TreasureModel m_treasureModel;
        TreasureModel treasureModel { get { return m_treasureModel ?? (m_treasureModel = ModelCenter.Instance.GetModel<TreasureModel>()); } }
 
        PlayerMainDate m_MainModel;
        PlayerMainDate mainModel { get { return m_MainModel ?? (m_MainModel = ModelCenter.Instance.GetModel<PlayerMainDate>()); } }
        private int FabaoId;
        private int AwaitSecond;
        private int AwaitSecondNext;
        private float LatencyTime = 0;//等待时间
        #region Built-in
        protected override void BindController()
        {
            var config = FuncConfigConfig.Get("TaskContinue");
            FabaoId = int.Parse(config.Numerical1);
            AwaitSecond = int.Parse(config.Numerical2);
            AwaitSecondNext = int.Parse(config.Numerical3);
        }
 
        protected override void AddListeners()
        {
            _BtnRewards.onClick.AddListener(BtnRewards);
            _Close.onClick.AddListener(Closee);
        }
 
        protected override void OnPreOpen()
        {
            LatencyTime = 0;
 
            _TextTaskDescription.text = "";
            _Gold = (int)PlayerDatas.Instance.baseData.diamond;
            _BtnRewards.SetActive(false);
            _AllMissionDict = taskmodel.allMissionDict;
            _TaskId = taskmodel._TaskNow;
            _NpcID = taskmodel.NPCid;
            if (taskmodel.MainTaskDic.ContainsKey(_TaskId))
            {
                m_AutomaticThreadTask_Text.SetActive(true);
            }
            else
            {
                m_AutomaticThreadTask_Text.SetActive(false);
            }
            StrConversa = null;
            StrConversa = taskmodel._conversation;
            TypeJudgment();//类型判断                                
            ContentAssignment();//内容赋值 
 
            if (!taskmodel.MainTaskDic.ContainsKey(_TaskId))
            {
                var npcConfig = NPCConfig.Get(_NpcID);
                if (npcConfig != null)
                {
                    if (npcConfig.NPCSpeakID != 0)
                    {
                        SoundPlayer.Instance.PlayNpcAudio(npcConfig.NPCSpeakID);
                    }
                }
            }
        }
 
        protected override void OnAfterOpen()
        {
            StartCoroutine("GetEnumerator");//自动任务
        }
 
        protected override void OnPreClose()
        {
            if (PlayerDatas.Instance.hero.State != E_ActorState.AutoRun)
            {
                MapTransferUtility.Instance.Clear();
            }
            StopCoroutine("GetEnumerator");
            StopCoroutine("LateRelease");
        }
 
        protected override void OnAfterClose()
        {
        }
 
        private void IsOpenMaininterface()
        {
            Close();
        }
        #endregion
        IEnumerator GetEnumerator()
        {
            yield return WaitingForSecondConst.WaitMS1500;
            TheAutomaticTask();
            yield break;
        }
 
        void TheAutomaticTask()//自动任务
        {
            if (_AllMissionDict.ContainsKey(_TaskId))
            {
 
                if (_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12)
                {
                    if (!ModelCenter.Instance.GetModel<TeamModel>().teamPrepare.isPreparing)
                    {
                        taskmodel.RequestGetTaskAward("OK", _TaskId);
                        WindowCenter.Instance.Close<TaskBoxBGMWin>();
                        WindowCenter.Instance.Open<MainInterfaceWin>();
                    }
                   
                }
            }
        }
        void BtnRewards()
        {
            int blank = playerPack.GetEmptyGridCount(PackType.Item);
            if (blank < 1)
            {
                ServerTipDetails.DisplayNormalTip(Language.Get("BackpackReward_Z"));
                return;
            }
            if (!_AllMissionDict.ContainsKey(_TaskId))
            {
                Closee();
                return;
            }
            taskmodel.RequestGetTaskAward("OK", _TaskId);
            mainModel.IsSelfMotionTask = false;
            SelectionManager.Release(SelectionManager.E_Type.Green);
            StartCoroutine("LateRelease");
        }
 
        IEnumerator LateRelease()
        {
            yield return WaitingForSecondConst.WaitMS500;
            WindowCenter.Instance.Close<TaskBoxBGMWin>();
            WindowCenter.Instance.Open<MainInterfaceWin>();
            yield break;
        }
 
        void Closee()
        {
            C080A_tagCCancelEvent _C080A = new C080A_tagCCancelEvent();
            GameNetSystem.Instance.SendInfo(_C080A);
            Close();
            WindowCenter.Instance.Open<MainInterfaceWin>();
            SelectionManager.Release(SelectionManager.E_Type.Green);
            StopCoroutine("GetEnumerator");
            StopCoroutine("LateRelease");
        }
 
        void ContentAssignment()//内容赋值
        {
            NPCConfig Npc = NPCConfig.Get(_NpcID);
            _NpcName.text = Npc.charName;
            var config = TASKINFOConfig.Get(_AllMissionDict[_TaskId].Name);
            if (config == null)
            {
                DebugEx.LogError("任务表格配置错误");
                return;
            }
            _TextTaskName.text = config.show_writing;
            var taskInfoConfig = TASKINFOConfig.Get(StrConversa);
            if (taskInfoConfig == null)
            {
                taskInfoConfig = TASKINFOConfig.Get(StrConversa.ToLower());
                if(taskInfoConfig == null) 
                {
                    DebugEx.LogError("任务表格配置错误");
                    return;
                }
               
            }
            if (taskmodel.BountyDic.ContainsKey(_TaskId) || taskmodel.FairyAuDic.ContainsKey(_TaskId))
            {
                string _taskInfoKey = string.Format("d_{0}_0_1", _NpcID);
                if (TASKINFOConfig.Get(_taskInfoKey) == null)
                    return;
                TASKINFOConfig DefaultDialogContent = TASKINFOConfig.Get(_taskInfoKey);
                _TextTaskDescription.text= DefaultDialogContent.show_writing;
            }
            else
            {
                _TextTaskDescription.text = taskInfoConfig.show_writing;
            }
 
         
 
            var rewardTaskInfoConfig = TASKINFOConfig.Get(_AllMissionDict[_TaskId].RewardList);
            if (rewardTaskInfoConfig == null)
            {
                DebugEx.LogError("任务表格配置错误");
                return;
            }
            string _RewardStr = TaskAllocation.Instance.GetTaskInfo(rewardTaskInfoConfig.show_writing, _TaskId);//获取奖励信息
            RewardAnalysis.Inst.GetReward(_RewardStr, ref rewardList);
            RewardInformationDisplay(rewardList);
        }
 
        void TypeJudgment()//类型判断
        {
            _AllMissionDict = taskmodel.allMissionDict;
            if (_TaskId == 0 || !_AllMissionDict.ContainsKey(_TaskId))
            {
                foreach (int key in _AllMissionDict.Keys)
                {
                    if (_AllMissionDict[key].LightList.Equals(default(TsakLight)))
                    {
                        continue;
                    }                   
                    for (int i = 0; i < _AllMissionDict[key].LightList.Count; i++)
                    {
                        if (_AllMissionDict[key].LightList[i].NpcId == _NpcID)
                        {
                            _TaskId = key;
                        }
                    }
                    if (_NpcID == _AllMissionDict[key].NPC_ID)
                    {
                        _TaskId = key;
                    }
                    //if (_NpcID == _AllMissionDict[key].LightList.NpcId)
                    //    _TaskId = key;
                    //else if (_NpcID == _AllMissionDict[key].NPC_ID)
                    //    _TaskId = key;
                }
            }
            int _TaskType = 0;
            _TaskType = int.Parse(FuncConfigConfig.Get("MissionType").Numerical1);
            _BtnRewards.SetActive(true);
 
 
            if (_AllMissionDict[_TaskId].ColorLV == 2 && _AllMissionDict[_TaskId].MissionState == 1)
            {
                _TextRewards.text = Language.Get("EnterACopy_Z");
                m_ImageReward.SetActive(true);
            }
            else if ((_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12) && _AllMissionDict[_TaskId].MissionState == 1)
            {
                _TextRewards.text = Language.Get("TaskBoxWin_BtnReward_Text_1");
                m_ImageReward.SetActive(true);
            }
            else
            {
                _TextRewards.text = Language.Get("TaskBoxWin_BtnGetReward_Text_1");
                m_ImageReward.SetActive(true);
            }
            if (_AllMissionDict[_TaskId].Type == 13 || _AllMissionDict[_TaskId].Type == 14)
            {
                _TextRewards.text = Language.Get("TaskBoxWin_BtnReward_Text_1");
                m_ImageReward.SetActive(false);
            }
        }
 
        void RewardInformationDisplay(List<RewardAnalysis.RewardInfo> rewardList)//奖励信息
        {
            if (_Grid.childCount != 0)
            {
                for (int i = 0; i < _Grid.childCount; i++)
                {
                    DestroyObject(_Grid.GetChild(i).gameObject);
                }
            }
            if (rewardList.Count == 0)
                return;
            if ((_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12) && _AllMissionDict[_TaskId].MissionState == 1)
                return;
            for (int i = 0; i < rewardList.Count; i++)
            {
                GameObject go = GameObject.Instantiate(UILoader.LoadPrefab("ItemCell"));
                ItemCell itemcell = go.GetComponent<ItemCell>();
                go.transform.SetParent(_Grid);
                go.transform.localScale = Vector3.one;
                Vector3 pos = go.transform.localPosition;
                go.transform.localPosition = pos.SetZ(0);
                Button _button = go.transform.GetComponent<Button>();
                ulong number = 0;
                if (rewardList[i].expPoint != 0)
                {
                    number = (ulong)rewardList[i].expPoint * 100000000;
                    number += (ulong)rewardList[i].num;
                }
                else
                {
                    number = (ulong)rewardList[i].num;
                }
                ItemCellModel cellModel = new ItemCellModel(rewardList[i].itemCfg.ID, true, (ulong)number);
                itemcell.Init(cellModel);
                itemcell.button.RemoveAllListeners();
                int tab = i;
                itemcell.button.AddListener(() =>
                {
                    ItemTipUtility.Show(rewardList[tab].itemCfg.ID);
                });
            }
        }
 
        protected override void LateUpdate()
        {
            base.LateUpdate();
            if (WindowCenter.Instance.IsOpen("MainInterfaceWin"))
            {
                WindowCenter.Instance.Close<TaskBoxBGMWin>();
            }
 
            GetMainSelfMotionLaupdate();
 
            var hero = PlayerDatas.Instance.hero;
            if (hero != null && hero.LockTarget != null)
            {
                var checkDistSqrt = MathUtility.DistanceSqrtXZ(hero.Pos, hero.LockTarget.Pos);
                if (checkDistSqrt > Mathf.Pow(GeneralDefine.FarawayNpcDist, 2))
                {
                    WindowCenter.Instance.Close<TaskBoxBGMWin>();
                    WindowCenter.Instance.Open<MainInterfaceWin>();
                    hero.LockTarget = null;
                }
            }
        }
 
        private void GetMainSelfMotionLaupdate()
        {
            Treasure treasure = null;
            if (treasureModel.TryGetTreasure(FabaoId, out treasure))
            {
                if (treasure.state == TreasureState.Collected || NewBieCenter.Instance.inGuiding)
                {
                    if (m_AutomaticThreadTask_Text.gameObject.activeSelf)
                    {
                        m_AutomaticThreadTask_Text.SetActive(false);
                    }
                    return;
                }
            }
            if (taskmodel.MainTaskDic.ContainsKey(_TaskId))
            {
                if (!m_AutomaticThreadTask_Text.gameObject.activeSelf)
                {
                    m_AutomaticThreadTask_Text.SetActive(true);
                }
                LatencyTime += Time.deltaTime;
                if (mainModel.IsSelfMotionTask)
                {
                    if (AwaitSecondNext >= LatencyTime)
                    {
                        m_AutomaticThreadTask_Text.text = string.Format(Language.Get("TaskContinueCount"), AwaitSecondNext - (int)LatencyTime);
                    }
                    else
                    {
                        m_AutomaticThreadTask_Text.SetActive(false);
                        Autorun();
                    }
                }
                else
                {
                    if (AwaitSecond >= LatencyTime)
                    {
                        m_AutomaticThreadTask_Text.text = string.Format(Language.Get("TaskContinueCount"), AwaitSecond - (int)LatencyTime);
                    }
                    else
                    {
                        m_AutomaticThreadTask_Text.SetActive(false);
                        Autorun();
                    }
                }
            }
 
        }
        private void Autorun()
        {
            int blank = playerPack.GetEmptyGridCount(PackType.Item);
            if (blank < 1)
            {
                ServerTipDetails.DisplayNormalTip(Language.Get("BackpackReward_Z"));
                return;
            }
            if (!_AllMissionDict.ContainsKey(_TaskId))
            {
                Closee();
                return;
            }
            taskmodel.RequestGetTaskAward("OK", _TaskId);
            mainModel.IsSelfMotionTask = true;
            SelectionManager.Release(SelectionManager.E_Type.Green);
            StartCoroutine("LateRelease");
        }
    }
 
}