yyl
2025-09-04 f85d3a9e42c389244227bbb7c2697174aa277ab8
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using LitJson;
 
using UnityEngine;
public class AutoFightModel : GameSystemManager<AutoFightModel>
{
    //战斗倍数:值越大越快,影响战斗表现,掉落速度等
    public int fightSpeed
    {
        get
        {
            int value = QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.AutoFight_Speed, 0);
            return Math.Min(Math.Max(value, 1), maxSpeed);
        }
        set
        {
            QuickSetting.Instance.SetQuickSetting(QuickSettingType.AutoFight_Speed, value);
        }
    }
 
    //消耗倍数
    public int fightCost
    {
        get
        {
            int value = QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.AutoFight_Cost, 0);
            return Math.Min(Math.Max(value, 1), maxCost);
        }
        set
        {
            QuickSetting.Instance.SetQuickSetting(QuickSettingType.AutoFight_Cost, value);
        }
    }
 
    //自动模式, 真正点击战锤消耗开启,和休息(或无材料)停止
    public bool isAutoAttack = false;
 
    //是否开启自动战斗设置
    public bool isAutoAttackSet
    {
        get
        {
            return QuickSetting.Instance.GetQuickSettingBool(QuickSettingType.AutoFight_Open, 0);
        }
        set
        {
            QuickSetting.Instance.SetQuickSetting(QuickSettingType.AutoFight_Open, value);
        }
    }
 
    //更好装备停止战斗
    public bool isStopFightByBetterEquip
    {
        get
        {
            return QuickSetting.Instance.GetQuickSettingBool(QuickSettingType.AutoFight_FightPower, 0);
        }
        set
        {
            QuickSetting.Instance.SetQuickSetting(QuickSettingType.AutoFight_FightPower, value);
        }
    }
 
 
    public event Action ChangeAutoEvent;
 
    public int maxSpeed = 3; //最高速度
    public int maxCost; //最高消耗
    public int[] autoCostWithBlessLV; //自动战斗消耗倍数关联祝福等级
    public int speed2UnlockMissionID;
    public int speed3UnlockCTGID;
    public override void Init()
    {
        ParseConfig();
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerInit;
        BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField;
        EventBroadcast.Instance.AddListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnSkillCast);
 
    }
 
    public override void Release()
    {
        BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField;
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= BeforePlayerInit;
 
    }
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("AutoGuaji");
        autoCostWithBlessLV = JsonMapper.ToObject<int[]>(config.Numerical1);
        speed2UnlockMissionID = int.Parse(config.Numerical2);
        speed3UnlockCTGID = int.Parse(config.Numerical3);
        maxCost = autoCostWithBlessLV.Length;
    }
 
 
    void BeforePlayerInit()
    {
        fightingHeroSkinID = 0;
        heroGuid = "";
    }
 
    public void SaveAutoFightSetting()
    {
        if (PlayerDatas.Instance.baseData.UseHarmerCount != fightCost)
        {
            PlayerDatas.Instance.baseData.UseHarmerCount = fightCost;
            BattleManager.Instance.MainFightRequest(1, (uint)fightCost);
        }
 
        StoryBattleField storyBattleField = BattleManager.Instance.storyBattleField;
 
        if (storyBattleField != null && storyBattleField.GetBattleMode() != BattleMode.Stop)
        {
            //战斗中改变模式
            storyBattleField.AutoSetBattleMode();
        }
 
        QuickSetting.Instance.SendPackage();
        ChangeAutoEvent?.Invoke();
    }
 
 
    //自动处理装备,需要等待穿戴返回false,其他情况返回true
    public bool TryAutoFightDoEquip(ItemModel item)
    {
        if (!isAutoAttack)
            return false;
 
        if (item == null)
            return true;
 
        long showFightPower = FightPowerManager.Instance.GetFightPowerChange(item);
 
        if (showFightPower < 0)
        {
            EquipModel.Instance.SendEquipOP(new ushort[] { (ushort)item.gridIndex }, 1);
            return true;
        }
        else
        {
            if (isStopFightByBetterEquip)
                return false;
 
            EquipModel.Instance.SendEquipOP(new ushort[] { (ushort)item.gridIndex }, 1);
            return true;
 
        }
 
    }
 
    #region 主线战斗(自动和手动)
 
    public void StartFight()
    {
        if (isAutoAttack)
            return;
 
        StoryBattleField storyBattleField = BattleManager.Instance.storyBattleField;
        if (storyBattleField == null)
        {
            return;
        }
 
        if (!ItemLogicUtility.CheckCurrencyCount(41, PlayerDatas.Instance.baseData.UseHarmerCount, 2))
        {
            if (storyBattleField.GetBattleMode() != BattleMode.Stop)
                storyBattleField.HaveRest();
            return;
        }
 
        if (isAutoAttackSet)
        {
            isAutoAttack = true;
        }
 
        //手动会一直进入这个逻辑, 自动触发一次
        storyBattleField.AutoSetBattleMode();
        storyBattleField.operationAgent.DoNext();
    }
 
    void OnCreateBattleField(string guid, BattleField battleField)
    {
        if (string.IsNullOrEmpty(guid) && BattleManager.Instance.storyBattleField != null)
        {
            BattleManager.Instance.storyBattleField.ChangeBattleModeEvent -= ChangeBattleModeEvent;
            BattleManager.Instance.storyBattleField.ChangeBattleModeEvent += ChangeBattleModeEvent;
        }
 
    }
 
 
    void ChangeBattleModeEvent(BattleMode _battleMode)
    {
        if (_battleMode == BattleMode.Stop)
        {
            isAutoAttack = false;
        }
        OnFightEvent?.Invoke(false);
    }
 
    public int fightingHeroSkinID;  //当前战斗的英雄皮肤ID
    public string heroGuid; //战斗中的武将
    public event Action<bool> OnFightEvent; //战斗模式变更通知 战斗释放技能通知
 
 
    /// <summary>
    /// 技能释放 通知UI处理
    /// </summary>
    /// <param name="guid">空为主线</param>
    /// <param name="skillConfig">用于怒气等显示</param>
    /// <param name="teamHero">战斗中的武将</param>
    void OnSkillCast(string guid, SkillConfig skillConfig, TeamHero teamHero)
    {
        if (!string.IsNullOrEmpty(guid))
            return;
 
        //只通知玩家武将的战斗
        if (teamHero.NPCID != 0)
            return;
 
        fightingHeroSkinID = teamHero.SkinID;
        //战斗时没有GUID ,通过heroid查找
        var hero = TeamManager.Instance.GetTeam(TeamType.Story).GetHeroByHeroID(teamHero.heroId);
        if (hero != null)
        {
            heroGuid = hero.guid;
        }
        else
        {
            heroGuid = "";
        }
        OnFightEvent?.Invoke(true);
    }
 
    public bool CanChallengeBoss()
    {
        //最后一波通过,且当前波还是最后一波;倒退只倒退波不会倒退关卡
        if (PlayerDatas.Instance.baseData.ExAttr2 != PlayerDatas.Instance.baseData.ExAttr1)
        {
            return false;
        }
        var value = PlayerDatas.Instance.baseData.ExAttr2;
        var chapterID = value / 10000;
        var levelNum = value % 10000 / 100;
        var waveID = value % 100;
 
        var config = MainLevelConfig.GetMainLevelConfig(chapterID, levelNum);
        if (waveID < MainLevelConfig.GetwaveCount(config))
        {
            return false;
        }
 
        return true;
    }
 
    #endregion
 
 
}