using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
public class ClientHazyPreciousDungeonStage : DungeonStage
|
{
|
readonly Vector3 s_PlayerPosition = new Vector3(17.609f, 5.469f, 2.233f);
|
readonly Vector3 s_BossPosition = new Vector3(11.46125f, 5.810412f, 11.24522f);
|
readonly Vector3 s_PreciousPosition = new Vector3(5.76f, 6.708447f, 23.48f);
|
readonly Vector3 s_PreciousEffectPosition = new Vector3(5.8f, 6.708447f, 23.34f);
|
readonly Vector3 s_IndicationPosition = new Vector3(12.1f, 6f, 11.95f);
|
readonly Vector3 s_IndicationAngle = new Vector3(0, -30.74f, 0);
|
|
readonly float s_BossAngle = 148.57f;
|
readonly float s_PreciousAngle = -29.531f;
|
readonly float s_PreciousEffectAngle = 77f;
|
|
int m_LineId = 0;
|
|
int[] stepTimes;
|
|
int m_BossNpcId = 0;
|
int m_PreciousNpcId = 0;
|
int m_PreciousEffectNpcId = 0;
|
|
uint m_PreciousSid = 0;
|
|
SFXController m_Indication;
|
SFXController m_PreciousEffect;
|
Clock m_PrepareClock;
|
Clock m_ExitClock;
|
|
GA_NpcClientFightBoss clientBoss;
|
GA_NpcClientCollect clientPrecious;
|
|
static UnityEngine.AI.NavMeshObstacle s_Obstacle = null;
|
|
Step m_Step = Step.None;
|
public Step step
|
{
|
get { return m_Step; }
|
set
|
{
|
if (m_Step != value)
|
{
|
switch (m_Step)
|
{
|
case Step.Prepare:
|
break;
|
case Step.Fight:
|
OnExitFight();
|
break;
|
case Step.Collect:
|
OnExitCollect();
|
break;
|
case Step.Over:
|
break;
|
}
|
|
m_Step = value;
|
switch (m_Step)
|
{
|
case Step.Prepare:
|
OnEnterPrepare();
|
break;
|
case Step.Fight:
|
OnEnterFight();
|
break;
|
case Step.Collect:
|
OnEnterCollect();
|
break;
|
case Step.Over:
|
OnEnterOver();
|
break;
|
}
|
}
|
}
|
}
|
|
DungeonModel model { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
HazyRegionModel hazyRegionModel { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
|
|
public override void Initialize()
|
{
|
base.Initialize();
|
|
step = Step.None;
|
|
var incidentId = hazyRegionModel.GetIncidentId(ClientDungeonStageUtility.dungeonInfo.mapId, ClientDungeonStageUtility.dungeonInfo.lineId);
|
var incidentConfig = HazyRegionConfig.Get(incidentId);
|
var dungeonId = model.GetDungeonId(incidentConfig.dungeonId, incidentConfig.lineId);
|
var config = DungeonConfig.Get(dungeonId);
|
stepTimes = LitJson.JsonMapper.ToObject<int[]>(config.StepTime);
|
var npcArray = LitJson.JsonMapper.ToObject<int[]>(config.RefreshNPC);
|
m_BossNpcId = npcArray[0];
|
m_PreciousNpcId = npcArray[1];
|
m_PreciousEffectNpcId = npcArray[2];
|
m_LineId = incidentConfig.lineId;
|
|
UnloadAssets();
|
|
BossShowModel.Instance.bossShowCompletedEvent += BossShowCompletedEvent;
|
ClientCollectUtility.OnCollectFinished += OnCollectFinished;
|
model.onDungeonResultEvent += OnDungeonResultEvent;
|
PersonalEnemy.OnNpcAppear += OnNpcAppear;
|
}
|
|
protected override void OnUpdate()
|
{
|
base.OnUpdate();
|
|
switch (step)
|
{
|
case Step.None:
|
break;
|
case Step.Prepare:
|
break;
|
case Step.Fight:
|
if (clientBoss != null && clientBoss.ActorInfo.serverDie)
|
{
|
step = Step.Collect;
|
}
|
break;
|
case Step.Collect:
|
break;
|
case Step.Over:
|
break;
|
}
|
}
|
|
protected override void OnStageLoadFinish()
|
{
|
base.OnStageLoadFinish();
|
|
StartCoroutine(Co_VerityExistBossShow());
|
|
InitializePlayer();
|
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
|
}
|
|
private IEnumerator Co_VerityExistBossShow()
|
{
|
yield return WaitingForSecondConst.WaitMS500;
|
if (!BossShowModel.Instance.BossShowing)
|
{
|
BossShowCompletedEvent();
|
}
|
}
|
|
private void OnPlayerLoginOk()
|
{
|
if (step <= Step.Fight)
|
{
|
InitializeBoss();
|
}
|
}
|
|
public override void UnInitialize()
|
{
|
base.UnInitialize();
|
|
UnloadAssets();
|
|
StopAllCoroutines();
|
|
BossShowModel.Instance.bossShowCompletedEvent -= BossShowCompletedEvent;
|
ClientCollectUtility.OnCollectFinished -= OnCollectFinished;
|
model.onDungeonResultEvent -= OnDungeonResultEvent;
|
PersonalEnemy.OnNpcAppear -= OnNpcAppear;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
|
}
|
|
private void OnDungeonResultEvent()
|
{
|
step = Step.Over;
|
}
|
|
private void InitializePlayer()
|
{
|
var hero = PlayerDatas.Instance.hero;
|
if (hero != null)
|
{
|
hero.Pos = s_PlayerPosition;
|
}
|
}
|
|
private void InitializeNpc()
|
{
|
InitializeBoss();
|
|
clientPrecious = GAMgr.Instance.ReqClntNoFightNpc<GA_NpcClientCollect>((uint)m_PreciousNpcId, E_ActorGroup.FuncNpc);
|
clientPrecious.Pos = s_PreciousPosition;
|
clientPrecious.Rotation = Quaternion.Euler(0, s_PreciousAngle, 0);
|
|
var npcConfig = NPCConfig.Get(m_PreciousNpcId);
|
if (npcConfig.ModeProportion != 1)
|
{
|
clientPrecious.Root.localScale = Vector3.one * npcConfig.ModeProportion;
|
}
|
m_PreciousSid = clientPrecious.ServerInstID;
|
|
npcConfig = NPCConfig.Get(m_PreciousEffectNpcId);
|
m_PreciousEffect = SFXPlayUtility.Instance.PlayWithEulerAngle(npcConfig.NPCEffect, s_PreciousEffectPosition
|
, new Vector3(0, s_PreciousEffectAngle, 0));
|
var animator = m_PreciousEffect.GetComponentInChildren<Animator>(true);
|
if (animator != null)
|
{
|
animator.Play(GAStaticDefine.State_IdleHash);
|
}
|
}
|
|
private void InitializeBoss()
|
{
|
uint hp = 0;
|
uint hpEx = 0;
|
var position = s_BossPosition;
|
if (clientBoss != null)
|
{
|
hp = (uint)(clientBoss.ActorInfo.Hp % Constants.ExpPointValue);
|
hpEx = (uint)(clientBoss.ActorInfo.Hp / Constants.ExpPointValue);
|
position = clientBoss.Pos;
|
PersonalEnemy.Release(clientBoss);
|
}
|
|
PersonalEnemy.Create((uint)m_BossNpcId, E_ActorGroup.Enemy, position, hp, hpEx);
|
}
|
|
void OnEnterPrepare()
|
{
|
var seconds = GetStepSeconds(Step.Prepare);
|
model.UpdateCoolDown(DungeonCoolDownType.WaitStart, (uint)seconds * 1000);
|
m_PrepareClock = Clock.AlarmAfter(seconds, () =>
|
{
|
step = Step.Fight;
|
});
|
|
UpdateMissionData();
|
}
|
|
void OnEnterFight()
|
{
|
InitializeNpc();
|
|
s_Obstacle = SoMap.CreateImpasse.General(new Vector3(7.38f, 0, 20.62f),
|
new Vector3(0, -27.4f, 0), new Vector3(5.07f, 1f, 0.43f));
|
|
var seconds = GetStepSeconds(Step.Fight);
|
model.UpdateCoolDown(DungeonCoolDownType.FightStart, (uint)seconds * 1000);
|
|
m_ExitClock = Clock.AlarmAfter(seconds, OnExitDungeon);
|
|
UpdateMissionData();
|
}
|
|
void OnExitFight()
|
{
|
var animator = m_PreciousEffect.GetComponentInChildren<Animator>(true);
|
if (animator != null)
|
{
|
animator.Play(GAStaticDefine.State_DeadHash);
|
}
|
}
|
|
void OnEnterCollect()
|
{
|
m_Indication = SFXPlayUtility.Instance.PlayWithEulerAngle(1051, s_IndicationPosition, s_IndicationAngle);
|
|
if (s_Obstacle != null)
|
{
|
Destroy(s_Obstacle.gameObject);
|
s_Obstacle = null;
|
}
|
|
StartCoroutine(Co_GotoCollect());
|
|
UpdateMissionData();
|
}
|
|
void OnExitCollect()
|
{
|
if (m_ExitClock != null)
|
{
|
Clock.Stop(m_ExitClock);
|
m_ExitClock = null;
|
}
|
}
|
|
void OnEnterOver()
|
{
|
var seconds = GetStepSeconds(Step.Over);
|
model.UpdateCoolDown(DungeonCoolDownType.LeaveMap, (uint)seconds * 1000);
|
|
m_ExitClock = Clock.AlarmAfter(seconds, OnExitDungeon);
|
|
UpdateMissionData();
|
}
|
|
IEnumerator Co_GotoCollect()
|
{
|
yield return WaitingForSecondConst.WaitMS2000;
|
var hero = PlayerDatas.Instance.hero;
|
if (hero != null && clientPrecious != null)
|
{
|
if (hero.Behaviour != null)
|
{
|
hero.Behaviour.StopHandupAI(true);
|
}
|
|
if (hazyRegionModel.auto)
|
{
|
MapTransferUtility.Instance.MoveToNPC(clientPrecious.NpcConfig.NPCID);
|
}
|
else
|
{
|
hero.MoveToTarget(clientPrecious, 1f, true);
|
}
|
}
|
}
|
|
int GetStepSeconds(Step step)
|
{
|
switch (step)
|
{
|
case Step.Prepare:
|
return stepTimes != null && stepTimes.Length > 0 ? stepTimes[0] : 3;
|
case Step.Fight:
|
return stepTimes != null && stepTimes.Length > 1 ? stepTimes[1] : 480;
|
case Step.Collect:
|
return stepTimes != null && stepTimes.Length > 3 ? stepTimes[3] : 5;
|
case Step.Over:
|
return stepTimes != null && stepTimes.Length > 2 ? stepTimes[2] : 10;
|
}
|
return 0;
|
}
|
|
private void UpdateMissionData()
|
{
|
var npcTotal = 0;
|
var missionData = new DungeonMissionData()
|
{
|
lineID = m_LineId,
|
step = (int)step < (int)Step.Collect ? 1 : 2,
|
npcTotal = npcTotal,
|
};
|
model.UpdateJiaDungeonMission(31190, missionData);
|
}
|
|
void UnloadAssets()
|
{
|
if (m_Indication != null)
|
{
|
SFXPlayUtility.Instance.Release(m_Indication);
|
m_Indication = null;
|
}
|
if (m_PrepareClock != null)
|
{
|
Clock.Stop(m_PrepareClock);
|
m_PrepareClock = null;
|
}
|
|
if (clientBoss != null)
|
{
|
clientBoss = null;
|
}
|
|
if (clientPrecious != null)
|
{
|
GAMgr.Instance.ServerDie(clientPrecious.ServerInstID);
|
GAMgr.Instance.Release(clientPrecious);
|
clientPrecious = null;
|
}
|
|
if (m_PreciousEffect != null)
|
{
|
SFXPlayUtility.Instance.Release(m_PreciousEffect);
|
m_PreciousEffect = null;
|
}
|
|
if (s_Obstacle != null)
|
{
|
Destroy(s_Obstacle.gameObject);
|
s_Obstacle = null;
|
}
|
|
if (m_ExitClock != null)
|
{
|
Clock.Stop(m_ExitClock);
|
m_ExitClock = null;
|
}
|
}
|
|
void OnExitDungeon()
|
{
|
ClientDungeonStageUtility.ExitNormalClientDungeon();
|
}
|
|
private void BossShowCompletedEvent()
|
{
|
step = Step.Prepare;
|
}
|
|
private void OnCollectFinished(uint sid)
|
{
|
if (sid == m_PreciousSid)
|
{
|
ClientSceneManager.Instance.lastDeadPos = s_PreciousPosition;
|
var pak = new CA234_tagCMGetCustomSceneCollectAward();
|
pak.NPCID = (uint)m_PreciousNpcId;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
}
|
|
private void OnNpcAppear(GA_NpcClientFightNorm _npc)
|
{
|
if (_npc != null && _npc is GA_NpcClientFightBoss)
|
{
|
clientBoss = _npc as GA_NpcClientFightBoss;
|
}
|
}
|
|
public enum Step
|
{
|
None,
|
Prepare,
|
Fight,
|
Collect,
|
Over,
|
}
|
}
|
}
|
|