少年修仙传客户端代码仓库
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
namespace vnxbqy.UI
{
    
    public class GuardModel : Model, IAfterPlayerDataInitialize, IPlayerLoginOk
    {
        List<int> fairyLandGuardItems = new List<int>();
 
        public bool fairyLandGuard { get; set; }
        public ItemModel fairyLandItemModel { get; private set; }
 
        public event Action onDungeonEquipGuardEvent;
 
        PackModel pack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
 
        public override void Init()
        {
            ParseConfig();
            StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
            pack.refreshItemCountEvent += RefreshItemCountAct;
            KnapsackTimeCDMgr.Instance.RefreshItemOverdueAct += RefreshItemOverdueTimeAct;
        }
 
        public void OnAfterPlayerDataInitialize()
        {
        }
 
        public void OnPlayerLoginOk()
        {
            SnxxzGame.Instance.StartCoroutine(Co_LoadGuard());
        }
 
        public override void UnInit()
        {
 
        }
 
        IEnumerator Co_LoadGuard()
        {
            yield return null;
            GA_Hero _hero = PlayerDatas.Instance.hero;
            if (_hero == null)
            {
                yield break;
            }
            var equipIndex = EquipSet.ClientPlaceToServerPlace(new Int2(0, (int)RoleEquipType.Guard));
            var _itemModel = pack.GetItemByIndex(PackType.Equip, equipIndex);
            if (_itemModel != null && _itemModel.itemInfo != null)
            {
                _hero.SwitchGuard((uint)_itemModel.itemId);
            }
        }
 
        private void RefreshItemCountAct(PackType type, int arg2, int _id)
        {
            if (fairyLandGuard)
            {
                if (type == PackType.Equip || fairyLandGuardItems.Contains(_id))
                {
                    CheckFairyLandGuard();
                }
            }
        }
 
        IEnumerator Co_DungeonDuardCheck()
        {
            yield return WaitingForSecondConst.WaitMS500;
            CheckFairyLandGuard();
        }
 
        private void OnStageLoadFinish()
        {
            var _mapId = dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);
            if (_mapId == 31080)
            {
                SnxxzGame.Instance.StartCoroutine(Co_DungeonDuardCheck());
            }
        }
 
        private void RefreshItemOverdueTimeAct(string _guid)
        {
            if (fairyLandGuard)
            {
                var itemModel = pack.GetItemByGuid(_guid);
                if (itemModel != null && fairyLandItemModel != null && itemModel.itemId == fairyLandItemModel.itemId)
                {
                    CheckFairyLandGuard();
                }
            }
        }
 
        private void CheckFairyLandGuard()
        {
            fairyLandGuard = false;
            var equipPlace = EquipPlaceMapConfig.GetServerPlace(0, (int)RoleEquipType.Guard);
            var itemModel = pack.GetItemByIndex(PackType.Equip, equipPlace);
            if (itemModel == null || !fairyLandGuardItems.Contains(itemModel.itemId))
            {
                for (int i = 0; i < fairyLandGuardItems.Count; i++)
                {
                    var list = pack.GetSinglePack(PackType.Item).GetItemsById(fairyLandGuardItems[i]);
                    if (list != null && list.Count > 0)
                    {
                        for (int k = 0; k < list.Count; k++)
                        {
                            bool isOverdue = ItemLogicUtility.Instance.IsOverdue(list[k].guid);
 
                            if (!isOverdue)
                            {
                                fairyLandGuard = true;
                                fairyLandItemModel = list[k];
                                if (onDungeonEquipGuardEvent != null)
                                {
                                    onDungeonEquipGuardEvent();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            if (onDungeonEquipGuardEvent != null)
            {
                onDungeonEquipGuardEvent();
            }
        }
 
        #region 配置
        public float speed { get; private set; }
        public float pickUpViewRange { get; private set; }
        public float pickUpAreaRange { get; private set; }
        public float traceRange { get; private set; }
        public float impendRange { get; private set; }
        public float idleTimeMin { get; private set; }
        public float idleTimeMax { get; private set; }
        public float stopAnimationSpeed { get; private set; }
        public float height { get; private set; }
        public float pickUpSfxSpeed { get; private set; }
        public float resetDistance { get; private set; }
 
        void ParseConfig()
        {
            var config = FuncConfigConfig.Get("XjmjGuardian");
            fairyLandGuardItems.AddRange(ConfigParse.GetMultipleStr<int>(config.Numerical1));
            fairyLandGuardItems.Sort(Compare);
 
            config = FuncConfigConfig.Get("GuardianSpeed");
            speed = float.Parse(config.Numerical1);
            stopAnimationSpeed = float.Parse(config.Numerical2);
            pickUpSfxSpeed = float.Parse(config.Numerical3);
 
            config = FuncConfigConfig.Get("GuardianPickupRange");
            pickUpViewRange = float.Parse(config.Numerical1);
            pickUpAreaRange = float.Parse(config.Numerical2);
 
            config = FuncConfigConfig.Get("GuardianTraceRange");
            traceRange = float.Parse(config.Numerical1);
            resetDistance = float.Parse(config.Numerical2);
 
            config = FuncConfigConfig.Get("GuardianImpendRange");
            impendRange = float.Parse(config.Numerical1);
 
            config = FuncConfigConfig.Get("GuardianRandomIdle");
            idleTimeMin = float.Parse(config.Numerical1);
            idleTimeMax = float.Parse(config.Numerical2);
 
            config = FuncConfigConfig.Get("GuardianHigh");
            height = float.Parse(config.Numerical1);
        }
        #endregion
 
        int Compare(int x, int y)
        {
            return x.CompareTo(y);
        }
    }
}