using vnxbqy.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
public class ClientPersonalBossDungeonStage : DungeonStage
|
{
|
static readonly Vector3 s_PlayerPosition = new Vector3(16.19f, 0.825f, 7.62f);
|
static readonly Vector3 s_NpcPosition = new Vector3(11.9f, 0.825f, 9.64f);
|
|
static readonly float s_PlayerAngle = -70.925f;
|
|
static int[] s_StepTimes = null;
|
|
static Clock s_StepClock = null;
|
|
Step m_Step = Step.None;
|
public Step step
|
{
|
get { return m_Step; }
|
set
|
{
|
if (m_Step != value)
|
{
|
switch (m_Step)
|
{
|
case Step.Prepare:
|
OnExitPrepare();
|
break;
|
case Step.Fight:
|
OnExitFight();
|
break;
|
}
|
|
m_Step = value;
|
|
switch (m_Step)
|
{
|
case Step.Prepare:
|
OnEnterPrepare();
|
break;
|
case Step.Fight:
|
OnEnterFight();
|
break;
|
case Step.Over:
|
OnEnterOver();
|
break;
|
}
|
}
|
}
|
}
|
|
static GA_NpcClientFightBoss s_ClientBoss = null;
|
|
static PersonalBossModel model { get { return ModelCenter.Instance.GetModel<PersonalBossModel>(); } }
|
static DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
public override void Initialize()
|
{
|
base.Initialize();
|
|
step = Step.None;
|
|
var npcId = model.GetBossNpcId(ClientDungeonStageUtility.dungeonInfo.lineId);
|
var config = PersonalBossConfig.Get(npcId);
|
if (config != null)
|
{
|
var dungeonId = dungeonModel.GetDungeonId(PersonalBossModel.PERSONALBOSS_MAPID, config.lineId);
|
var dungeonConfig = DungeonConfig.Get(dungeonId);
|
if (dungeonConfig != null)
|
{
|
s_StepTimes = LitJson.JsonMapper.ToObject<int[]>(dungeonConfig.StepTime);
|
}
|
}
|
|
dungeonModel.onDungeonResultEvent += OnDungeonResultEvent;
|
PersonalEnemy.OnNpcAppear += OnNpcAppear;
|
}
|
|
protected override void OnStageLoadFinish()
|
{
|
base.OnStageLoadFinish();
|
|
InitializePlayer();
|
|
step = Step.Prepare;
|
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += PlayerLoginOk;
|
}
|
|
void InitializePlayer()
|
{
|
var hero = PlayerDatas.Instance.hero;
|
if (hero != null)
|
{
|
hero.Pos = s_PlayerPosition;
|
hero.Rotation = Quaternion.Euler(0, s_PlayerAngle, 0);
|
}
|
CameraController.Instance.Apply();
|
}
|
|
void OnEnterPrepare()
|
{
|
var seconds = s_StepTimes[0];
|
dungeonModel.UpdateCoolDown(DungeonCoolDownType.WaitStart, (uint)seconds * 1000);
|
|
s_StepClock = Clock.AlarmAfter(seconds, () =>
|
{
|
step = Step.Fight;
|
});
|
}
|
|
void OnExitPrepare()
|
{
|
if (s_StepClock != null)
|
{
|
Clock.Stop(s_StepClock);
|
s_StepClock = null;
|
}
|
}
|
|
void OnEnterFight()
|
{
|
InitializeNpc();
|
|
var seconds = s_StepTimes[1];
|
dungeonModel.UpdateCoolDown(DungeonCoolDownType.FightStart, (uint)seconds * 1000);
|
|
s_StepClock = Clock.AlarmAfter(seconds, () =>
|
{
|
ClientDungeonStageUtility.ExitNormalClientDungeon();
|
});
|
}
|
|
private void OnExitFight()
|
{
|
if (s_StepClock != null)
|
{
|
Clock.Stop(s_StepClock);
|
s_StepClock = null;
|
}
|
}
|
|
private void OnEnterOver()
|
{
|
var seconds = s_StepTimes[2];
|
dungeonModel.UpdateCoolDown(DungeonCoolDownType.LeaveMap, (uint)seconds * 1000);
|
s_StepClock = Clock.AlarmAfter(seconds, () =>
|
{
|
ClientDungeonStageUtility.ExitNormalClientDungeon();
|
});
|
}
|
|
void InitializeNpc()
|
{
|
uint hp = 0;
|
uint hpEx = 0;
|
var position = s_NpcPosition;
|
if (s_ClientBoss != null)
|
{
|
hp = (uint)(s_ClientBoss.ActorInfo.Hp % Constants.ExpPointValue);
|
hpEx = (uint)(s_ClientBoss.ActorInfo.Hp / Constants.ExpPointValue);
|
position = s_ClientBoss.Pos;
|
PersonalEnemy.Release(s_ClientBoss);
|
}
|
|
var npcId = model.GetBossNpcId(ClientDungeonStageUtility.dungeonInfo.lineId);
|
PersonalEnemy.Create((uint)npcId, E_ActorGroup.Enemy, position, hp, hpEx);
|
}
|
|
private void OnDungeonResultEvent()
|
{
|
step = Step.Over;
|
}
|
|
private void PlayerLoginOk()
|
{
|
if (step < Step.Over)
|
{
|
InitializeNpc();
|
}
|
}
|
|
public override void UnInitialize()
|
{
|
base.UnInitialize();
|
|
dungeonModel.onDungeonResultEvent -= OnDungeonResultEvent;
|
PersonalEnemy.OnNpcAppear -= OnNpcAppear;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= PlayerLoginOk;
|
|
if (s_ClientBoss != null)
|
{
|
s_ClientBoss = null;
|
}
|
|
if (s_StepClock != null)
|
{
|
Clock.Stop(s_StepClock);
|
s_StepClock = null;
|
}
|
}
|
|
private void OnNpcAppear(GA_NpcClientFightNorm _npc)
|
{
|
if (_npc != null && _npc is GA_NpcClientFightBoss)
|
{
|
s_ClientBoss = _npc as GA_NpcClientFightBoss;
|
}
|
}
|
|
#if UNITY_EDITOR
|
private void OnGUI()
|
{
|
if (GUILayout.Button("Exit"))
|
{
|
ClientDungeonStageUtility.ExitNormalClientDungeon();
|
}
|
}
|
#endif
|
|
public enum Step
|
{
|
None,
|
Prepare,
|
Fight,
|
Over,
|
}
|
}
|