shaoxiadiablo/Assets/AGame/Scripts/Proxy/AdventureProxy.cs

147 lines
3.3 KiB
C#
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-05-01
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "AdventureProxy" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using PureMVC.Interfaces;
using UnityEngine;
namespace G
{
/// <summary>
///
/// </summary>
public class AdventureProxy : F.GameProxy
{
#region Field
/// <summary>
///
/// </summary>
private readonly Dictionary<int, ItemAdventure> _globalAdventures = new Dictionary<int, ItemAdventure>();
/// <summary>
///
/// </summary>
private readonly List<ItemAdventure> _stageAdventures = new List<ItemAdventure>();
#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);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="callback"></param>
public bool ShowStageAdventure(int id, bool auto, Callback callback)
{
ItemAdventure adventure = null;
if (id > 0)
{
adventure = ItemProxy.Instance.GetStaticItem<ItemAdventure>(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<AdventureProxy>();
public override void LoadCompleted()
{
if (_globalAdventures.Count == 0 && _stageAdventures.Count == 0)
{
var adventures = ItemProxy.Instance.GetStaticItems<ItemAdventure>();
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<int> 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
}
}