From 6a7ac631c3fdd1e5b1a760ebaf198342be41e0f6 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 29 八月 2025 19:01:09 +0800
Subject: [PATCH] 95 【主界面】自动挂机
---
Main/System/Battle/BattleField/BattleField.cs | 9 +
Main/System/Main/AutoFightModel.cs | 71 +++++++++++
Main/System/Battle/BattleManager.cs | 42 +++++-
Main/System/Main/MainWin.cs | 13 -
Main/System/Battle/BattleField/OperationAgent/AutoModeOperationAgent.cs | 25 +--
Main/System/KnapSack/Logic/ItemLogicUtility.cs | 14 +
Main/System/Battle/BattleField/StoryBattleField.cs | 112 ++++++++++++++++--
Main/Core/NetworkPackage/DTCFile/ServerPack/HB4_FightDefine/DTCB425_tagSCTurnFightReportSign.cs | 3
Main/System/Battle/BattleField/OperationAgent/HandModeOperationAgent.cs | 70 -----------
9 files changed, 232 insertions(+), 127 deletions(-)
diff --git a/Main/Core/NetworkPackage/DTCFile/ServerPack/HB4_FightDefine/DTCB425_tagSCTurnFightReportSign.cs b/Main/Core/NetworkPackage/DTCFile/ServerPack/HB4_FightDefine/DTCB425_tagSCTurnFightReportSign.cs
index b4e3b53..9291e7b 100644
--- a/Main/Core/NetworkPackage/DTCFile/ServerPack/HB4_FightDefine/DTCB425_tagSCTurnFightReportSign.cs
+++ b/Main/Core/NetworkPackage/DTCFile/ServerPack/HB4_FightDefine/DTCB425_tagSCTurnFightReportSign.cs
@@ -29,7 +29,8 @@
base.Done(vNetPack);
HB425_tagSCTurnFightReportSign vNetData = vNetPack as HB425_tagSCTurnFightReportSign;
-
+ //涓荤嚎鎵嶆湁鐨勫寘
+ BattleManager.Instance.isWaitServerStory = false;
// 鎴柇 PackageRegedit Distribute 閲岀殑灏佸寘
// 鐩村埌sign = 1;
diff --git a/Main/System/Battle/BattleField/BattleField.cs b/Main/System/Battle/BattleField/BattleField.cs
index 59c2595..d1e5180 100644
--- a/Main/System/Battle/BattleField/BattleField.cs
+++ b/Main/System/Battle/BattleField/BattleField.cs
@@ -60,6 +60,7 @@
public BattleRootNode battleRootNode;
private BattleMode battleMode;
+ public event Action<BattleMode> ChangeBattleModeEvent;
public Action<bool> OnBattlePause;
@@ -120,6 +121,12 @@
{
battleMode = _battleMode;
CreateAgent();
+ ChangeBattleModeEvent?.Invoke(battleMode);
+ }
+
+ public BattleMode GetBattleMode()
+ {
+ return battleMode;
}
public virtual void Release()
@@ -438,7 +445,7 @@
{
// 鎴樻枟澶辫触
Debug.LogError("鎴樻枟澶辫触");
- HaveRest();
+ // HaveRest();
}
IsBattleFinish = true;
diff --git a/Main/System/Battle/BattleField/OperationAgent/AutoModeOperationAgent.cs b/Main/System/Battle/BattleField/OperationAgent/AutoModeOperationAgent.cs
index b950d2c..c32c6bd 100644
--- a/Main/System/Battle/BattleField/OperationAgent/AutoModeOperationAgent.cs
+++ b/Main/System/Battle/BattleField/OperationAgent/AutoModeOperationAgent.cs
@@ -3,33 +3,24 @@
public class AutoModeOperationAgent : IOperationAgent
{
+ protected StoryBattleField storyBattleField;
public AutoModeOperationAgent(BattleField battleField) : base(battleField)
{
-
+ storyBattleField = battleField as StoryBattleField;
}
+ float lastTime;
public override void Run()
{
- if (!battleField.IsBattleFinish)
- {
+ //鏈�浣�1绉�
+ if (Time.time - lastTime < 1f)
return;
- }
-
- base.Run();
-
- if (!battleField.recordPlayer.IsPlaying())
- {
- DoNext();
- }
+ lastTime = Time.time;
+ DoNext();
}
public override void DoNext()
{
- base.DoNext();
-
- if (!battleField.recordPlayer.IsPlaying())
- {
- // ask for next action
- }
+ storyBattleField.RequestFight();
}
}
\ No newline at end of file
diff --git a/Main/System/Battle/BattleField/OperationAgent/HandModeOperationAgent.cs b/Main/System/Battle/BattleField/OperationAgent/HandModeOperationAgent.cs
index 228ea08..bb1a516 100644
--- a/Main/System/Battle/BattleField/OperationAgent/HandModeOperationAgent.cs
+++ b/Main/System/Battle/BattleField/OperationAgent/HandModeOperationAgent.cs
@@ -23,75 +23,7 @@
base.DoNext();
- // 褰撳墠娌℃湁鍦ㄦ挱鏀炬垬鏂楀綍鍍�
- if (!battleField.recordPlayer.IsPlaying())
- {
- BattleDebug.LogError("HandModeOperationAgent DoNext 1");
- // 娌℃湁涓嬩竴涓寘鍙互鍙戜簡
- if (!BattleManager.Instance.DistributeNextPackage())
- {
- // 璇锋眰涓嬩竴涓垬鏂楀寘 鎴栬�呮鏌ユ垬鏂楁槸鍚︾粨鏉�
- // ReqType; // 0-鍋滄鎴樻枟鍥炲煄锛�1-璁剧疆娑堣�楀�嶅�硷紱2-鎸戞垬鍏冲崱灏忔�紱3-鎸戞垬鍏冲崱boss锛�4-缁х画鎴樻枟锛�
-
- // 濡傛灉鍦ㄤ紤鎭� 鐐逛竴涓嬩箣鍚庡簲璇ユ槸鎸戞垬灏忔�垨鑰呮寫鎴樺叧鍗�
- // 濡傛灉鍦ㄦ垬鏂� 鎴樻枟鏄惁缁撴潫/鎴樻枟鎸佺画涓� 缁撴潫搴旇鏄寫鎴樹笅涓�鍏� 鎸佺画搴旇鏄户缁垬鏂�
-
-
- // 妫�鏌ヤ竴涓嬮敜瀛愮殑娑堣��
- //useHarmerCount 鐢ㄤ簬璁板綍娑堣�楁垬閿ゅ�嶆暟锛屽皬浜庣瓑浜�1鏃堕粯璁�1鍊嶏紝澶т簬1鏃朵负瀵瑰簲娑堣�楀�嶅�硷紝0418鍒锋柊绫诲瀷22
- BattleDebug.LogError("HandModeOperationAgent DoNext 2");
- long costRate = PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.UseHarmerCount);
-
- long cost = (costRate > 1 ? costRate : 1) * 1; // 1鏄粯璁ゆ秷鑰�
-
-
-
- BattleDebug.LogError("HandModeOperationAgent DoNext 3");
- byte reqType;
-
- if (storyBattleField.battleState == StoryBattleState.Break)
- {
- reqType = 2;
- }
- else if (storyBattleField.battleState == StoryBattleState.Battle)
- {
- if (battleField.IsBattleEnd())
- {
- reqType = 2; // 缁х画鎸戞垬灏忔��
- }
- else
- {
- reqType = 4; // 缁х画鎴樻枟
- }
- }
- else
- {
- BattleDebug.LogError("unknown battle state");
- return;
- }
-
- BattleDebug.LogError("HandModeOperationAgent DoNext 4 reqType is " + reqType);
-
- // 妫�鏌ヤ竴涓嬮敜瀛愮殑娑堣��
- if (!ItemLogicUtility.CheckCurrencyCount(41, cost, true))
- {
- return;
- }
-
- // 濡傛灉璇锋眰鐨勬槸2 璇存槑瑕佸垵濮嬪寲涓�涓嬫垬鍦�
- BattleManager.Instance.MainFightRequest(reqType);
-
- // 鍒濆鍖栨垬鍦哄悗鏈潵涓嶄細鑷姩鎵� 閭d箞灏遍渶瑕佸啀璇锋眰涓�娆�4缁х画鎴樻枟 鏉ュ紑濮嬫垬鏂�
- if (reqType == 2)
- {
- BattleManager.Instance.MainFightRequest(4);
- }
- }
- }
- else
- {
- BattleDebug.LogError("action doesnt finish, wait a moment please");
- }
+ storyBattleField.RequestFight();
}
diff --git a/Main/System/Battle/BattleField/StoryBattleField.cs b/Main/System/Battle/BattleField/StoryBattleField.cs
index 0101c88..0ae28ef 100644
--- a/Main/System/Battle/BattleField/StoryBattleField.cs
+++ b/Main/System/Battle/BattleField/StoryBattleField.cs
@@ -49,7 +49,7 @@
battleState = StoryBattleState.Battle;
}
- LoadBattleMode();
+ // LoadBattleMode();
chapter = FuncLineID / 10000;
wave = MapID == 1 ? FuncLineID % 100 : 1;//绗嚑娉㈡��
@@ -70,18 +70,23 @@
protected void LoadBattleMode()
{
- string savedStr = LocalSave.GetString("StoryBattleFieldBattleMode");
- if (string.IsNullOrEmpty(savedStr))
+ //涓荤嚎妯″紡锛歴top浼戞伅 鏃犳�紱Hand/Auto 鏈夋�� 绛夊緟鎸囦护
+ BattleMode mode = BattleMode.Hand;
+ if (AutoFightModel.Instance.isAutoAttackSet)
{
- savedStr = "Hand";
+ mode = BattleMode.Auto;
}
- SetBattleMode((BattleMode)Enum.Parse(typeof(BattleMode), savedStr));
+ if (GetBattleMode() == mode)
+ return;
+
+ SetBattleMode(mode);
}
public override void AutoSetBattleMode()
{
LoadBattleMode();
}
+
public override void TurnFightState(int TurnNum, int State,
uint FuncLineID, JsonData extendData)
@@ -149,18 +154,99 @@
// // HaveRest();
// }
- // public override void Run()
- // {
- // // 涓�瀹氳璁颁綇杩欎釜
- // if (IsPause)
- // return;
-
- // base.Run();
- // }
+ public override void Run()
+ {
+ if (operationAgent == null)
+ {
+ //闃茶寖寮傚父
+ HaveRest();
+ return;
+ }
+ base.Run();
+ }
public override void DistributeNextPackage()
{
// 涓嶈璋冪敤base鐨勫嚱鏁�
BattleManager.Instance.DistributeNextPackage();
}
+
+
+ //璇锋眰鍗曟鎴樻枟
+ public void RequestFight()
+ {
+ if (IsPause)
+ {
+ //杩橀渶鑰冭檻鍏朵粬涓嶅彲鎴樻枟鐘跺喌锛屼富绾跨殑BOSS鎴樻枟涔熸槸鍙﹀涓�涓満鏅笖涓嶈兘鍒囧嚭鏉� 绛夎烦杩囨垨鑰呯粨鏉�
+ //澶栭儴缁熶竴鎺у埗 IsPause
+ return;
+ }
+ if (BattleManager.Instance.isWaitServerStory)
+ return;
+
+ // 褰撳墠娌℃湁鍦ㄦ挱鏀炬垬鏂楀綍鍍�
+ if (!recordPlayer.IsPlaying())
+ {
+ BattleDebug.LogError("HandModeOperationAgent DoNext 1");
+ // 娌℃湁涓嬩竴涓寘鍙互鍙戜簡
+ if (!BattleManager.Instance.DistributeNextPackage())
+ {
+
+ BattleDebug.LogError("HandModeOperationAgent DoNext 2");
+
+ // 妫�鏌ヤ竴涓嬮敜瀛愮殑娑堣��
+ if (!ItemLogicUtility.CheckCurrencyCount(41, PlayerDatas.Instance.baseData.UseHarmerCount, 2))
+ {
+ //澶氭闃茶寖
+ if (GetBattleMode() != BattleMode.Stop)
+ HaveRest();
+ return;
+ }
+
+ // 璇锋眰涓嬩竴涓垬鏂楀寘 鎴栬�呮鏌ユ垬鏂楁槸鍚︾粨鏉�
+ // ReqType; // 0-鍋滄鎴樻枟鍥炲煄锛�1-璁剧疆娑堣�楀�嶅�硷紱2-鎸戞垬鍏冲崱灏忔�紱3-鎸戞垬鍏冲崱boss锛�4-缁х画鎴樻枟锛�
+ // 濡傛灉鍦ㄦ垬鏂� 鎴樻枟鏄惁缁撴潫/鎴樻枟鎸佺画涓� 缁撴潫搴旇鏄寫鎴樹笅涓�鍏� 鎸佺画搴旇鏄户缁垬鏂�
+
+ BattleDebug.LogError("HandModeOperationAgent DoNext 3");
+ byte reqType;
+
+ if (battleState == StoryBattleState.Break)
+ {
+ reqType = 2;
+ }
+ else if (battleState == StoryBattleState.Battle)
+ {
+ if (IsBattleEnd())
+ {
+ reqType = 2; // 缁х画鎸戞垬灏忔��
+ }
+ else
+ {
+ reqType = 4; // 缁х画鎴樻枟
+ }
+ }
+ else
+ {
+ BattleDebug.LogError("unknown battle state");
+ return;
+ }
+
+ BattleDebug.LogError("HandModeOperationAgent DoNext 4 reqType is " + reqType);
+
+
+ // 濡傛灉璇锋眰鐨勬槸2 璇存槑瑕佸垵濮嬪寲涓�涓嬫垬鍦�
+ BattleManager.Instance.MainFightRequest(reqType);
+
+ // 鍒濆鍖栨垬鍦哄悗鏈潵涓嶄細鑷姩鎵� 閭d箞灏遍渶瑕佸啀璇锋眰涓�娆�4缁х画鎴樻枟 鏉ュ紑濮嬫垬鏂�
+ if (reqType == 2)
+ {
+ BattleManager.Instance.MainFightRequest(4);
+ }
+ }
+ }
+ // else
+ // {
+ // BattleDebug.LogError("action doesnt finish, wait a moment please");
+ // }
+ }
}
\ No newline at end of file
diff --git a/Main/System/Battle/BattleManager.cs b/Main/System/Battle/BattleManager.cs
index 66d7964..588112a 100644
--- a/Main/System/Battle/BattleManager.cs
+++ b/Main/System/Battle/BattleManager.cs
@@ -15,12 +15,16 @@
public Action<string, BattleField> onBattleFieldDestroy;
+ public bool isWaitServerStory = false; //涓荤嚎绛夋湇鍔$鍥炴姤 0425
+
public override void Init()
{
base.Init();
LogicEngine.Instance.OnUpdate += Run;
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
+ DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerInit;
+
}
public override void Release()
@@ -28,6 +32,7 @@
base.Release();
LogicEngine.Instance.OnUpdate -= Run;
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
+ DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= BeforePlayerInit;
}
protected void OnPlayerLoginOk()
@@ -39,6 +44,11 @@
int FuncLineID = (int)exAttr2;
CreateStoryBattle(MapID, FuncLineID, null, null);
+ }
+
+ void BeforePlayerInit()
+ {
+ isWaitServerStory = false; //鍚庣画鑰冭檻鏂嚎閲嶈繛
}
// 涓婃父鎴忕殑鏃跺�� 绛夋垬鏂楅樀瀹规洿鏂板畬姣� 鍒涘缓涓荤嚎鍓湰 鏁屾柟鐨勬暟鎹彲浠ユ殏鏃朵笉鏄剧ず 宸辨柟琛ㄧ幇涓虹潯瑙�
@@ -322,22 +332,34 @@
{
BattleField battleField = null;
+ bool isCreate = true;
if (battleFields.TryGetValue(guid, out battleField))
{
- BattleDebug.LogError("鎴樺満宸插瓨鍦� 鍏堣繘琛岄攢姣�");
- battleField.Destroy();
+ //涓荤嚎鎴樺満闇�涓�鐩村瓨鍦�
+ if (string.IsNullOrEmpty(guid))
+ {
+ isCreate = false;
+ }
+ else
+ {
+ BattleDebug.LogError("鎴樺満宸插瓨鍦� 鍏堣繘琛岄攢姣�");
+ battleField.Destroy();
+ }
}
- battleField = BattleFieldFactory.CreateBattleField(guid, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
+ if (isCreate)
+ {
+ battleField = BattleFieldFactory.CreateBattleField(guid, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
+ onBattleFieldCreate?.Invoke(guid, battleField);
- onBattleFieldCreate?.Invoke(guid, battleField);
-
- if (string.IsNullOrEmpty(guid))
- {
- storyBattleField = (StoryBattleField)battleField;
+ if (string.IsNullOrEmpty(guid))
+ {
+ storyBattleField = (StoryBattleField)battleField;
+ }
+ battleFields.Add(guid, battleField);
}
- battleFields.Add(guid, battleField);
+
battleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList);
@@ -383,6 +405,8 @@
req.ReqValue = reqValue;
GameNetSystem.Instance.SendInfo(req);
+ if (reqType >= 2)
+ isWaitServerStory = true;
}
diff --git a/Main/System/KnapSack/Logic/ItemLogicUtility.cs b/Main/System/KnapSack/Logic/ItemLogicUtility.cs
index 2602329..1d33e2b 100644
--- a/Main/System/KnapSack/Logic/ItemLogicUtility.cs
+++ b/Main/System/KnapSack/Logic/ItemLogicUtility.cs
@@ -296,7 +296,8 @@
return isEnough;
}
- public static bool CheckCurrencyCount(int moneyType, long needCount, bool needTips = false)
+ /// <param name="needTips">0 涓嶅搷搴� 1 寮规彁绀� 2 寮硅幏鍙栭�斿緞tips</param>
+ public static bool CheckCurrencyCount(int moneyType, long needCount, int needTips = 0)
{
if (needCount <= 0)
{
@@ -307,9 +308,16 @@
bool isEnough = haveCount >= needCount;
- if (!isEnough && needTips)
+ if (!isEnough)
{
- SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType);
+ if (needTips == 1)
+ {
+ SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType);
+ }
+ else if (needTips == 2)
+ {
+ ItemTipUtility.ShowMoneyTip(moneyType);
+ }
}
return isEnough;
diff --git a/Main/System/Main/AutoFightModel.cs b/Main/System/Main/AutoFightModel.cs
index ec225e4..5f2fc5f 100644
--- a/Main/System/Main/AutoFightModel.cs
+++ b/Main/System/Main/AutoFightModel.cs
@@ -76,11 +76,15 @@
{
ParseConfig();
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
+ BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField;
+
}
public override void Release()
{
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
+ BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField;
+
}
void ParseConfig()
@@ -104,6 +108,15 @@
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();
}
@@ -114,7 +127,7 @@
{
if (!isAutoAttack)
return false;
-
+
if (item == null)
return true;
@@ -129,11 +142,63 @@
{
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
+
+
}
diff --git a/Main/System/Main/MainWin.cs b/Main/System/Main/MainWin.cs
index ba3322f..f88f5cd 100644
--- a/Main/System/Main/MainWin.cs
+++ b/Main/System/Main/MainWin.cs
@@ -132,17 +132,8 @@
{
if (currentSubUI != null && currentSubUI.name == "HomeWin")
{
- Debug.Log("鐐瑰嚮涓荤晫闈㈡寜閽�");
- //鎵撳紑涓荤晫闈㈢殑鎯呭喌涓嬪啀鐐瑰嚮鎸夐挳锛屾墽琛屾敾鍑婚�昏緫
- if (AutoFightModel.Instance.isAutoAttackSet)
- {
- AutoFightModel.Instance.isAutoAttack = true;
- }
- StoryBattleField storyBattleField = BattleManager.Instance.storyBattleField;
- if (storyBattleField != null)
- {
- storyBattleField.operationAgent.DoNext();
- }
+ //鎵嬪姩鑷姩涓�璧峰鐞�
+ AutoFightModel.Instance.StartFight();
}
}
SelectBottomTab(index);
--
Gitblit v1.8.0