hch
2025-08-29 6a7ac631c3fdd1e5b1a760ebaf198342be41e0f6
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
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();
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
        BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField;
 
    }
 
    public override void Release()
    {
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
        BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField;
 
    }
 
    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 OnPlayerLoginOk()
    {
        //登录时有装备的处理
    }
 
    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 (UIHelper.GetMoneyCnt(41) < PlayerDatas.Instance.baseData.UseHarmerCount)
        {
            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;
        }
    }
    
    #endregion
 
 
}