| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 | 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 JetBrains.Annotations;using UnityEngine;using Utility;using Random = UnityEngine.Random;public class DialogueManager : Singleton<DialogueManager>{    private int currentDialogueID;    private Action onDialogueComplete;    private Action onCancel;    private EventConfig eventConfig;    private AccountFileInfo.EventList CurrentEventList;    /// <summary>    /// 开始对话    /// </summary>    public async CTask StartDialogue(AccountFileInfo.EventList CurrentEventList, int dialogueID, int eventId,        Action onComplete = null, Action onCancel = null)    {        this.onCancel = onCancel;        this.CurrentEventList = CurrentEventList;        currentDialogueID = dialogueID;        onDialogueComplete = onComplete;        eventConfig = ConfigComponent.Instance.Get<EventConfig>(eventId);        if (eventConfig.EventType == 2)        {            EndDialogue1();        }        else        {            await PlayDialogue(dialogueID, true);        }        // EndDialogue1();    }    private void UpdateDiaLogutLinkId(int dialogueID)    {        currentDialogueID = dialogueID;        //神识探索的事件记录步骤        if (EventSystemManager.Instance.CurrentEventList != null)        {            EventConfig eventConfig =                ConfigComponent.Instance.Get<EventConfig>(EventSystemManager.Instance.CurrentEventList.eventID);            if (eventConfig.EventLinksId.Contains(currentDialogueID))            {                EventSystemManager.Instance.CurrentEventList.curStep = currentDialogueID;                //记录步骤 日志使用                if (!EventSystemManager.Instance.CurrentEventList.selectEventLinkIds.Contains(currentDialogueID))                    EventSystemManager.Instance.CurrentEventList.selectEventLinkIds.Add(currentDialogueID);            }        }    }    private async CTask PlayDialogue(int dialogueID, bool isShowTips = false)    {        currentDialogueID = dialogueID;        UpdateDiaLogutLinkId(dialogueID);        // 找到当前对话组        var dialogueConfig = ConfigComponent.Instance.Get<EventLinkConfig>(dialogueID);        if (CurrentEventList != null)        {            var eventLinkDatas = CurrentEventList.eventLinks.FirstOrDefault(el => el.eventLinkId == dialogueID);            if (eventLinkDatas != null &&                !EventSystemManager.Instance.CeekEventGroupComplete(eventLinkDatas.eventConditions))            {                if (isShowTips)                    EventTipsPanel.OpenPanel(eventLinkDatas);                onCancel?.Invoke();                return;            }        }        if (dialogueConfig.ID == 0)        {            EndDialogue();            return;        }        if (dialogueConfig.NPCID != 0)        {            EventNPC eventNpc = ConfigComponent.Instance.Get<EventNPC>(dialogueConfig.NPCID);            if (eventNpc.ID != 0 && eventNpc.DaoyouID != 0)            {                if (AccountFileInfo.Instance.playerData.daoYouDatas.FirstOrDefault(dy => dy.id == eventNpc.DaoyouID) ==                    null)                {                    AccountFileInfo.DaoYouData daoYouData = new AccountFileInfo.DaoYouData();                    daoYouData.id = eventNpc.DaoyouID;                    daoYouData.favorabilityLv = 1;                    daoYouData.emotion = Random.Range(1, 4);                    daoYouData.emotionTime = TimeHelper.ClientNow();                    daoYouData.emotionValue = (int)(100 / (float)daoYouData.emotion);                    AccountFileInfo.Instance.playerData.daoYouDatas.Add(daoYouData);                    AccountFileInfo.Instance.SavePlayerData();                }            }        }        //处理前置表现        if (dialogueConfig.PreShow == 1)        {            UIManager.Instance.HindCurrAllShowPanel();            CombatDrive.Instance.CombatController.ChangeState(CombatController.update);            CombatController.currActiveCombat.CombatSenceController.Flight(dialogueConfig.PreShowPar, -90, 10);            UIManager.Instance.SetEventSystemEnable(false);            await TimerComponent.Instance.WaitAsync(dialogueConfig.PreShowPar * 1000 + 1200);            CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);            UIManager.Instance.SetEventSystemEnable(true);            UIManager.Instance.ShowLastHindAllShowPanel();        }        AccountFileInfo.Instance.SavePlayerData();        //挂机事件 弹出简单气泡对话        if (eventConfig.EventTriggerType != 2)        {            if (dialogueConfig.LanID != null)            {                await DialoguePanel.OpenDialoguePanel(CurrentEventList, dialogueConfig.ID, null,                    ShowDialogueEventData.MessageShowType.Verbatim,                    FishDialogue);            }            else            {                FishDialogue(null);            }        }        else        {            await DialogueBubblePanel.OpenDialoguePanel(dialogueConfig.ID, FishDialogue);        }    }    public void FishDialogue(int? selectedOptionID)    {        if (selectedOptionID.HasValue && selectedOptionID.Value != -1)        {            if (selectedOptionID.Value == 0)            {                // 无选                EndDialogue1();            }            else            {                // 玩家选择了选项,处理结果                SelectOption(selectedOptionID.Value);            }        }        //取消事件        else if (selectedOptionID.HasValue && selectedOptionID.Value == -1)        {            onCancel?.Invoke();        }        else        {            // 无选            EndDialogue1();        }    }    /// <summary>    /// 处理选项选择    /// </summary>    public void SelectOption(int optionID)    {        PlayDialogue(optionID);    }    /// <summary>    /// 结束对话     /// </summary>    private async void EndDialogue1()    {        if (CurrentEventList == null)            return;        EventLinkConfig dialogueConfig = ConfigComponent.Instance.Get<EventLinkConfig>(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 ComBatFrontPanel.OpenPanel(dialogueConfig.optionPara1[0], CurrentEventList);                    if (relust)                    {                        CTask cTask = CTask.Create();                        CombatDrive.Instance.LoadLevelBattleCombat(dialogueConfig.optionPara1[0], true,                            CurrentEventList.heroLevel,                            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], false,                        CurrentEventList.heroLevel,                        delegate(bool isWin)                        {                            LogTool.Log("战斗完成" + isWin);                            isCombatWin = isWin;                            cTask.SetResult();                        });                    await cTask;                    CombatDrive.Instance.CombatController.ChangeState(CombatController.idle);                }                break;            //获得奖励            case 3:                List<ItemInfo> itemInfos = new List<ItemInfo>();                for (var i = 0; i < dialogueConfig.PrizeIDs.Length; i++)                {                    DropConfig dropConfig = ConfigComponent.Instance.Get<DropConfig>(dialogueConfig.PrizeIDs[i]);                    if (dropConfig.dropType == 3)                    {                        ItemInfo itemInfo = new ItemInfo(dropConfig.dropGroupID[0], dialogueConfig.PrizeNums[i]);                        itemInfos.Add(itemInfo);                    }                    else                    {                        List<ItemInfo> items = DropManager.Instance.DropItem(dialogueConfig.PrizeIDs[i]);                        itemInfos.AddRange(items);                    }                }                await OpenRewardsPanel(eventConfig.ID, itemInfos);                LogTool.Log("对话结束,获得奖励");                break;            //扣除道具            case 4:                for (var i = 0; i < dialogueConfig.optionPara1.Length; i++)                {                    PlayerManager.Instance.BagController.DeductItem(dialogueConfig.optionPara1[i],                        dialogueConfig.optionPara2[i]);                }                break;            //关闭任务            case 5:                if (dialogueConfig.ResultType == 1)                {                    UpdateDiaLogutLinkId(dialogueConfig.ResultOptions[0]);                }                onCancel?.Invoke();                return;                break;        }        if (CurrentEventList != null)        {            AccountFileInfo.EventLinkData eventLinkData =                CurrentEventList.eventLinks.FirstOrDefault(el => el.eventLinkId == currentDialogueID);            if (eventLinkData != null)            {                foreach (var eventConditionData in eventLinkData?.eventConditions)                {                    if (!EventSystemManager.Instance.IsEvenkLinkComplete(eventConditionData))                    {                        onCancel?.Invoke();                        return;                    }                }            }        }        //如果当前链条没有在事件链条里,不走结束逻辑        if (!eventConfig.EventLinksId.Contains(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                {                    if (dialogueConfig.ResultOptions.Length > 1)                    {                        PlayDialogue(dialogueConfig.ResultOptions[1]);                    }                    else                    {                        onCancel?.Invoke();                    }                }                break;            //触发新的事件 eventConfigId            case 3:                // if ()                // {                //                     // }                AccountFileInfo.EventList eventList =                    EventSystemManager.Instance.AddEvent(dialogueConfig.ResultOptions[0]);                if (eventList != null)                {                    AccountFileInfo.Instance.playerData.eventList.Add(eventList);                    AccountFileInfo.Instance.SavePlayerData();                }                EndDialogue();                break;            //结束事件            default:                // if (eventConfig.EventLinksId.Contains(dialogueConfig.ID))            {                EndDialogue();            }                break;        }    }    /// <summary>    /// 结束对话    /// </summary>    private void EndDialogue()    {        onDialogueComplete?.Invoke();    }    public async CTask OpenRewardsPanel(int eventId, List<ItemInfo> rewardsDic, Action onClose = null, int titleId = 0)    {        EventConfig eventConfig = ConfigComponent.Instance.Get<EventConfig>(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        {            foreach (var itemInfo in rewardsDic)            {                CurrentEventList.itemInfos.Add(itemInfo.ToItemData());            }            AccountFileInfo.Instance.SavePlayerData();            // RewardsPanel rewardsPanel = await RewardsPanel.OpenPanel(rewardsDic, onClose, titleId);            // await rewardsPanel.UIClosed();        }    }    public void ChancleEvent()    {        CurrentEventList = null;        onDialogueComplete = null;        onCancel = null;        currentDialogueID = 0;        eventConfig = default;        UIManager.Instance.HideUIUIPanel<DialogueBubblePanel>();    }}
 |