少年修仙传客户端代码仓库
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
using UnityEngine;
namespace vnxbqy.UI
{
    //福地-福地详情
    public class BlessedLandDetailsWin : Window
    {
        [SerializeField] ImageEx imgItemIcon;
        [SerializeField] ImageEx imgMy;
        [SerializeField] ImageEx imgLeftDownArrow;
        [SerializeField] ImageEx imgRightDownArrow;
        [SerializeField] ImageEx imgLeftSpriteAnimation;
        [SerializeField] ImageEx imgRightSpriteAnimation;
        [SerializeField] ImageEx imgLeftWorkersCountBG;
        [SerializeField] ImageEx imgRightWorkersCountBG;
        [SerializeField] AvatarCell rightHead;
        [SerializeField] AvatarCell leftHead;
        [SerializeField] TextEx txtLeftCount;
        [SerializeField] TextEx txtRightCount;
        [SerializeField] TextEx txtLeftHostCollectionFlag;
        [SerializeField] TextEx txtRightHostCollectionFlag;
        [SerializeField] TextEx txtLeftName;
        [SerializeField] TextEx txtRightName;
        [SerializeField] TextEx txtLeftCollectionFlag;
        [SerializeField] TextEx txtRightCollectionFlag;
        [SerializeField] TextEx txtChooseWorkerCount;
        [SerializeField] TextEx txtCollectionTime;
        [SerializeField] TextEx txtTime;
        [SerializeField] TextEx txtItemCount;
        [SerializeField] TextEx txtItemMaxWorkerCount;
        [SerializeField] TextEx txtCollectionByOther;
        [SerializeField] ButtonEx btnClose;
        [SerializeField] ButtonEx btnReduce;
        [SerializeField] ButtonEx btnAdd;
        [SerializeField] ButtonEx btnRecall1;
        [SerializeField] ButtonEx btnRecall2;
        [SerializeField] ButtonEx btnCollection1;
        [SerializeField] ButtonEx btnCollection2;
        [SerializeField] ButtonEx btnCollection3;
        [SerializeField] ButtonEx btnPK1;
        [SerializeField] ButtonEx btnPK2;
        [SerializeField] ItemCell itemCell;
 
        MineItemInfo itemInfos;
        int state;
        int itemMaxWorkerCount;
        int needSeconds;
 
        int nowDispatchCount;   //当前已经派遣了多少人 没派遣是0
        int nowFreeWorkerCount; //当前空闲人数
        int maxDispatchCount;   //当前最大还能派遣多少人
        int realDispatchCount;   //当前实际还能派遣多少人
        int chooseWorkerCount;  //当前派遣人数
        BlessedLandModel blessedLandModel { get { return ModelCenter.Instance.GetModel<BlessedLandModel>(); } }
        RoleParticularModel roleParticularModel { get { return ModelCenter.Instance.GetModel<RoleParticularModel>(); } }
 
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
            btnCollection1.SetListener(() => TryCollection());
            btnCollection2.SetListener(() => TryCollection());
            btnCollection3.SetListener(() => TryCollection());
            btnRecall1.SetListener(() => TryRecall());
            btnRecall2.SetListener(() => TryRecall());
            btnPK1.SetListener(() => TryPK());
            btnPK2.SetListener(() => TryPK());
 
            btnAdd.SetListener(() =>
            {
                //派遣的工人数不能超过物品派遣工人上限
                if (chooseWorkerCount >= itemMaxWorkerCount)
                    return;
                //派遣的工人数超过当前最大可以调配的工人数
                if (chooseWorkerCount >= maxDispatchCount)
                    return;
                if (chooseWorkerCount < itemMaxWorkerCount)
                    chooseWorkerCount += 1;
                txtChooseWorkerCount.text = StringUtility.Contact(chooseWorkerCount, "/", realDispatchCount);
                blessedLandModel.SendCB030Pack(blessedLandModel.showPlayerId, blessedLandModel.detailsIndex, (byte)chooseWorkerCount, 1);
            });
 
            btnReduce.SetListener(() =>
            {
                //派遣的工人数不能小于0
                if (chooseWorkerCount <= 0)
                    return;
                //有可派遣的工人 最小能减到显示1 没有可派遣的工人时 最小能减到0
                if (realDispatchCount > 0)
                {
                    if (chooseWorkerCount > 1)
                        chooseWorkerCount -= 1;
                }
                else
                {
                    if (chooseWorkerCount >= 1)
                        chooseWorkerCount -= 1;
                }
                txtChooseWorkerCount.text = StringUtility.Contact(chooseWorkerCount, "/", realDispatchCount);
                blessedLandModel.SendCB030Pack(blessedLandModel.showPlayerId, blessedLandModel.detailsIndex, (byte)chooseWorkerCount, 1);
            });
 
            btnClose.SetListener(() =>
            {
                WindowCenter.Instance.Close<BlessedLandDetailsWin>();
            });
        }
 
        protected override void OnPreOpen()
        {
            blessedLandModel.UpdatePullPreviewMine += OnUpdatePullPreviewMine;
            GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
            needSeconds = blessedLandModel.WorkerCount == blessedLandModel.GetWorkingCount() ? 0 : (int)ModelCenter.Instance.GetModel<BlessedLandModel>().NeedSeconds;
            //是自己的福地资源还是别人的
            if (blessedLandModel.showPlayerId == blessedLandModel.myPlayerId)
            {
                itemInfos = blessedLandModel.newAreaDataDict[blessedLandModel.myPlayerId].MineItems[blessedLandModel.detailsIndex];
 
                itemMaxWorkerCount = blessedLandModel.itemLevelMaxWorkersArr[MineAreaItemConfig.Get(itemInfos.MineID).ItemLV - 1];
                nowDispatchCount = blessedLandModel.GetItemWorkingCount(blessedLandModel.showPlayerId, blessedLandModel.detailsIndex);
                nowFreeWorkerCount = blessedLandModel.WorkerCount - blessedLandModel.GetWorkingCount();
                maxDispatchCount = nowFreeWorkerCount + nowDispatchCount;
                realDispatchCount = Mathf.Min(maxDispatchCount, itemMaxWorkerCount);
                chooseWorkerCount = nowDispatchCount > 0 ? (byte)nowDispatchCount : realDispatchCount > 0 ? (byte)1 : (byte)0;
 
                state = blessedLandModel.GetMyBlessedLandCellState(blessedLandModel.detailsIndex);
                //0 无物品 1 有物品-超级物品-无人拉 2 有物品-超级物品-自己拉
                //3 有物品-普通物品-无人拉 4 有物品-普通物品-自己拉 5 有物品-普通物品-对方拉
                //6 有物品-普通物品-双方拉-向自己移动 7 有物品-普通物品-双方拉-向对方移动
                //在自己福地 左边是抢夺者 右边是房主
                bool isMy = state == 2 || state == 4 || state == 6 || state == 7;
                bool isEnemy = state == 5 || state == 6 || state == 7;
                bool isMoveToMine = state == 2 || state == 4 || state == 6;
                bool isMoveToEnemy = state == 5 || state == 7;
                imgLeftWorkersCountBG.SetActive(isEnemy);
                imgRightWorkersCountBG.SetActive(isMy);
                txtLeftName.SetActive(isEnemy);
                imgRightDownArrow.SetActive(isMoveToMine);
                imgLeftDownArrow.SetActive(isMoveToEnemy);
                txtLeftCollectionFlag.SetActive(state == 3 || state == 4);
                txtRightCollectionFlag.SetActive(state == 3 || state == 5);
                imgLeftSpriteAnimation.SetActive(state == 3 || state == 4 || state == 5 || state == 6 || state == 7);
                txtLeftHostCollectionFlag.SetActive(false);
                txtRightHostCollectionFlag.SetActive(state == 1);
                imgMy.SetActive(isMy);
                txtCollectionByOther.SetActive(false);
                txtRightName.SetActive(false);
                txtCollectionTime.SetActive(true);
                btnRecall1.SetActive(state == 2 || state == 4);
                btnRecall2.SetActive(state == 6 || state == 7);
                btnCollection1.SetActive(state == 1 || state == 3);
                btnCollection2.SetActive(state == 2 || state == 4 || state == 5);
                btnCollection3.SetActive(state == 6 || state == 7);
                btnPK1.SetActive(state == 6 || state == 7);
                btnPK2.SetActive(state == 5);
                ItemCellShow();
                imgRightSpriteAnimation.sprite = isMy ? UILoader.LoadSprite("BlessedLand02") : UILoader.LoadSprite("BlessedLand01");
                imgLeftSpriteAnimation.sprite = isEnemy ? UILoader.LoadSprite("BlessedLand02") : UILoader.LoadSprite("BlessedLand01");
                txtRightCount.text = itemInfos.WorkerCount.ToString();
                txtLeftCount.text = itemInfos.RobWorkerCount.ToString();
                txtLeftName.text = itemInfos.RobPlayerID < 10000 ? blessedLandModel.GetNameForPlayerId((int)itemInfos.RobPlayerID) : UIHelper.ServerStringTrim(itemInfos.RobPlayerName);
                imgItemIcon.SetSprite(ItemConfig.Get(MineAreaItemConfig.Get(itemInfos.MineID).ItemID).IconKey);
                txtItemCount.text = MineAreaItemConfig.Get(itemInfos.MineID).ItemCount.ToString();
                txtChooseWorkerCount.text = StringUtility.Contact(chooseWorkerCount, "/", realDispatchCount);
                txtChooseWorkerCount.colorType = realDispatchCount > 0 ? TextColType.White : TextColType.Red;
                txtItemMaxWorkerCount.text = Language.Get("BlessedLand047", itemMaxWorkerCount);
                ChangeCollectionTime(needSeconds);
                leftHead.InitUI(itemInfos.RobPlayerID < 10000 ? blessedLandModel.GetModelForPlayerId((int)itemInfos.RobPlayerID) : AvatarHelper.GetAvatarModel((int)itemInfos.RobPlayerID, (int)itemInfos.RobFace, (int)itemInfos.RobFacePic, (int)itemInfos.RobJob));
                rightHead.InitUI(AvatarHelper.GetMyAvatarModel());
            }
            else
            {
                itemInfos = blessedLandModel.newAreaDataDict[blessedLandModel.showPlayerId].MineItems[blessedLandModel.detailsIndex];
 
                itemMaxWorkerCount = blessedLandModel.itemLevelMaxWorkersArr[MineAreaItemConfig.Get(itemInfos.MineID).ItemLV - 1];
                nowDispatchCount = blessedLandModel.GetItemWorkingCount(blessedLandModel.showPlayerId, blessedLandModel.detailsIndex);
                nowFreeWorkerCount = blessedLandModel.WorkerCount - blessedLandModel.GetWorkingCount();
                maxDispatchCount = nowFreeWorkerCount + nowDispatchCount;
                realDispatchCount = Mathf.Min(maxDispatchCount, itemMaxWorkerCount);
                chooseWorkerCount = nowDispatchCount > 0 ? (byte)nowDispatchCount : realDispatchCount > 0 ? (byte)1 : (byte)0;
 
                state = blessedLandModel.GetOtherBlessedLandCellState(blessedLandModel.detailsIndex);
                //0 无物品 1 有物品-超级物品-无人拉 2 有物品-超级物品-房主拉
                //3 有物品-普通物品-无人拉 4 有物品-普通物品-房主拉 5 有物品-普通物品-玩家拉 6 有物品-普通物品-别人拉
                //7 有物品-普通物品-房主和玩家抢-向房主移动 8 有物品-普通物品-房主和玩家抢-向玩家移动
                //9 有物品-普通物品-房主和别人抢-向房主移动 10 有物品-普通物品-房主和别人抢-向别人移动
                //在别人福地 左边是房主 右面是抢夺者
                bool isHost = state == 2 || state == 4 || state == 7 || state == 8 || state == 9 || state == 10;
                bool isTheft = state == 5 || state == 6 || state == 7 || state == 8 || state == 9 || state == 10;
                bool isPlayer = state == 5 || state == 7 || state == 8;
                bool isMoveTosHost = state == 2 || state == 4 || state == 7 || state == 9;
                bool isMoveToTheft = state == 5 || state == 6 || state == 8 || state == 10;
                imgLeftWorkersCountBG.SetActive(isHost);
                imgRightWorkersCountBG.SetActive(isTheft);
                txtLeftName.SetActive(isHost);
                txtRightName.SetActive(state == 6 || state == 9 || state == 10);
                imgRightDownArrow.SetActive(isMoveToTheft);
                imgLeftDownArrow.SetActive(isMoveTosHost);
                txtLeftHostCollectionFlag.SetActive(state == 3 || state == 5 || state == 6);
                txtRightHostCollectionFlag.SetActive(false);
                txtLeftCollectionFlag.SetActive(false);
                txtRightCollectionFlag.SetActive(state == 3 || state == 4);
                txtCollectionByOther.SetActive(state == 6 || state == 9 || state == 10);
                txtCollectionTime.SetActive(state == 3 || state == 4 || state == 5 || state == 7 || state == 8);
                imgMy.SetActive(isPlayer);
                imgLeftSpriteAnimation.SetActive(true);
                btnRecall1.SetActive(isPlayer);
                btnRecall2.SetActive(false);
                btnCollection1.SetActive(state == 3 || state == 4);
                btnCollection2.SetActive(isPlayer);
                btnCollection3.SetActive(false);
                btnPK1.SetActive(false);
                btnPK2.SetActive(false);
                ItemCellShow();
                imgLeftSpriteAnimation.sprite = isHost ? UILoader.LoadSprite("BlessedLand02") : UILoader.LoadSprite("BlessedLand01");
                imgRightSpriteAnimation.sprite = isTheft ? UILoader.LoadSprite("BlessedLand02") : UILoader.LoadSprite("BlessedLand01");
                txtLeftCount.text = itemInfos.WorkerCount.ToString();
                txtRightCount.text = itemInfos.RobWorkerCount.ToString();
                txtLeftName.text = blessedLandModel.newAreaDataDict[blessedLandModel.showPlayerId].PlayerName;
                txtRightName.text = itemInfos.RobPlayerID < 10000 ? blessedLandModel.GetNameForPlayerId((int)itemInfos.RobPlayerID) : UIHelper.ServerStringTrim(itemInfos.RobPlayerName);
                itemMaxWorkerCount = blessedLandModel.itemLevelMaxWorkersArr[MineAreaItemConfig.Get(itemInfos.MineID).ItemLV - 1];
                txtChooseWorkerCount.text = StringUtility.Contact(chooseWorkerCount, "/", realDispatchCount);
                txtChooseWorkerCount.colorType = realDispatchCount > 0 ? TextColType.White : TextColType.Red;
                imgItemIcon.SetSprite(ItemConfig.Get(MineAreaItemConfig.Get(itemInfos.MineID).ItemID).IconKey);
                txtItemCount.text = MineAreaItemConfig.Get(itemInfos.MineID).ItemCount.ToString();
                txtItemMaxWorkerCount.text = Language.Get("BlessedLand047", itemMaxWorkerCount);
                ChangeCollectionTime(needSeconds);
                MineAreaInfo mineAreaInfo = blessedLandModel.newAreaDataDict[blessedLandModel.showPlayerId];
                leftHead.InitUI(itemInfos.RobPlayerID < 10000 ? blessedLandModel.GetModelForPlayerId((int)blessedLandModel.showPlayerId) : AvatarHelper.GetAvatarModel((int)mineAreaInfo.PlayerID, (int)mineAreaInfo.Face, (int)mineAreaInfo.FacePic, (int)mineAreaInfo.Job));
                rightHead.InitUI(itemInfos.RobPlayerID < 10000 ? blessedLandModel.GetModelForPlayerId((int)itemInfos.RobPlayerID) : AvatarHelper.GetAvatarModel((int)itemInfos.RobPlayerID, (int)itemInfos.RobFace, (int)itemInfos.RobFacePic, (int)itemInfos.RobJob));
                blessedLandModel.SendCB030Pack(blessedLandModel.showPlayerId, blessedLandModel.detailsIndex, itemInfos.RobPlayerID == blessedLandModel.myPlayerId ? (byte)Mathf.Max(itemInfos.RobWorkerCount, 1) : (byte)1, 1);
 
            }
        }
 
        protected override void OnAfterOpen()
        {
 
        }
 
        protected override void OnAfterClose()
        {
 
        }
 
        protected override void OnPreClose()
        {
            GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
            blessedLandModel.UpdatePullPreviewMine -= OnUpdatePullPreviewMine;
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        }
 
        private void OnBeforePlayerDataInitialize()
        {
            if (WindowCenter.Instance.IsOpen<BlessedLandDetailsWin>())
            {
                WindowJumpMgr.Instance.ClearJumpData();
                WindowCenter.Instance.CloseAll();
            }
        }
 
        private void OnSecondEvent()
        {
            if (state == 0 || state == 1 || state == 3)
                return;
            if (needSeconds == 0)
                return;
            needSeconds -= 1;
            ChangeCollectionTime(needSeconds);
            if (needSeconds == 0 && WindowCenter.Instance.IsOpen<BlessedLandDetailsWin>())
                WindowCenter.Instance.Close<BlessedLandDetailsWin>();
        }
 
        private void OnUpdatePullPreviewMine()
        {
            needSeconds = (int)ModelCenter.Instance.GetModel<BlessedLandModel>().NeedSeconds;
            ChangeCollectionTime(needSeconds);
        }
 
        void ChangeCollectionTime(int needSeconds)
        {
            string time = TimeUtility.SecondsToDHMS(needSeconds);
            if (blessedLandModel.showPlayerId == blessedLandModel.myPlayerId)
            {
                txtCollectionTime.text = state == 1 || state == 3 || state == 5 ? Language.Get("BlessedLand032") : Language.Get("BlessedLand033");
                txtTime.text = time.ToString();
            }
            else
            {
                txtCollectionTime.text = state == 3 || state == 4 ? Language.Get("BlessedLand032") : Language.Get("BlessedLand033");
                txtTime.text = time.ToString();
            }
        }
 
        void ItemCellShow()
        {
            int mineID = itemInfos.MineID;
            int itemID = MineAreaItemConfig.Get(mineID).ItemID;
            int itemLV = MineAreaItemConfig.Get(mineID).ItemLV;
            itemCell.Init(new ItemCellModel(itemID, false, (ulong)itemLV));
            itemCell.countText.SetActive(true);
            itemCell.countText.text = Language.Get("FashionDress106", itemLV);
            itemCell.button.SetListener(() =>
            {
                ItemTipUtility.Show(itemID);
            });
        }
 
        void TryCollection()
        {
            //工人体力耗尽
            if (blessedLandModel.EnergyUsed >= blessedLandModel.GetTotalEnergy())
            {
                SysNotifyMgr.Instance.ShowTip("BlessedLand01");
                return;
            }
            //同时采集同一个人的多个资源
            if (blessedLandModel.showPlayerId != blessedLandModel.myPlayerId && blessedLandModel.IsSnatchItem())
            {
                SysNotifyMgr.Instance.ShowTip("BlessedLand02");
                return;
            }
            //当前资源正在被别人采
            if (blessedLandModel.showPlayerId != blessedLandModel.myPlayerId && itemInfos.RobWorkerCount > 0 && itemInfos.RobPlayerID != blessedLandModel.myPlayerId)
            {
                SysNotifyMgr.Instance.ShowTip("BlessedLand03");
                return;
            }
            //没有空闲工人
            if (realDispatchCount <= 0)
            {
                SysNotifyMgr.Instance.ShowTip("BlessedLand04");
                return;
            }
            blessedLandModel.SendCB030Pack(blessedLandModel.showPlayerId, blessedLandModel.detailsIndex, (byte)chooseWorkerCount, 0);
            WindowCenter.Instance.Close<BlessedLandDetailsWin>();
        }
 
        void TryRecall()
        {
            ConfirmCancel.ShowPopConfirm(
                Language.Get("L1003"),
                Language.Get("BlessedLand020"),
                (bool isOk) =>
                {
                    if (isOk)
                    {
                        blessedLandModel.SendCB030Pack(blessedLandModel.showPlayerId, blessedLandModel.detailsIndex, 0, 0);
                        WindowCenter.Instance.Close<BlessedLandDetailsWin>();
                    }
                });
            return;
        }
 
        void TryPK()
        {
            blessedLandModel.helpType = 0;
            blessedLandModel.robPlayerId = itemInfos.RobPlayerID;
            roleParticularModel.ViewCrossPlayerCacheData((int)blessedLandModel.robPlayerId, (int)ViewPlayerType.viewCrossPlayerDataBlessedLand);
        }
 
    }
}