using System; using System.Collections.Generic; using System.Linq; using Common.Utility.CombatEvent; using Core.Event.Event; using Excel2Json; using Fort23.Core; using Fort23.Mono; using Fort23.UTool; using GameLogic.Bag; using GameLogic.Combat; using GameLogic.Combat.CombatTool; using GameLogic.Player; using UnityEngine; using Utility; public class DialogueManager : Singleton { private int currentDialogueID; private Action onDialogueComplete; private Action onCancel; private EventConfig eventConfig; /// /// 开始对话 /// public void StartDialogue(int dialogueID, int eventId, Action onComplete = null, Action onCancel = null) { this.onCancel = onCancel; currentDialogueID = dialogueID; onDialogueComplete = onComplete; eventConfig = ConfigComponent.Instance.Get(eventId); if (eventConfig.EventType == 2) { EndDialogue1(); } else { PlayDialogue(dialogueID); } // EndDialogue1(); } private void PlayDialogue(int dialogueID) { currentDialogueID = dialogueID; // 找到当前对话组 var dialogueConfig = ConfigComponent.Instance.Get(dialogueID); if (!EventSystemManager.Instance.IsEvenkLinkComplete(currentDialogueID) && dialogueConfig.optionType != 2) { onCancel?.Invoke(); return; } //神识探索的事件记录步骤 if (EventSystemManager.Instance.CurrentEventList != null) { EventConfig eventConfig = ConfigComponent.Instance.Get(EventSystemManager.Instance.CurrentEventList.eventID); if (eventConfig.EventLinksId.Contains(currentDialogueID)) { EventSystemManager.Instance.CurrentEventList.curStep = currentDialogueID; } } if (dialogueConfig.ID == 0) { EndDialogue(); return; } AccountFileInfo.Instance.SavePlayerData(); //挂机事件 弹出简单气泡对话 if (eventConfig.EventTriggerType != 2) { if (dialogueConfig.LanID != null) { DialoguePanel.OpenDialoguePanel(dialogueConfig.ID, null, ShowDialogueEventData.MessageShowType.Verbatim, FishDialogue); } else { FishDialogue(null); } } else { DialogueBubblePanel.OpenDialoguePanel(dialogueConfig.ID, FishDialogue); } } public void FishDialogue(int? selectedOptionID) { if (selectedOptionID.HasValue && selectedOptionID.Value != -1) { // 玩家选择了选项,处理结果 SelectOption(selectedOptionID.Value); } //取消事件 else if (selectedOptionID.HasValue && selectedOptionID.Value == -1) { onCancel?.Invoke(); } else { // 无选 EndDialogue1(); } } /// /// 处理选项选择 /// public void SelectOption(int optionID) { PlayDialogue(optionID); } /// /// 结束对话 /// private async void EndDialogue1() { EventLinkConfig dialogueConfig = ConfigComponent.Instance.Get(currentDialogueID); bool isCombatWin = false; switch (dialogueConfig.optionType) { //选项在这里不处理 在ui层处理 所有这里不是走到1 直接return case 1: EndDialogue(); return; //进入战斗 case 2: LogTool.Log("对话结束,进入战斗"); //不是一次性事件弹出boss界面 if (eventConfig.EventTriggerType != 2) { bool relust = await BossInfoPanel.OpenPanel(dialogueConfig.optionPara1[0]); if (relust) { CTask cTask = CTask.Create(); CombatDrive.Instance.LoadLevelBattleCombat(dialogueConfig.optionPara1[0], delegate(bool isWin) { LogTool.Log("战斗完成" + isWin); isCombatWin = isWin; cTask.SetResult(); }); await cTask; CombatDrive.Instance.CombatController.ChangeState(CombatController.idle); } else { onCancel?.Invoke(); return; } } else { CTask cTask = CTask.Create(); CombatDrive.Instance.LoadLevelBattleCombat(dialogueConfig.optionPara1[0], delegate(bool isWin) { LogTool.Log("战斗完成" + isWin); isCombatWin = isWin; cTask.SetResult(); }); await cTask; CombatDrive.Instance.CombatController.ChangeState(CombatController.idle); } break; //获得奖励 case 3: List itemInfos = new List(); for (var i = 0; i < dialogueConfig.PrizeIDs.Length; i++) { DropConfig dropConfig = ConfigComponent.Instance.Get(dialogueConfig.PrizeIDs[i]); if (dropConfig.dropType == 3) { ItemInfo itemInfo = new ItemInfo(dropConfig.dropGroupID[0], dialogueConfig.PrizeNums[i]); itemInfos.Add(itemInfo); } else { List items = DropManager.Instance.DropItem(dialogueConfig.PrizeIDs[i]); itemInfos.AddRange(items); } } await OpenRewardsPanel(eventConfig.ID, itemInfos); LogTool.Log("对话结束,获得奖励"); break; } if (!EventSystemManager.Instance.IsEvenkLinkComplete(currentDialogueID)) { onCancel?.Invoke(); return; } switch (dialogueConfig.ResultType) { //直接走下一个id case 1: PlayDialogue(dialogueConfig.ResultOptions[0]); break; //根据战斗结果判断走哪一个事件id case 2: if (isCombatWin) { PlayDialogue(dialogueConfig.ResultOptions[0]); } else { PlayDialogue(dialogueConfig.ResultOptions[1]); } break; //触发新的事件 eventConfigId case 3: AccountFileInfo.EventList eventList = EventSystemManager.Instance.AddEvent(dialogueConfig.ResultOptions[0]); if (eventList != null) { AccountFileInfo.Instance.playerData.eventList.Add(eventList); AccountFileInfo.Instance.SavePlayerData(); } EndDialogue(); break; //结束事件 default: EndDialogue(); break; } } /// /// 结束对话 /// private void EndDialogue() { onDialogueComplete?.Invoke(); } public async CTask OpenRewardsPanel(int eventId, List rewardsDic, Action onClose = null, int titleId = 0) { EventConfig eventConfig = ConfigComponent.Instance.Get(eventId); if (eventConfig.EventTriggerType == 2) { Vector3 worldPos = CombatDrive.Instance.CombatController.playerHeroEntity.combatHeroGameObject.hpTransform.position; worldPos.y += 0.5f; await ShowItemNumberCom.Open(worldPos, rewardsDic[0]); await TimerComponent.Instance.WaitAsync(100); } else { RewardsPanel rewardsPanel = await RewardsPanel.OpenPanel(rewardsDic, onClose, titleId); await rewardsPanel.UIClosed(); } } }