using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using Snxxz.UI;
|
|
|
public class GuardDungeonStage : DungeonStage
|
{
|
DungeonModel m_Model { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
int stepBuf = -1;
|
|
int guardNPCID = 32504001;
|
int bossNPCID = 32503001;
|
int monsterNPCID = 32501001;
|
|
BossShowStep bossShowStep;
|
KillMonsterStep killMonsterStep;
|
DestroyCageStep destroyCageStep;
|
GuardDialogueStep guardDialogueStep;
|
DungeonOver dungeonOverStep;
|
|
Step m_Step = Step.None;
|
Step step {
|
get { return m_Step; }
|
set {
|
if (m_Step != value)
|
{
|
switch (m_Step)
|
{
|
case Step.BossShow:
|
bossShowStep.OnExit();
|
break;
|
case Step.KillMonster:
|
killMonsterStep.OnExit();
|
break;
|
case Step.DestroyCage:
|
destroyCageStep.OnExit();
|
break;
|
case Step.GuardDialogue:
|
guardDialogueStep.OnExit();
|
break;
|
case Step.Over:
|
dungeonOverStep.OnExit();
|
break;
|
}
|
|
m_Step = value;
|
switch (m_Step)
|
{
|
case Step.BossShow:
|
bossShowStep.OnEnter();
|
break;
|
case Step.KillMonster:
|
killMonsterStep.OnEnter();
|
break;
|
case Step.DestroyCage:
|
destroyCageStep.OnEnter();
|
break;
|
case Step.GuardDialogue:
|
guardDialogueStep.OnEnter();
|
break;
|
case Step.Over:
|
dungeonOverStep.OnEnter();
|
break;
|
}
|
|
}
|
}
|
}
|
|
|
int guardDialogueIndex = 0;
|
float guardDialogueAbleTime = 0f;
|
|
public override void Initialize()
|
{
|
base.Initialize();
|
|
bossShowStep = new BossShowStep(this);
|
killMonsterStep = new KillMonsterStep(this);
|
destroyCageStep = new DestroyCageStep(this);
|
guardDialogueStep = new GuardDialogueStep(this);
|
dungeonOverStep = new DungeonOver(this);
|
|
step = Step.None;
|
stepBuf = -1;
|
|
PlayerDatas.Instance.hero.aiHandler.PriorityNpcID = monsterNPCID;
|
|
m_Model.updateMissionEvent += OnDungeonMissionUpdate;
|
BossShowModel.Instance.bossShowPreparedEvent += OnBossShowBegin;
|
}
|
|
public override void UnInitialize()
|
{
|
m_Model.updateMissionEvent -= OnDungeonMissionUpdate;
|
BossShowModel.Instance.bossShowPreparedEvent -= OnBossShowBegin;
|
|
base.UnInitialize();
|
}
|
|
protected override void OnStageLoadFinish()
|
{
|
base.OnStageLoadFinish();
|
}
|
|
protected override void OnUpdate()
|
{
|
base.OnUpdate();
|
|
switch (step)
|
{
|
case Step.BossShow:
|
bossShowStep.OnUpdate();
|
break;
|
case Step.KillMonster:
|
killMonsterStep.OnUpdate();
|
break;
|
case Step.DestroyCage:
|
destroyCageStep.OnUpdate();
|
break;
|
case Step.GuardDialogue:
|
guardDialogueStep.OnUpdate();
|
break;
|
case Step.Over:
|
dungeonOverStep.OnUpdate();
|
break;
|
}
|
}
|
|
private void OnDungeonMissionUpdate()
|
{
|
var mission = m_Model.mission;
|
|
if (mission.step != 0)
|
{
|
if (stepBuf != mission.step)
|
{
|
step = (Step)mission.step;
|
stepBuf = mission.step;
|
}
|
}
|
}
|
|
private void OnBossShowBegin()
|
{
|
step = Step.BossShow;
|
}
|
|
class BossShowStep
|
{
|
float timer = 0f;
|
float monsterExclaimTime = 6.4f;
|
float monsterRunTime = 7f;
|
bool exclaimed = false;
|
float monsterMoveSpeed = 0.5f;
|
|
GuardDungeonStage dungeonStage;
|
public BossShowStep(GuardDungeonStage _stage)
|
{
|
dungeonStage = _stage;
|
}
|
|
public void OnEnter()
|
{
|
timer = 0f;
|
exclaimed = false;
|
var showActors = BossShowModel.Instance.showTargetList;
|
for (int i = 0; i < showActors.Count; i++)
|
{
|
var showActor = showActors[i];
|
if (showActor.npcId == dungeonStage.guardNPCID)
|
{
|
showActor.m_Model.transform.localScale = Vector3.one * 3;
|
}
|
}
|
|
for (int i = 0; i < showActors.Count; i++)
|
{
|
var showActor = showActors[i];
|
if (dungeonStage.monsterNPCID == showActor.npcId)
|
{
|
var mountPoint = showActor.m_Model.transform.GetChildTransformDeeply("A_Name");
|
|
switch (i)
|
{
|
case 2:
|
StoryDialogueBubble.StoryShow(Language.Get("BossShowTalk2"), mountPoint, BossShowModel.Instance.showCamera, 0.5f);
|
break;
|
case 3:
|
StoryDialogueBubble.StoryShow(Language.Get("BossShowTalk3"), mountPoint, BossShowModel.Instance.showCamera, 1f);
|
break;
|
case 5:
|
StoryDialogueBubble.StoryShow(Language.Get("BossShowTalk4"), mountPoint, BossShowModel.Instance.showCamera, 1.5f);
|
break;
|
case 6:
|
StoryDialogueBubble.StoryShow(Language.Get("BossShowTalk5"), mountPoint, BossShowModel.Instance.showCamera, 2f);
|
break;
|
}
|
}
|
else if (dungeonStage.bossNPCID == showActor.npcId)
|
{
|
var mountPoint = showActor.m_Model.transform.GetChildTransformDeeply("A_Stun");
|
StoryDialogueBubble.StoryShow(Language.Get("BossShowTalk1"), mountPoint, BossShowModel.Instance.showCamera);
|
}
|
}
|
|
}
|
|
public void OnUpdate()
|
{
|
timer += Time.deltaTime;
|
var showActors = BossShowModel.Instance.showTargetList;
|
if (!exclaimed && timer > monsterExclaimTime)
|
{
|
exclaimed = true;
|
|
for (int i = 0; i < showActors.Count; i++)
|
{
|
var showActor = showActors[i];
|
|
if (dungeonStage.monsterNPCID == showActor.npcId)
|
{
|
var mountPoint = showActor.m_Model.transform.GetChildTransformDeeply("A_Name");
|
HeadUpStorySign.Display(mountPoint, BossShowModel.Instance.showCamera);
|
showActor.m_Model.transform.LookAt(BossShowModel.Instance.showCamera.transform);
|
showActor.m_Model.transform.localEulerAngles = showActor.m_Model.transform.localEulerAngles.SetX(0f);
|
}
|
else if (dungeonStage.bossNPCID == showActor.npcId)
|
{
|
var mountPoint = showActor.m_Model.transform.GetChildTransformDeeply("A_Stun");
|
HeadUpStorySign.Display(mountPoint, BossShowModel.Instance.showCamera);
|
}
|
}
|
}
|
|
if (exclaimed && timer > monsterRunTime)
|
{
|
for (int i = 0; i < showActors.Count; i++)
|
{
|
var showActor = showActors[i];
|
if (showActor.m_Model != null)
|
{
|
if (dungeonStage.monsterNPCID == showActor.npcId)
|
{
|
var cameraPosition = BossShowModel.Instance.showCamera.transform.position;
|
var monsterPosition = showActor.m_Model.transform.position;
|
var direction = (cameraPosition.SetY(monsterPosition.y) - monsterPosition).normalized;
|
showActor.m_Model.transform.position += direction * monsterMoveSpeed * Time.deltaTime;
|
|
showActor.m_Model.transform.LookAt(BossShowModel.Instance.showCamera.transform);
|
showActor.m_Model.transform.localEulerAngles = showActor.m_Model.transform.localEulerAngles.SetX(0f);
|
}
|
}
|
}
|
}
|
|
if (Time.time > dungeonStage.guardDialogueAbleTime)
|
{
|
for (int i = 0; i < showActors.Count; i++)
|
{
|
var showActor = showActors[i];
|
if (dungeonStage.guardNPCID == showActor.npcId)
|
{
|
dungeonStage.guardDialogueAbleTime = Time.time + GeneralDefine.guardBubbleInterval;
|
var mountPoint = showActor.m_Model.transform.GetChildTransformDeeply("A_Name");
|
|
var index = dungeonStage.guardDialogueIndex % 5 + 1;
|
dungeonStage.guardDialogueIndex++;
|
var content = Language.Get(StringUtility.Contact("BabyDragonWord", index));
|
StoryDialogueBubble.StoryShow(content, mountPoint, BossShowModel.Instance.showCamera);
|
}
|
}
|
}
|
|
}
|
|
public void OnExit()
|
{
|
}
|
|
}
|
|
class KillMonsterStep
|
{
|
GuardDungeonStage dungeonStage;
|
SFXController cageInvincibleEffect;
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
bool guardScaled = false;
|
bool guardAdjustPosition = false;
|
|
public KillMonsterStep(GuardDungeonStage _stage)
|
{
|
dungeonStage = _stage;
|
}
|
|
public void OnEnter()
|
{
|
guardScaled = false;
|
guardAdjustPosition = false;
|
cageInvincibleEffect = null;
|
}
|
|
public void OnUpdate()
|
{
|
var actors = GAMgr.Instance.GetGroupList(E_ActorGroup.Enemy);
|
if (actors == null)
|
{
|
return;
|
}
|
|
if (cageInvincibleEffect == null)
|
{
|
for (int i = 0; i < actors.Count; i++)
|
{
|
var actor = actors[i] as GActorNpcFight;
|
if (actor != null
|
&& actor.NpcConfig.NPCID == GeneralDefine.guardDungeonCageNPCID)
|
{
|
cageInvincibleEffect = SFXPlayUtility.Instance.PlayBattleEffect(3010, actor, 2f);
|
break;
|
}
|
}
|
}
|
|
if (guardAdjustPosition)
|
{
|
var functionNpcs = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
|
if (functionNpcs != null && cageInvincibleEffect != null)
|
{
|
for (int i = 0; i < functionNpcs.Count; i++)
|
{
|
var actor = functionNpcs[i] as GA_NpcFunc;
|
if (actor.NpcConfig.NPCID == dungeonStage.guardNPCID)
|
{
|
var yoffset = actor.Pos.y;
|
actor.Pos = cageInvincibleEffect.transform.position.SetY(yoffset);
|
}
|
}
|
}
|
}
|
|
if (!guardScaled)
|
{
|
var functionNpcs = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
|
if (functionNpcs != null)
|
{
|
for (int i = 0; i < functionNpcs.Count; i++)
|
{
|
var actor = functionNpcs[i] as GA_NpcFunc;
|
if (actor.NpcConfig.NPCID == dungeonStage.guardNPCID)
|
{
|
actor.Root.localScale = Vector3.one * 3;
|
var npcInteractor = actor.Root.GetComponent<NPCInteractProcessor>();
|
if (npcInteractor != null)
|
{
|
npcInteractor.enabled = false;
|
}
|
guardScaled = true;
|
guardAdjustPosition = true;
|
}
|
}
|
}
|
}
|
|
for (int i = 0; i < actors.Count; i++)
|
{
|
var actor = actors[i] as GActorNpcFight;
|
if (actor.NpcConfig.NPCID == dungeonStage.monsterNPCID && !actor.ActorInfo.serverDie)
|
{
|
if (PlayerDatas.Instance.hero.aiHandler.IsAuto())
|
{
|
PlayerDatas.Instance.hero.SelectTarget = actor;
|
PlayerDatas.Instance.hero.LockTarget = actor;
|
}
|
break;
|
}
|
else if (actor.NpcConfig.NPCID == dungeonStage.bossNPCID && !actor.ActorInfo.serverDie)
|
{
|
if (PlayerDatas.Instance.hero.aiHandler.IsAuto())
|
{
|
PlayerDatas.Instance.hero.SelectTarget = actor;
|
PlayerDatas.Instance.hero.LockTarget = actor;
|
}
|
break;
|
}
|
}
|
|
if (Time.time > dungeonStage.guardDialogueAbleTime)
|
{
|
var functionNpcs = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
|
if (functionNpcs != null)
|
{
|
for (int i = 0; i < functionNpcs.Count; i++)
|
{
|
var showActor = functionNpcs[i] as GA_NpcFunc;
|
if (dungeonStage.guardNPCID == showActor.NpcConfig.NPCID)
|
{
|
dungeonStage.guardDialogueAbleTime = Time.time + GeneralDefine.guardBubbleInterval;
|
var mountPoint = showActor.MP_Name;
|
|
var index = dungeonStage.guardDialogueIndex % 5 + 1;
|
dungeonStage.guardDialogueIndex++;
|
var content = Language.Get(StringUtility.Contact("BabyDragonWord", index));
|
StoryDialogueBubble.StoryShow(content, mountPoint, CameraController.Instance.CameraObject);
|
}
|
}
|
}
|
}
|
|
}
|
|
public void OnExit()
|
{
|
if (cageInvincibleEffect != null)
|
{
|
SFXPlayUtility.Instance.Release(cageInvincibleEffect);
|
cageInvincibleEffect = null;
|
}
|
}
|
|
}
|
|
class DestroyCageStep
|
{
|
|
GuardDungeonStage dungeonStage;
|
public DestroyCageStep(GuardDungeonStage _stage)
|
{
|
dungeonStage = _stage;
|
}
|
|
public void OnEnter()
|
{
|
|
}
|
|
public void OnUpdate()
|
{
|
PlayerDatas.Instance.hero.aiHandler.PriorityNpcID = GeneralDefine.guardDungeonCageNPCID;
|
|
if (Time.time > dungeonStage.guardDialogueAbleTime)
|
{
|
var functionNpcs = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
|
if (functionNpcs != null)
|
{
|
for (int i = 0; i < functionNpcs.Count; i++)
|
{
|
var showActor = functionNpcs[i] as GA_NpcFunc;
|
if (dungeonStage.guardNPCID == showActor.NpcConfig.NPCID)
|
{
|
dungeonStage.guardDialogueAbleTime = Time.time + GeneralDefine.guardBubbleInterval;
|
var mountPoint = showActor.MP_Name;
|
|
var index = dungeonStage.guardDialogueIndex % 5 + 1;
|
dungeonStage.guardDialogueIndex++;
|
var content = Language.Get(StringUtility.Contact("BabyDragonWord", index));
|
StoryDialogueBubble.StoryShow(content, mountPoint, CameraController.Instance.CameraObject);
|
}
|
}
|
}
|
}
|
|
}
|
|
public void OnExit()
|
{
|
|
}
|
|
}
|
|
class GuardDialogueStep
|
{
|
GuardDungeonStage dungeonStage;
|
public GuardDialogueStep(GuardDungeonStage _stage)
|
{
|
dungeonStage = _stage;
|
}
|
|
public void OnEnter()
|
{
|
var playerTaskDatas = ModelCenter.Instance.GetModel<PlayerTaskDatas>();
|
var questId = playerTaskDatas.currentMission;
|
playerTaskDatas.AutomaticTripToTask(questId);
|
|
var functionNpcs = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
|
if (functionNpcs != null)
|
{
|
for (int i = 0; i < functionNpcs.Count; i++)
|
{
|
var actor = functionNpcs[i] as GA_NpcFunc;
|
if (actor.NpcConfig.NPCID == dungeonStage.guardNPCID)
|
{
|
var npcInteractor = actor.Root.GetComponent<NPCInteractProcessor>();
|
if (npcInteractor != null)
|
{
|
npcInteractor.enabled = true;
|
}
|
}
|
}
|
}
|
}
|
|
public void OnUpdate()
|
{
|
|
}
|
|
public void OnExit()
|
{
|
}
|
|
}
|
|
class DungeonOver
|
{
|
GuardDungeonStage dungeonStage;
|
float timer = 0f;
|
float transformDuration = 2f;
|
|
GA_NpcFunc m_GuardNpc;
|
Animator m_GuardAnimator;
|
bool m_OnGuardDancing = false;
|
bool m_GuardDanceComplete = false;
|
|
SFXController m_GuardEffect;
|
|
public DungeonOver(GuardDungeonStage _stage)
|
{
|
dungeonStage = _stage;
|
}
|
|
public void OnEnter()
|
{
|
timer = 0f;
|
m_GuardNpc = null;
|
m_OnGuardDancing = false;
|
m_GuardAnimator = null;
|
m_GuardEffect = null;
|
}
|
|
public void OnUpdate()
|
{
|
timer += Time.deltaTime;
|
|
Transform guard = null;
|
var functionNpcs = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
|
if (functionNpcs != null)
|
{
|
for (int i = 0; i < functionNpcs.Count; i++)
|
{
|
var actor = functionNpcs[i] as GA_NpcFunc;
|
if (actor.NpcConfig.NPCID == dungeonStage.guardNPCID)
|
{
|
guard = actor.Root;
|
m_GuardNpc = actor;
|
if (m_GuardAnimator == null)
|
{
|
m_GuardAnimator = m_GuardNpc.Root.GetComponentInChildren<Animator>();
|
}
|
if (m_GuardEffect == null)
|
{
|
m_GuardEffect = SFXPlayUtility.Instance.PlayBattleEffect(1014, actor, 1);
|
var mountPoint = guard.GetChildTransformDeeply(GAStaticDefine.MountPointBoneName);
|
m_GuardEffect.duration = 0;
|
m_GuardEffect.transform.SetParent(mountPoint);
|
m_GuardEffect.transform.localPosition = Vector3.zero;
|
}
|
break;
|
}
|
}
|
}
|
|
if (guard != null)
|
{
|
if (timer < transformDuration)
|
{
|
guard.localScale = Mathf.Lerp(3, 1, timer / transformDuration) * Vector3.one;
|
}
|
else
|
{
|
var hero = PlayerDatas.Instance.hero;
|
if (!m_GuardDanceComplete)
|
{
|
m_GuardNpc.ReleaseName();
|
SelectionManager.Release(SelectionManager.E_Type.Green);
|
m_GuardNpc.ReleaseShadow();
|
GuardDancing();
|
return;
|
}
|
if (MathUtility.CalDistance(guard.transform.position, hero.Root.position) > 1.0f)
|
{
|
guard.LookAt(new Vector3(hero.Root.position.x, hero.Root.position.y + 0.5f, hero.Root.position.z));
|
guard.Translate(Vector3.forward * hero.ActorInfo.moveSpeed * Time.deltaTime);
|
}
|
}
|
}
|
}
|
|
public void GuardDancing()
|
{
|
var hero = PlayerDatas.Instance.hero;
|
if (m_GuardNpc != null)
|
{
|
var nextPosition = hero.Root.position + hero.Root.right.normalized * 0.6f - hero.Forward.normalized * 0.3f;
|
nextPosition.y = hero.Root.position.y + 1.0f;
|
var dis = Vector3.Distance(nextPosition, m_GuardNpc.Root.position);
|
if (dis > 0.1f)
|
{
|
m_GuardNpc.Forward = nextPosition - m_GuardNpc.Root.position;
|
var deltapos = Vector3.Lerp(m_GuardNpc.Root.position, nextPosition, hero.ActorInfo.moveSpeed * Time.deltaTime);
|
m_GuardNpc.Root.position = deltapos;
|
}
|
else
|
{
|
if (!m_OnGuardDancing && m_GuardNpc.NextAction != GA_Guard.GuardAction_Dance2)
|
{
|
m_GuardNpc.Forward = hero.Forward;
|
m_GuardNpc.NextAction = GA_Guard.GuardAction_Dance2;
|
m_OnGuardDancing = true;
|
}
|
else if (m_OnGuardDancing && m_GuardAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.90f
|
&& !m_GuardAnimator.IsInTransition(0))
|
{
|
m_GuardNpc.NextAction = GA_Guard.GuardAction_Run;
|
m_GuardDanceComplete = true;
|
}
|
}
|
}
|
else
|
{
|
m_GuardDanceComplete = true;
|
}
|
}
|
|
public void OnExit()
|
{
|
if (m_GuardEffect != null)
|
{
|
SFXPlayUtility.Instance.Release(m_GuardEffect);
|
m_GuardEffect = null;
|
}
|
}
|
}
|
|
enum Step
|
{
|
None = -1,
|
BossShow = 0,
|
KillMonster = 1,
|
DestroyCage = 2,
|
GuardDialogue = 3,
|
Over = 4,
|
}
|
|
}
|