using System.Collections.Generic; using UnityEngine; public struct RobotFishingQueue { public FishingChangeState changeState; public float 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; List fishingStateList = new List(); 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(); switch (robotFishingQueue.changeState) { case FishingChangeState.Cast: fishingStateList.Add($"{0}:{robotFishingQueue.fishItemId}"); break; case FishingChangeState.FishingSuccess: fishingStateList.Add($"{1}:{robotFishingQueue.point}:{robotFishingQueue.fishCardAdd}:{robotFishingQueue.fishingRodAdd}"); break; case FishingChangeState.FishingFail: fishingStateList.Add($"{2}"); break; default: break; } FDM.ReceiveRobotFishingStateList(fishingStateList); if (robotQueue.Count > 0) { robotFishingQueue = robotQueue.Peek(); robotUpdateTime += robotFishingQueue.waitTimer; Debug.Log("机器人下一个状态:" + robotFishingQueue.changeState + " 等待时间:" + robotFishingQueue.waitTimer); } } } void SetFishingQueue() { DuelFishingData robotInfo; robotUpdateTime = robotInfos[0].st / 2; bool preFail = false; for (int i = 0; i < robotInfos.Count; i++) { robotInfo = robotInfos[i]; RobotFishingQueue robotFishingQueue = new RobotFishingQueue { changeState = FishingChangeState.Cast, waitTimer = robotInfo.st, fishItemId = robotInfo.id }; if (preFail) { robotFishingQueue.waitTimer /= 2; //如果上一个是失败,则静默时间减半 } robotQueue.Enqueue(robotFishingQueue); robotFishingQueue = new RobotFishingQueue { changeState = FishingChangeState.FishingSuccess, waitTimer = robotInfo.ft, fishItemId = robotInfo.id, point = robotInfo.p, fishCardAdd = robotInfo.ca, fishingRodAdd = robotInfo.ra }; preFail = !robotInfo.w; if (robotInfo.p == 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); } }