using System.Collections; using System.Collections.Generic; using UniRx; using UnityEngine; public struct RobotFishingQueue { public FishingChangeState changeState; public int waitTimer; public int fishItemId; public int point; public float fishCardAdd; public float fishingRodAdd; } public class DuelRobotEntity : MonoBehaviour { List robotInfos; FishingDuelManager FDM; Queue robotQueue = new Queue(); float chooseRodTime; public void Init(List robotInfos, FishingDuelManager FDM) { this.robotInfos = robotInfos; this.FDM = FDM; SetFishingQueue(); WaitStart(); } float allUpdateTime = 0f; float robotUpdateTime = 0f; private void Update() { if (robotInfos == null || robotInfos.Count == 0 || robotQueue.Count == 0 || FDM.RodState < 2) { return; } allUpdateTime += Time.unscaledDeltaTime; if (allUpdateTime > robotUpdateTime) { RobotFishingQueue robotFishingQueue = robotQueue.Dequeue(); FDM.ReceiveFishingQueue(robotFishingQueue); if (robotQueue.Count > 0) { robotFishingQueue = robotQueue.Peek(); robotUpdateTime += robotFishingQueue.waitTimer; #if UNITY_EDITOR Debug.Log("机器人下一个状态:" + robotFishingQueue.changeState + " 等待时间:" + robotFishingQueue.waitTimer); #endif } } } void SetFishingQueue() { DuelFishingData robotInfo; robotUpdateTime = robotInfos[0].slienceTime / 2; bool preFail = false; for (int i = 0; i < robotInfos.Count; i++) { robotInfo = robotInfos[i]; RobotFishingQueue robotFishingQueue = new RobotFishingQueue { changeState = FishingChangeState.Cast, waitTimer = robotInfo.slienceTime, fishItemId = robotInfo.fishItemId }; if (preFail) { robotFishingQueue.waitTimer /= 2; //如果上一个是失败,则静默时间减半 } robotQueue.Enqueue(robotFishingQueue); //robotFishingQueue = new RobotFishingQueue //{ // changeState = FishingChangeState.StartFishing, // waitTimer = robotInfo.castingTime, // fishItemId = robotInfo.fishItemId //}; //robotQueue.Enqueue(robotFishingQueue); robotFishingQueue = new RobotFishingQueue { changeState = FishingChangeState.FishingSuccess, waitTimer = robotInfo.fishingTime, fishItemId = robotInfo.fishItemId, point = robotInfo.point, fishCardAdd = robotInfo.fishCardAdd, fishingRodAdd = robotInfo.fishRodAdd }; preFail = !robotInfo.isWin; if (robotInfo.point == 0) { robotFishingQueue.changeState = FishingChangeState.FishingFail; } robotQueue.Enqueue(robotFishingQueue); } } async void WaitStart() { var RobotChooseRodTime = FDM.eventSoloConfig.RobotChooseRodTime; chooseRodTime = Random.Range(RobotChooseRodTime[0], RobotChooseRodTime[1]); await Awaiters.Seconds(chooseRodTime); FDM.ReceiveEnemyRodData(FDM.robotRod); } }