少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 f1f2599ba0e6b64358ffef7ae5c9f9af3ed8b8b4
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, December 26, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
//剧情对话面板
namespace Snxxz.UI
{
 
    public class DialogueDuidanceWin : Window
    {
        [SerializeField] Button m_MarkRay;
        [SerializeField] Button m_SKIPButton;
 
        [SerializeField] GameObject m_BaseboardImageNPC;
        [SerializeField] RawImage m_NPCIcon;
        [SerializeField] Text m_NPCNameText;
        [SerializeField] Text m_ContentText_Npc;
 
        [SerializeField] GameObject m_BaseboardImagePlayer;
        [SerializeField] RawImage m_playerIcon;
        [SerializeField] Text m_PlayerNameText;
        [SerializeField] Text m_ContentText;
 
        [SerializeField] Text m_NextText;
 
        int[] sPeaker;//对话对应半身像(0为主角/1为NPC)
        int taskIndex = 0;//获取当前的任务
        int typesPeaker = -1;
 
        public static int storyMissionId = 0;
 
        private float timeType = 0f;
        TaskModel m_TaskModel;
        TaskModel taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<TaskModel>()); } }
 
        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 IsMultistage = 0;//是否有多段对话0,没有1,有
        private int FabaoId;
        private int AwaitSecond;
        #region Built-in
        private enum TaskType
        {
            OK = 0,
            FB = 1,
            Double = 2,
        }
        protected override void BindController()
        {
            var config = FuncConfigConfig.Get("TaskContinue");
            FabaoId = int.Parse(config.Numerical1);
            AwaitSecond = int.Parse(config.Numerical2);
        }
 
        protected override void AddListeners()
        {
            m_MarkRay.AddListener(OnClickMarkRay);
            m_SKIPButton.AddListener(OnClickSKIPButton);
        }
 
        protected override void OnPreOpen()
        {
            MainInterfaceWin.IsOpenMaininterface += IsOpenMaininterface;
            timeType = 0;
            m_NextText.text = string.Format(Language.Get("TaskContinueCount"), AwaitSecond);
            IsCloseWindow();
            typesPeaker = -1;
            var config = StoryMissionsConfig.Get(storyMissionId);
            if (config.TaskMusic != 0)
            {
                SoundPlayer.Instance.PlayNpcAudio(config.TaskMusic);
            }
            if (config == null)
            {
                return;
            }
 
            sPeaker = config.Speaker1;
 
            taskIndex = config.TalkNum[0];
            ShowDialogSelect(sPeaker[0], taskIndex);
        }
 
        private void IsCloseWindow()
        {
            if (WindowCenter.Instance.IsOpen<DungeonFightWin>())
            {
                WindowCenter.Instance.Close<DungeonFightWin>();
            }
            if (WindowCenter.Instance.IsOpen<DungeonMissionDetailsWin>())
            {
                WindowCenter.Instance.Close<DungeonMissionDetailsWin>();
            }
        }
 
        protected override void OnAfterOpen()
        {
 
        }
        protected override void OnPreClose()
        {
            MainInterfaceWin.IsOpenMaininterface -= IsOpenMaininterface;
            UI3DModelExhibition.Instance.StopShow();
        }
 
        private void IsOpenMaininterface()
        {
            Close();
        }
 
        protected override void OnAfterClose()
        {
            bool _bool = IsDungeon();
            if (_bool)
            {
                WindowCenter.Instance.Open<DungeonFightWin>();
            }
            if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
            {
                WindowCenter.Instance.Open<MainInterfaceWin>();
            }
        }
        protected override void LateUpdate()
        {
            timeType += Time.deltaTime;
            if (timeType >= AwaitSecond)
            {
                m_NextText.text = string.Format(Language.Get("TaskContinueCount"), 0);
                OnClickSKIPButton();
                mainModel.IsSelfMotionTask = true;
            }
            else
            {
                m_NextText.text= string.Format(Language.Get("TaskContinueCount"), AwaitSecond - (int)timeType);
            }
 
            if (this is BossShowDialogueWin)
            {
                return;
            }
 
            if (!WindowCenter.Instance.IsOpen<DialogueDuidanceWin>())
            {
                return;
            }
 
            GA_Hero _hero = PlayerDatas.Instance.hero;
            if (_hero == null)
            {
                return;
            }
 
            if (_hero.LockTarget == null)
            {
                return;
            }
 
            float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, _hero.LockTarget.Pos);
            if (_chkDistSqrt > Mathf.Pow(GeneralDefine.FarawayNpcDist, 2))
            {
 
                WindowCenter.Instance.Close<DialogueDuidanceWin>();
                WindowCenter.Instance.Open<MainInterfaceWin>();
 
                _hero.LockTarget = null;
            }
        }
        private void OnClickMarkRay()
        {
            timeType = 0;
            var config = StoryMissionsConfig.Get(storyMissionId);
            if (config == null)
            {
                return;
            }
 
            taskIndex += 1;
            var end = config.TalkNum.Length > 1 ? config.TalkNum[1] : config.TalkNum[0];
 
            if (taskIndex <= end)//下一条
            {
                ShowDialogSelect(sPeaker[taskIndex], taskIndex);
            }
            else//最后一条
            {
                SessionEnd(TaskType.OK);
                Close();
                WindowCenter.Instance.Open<MainInterfaceWin>();
                bool _bool = IsDungeon();
                if (_bool)
                {
                    WindowCenter.Instance.Open<DungeonFightWin>();
                }
            }
 
 
        }
        private void OnClickSKIPButton()
        {
            var config = StoryMissionsConfig.Get(storyMissionId);
            if (config != null)
            {
                SessionEnd(TaskType.OK);
            }
            mainModel.IsSelfMotionTask = false;
            Close();
            HeroAIRecorder.ClearRecord();
            WindowCenter.Instance.Open<MainInterfaceWin>();
        }
        #endregion
        private void ShowDialogSelect(int type, int stepNum)
        {
 
            if (type == 0)
            {
                if (typesPeaker != type)
                {
                    m_BaseboardImageNPC.SetActive(false);
                    m_BaseboardImagePlayer.SetActive(true);
                }
 
                int playerJob = PlayerDatas.Instance.baseData.Job;
 
                UI3DModelExhibition.Instance.ShowPlayer(m_playerIcon, playerJob, true);
 
                m_PlayerNameText.text = PlayerDatas.Instance.baseData.PlayerName;
 
                string platercContentKey = StoryMissionsConfig.Get(storyMissionId).content;
                var config = TASKINFOConfig.Get(string.Format(platercContentKey, stepNum));
                if (config != null)
                {
                    m_ContentText.text = config.show_writing;
                }
                else
                {
                    DebugEx.LogError("TaskInFo中没有这个Key。。" + string.Format(platercContentKey, stepNum));
                }
 
            }
            if (type == 1)
            {
                if (typesPeaker != type)
                {
                    m_BaseboardImageNPC.SetActive(true);
                    m_BaseboardImagePlayer.SetActive(false);
                }
                var configStoryMissions = StoryMissionsConfig.Get(storyMissionId);
                if (configStoryMissions == null)
                {
                    return;
                }
                int npcId = configStoryMissions.NpcID;
                var npcConfig = NPCConfig.Get(npcId);
                m_NPCNameText.text = npcConfig.charName;
                string npcContentKey = configStoryMissions.content;
                var taskInfo = TASKINFOConfig.Get(string.Format(npcContentKey, stepNum));
                if (taskInfo == null)
                {
                    DebugEx.LogError("TASKINFOConfig中没有找到对应的Key");
                }
                else
                {
                    m_ContentText_Npc.text = taskInfo.show_writing;
                }
                
                var data = new UI3DNPCExhibitionData()
                {
                    npcId = npcId,
                    isDialogue = true,
                };
                UI3DModelExhibition.Instance.ShowNPC(m_NPCIcon,data);
            }
            typesPeaker = type;
        }
 
        private void SessionEnd(TaskType taskType)
        {
            switch (taskType)
            {
                case TaskType.OK:
                case TaskType.FB:
                    taskmodel.RequestGetTaskAward("OK");
                    break;
                case TaskType.Double:
                    taskmodel.RequestGetTaskAward("Double");
                    break;
                default:
                    break;
            }
        }
 
        private bool IsDungeon()
        {
            var mapId = PlayerDatas.Instance.baseData.MapID;
            var mapConfig = MapConfig.Get(mapId);
            return mapConfig != null && mapConfig.MapFBType != 0;
        }
    }
 
}