// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2021-05-01 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using System.Collections; using System.Collections.Generic; using PureMVC.Interfaces; using UnityEngine; namespace G { /// /// /// public class AdventureProxy : F.GameProxy { #region Field /// /// /// private readonly Dictionary _globalAdventures = new Dictionary(); /// /// /// private readonly List _stageAdventures = new List(); #endregion #region Method public void ShowGlobalAdventure(int id) { if (_globalAdventures.TryGetValue(id, out var adventure)) { if (adventure.story > 0) StartCoroutine(ShowAdventure(adventure)); else UI.AdventureBox.ShowAdventure(adventure); } } private IEnumerator ShowAdventure(ItemAdventure adventure) { var storying = false; storying = StoryProxy.Instance.TriggerStory(adventure.story, () => { storying = false; }); while (storying) { yield return null; } UI.AdventureBox.ShowAdventure(adventure); } /// /// /// /// /// public bool ShowStageAdventure(int id, bool auto, Callback callback) { ItemAdventure adventure = null; if (id > 0) { adventure = ItemProxy.Instance.GetStaticItem(id); } if (adventure == null) { if (_stageAdventures.Count > 0) { adventure = _stageAdventures[Random.Range(0, _stageAdventures.Count)]; } } if (adventure != null) { UI.AdventureBox.ShowAdventure(adventure, auto, callback); return true; } else { return false; } } #endregion #region Proxy public static AdventureProxy Instance => GetInstance(); public override void LoadCompleted() { if (_globalAdventures.Count == 0 && _stageAdventures.Count == 0) { var adventures = ItemProxy.Instance.GetStaticItems(); for (int i = 0; i < adventures.Count; i++) { var adventure = adventures[i]; if (adventure.type == 2) { int missionId = adventure.typeArgs != null && adventure.typeArgs.Length > 0 ? adventure.typeArgs[0] : 0; if (missionId > 0) _globalAdventures.Add(missionId, adventure); } else if (adventure.type == 1) { _stageAdventures.Add(adventures[i]); } } } } static readonly int[] _ListNotificationInterests = new int[] { GlobalDefine.EVENT_MISSION_COMPLETED, }; public override IList ListNotificationInterests() { return _ListNotificationInterests; } public override void HandleNotification(INotification notification) { if (notification.Name == GlobalDefine.EVENT_MISSION_COMPLETED) if (notification.Body is Mission mission) { ShowGlobalAdventure(mission.id); } } #endregion } }