少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
namespace Snxxz.UI
{
    [XLua.Hotfix]
    [XLua.LuaCallCSharp]
    public class GatherSoulDungeonModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        public const int DUNGEON_MAPID = 31340;
 
        GatherSoulDungeonHelp m_Mission;
        public GatherSoulDungeonHelp mission {
            get { return m_Mission; }
            private set {
                m_Mission = value;
            }
        }
 
        public int attckDefendNpcId { get; private set; }
        public int iceDefendNpcId { get; private set; }
        public int defendPointNpcId { get; private set; }
 
        public int attackDefendCountLimit { get; private set; }
        public int iceDefendCountLimit { get; private set; }
        public int generateBossCost { get; private set; }
        public int dungeonWeelCount { get; private set; }
 
        public bool clickGenerateMonster { get; set; }
 
        Dictionary<int, List<ItemInfo>> dungeonItemDict = new Dictionary<int, List<ItemInfo>>();
 
        readonly List<int> itemTypeSort = new List<int>() { GatheringSoulModel.GATHERSOUL_CORE_TYPE,
            GatheringSoulModel.GATHERSOUL_SOUL_TYPE,GatheringSoulModel.GATHERSOUL_ESSENCE_TYPE};
 
        public event Action missionHelpUpdate;
        public event Action monsterAppearEvent;
 
        public override void Init()
        {
            ParseConfig();
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            ResetDungeonMessage();
        }
 
        public void OnPlayerLoginOk()
        {
        }
 
        public override void UnInit()
        {
        }
 
        public int GetAttackDefendSurplusCount()
        {
            var count = GetDefendNpcCount(attckDefendNpcId);
            return attackDefendCountLimit - count;
        }
 
        public int GetIceDefendSurplusCount()
        {
            var count = GetDefendNpcCount(iceDefendNpcId);
            return iceDefendCountLimit - count;
        }
 
        void ParseConfig()
        {
            var funcConfig = FuncConfigConfig.Get("GatherSoulDungeon");
            if (funcConfig != null)
            {
                attckDefendNpcId = int.Parse(funcConfig.Numerical1);
                iceDefendNpcId = int.Parse(funcConfig.Numerical2);
                defendPointNpcId = int.Parse(funcConfig.Numerical3);
            }
 
            funcConfig = FuncConfigConfig.Get("GatherSoulAttacker");
            if (funcConfig != null)
            {
                attackDefendCountLimit = int.Parse(funcConfig.Numerical1);
                iceDefendCountLimit = int.Parse(funcConfig.Numerical2);
            }
 
            funcConfig = FuncConfigConfig.Get("GatherSoulGoldBoss");
            if (funcConfig != null)
            {
                generateBossCost = int.Parse(funcConfig.Numerical1);
            }
 
            funcConfig = FuncConfigConfig.Get("GatherSoulDungeonTurn");
            if (funcConfig != null)
            {
                dungeonWeelCount = int.Parse(funcConfig.Numerical1);
            }
        }
 
        public void OnReceiveDungeonMessage(string _mission)
        {
            mission = LitJson.JsonMapper.ToObject<GatherSoulDungeonHelp>(_mission);
            if (clickGenerateMonster && mission.step == 2)
            {
                if (monsterAppearEvent != null)
                {
                    monsterAppearEvent();
                }
            }
 
            dungeonItemDict.Clear();
            if (mission.gsItemInfo != null)
            {
                foreach (var key in mission.gsItemInfo.Keys)
                {
                    var weel = int.Parse(key);
                    List<ItemInfo> list;
                    if (!dungeonItemDict.TryGetValue(weel, out list))
                    {
                        list = new List<ItemInfo>();
                        dungeonItemDict.Add(weel, list);
                    }
                    if (mission.gsItemInfo[key] != null)
                    {
                        list.AddRange(mission.gsItemInfo[key]);
                        list.Sort(Compare);
                    }
                }
            }
 
            clickGenerateMonster = false;
 
            bool requreStepHint = mission.step == 1 && (GetDefendNpcCount(attckDefendNpcId) < attackDefendCountLimit
                || GetDefendNpcCount(iceDefendNpcId) < iceDefendCountLimit);
            if (requreStepHint && !WindowCenter.Instance.IsOpen<GatherSoulDungeonStepHintWin>())
            {
                WindowCenter.Instance.Open<GatherSoulDungeonStepHintWin>();
            }
            else if (!requreStepHint && WindowCenter.Instance.IsOpen<GatherSoulDungeonStepHintWin>())
            {
                WindowCenter.Instance.Close<GatherSoulDungeonStepHintWin>();
            }
 
            if (missionHelpUpdate != null)
            {
                missionHelpUpdate();
            }
        }
 
        public bool TryGetDungeonItems(int weel, out List<ItemInfo> list)
        {
            return dungeonItemDict.TryGetValue(weel, out list);
        }
 
        public int GetDefendNpcCount(int npcId)
        {
            if (mission.npc != null)
            {
                for (int i = 0; i < mission.npc.Length; i++)
                {
                    var npcInfo = mission.npc[i];
                    if (npcInfo.NPCID == npcId)
                    {
                        return npcInfo.killCnt;
                    }
                }
            }
            return 0;
        }
 
        public void ResetDungeonMessage()
        {
            mission = default(GatherSoulDungeonHelp);
            clickGenerateMonster = false;
            dungeonItemDict.Clear();
        }
 
        int Compare(ItemInfo lhs, ItemInfo rhs)
        {
            var lhsConfig = ItemConfig.Get(lhs.ItemID);
            var rhsConfig = ItemConfig.Get(rhs.ItemID);
            var lhsTypeSort = itemTypeSort.IndexOf(lhsConfig.Type);
            var rhsTypeSort = itemTypeSort.IndexOf(rhsConfig.Type);
            if (lhsTypeSort != rhsTypeSort)
            {
                return lhsTypeSort.CompareTo(rhsTypeSort);
            }
            if (lhsConfig.ItemColor != rhsConfig.ItemColor)
            {
                return -lhsConfig.ItemColor.CompareTo(rhsConfig.ItemColor);
            }
            return 0;
        }
 
        public struct ItemInfo
        {
            public int ItemID;
            public int Count;
        }
    }
 
    public struct GatherSoulDungeonHelp
    {
        public int lineID;
        public int wheel;
        public int step;
        public DungeonNPCInfo[] npc;
        public int isAuto;
        public int hasRefreshBoss;
        public Dictionary<string, GatherSoulDungeonModel.ItemInfo[]> gsItemInfo;
    }
}