少年修仙传客户端代码仓库
client_linchunjie
2019-05-14 bc2d65658f516301b60eb83cb1640e69d6e2e4f2
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Snxxz.UI
{
    public class TaskFeedbackModel : Model
    {
        Dictionary<int, TaskFeedback> m_TaskFeedbacks = new Dictionary<int, TaskFeedback>();
 
        ReikiRootModel reikiRootModel { get { return ModelCenter.Instance.GetModel<ReikiRootModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        TaskModel taskModel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
 
        public override void Init()
        {
            ParseConfig();
        }
 
        public override void UnInit()
        {
        }
 
        void ParseConfig()
        {
            var configs = TaskFeedbackConfig.GetValues();
            foreach (var config in configs)
            {
                if (config.type == 100)
                {
                    continue;
                }
 
                var feedback = new TaskFeedback()
                {
                    taskId = config.taskId,
                    type = (TaskFeedbackType)config.type,
                };
 
                switch (feedback.type)
                {
                    case TaskFeedbackType.FightPower:
                    case TaskFeedbackType.ReikiPoint:
                    case TaskFeedbackType.Copper:
                        feedback.condition = int.Parse(config.condition);
                        break;
                    case TaskFeedbackType.SideTask:
                        {
                            var array = LitJson.JsonMapper.ToObject<int[][]>(config.condition);
                            if (array != null)
                            {
                                List<int[]> sideTasks = new List<int[]>(array.Length);
                                for (int i = 0; i < array.Length; i++)
                                {
                                    sideTasks.Add(array[i]);
                                }
                                feedback.sideTasks = sideTasks;
                            }
                        }
                        break;
                    case TaskFeedbackType.Equip:
                        {
                            var array = LitJson.JsonMapper.ToObject<int[]>(config.condition);
                            feedback.equipCondition = array;
                        }
                        break;
                }
 
                m_TaskFeedbacks.Add(config.taskId, feedback);
            }
        }
 
        public bool TryGetTaskFeedback(int taskId, out TaskFeedback feedback)
        {
            return m_TaskFeedbacks.TryGetValue(taskId, out feedback);
        }
 
        public void ExecuteTaskFeedback(int taskId)
        {
            TaskFeedback feedback;
            if (TryGetTaskFeedback(taskId, out feedback))
            {
                var config = TaskFeedbackConfig.Get(taskId);
 
                switch (feedback.type)
                {
                    case TaskFeedbackType.FightPower:
                    case TaskFeedbackType.ReikiPoint:
                    case TaskFeedbackType.Guide:
                    case TaskFeedbackType.Equip:
                        {
                            int condition = 0;
                            if (IsSatisfyCondition(feedback, out condition))
                            {
                                if (config.succGuide != 0)
                                {
                                    ExecuteGuide(config.succGuide);
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(config.remind))
                                {
                                    SysNotifyMgr.Instance.ShowTip(config.remind);
                                }
                                if (config.failGuide != 0)
                                {
                                    ExecuteGuide(config.succGuide);
                                }
                            }
                        }
                        break;
                    case TaskFeedbackType.SideTask:
                        {
                            int condition = 0;
                            if (IsSatisfyCondition(feedback, out condition))
                            {
                                if (config.succGuide != 0)
                                {
                                    ExecuteGuide(config.succGuide);
                                }
                            }
                            else
                            {
                                var sideFeedbackConfig = TaskFeedbackConfig.Get(condition);
                                if (!string.IsNullOrEmpty(sideFeedbackConfig.remind))
                                {
                                    SysNotifyMgr.Instance.ShowTip(sideFeedbackConfig.remind);
                                }
                                if (sideFeedbackConfig != null && sideFeedbackConfig.failGuide != 0)
                                {
                                    ExecuteGuide(sideFeedbackConfig.failGuide);
                                }
                            }
                        }
                        break;
                }
            }
        }
 
        public void ExecuteGuide(int id)
        {
            var config = GuideConfig.Get(id);
            if (config == null)
            {
                DebugEx.LogFormat("引导<color=#ff0000>{0}</color>未添加", id);
                return;
            }
            switch ((GuideType)config.Type)
            {
                case GuideType.Functional:
                    FunctionalGuideCenter.Instance.StartGuide(id);
                    break;
                default:
                    NewBieCenter.Instance.StartNewBieGuide(id);
                    break;
            }
        }
 
        public bool IsSatisfyCondition(TaskFeedback feedback, out int condition)
        {
            condition = feedback.condition;
            switch (feedback.type)
            {
                case TaskFeedbackType.FightPower:
                    return PlayerDatas.Instance.baseData.FightPoint >= feedback.condition;
                case TaskFeedbackType.SideTask:
                    foreach (var taskId in taskModel.SideQuestsDic.Keys)
                    {
                        for (int i = 0; i < feedback.sideTasks.Count; i++)
                        {
                            if (taskId >= feedback.sideTasks[i][0]
                                && taskId <= feedback.sideTasks[i][1])
                            {
                                condition = taskId;
                                return false;
                            }
                        }
                    }
                    return true;
                case TaskFeedbackType.ReikiPoint:
                    return reikiRootModel.GetReikiRootTotalPoint() >= feedback.condition;
                case TaskFeedbackType.Equip:
                    var items = packModel.GetItems(PackType.Item, new SinglePack.FilterParams()
                    {
                        levels = new List<int>() { feedback.equipCondition[0] },
                        qualitys = new List<int>() { feedback.equipCondition[1] },
                    });
                    return items != null && items.Count > 0;
                case TaskFeedbackType.Copper:
                    return PlayerDatas.Instance.baseData.allCopper >= (ulong)feedback.condition;
                case TaskFeedbackType.Guide:
                    return true;
            }
            return false;
        }
    }
 
    public struct TaskFeedback
    {
        public int taskId;
        public TaskFeedbackType type;
        public int condition;
        public List<int[]> sideTasks;
        public int[] equipCondition;
    }
 
    public enum TaskFeedbackType
    {
        FightPower = 1,
        SideTask = 2,
        ReikiPoint = 3,
        Equip = 4,
        Copper = 5,
        Guide = 6,
    }
}