yyl
7 天以前 871594462e82d6bc1341918d39e11ab036d59563
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using LitJson;
using UnityEngine.UI;
 
 
public class EquipModel : GameSystemManager<EquipModel>
{
    public const int TotleEquip = 12;  //装备栏大小
    public bool waitEquipOPPack = false;    // 穿戴装备的操作 不含分解
    public event Action<bool, int> OnEquipOPResultAction;    //是否换上了新装备且分解了 装备索引
    public event Action<List<int>, RectTransform> OnItemDropEvent;
 
    //用于飘动逻辑
    // public Dictionary<int, EquipOnFloorInfo> equipFloorInfo = new Dictionary<int, EquipOnFloorInfo>(); //真实背包的索引,对应地板装备的信息
 
    public int[] equipUIEffectLights;  //装备掉落特效
    public float[] dropEffectScales;    //掉装备的动画缩放
    public Dictionary<int, int> newEquipIDToGuideID = new Dictionary<int, int>();  //装备掉落id,引导的id
    public int[] equipUIEffects;  //装备TIP面板特效
    public int[] equipUIGirdEffects;  //装备格子特效
    public ItemModel selectFloorEquip; //选中的地板装备
    public int lastShowEquipIndex = -1;  //上一次界面显示装备的索引,拾取后物品消失需记录下做表现
    public Queue<int> waitEquipOP = new Queue<int>();    //等待操作的装备,需要和UI交互确认 不含分解
 
    public List<int> lastDropIndexs = new List<int>(); //上一次掉落物品索引
 
    public override void Init()
    {
        DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnEquipResult;
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += BeforePlayerDataInitialize;
        EventBroadcast.Instance.AddListener<string, BattleDrops, Action>(EventName.BATTLE_DROP_ITEMS, OnDropEvent);
        ParseConfig();
    }
 
    public override void Release()
    {
        DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnEquipResult;
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= BeforePlayerDataInitialize;
        EventBroadcast.Instance.RemoveListener<string, BattleDrops, Action>(EventName.BATTLE_DROP_ITEMS, OnDropEvent);
    }
 
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("DropItem");
        equipUIEffectLights = JsonMapper.ToObject<int[]>(config.Numerical1);
        dropEffectScales = JsonMapper.ToObject<float[]>(config.Numerical2);
        newEquipIDToGuideID = ConfigParse.ParseIntDict(config.Numerical3);
 
        config = FuncConfigConfig.Get("EquipTip");
        equipUIEffects = JsonMapper.ToObject<int[]>(config.Numerical1);
    }
 
    void BeforePlayerDataInitialize()
    {
        selectFloorEquip = null;
        waitEquipOP.Clear();
        lastShowEquipIndex = -1;
        lastDropIndexs.Clear();
    }
 
 
    public static int GetItemServerEquipPlace(int itemId)
    {
        var config = ItemConfig.Get(itemId);
        if (config == null)
        {
            return -1;
        }
 
        if (config.EquipPlace > 0 && config.EquipPlace < 13)
        {
            return config.EquipPlace - 1;
        }
 
 
        return -1;
    }
 
    void OnDropEvent(string guid, BattleDrops drops, Action action)
    {
        if (!string.IsNullOrEmpty(guid))
            return;
 
        lastDropIndexs = drops.dropItemPackIndex;
        // Debug.Log("-掉落装备 " + lastDropIndexs.Count + " 个" + JsonMapper.ToJson(lastDropIndexs));
        NotifyItemDrop(drops.dropItemPackIndex, drops.rectTransform);
        action?.Invoke();
    }
 
    //掉落通知
    public void NotifyItemDrop(List<int> indexs, RectTransform rect)
    {
        // 界面不显示则立即处理
        if (!UIManager.Instance.IsOpened<HomeWin>())
        {
            for (int i = 0; i < indexs.Count; i++)
            {
                CalcFloorEquip(indexs[i]);
            }
        }
        else
        {
            OnItemDropEvent?.Invoke(indexs, rect);
        }
    }
 
    public void CalcFloorEquip(int itemIndex)
    {
        if (itemIndex == -1)
            return;
 
        var item = PackManager.Instance.GetItemByIndex(PackType.DropItem, itemIndex);
        if (item == null)
            return;
 
 
        //非自动模式下,筛选装备打开装备操作界面
        if (IsEquip(item))
        {
            OpenEquipExchangeWin(item);
        }
        else
        {
            SendEquipOP(new ushort[] { (ushort)itemIndex }, 0);
        }
    }
 
    private void OnEquipResult(HA814_tagMCMakeItemAnswer info)
    {
        if (info.MakeType != (int)MakeType.EquipOP)
            return;
        if (info.MakeValue == 0)
            return;
 
        if (info.MakeValue == 2)
            waitEquipOPPack = false;
        bool isDone = false;    // 换上新装备且分解了旧装备
        //选中的地板装备进行处理,替换还是找下一件,检查OnEquipOPResultAction
        if (selectFloorEquip != null)
        {
            Debug.Log("OnEquipResult selectFloorEquip ID:" + selectFloorEquip.itemId);
            if (PackManager.Instance.GetItemByIndex(PackType.DropItem, selectFloorEquip.gridIndex) == null)
            {
                selectFloorEquip = GetSelectFloorEquip();    //删除已选择的装备
                if (info.MakeValue == 2)
                    isDone = true;
            }
        }
        else
        {
            selectFloorEquip = GetSelectFloorEquip();
            if (info.MakeValue == 2)
                isDone = true;
        }
 
        if (selectFloorEquip == null)
        {
            if (UIManager.Instance.IsOpened<EquipExchangeWin>())
            {
                UIManager.Instance.CloseWindow<EquipExchangeWin>();
            }
        }
        else
        {
            if (!UIManager.Instance.IsOpened<EquipExchangeWin>())
            {
                UIManager.Instance.OpenWindow<EquipExchangeWin>();
            }
        }
 
        OnEquipOPResultAction?.Invoke(isDone, lastShowEquipIndex);
    }
 
    /// <summary>
    /// 装备操作, // 0 - 拾取非装备物品;1 - 分解;2 - 穿戴/替换
    /// </summary>
    /// <param name="itemIndexList"></param>
    /// <param name="opType"></param>
    /// <param name="autoDecompose"></param>
    public void SendEquipOP(ushort[] itemIndexList, byte opType, bool autoDecompose = false)
    {
        if (opType == 2 && waitEquipOPPack) return;
 
        // NoteFloorEquip(itemIndexList, opType);
        var pack = new CB415_tagCSMainDropItemOP();
        pack.Count = (byte)itemIndexList.Length;
        pack.IndexList = itemIndexList;
        pack.OPType = opType;
        pack.OPValue = (byte)(autoDecompose ? 1 : 0); // 替换后是否自动分解原装备:0否1是
 
        if (opType == 2)
            waitEquipOPPack = true;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    /// <summary>
    /// equipFloorInfo记录地板道具的最新一次信息,用于替换和分解装备的表现
    /// </summary>
    /// <param name="itemIndexList">地板道具索引</param>
    /// <param name="opType"></param>
    // public void NoteFloorEquip(ushort[] itemIndexList, int opType)
    // {
    //     equipFloorInfo.Clear();
    //     foreach (var girdIndex in itemIndexList)
    //     {
    //         var equip = PackManager.Instance.GetItemByIndex(PackType.DropItem, girdIndex);
    //         if (equip == null) continue;
    //         equipFloorInfo[girdIndex] = new EquipOnFloorInfo()
    //         {
    //             equipID = equip.itemId,
    //             posX = floorItemCellArr[girdIndex].transform.position.x,
    //             posY = floorItemCellArr[girdIndex].transform.position.y,
    //             opType = opType
    //         };
    //     }
 
    // }
 
    public class EquipOnFloorInfo
    {
        public int equipID; //道具或者装备,道具分解对应不同货币,装备固定货币
        public float posX;  //全局坐标 表现再转成local
        public float posY;
        public int opType;  // 0 - 拾取非装备物品;1 - 分解;2 - 穿戴/替换;
    }
 
    // public EquipOnFloorInfo FindExchangeEquipInfo()
    // {
    //     foreach (var info in equipFloorInfo)
    //     {
    //         if (info.Value.opType == 2)
    //             return info.Value;
    //     }
    //     return new EquipOnFloorInfo();
    // }
 
    public bool OpenEquipExchangeWin(ItemModel equip)
    {
        if (equip == null)
            return false;
 
        // if (!IsEquip(equip))
        //     return false;
 
        if (AutoFightModel.Instance.TryAutoFightDoEquip(equip))
        {
            //自动战力对比, 条件不满足的分解
            return false;
        }
 
        // 好几件装备需要处理的情况存起来
        waitEquipOP.Enqueue(equip.gridIndex);
        //未回复装备操作结果,否则会显示旧装备
        if (waitEquipOPPack)
            return false;
 
        // 后续补充引导或者其他情况下,不允许切换装备界面
        // if (NewBieCenter.Instance.inGuiding)
        //     return;
 
        if (UIManager.Instance.IsOpened<EquipExchangeWin>())
        {
            return false;
        }
 
        
        selectFloorEquip = GetSelectFloorEquip();
        if (selectFloorEquip == null)
            return false;
        
        UIManager.Instance.OpenWindow<EquipExchangeWin>();
        return true;
 
    }
 
 
    ItemModel GetSelectFloorEquip()
    {
        if (waitEquipOP.Count == 0)
            return null;
 
        return PackManager.Instance.GetItemByIndex(PackType.DropItem, waitEquipOP.Dequeue());
 
    }
 
 
 
    //等级
    public int GetEquipLV(ItemModel equip)
    {
        if (equip == null)
        {
            return 0;
        }
 
        return equip.GetUseDataFirstValue(22);
    }
 
    //基础属性ID列表
    public List<int> GetEquipBaseAttrs(ItemModel equip)
    {
        if (equip == null)
        {
            return new List<int>();
        }
        return equip.GetUseData(21);
    }
 
 
    //基础属性值列表
    public List<int> GetEquipBaseValues(ItemModel equip)
    {
        if (equip == null)
        {
            return new List<int>();
        }
        return equip.GetUseData(23);
    }
 
    //战斗属性ID列表
    public List<int> GetEquipFightAttrs(ItemModel equip)
    {
        if (equip == null)
        {
            return new List<int>();
        }
        return equip.GetUseData(17);
    }
 
    //战斗属性值列表
    public List<int> GetEquipFightValues(ItemModel equip)
    {
        if (equip == null)
        {
            return new List<int>();
        }
        return equip.GetUseData(19);
    }
 
 
    //得到装备位对应的部位名称
    public string GetEquipPlaceName(int place)
    {
 
        return Language.Get("equipPlace" + place);
    }
 
    //是否装备
    public bool IsEquip(ItemModel item)
    {
        return item.config.EquipPlace != 0;
    }
 
    public bool IsEquip(int itemID)
    {
        return ItemConfig.Get(itemID).EquipPlace != 0;
    }
 
    public ItemModel GetEquip(int index)
    { 
        return PackManager.Instance.GetItemByIndex(PackType.Equip, index);
    }
}