using Snxxz.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
public class ClientHazyDemonKingStage : DungeonStage
|
{
|
static readonly Vector3 playerBornPosition = new Vector3(10, 6.38f, 6.67f);
|
static readonly Vector3 bossBornPosition = new Vector3(8.35f, 6.37f, 9.7f);
|
|
static GA_NpcClientFightBoss clientFightBoss = null;
|
|
float totalTime = 20f;
|
float timer = 0f;
|
DateTime playerAtkTime = DateTime.Now;
|
Clock pickItemClock = null;
|
|
float stepTimer = 0f;
|
|
float existTime = 10f;
|
|
bool pickAllDropItem = false;
|
|
int itemCount = 0;
|
|
Step m_Step = Step.Fight;
|
Step step
|
{
|
get { return m_Step; }
|
set
|
{
|
if (m_Step != value)
|
{
|
m_Step = value;
|
switch (m_Step)
|
{
|
case Step.Fight:
|
stepTimer = 0f;
|
break;
|
case Step.PickItem:
|
stepTimer = 5f;
|
break;
|
case Step.Settle:
|
stepTimer = 0f;
|
break;
|
case Step.Exit:
|
stepTimer = 0f;
|
break;
|
}
|
}
|
}
|
}
|
|
HazyDemonKingModel model { get { return ModelCenter.Instance.GetModel<HazyDemonKingModel>(); } }
|
HazyRegionModel hazyRegionModel { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
public override void Initialize()
|
{
|
base.Initialize();
|
|
timer = 0f;
|
playerAtkTime = DateTime.MinValue;
|
m_Step = Step.None;
|
pickAllDropItem = false;
|
itemCount = 0;
|
|
DTC0403_tagPlayerLoginLoadOK.mapInitOkEvent += OnReconnected;
|
AttackHandler.OnAttackTarget += OnPlayerAttack;
|
ClientDungeonStageUtility.onReceiveCustomDropItme += OnReceiveCustomDropItme;
|
dungeonModel.onDungeonResultEvent += OnDungeonResultEvent;
|
ClientDropItemUtility.OnItemPickup += OnItemPickup;
|
}
|
|
protected override void OnStageLoadFinish()
|
{
|
base.OnStageLoadFinish();
|
|
InitializePlayer();
|
InitializeBoss();
|
|
step = Step.Fight;
|
}
|
|
public static uint GetClientBossSid()
|
{
|
if (clientFightBoss != null)
|
{
|
return clientFightBoss.ServerInstID;
|
}
|
return 0;
|
}
|
|
void InitializePlayer()
|
{
|
var hero = PlayerDatas.Instance.hero;
|
hero.Pos = playerBornPosition;
|
CameraController.Instance.Apply();
|
}
|
|
void InitializeBoss()
|
{
|
if (clientFightBoss != null)
|
{
|
clientFightBoss.ActorInfo.serverDie = true;
|
GAMgr.Instance.ServerDie(clientFightBoss.ServerInstID);
|
GAMgr.Instance.Release(clientFightBoss);
|
clientFightBoss = null;
|
}
|
|
var config = HazyRegionConfig.Get(hazyRegionModel.processingIncidentId);
|
var npcId = NPCConfig.Get(config.npcId);
|
|
clientFightBoss = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightBoss>((uint)config.npcId, E_ActorGroup.Enemy);
|
clientFightBoss.Pos = bossBornPosition;
|
clientFightBoss.LockTargetSID = PlayerDatas.Instance.PlayerId;
|
}
|
|
private void OnPlayerAttack(uint _attackerId, uint _victimId, byte _type, uint _damage)
|
{
|
if (clientFightBoss == null)
|
{
|
return;
|
}
|
|
if (_victimId == clientFightBoss.ServerInstID)
|
{
|
var progress = Mathf.Clamp01(1 - timer / totalTime);
|
var hp = (ulong)(clientFightBoss.ActorInfo.RealMaxHp * progress);
|
|
TargetBriefInfo.OnRefreshBossLifeBar(_victimId, clientFightBoss.NpcConfig.NPCID,
|
hp, clientFightBoss.ActorInfo.RealMaxHp);
|
|
playerAtkTime = DateTime.Now;
|
}
|
}
|
|
private void OnReceiveCustomDropItme(HB214_tagMCCuntomFBPrizeInfo package)
|
{
|
step = Step.PickItem;
|
if (package.PrizeItemCount <= 0)
|
{
|
pickAllDropItem = true;
|
}
|
else
|
{
|
itemCount = package.PrizeItemCount;
|
int[] items = new int[itemCount];
|
for (int i = 0; i < itemCount; i++)
|
{
|
items[i] = (int)package.PrizeItemIDList[i];
|
}
|
ClientDropItemUtility.Instance.Drop(bossBornPosition, items);
|
|
dungeonModel.UpdateCoolDown(DungeonCoolDownType.PickUpTime, 30 * 1000);
|
|
if (pickItemClock != null)
|
{
|
Clock.Stop(pickItemClock);
|
pickItemClock = null;
|
}
|
pickItemClock = Clock.AlarmAfter(30, OnPickUpItemLimit);
|
}
|
}
|
|
void OnPickUpItemLimit()
|
{
|
pickAllDropItem = true;
|
}
|
|
private void OnItemPickup(int itemId)
|
{
|
itemCount--;
|
if (itemCount == 0)
|
{
|
pickAllDropItem = true;
|
}
|
}
|
|
private void OnDungeonResultEvent()
|
{
|
step = Step.Settle;
|
dungeonModel.UpdateCoolDown(DungeonCoolDownType.LeaveMap, 10 * 1000);
|
}
|
|
protected override void OnUpdate()
|
{
|
base.OnUpdate();
|
|
if (timer < totalTime)
|
{
|
if ((DateTime.Now - playerAtkTime).TotalSeconds < 1f)
|
{
|
timer += Time.deltaTime;
|
if (timer >= totalTime)
|
{
|
OnBossDie();
|
}
|
}
|
}
|
|
switch (step)
|
{
|
case Step.Fight:
|
if (clientFightBoss == null)
|
{
|
stepTimer += Time.deltaTime;
|
if (stepTimer > 5f)
|
{
|
stepTimer = 0f;
|
RequestDropItem();
|
}
|
}
|
break;
|
case Step.PickItem:
|
if (pickAllDropItem)
|
{
|
stepTimer += Time.deltaTime;
|
if (stepTimer >= 5f)
|
{
|
RequestSettle();
|
stepTimer = 0f;
|
}
|
}
|
break;
|
case Step.Settle:
|
stepTimer += Time.deltaTime;
|
if (stepTimer >= existTime)
|
{
|
step = Step.Exit;
|
model.RequestExitClientDungeon();
|
}
|
break;
|
}
|
}
|
|
void OnBossDie()
|
{
|
if (clientFightBoss != null)
|
{
|
clientFightBoss.ActorInfo.serverDie = true;
|
GAMgr.Instance.ServerDie(clientFightBoss.ServerInstID);
|
clientFightBoss.Die();
|
clientFightBoss = null;
|
}
|
|
RequestDropItem();
|
}
|
|
void RequestDropItem()
|
{
|
var incidentId = hazyRegionModel.processingIncidentId;
|
var config = HazyRegionConfig.Get(incidentId);
|
ClientDungeonStageUtility.RequestClientDropItem(config.dungeonId, config.lineId);
|
}
|
|
void RequestSettle()
|
{
|
var incidentId = hazyRegionModel.processingIncidentId;
|
var config = HazyRegionConfig.Get(incidentId);
|
ClientDungeonStageUtility.RequestSettleClientDungeon(config.dungeonId, config.lineId);
|
}
|
|
private void OnReconnected()
|
{
|
var incidentId = hazyRegionModel.processingIncidentId;
|
var config = HazyRegionConfig.Get(incidentId);
|
ClientDungeonStageUtility.RequestStartClientDungeon(config.dungeonId, config.lineId);
|
}
|
|
public override void UnInitialize()
|
{
|
base.UnInitialize();
|
|
if (clientFightBoss != null)
|
{
|
clientFightBoss.ActorInfo.serverDie = true;
|
GAMgr.Instance.ServerDie(clientFightBoss.ServerInstID);
|
GAMgr.Instance.Release(clientFightBoss);
|
clientFightBoss = null;
|
}
|
|
if (pickItemClock != null)
|
{
|
Clock.Stop(pickItemClock);
|
pickItemClock = null;
|
}
|
|
DTC0403_tagPlayerLoginLoadOK.mapInitOkEvent -= OnReconnected;
|
AttackHandler.OnAttackTarget -= OnPlayerAttack;
|
ClientDungeonStageUtility.onReceiveCustomDropItme -= OnReceiveCustomDropItme;
|
dungeonModel.onDungeonResultEvent -= OnDungeonResultEvent;
|
ClientDropItemUtility.OnItemPickup -= OnItemPickup;
|
}
|
|
#if UNITY_EDITOR
|
private void OnGUI()
|
{
|
if (GUILayout.Button("Exit"))
|
{
|
model.RequestExitClientDungeon();
|
}
|
}
|
#endif
|
|
public enum Step
|
{
|
None,
|
Fight,
|
PickItem,
|
Settle,
|
Exit
|
}
|
}
|