using vnxbqy.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
public class ClientTreasureDungeonStage : DungeonStage
|
{
|
static readonly Vector3 PlayerBornPosition = new Vector3(24.496f, 0.048f, 8.258f);
|
static readonly Vector3 NpcBornPosition = new Vector3(7.5f, 0.04f, 8.02239f);
|
|
bool initialized = false;
|
|
int dialogueNpcId = 0;
|
int[] speakTypes = null;
|
string[] dialogues = null;
|
int[] musics = null;
|
int autoDialogueSecond = 10;
|
|
static GA_NpcClientFunc m_Npc;
|
|
Clock fightEndClock = null;
|
|
static bool IsCompleteDialogue = false;
|
|
SFXController m_CompleteSfx1;
|
List<SFXController> m_FlyControllers = new List<SFXController>();
|
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
public override void Initialize()
|
{
|
base.Initialize();
|
|
if (!initialized)
|
{
|
var funcConfig = FuncConfigConfig.Get("ClientTreasureDungeon");
|
dialogueNpcId = int.Parse(funcConfig.Numerical1);
|
speakTypes = ConfigParse.GetMultipleStr<int>(funcConfig.Numerical2);
|
dialogues = ConfigParse.GetMultipleStr(funcConfig.Numerical3);
|
musics = ConfigParse.GetMultipleStr<int>(funcConfig.Numerical4);
|
|
funcConfig = FuncConfigConfig.Get("TaskContinue");
|
autoDialogueSecond = int.Parse(funcConfig.Numerical2);
|
|
initialized = true;
|
}
|
|
UnInitializedNpc();
|
|
if (fightEndClock != null)
|
{
|
Clock.Stop(fightEndClock);
|
fightEndClock = null;
|
}
|
|
IsCompleteDialogue = false;
|
|
NormalDialogueWin.onDialogueComplete -= OnDialogueComplete;
|
NormalDialogueWin.onDialogueComplete += OnDialogueComplete;
|
GlobalTimeEvent.Instance.secondEvent -= PerSecond;
|
GlobalTimeEvent.Instance.secondEvent += PerSecond;
|
BossShowModel.Instance.bossShowCompletedEvent -= BossShowCompletedEvent;
|
BossShowModel.Instance.bossShowCompletedEvent += BossShowCompletedEvent;
|
dungeonModel.onDungeonResultEvent += OnDungeonResultEvent;
|
}
|
|
protected override void OnStageLoadFinish()
|
{
|
base.OnStageLoadFinish();
|
|
InitializePlayer();
|
|
if (!BossShowModel.Instance.BossShowing)
|
{
|
BossShowCompletedEvent();
|
}
|
}
|
|
void InitializePlayer()
|
{
|
var hero = PlayerDatas.Instance.hero;
|
hero.Pos = PlayerBornPosition;
|
CameraController.Instance.Apply();
|
}
|
|
void InitializeNpc()
|
{
|
m_Npc = GAMgr.Instance.ReqClntNoFightNpc<GA_NpcClientFunc>((uint)dialogueNpcId, E_ActorGroup.FuncNpc);
|
m_Npc.Pos = NpcBornPosition;
|
m_Npc.Rotation = Quaternion.Euler(0, 100, 0);
|
|
var npcConfig = NPCConfig.Get(dialogueNpcId);
|
if (npcConfig.ModeProportion != 1)
|
{
|
m_Npc.Root.localScale = Vector3.one * npcConfig.ModeProportion;
|
}
|
|
NPCInteractProcessor.s_NpcInteractEvent -= OnNpcTalkEvent;
|
NPCInteractProcessor.s_NpcInteractEvent += OnNpcTalkEvent;
|
}
|
|
private void OnNpcTalkEvent(E_NpcType arg1, int arg2, uint arg3)
|
{
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
NormalDialogueWin.customDialogueInfo = new CustomDialogueInfo()
|
{
|
dialogues = dialogues,
|
speakTypes = speakTypes,
|
npcId = dialogueNpcId,
|
autoSeconds = autoDialogueSecond,
|
musics = musics,
|
};
|
WindowCenter.Instance.Open<NormalDialogueWin>();
|
}
|
|
private void OnDialogueComplete()
|
{
|
IsCompleteDialogue = true;
|
var pak = new CA50E_tagCMOpenMagicWeapon();
|
pak.MWID = (uint)101;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
private void OnFightEnd()
|
{
|
if (!IsCompleteDialogue)
|
{
|
ClientDungeonStageUtility.ExitNormalClientDungeon();
|
}
|
}
|
|
private void BossShowCompletedEvent()
|
{
|
dungeonModel.UpdateCoolDown(DungeonCoolDownType.FightStart, 300 * 1000);
|
WindowCenter.Instance.Open<DungeonEndCoolDownWin>();
|
fightEndClock = Clock.AlarmAfter(300, OnFightEnd);
|
InitializeNpc();
|
PlayerDatas.Instance.hero.Behaviour.StartHandupAI();
|
}
|
|
private void OnDungeonResultEvent()
|
{
|
UnInitializeSFX();
|
|
m_CompleteSfx1 = SFXPlayUtility.Instance.Play(20045, NpcBornPosition, Vector3.forward);
|
|
if (m_Npc != null)
|
{
|
GAMgr.Instance.ServerDie(m_Npc.ServerInstID);
|
GAMgr.Instance.Release(m_Npc);
|
m_Npc = null;
|
}
|
|
StartCoroutine(Co_PlayFly());
|
}
|
|
IEnumerator Co_PlayFly()
|
{
|
yield return WaitingForSecondConst.WaitMS800;
|
var heroPos = PlayerDatas.Instance.hero.Pos;
|
for (int i = 0; i < 5; i++)
|
{
|
var startPos = NpcBornPosition + Vector3.up * 0.5f;
|
var endPos = heroPos + Vector3.up * 0.5f;
|
startPos.y = heroPos.y;
|
|
var sfx = SFXPlayUtility.Instance.Play(20046, startPos, Vector3.forward);
|
if (sfx == null)
|
{
|
yield break;
|
}
|
|
m_FlyControllers.Add(sfx);
|
var bezier = m_FlyControllers[i].AddMissingComponent<BezierMove>();
|
|
m_FlyControllers[i].gameObject.SetLayer(LayerUtility.DefaultLayer, true);
|
|
var axis = (endPos - startPos).normalized;
|
|
var center = (startPos + endPos) / 2 - axis * 0.3f;
|
var point = center + Vector3.up * 4;
|
|
point = Quaternion.AngleAxis((i - 2) * 30, axis) * (point - center) + center;
|
|
bezier.duration = 1f;
|
bezier.Begin(startPos, point, endPos, null);
|
}
|
}
|
|
private void PerSecond()
|
{
|
var hero = PlayerDatas.Instance.hero;
|
if (hero == null || m_Npc == null || BossShowModel.Instance.BossShowing)
|
{
|
return;
|
}
|
bool isAuto = hero.aiHandler != null && hero.aiHandler.IsAuto();
|
if (!hero.IsIdle())
|
{
|
return;
|
}
|
var dis = MathUtility.DistanceSqrtXZ(m_Npc.Pos, hero.Pos);
|
if (isAuto && dis <= 15f && !IsCompleteDialogue)
|
{
|
hero.Behaviour.StopHandupAI(true);
|
if (!WindowCenter.Instance.IsOpen<NormalDialogueWin>())
|
{
|
OnNpcTalkEvent(E_NpcType.Func, 0, 0);
|
}
|
}
|
}
|
|
void UnInitializedNpc()
|
{
|
if (m_Npc != null)
|
{
|
GAMgr.Instance.ServerDie(m_Npc.ServerInstID);
|
GAMgr.Instance.Release(m_Npc);
|
m_Npc = null;
|
}
|
|
if (fightEndClock != null)
|
{
|
Clock.Stop(fightEndClock);
|
fightEndClock = null;
|
}
|
|
UnInitializeSFX();
|
}
|
|
void UnInitializeSFX()
|
{
|
if (m_CompleteSfx1 != null)
|
{
|
SFXPlayUtility.Instance.Release(m_CompleteSfx1);
|
m_CompleteSfx1 = null;
|
}
|
|
if (m_FlyControllers.Count > 0)
|
{
|
foreach (var sfx in m_FlyControllers)
|
{
|
var bezier = sfx.GetComponent<BezierMove>();
|
if (bezier != null)
|
{
|
DestroyImmediate(bezier);
|
}
|
SFXPlayUtility.Instance.Release(sfx);
|
}
|
m_FlyControllers.Clear();
|
}
|
}
|
|
public override void UnInitialize()
|
{
|
base.UnInitialize();
|
|
UnInitializedNpc();
|
|
StopAllCoroutines();
|
|
NPCInteractProcessor.s_NpcInteractEvent -= OnNpcTalkEvent;
|
NormalDialogueWin.onDialogueComplete -= OnDialogueComplete;
|
GlobalTimeEvent.Instance.secondEvent -= PerSecond;
|
BossShowModel.Instance.bossShowCompletedEvent -= BossShowCompletedEvent;
|
dungeonModel.onDungeonResultEvent -= OnDungeonResultEvent;
|
}
|
#if UNITY_EDITOR
|
private void OnGUI()
|
{
|
if (GUILayout.Button("Test"))
|
{
|
OnDungeonResultEvent();
|
}
|
}
|
#endif
|
}
|