204 lines
6.2 KiB
C#
204 lines
6.2 KiB
C#
using DragonLi.Core;
|
||
using Mirror;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using XPlugin.Data.JsonLiteDB;
|
||
|
||
public class StoryManager : NetworkBehaviour
|
||
{
|
||
public static StoryManager Ins { get; private set; }
|
||
|
||
[SyncVar]
|
||
/// <summary>
|
||
/// 当前选择的难度
|
||
/// </summary>
|
||
public int gameDifficulty;
|
||
|
||
|
||
[SyncVar]
|
||
/// <summary>
|
||
/// 当前剧情在哪
|
||
/// </summary>
|
||
public int currentStoryIndex = 0;
|
||
|
||
|
||
|
||
|
||
// json数据库
|
||
private JsonLiteDB DB;
|
||
|
||
|
||
public static void Init()
|
||
{
|
||
Ins = new StoryManager();
|
||
}
|
||
|
||
[ClientRpc]
|
||
public void ShowResultPlane()
|
||
{
|
||
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
||
{
|
||
WorldUIManager.Ins.Cover("UI/ResultPlane", false);
|
||
}, 1f);
|
||
}
|
||
public void Start()
|
||
{
|
||
Ins = this;
|
||
// currentStoryIndex = 7;
|
||
EventDispatcher.AddEventListener("NextTrriger", NextTrriger);
|
||
}
|
||
|
||
[Command(requiresAuthority = false)]
|
||
public void SetGameDifficultyCmd(int index)
|
||
{
|
||
gameDifficulty = index;
|
||
}
|
||
|
||
public void NextTrriger()
|
||
{
|
||
StartCoroutine(MyCoroutine());
|
||
}
|
||
|
||
// public IEnumerator MyCoroutine1()
|
||
// {
|
||
// // 根据当前剧情索引获取剧情信息
|
||
// StoryInfo1 storyInfo1 = GameManager.Ins.GameStoryInfos[currentStoryIndex];
|
||
|
||
// //创建物体
|
||
|
||
// }
|
||
|
||
|
||
public IEnumerator MyCoroutine()
|
||
{
|
||
StoryInfo storyInfo = GameManager.Ins.StoryDescInfos[currentStoryIndex];
|
||
//根据难度选择
|
||
GameManager.Ins.AllEnemyAmount = storyInfo.ALLEnemyAmount[gameDifficulty];
|
||
int pathId = storyInfo.PathId;
|
||
int crackAmount = storyInfo.CrackAmount[gameDifficulty];
|
||
currentStoryIndex = storyInfo.NextId;
|
||
|
||
if (storyInfo.EnergyMask != null)
|
||
{
|
||
|
||
// 遍历字典的键值对
|
||
foreach (KeyValuePair<int, Vector3> kvp in storyInfo.EnergyMask)
|
||
{
|
||
int key = kvp.Key; // 获取键
|
||
Vector3 value = kvp.Value; // 获取值
|
||
GameManager.Ins.CreateProp((PropType)(key), value);
|
||
}
|
||
}
|
||
//表中传送门数量大于0 需要创建传送门
|
||
if (crackAmount > 0)
|
||
{
|
||
for (int i = 0; i < crackAmount; i++)
|
||
{
|
||
if (i > 0)
|
||
{
|
||
yield return new WaitForSeconds(3.0f);
|
||
}
|
||
else
|
||
{
|
||
//EventDispatcher.TriggerEvent("PlayEnemyInfo", storyInfo.Id);
|
||
ShowEnemyInfoMessage(storyInfo.Id);
|
||
}
|
||
GameObject crack = GameManager.Ins?.CreateCrack(storyInfo.CracksPos[i], storyInfo.Angle[i]);
|
||
//临时存储创建出来的传送门
|
||
GameManager.Ins?.cracksList.Add(crack);
|
||
//传送门创建出来后根据表内容创建怪物
|
||
for (int j = 0; j < storyInfo.EnemyAmount[gameDifficulty]; j++)
|
||
{
|
||
float interval = Random.Range(storyInfo.CreateInterva[0], storyInfo.CreateInterva[1]);
|
||
if (j > 0)
|
||
{
|
||
yield return new WaitForSeconds(interval); // <20><>ÿ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>֮<EFBFBD><D6AE>ȴ<EFBFBD>1<EFBFBD><31>
|
||
}
|
||
|
||
string pathid = (pathId + i).ToString();
|
||
GameManager.Ins?.GenerateEnemy((EnemyType)(storyInfo.type), storyInfo.EnemysPos[i], storyInfo.Angle[i], storyInfo.EnemysScale[0], pathid);
|
||
}
|
||
}
|
||
if (GameManager.Ins.cracksList.Count > 0)
|
||
{
|
||
for (int i = 0; i < GameManager.Ins.cracksList.Count; i++)
|
||
{
|
||
Crack crack = GameManager.Ins.cracksList[i].GetComponent<Crack>();
|
||
crack.CloseCrack();
|
||
}
|
||
}
|
||
}
|
||
//如果传送门为0;
|
||
else
|
||
{
|
||
//如果怪物个数超过1;
|
||
if (GameManager.Ins.AllEnemyAmount > 1)
|
||
{
|
||
yield return new WaitForSeconds(storyInfo.Wait);
|
||
//EventDispatcher.TriggerEvent("PlayEnemyInfo", storyInfo.Id);
|
||
ShowEnemyInfoMessage(storyInfo.Id);
|
||
for (int i = 0; i < storyInfo.EnemysPos.Length; i++)
|
||
{
|
||
if (i > 0)
|
||
{
|
||
yield return new WaitForSeconds(2.0f); //
|
||
}
|
||
for (int j = 0; j < storyInfo.EnemyAmount[gameDifficulty]; j++)
|
||
{
|
||
string pathid = (pathId + i).ToString();
|
||
GameManager.Ins?.GenerateEnemy((EnemyType)(storyInfo.type), storyInfo.EnemysPos[i], storyInfo.Angle[0], storyInfo.EnemysScale[0], pathid);
|
||
float interval = Random.Range(storyInfo.CreateInterva[0], storyInfo.CreateInterva[1]);
|
||
yield return new WaitForSeconds(interval);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
yield return new WaitForSeconds(storyInfo.Wait);
|
||
ShowEnemyInfoMessage(storyInfo.Id);
|
||
GameManager.Ins?.GenerateEnemy((EnemyType)(storyInfo.type), storyInfo.EnemysPos[0], storyInfo.Angle[0], storyInfo.EnemysScale[0], pathId.ToString());
|
||
}
|
||
}
|
||
}
|
||
|
||
[ClientRpc]
|
||
public void ShowEnemyInfoMessage(int index)
|
||
{
|
||
EventDispatcher.TriggerEvent("PlayEnemyInfo", index);
|
||
}
|
||
|
||
[Server]
|
||
public void CreateStoryItem()
|
||
{
|
||
StoryInfo storyInfo = GameManager.Ins.StoryDescInfos[currentStoryIndex];
|
||
if (storyInfo.EnergyPump != null)
|
||
{
|
||
foreach (KeyValuePair<int, Vector3> kvp in storyInfo.EnergyPump)
|
||
{
|
||
int key = kvp.Key; // 获取键
|
||
Vector3 value = kvp.Value; // 获取值
|
||
GameManager.Ins.CreateProp((PropType)(key), value);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
public void Update()
|
||
{
|
||
//Transform player= MRNetworkManager.Ins.roomSlots[0].transform;
|
||
|
||
//Debug.Log("玩家当前移动距离:" + Mathf.Floor(player.position.x) + "|" + Mathf.Floor(player.position.y) + "|" + Mathf.Floor(player.position.z));
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|