From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XCutScene.cs | 701 +++++++++++++++++++++++++ 1 file changed, 701 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XCutScene.cs (limited to 'Client/Assets/Scripts/XMainClient/XCutScene.cs') diff --git a/Client/Assets/Scripts/XMainClient/XCutScene.cs b/Client/Assets/Scripts/XMainClient/XCutScene.cs new file mode 100644 index 00000000..a3e1e9e4 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XCutScene.cs @@ -0,0 +1,701 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using XMainClient.UI; +using XMainClient.UI.UICommon; +using XUpdater; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XCutScene : XSingleton + { + public bool IsPlaying + { + get + { + return this._cut_scene; + } + } + + public bool IsExcludeNewBorn + { + get + { + return this._exclusive; + } + set + { + this._exclusive = value; + } + } + + public float Length + { + get + { + return this.IsPlaying ? this._cut_scene_data.Length : 0f; + } + } + + public string Name + { + get + { + return this._name; + } + } + + public Vector3 EndWithPos { get; set; } + + public float EndWithDir { get; set; } + + public uint GeneralMonsterID { get; set; } + + public Dictionary _common_actors = new Dictionary(); + + private List _common_fx = new List(); + + private bool _cut_scene = false; + + private bool _exclusive = true; + + private List _eventToken = new List(); + + private List _actors = null; + + protected List _fx = new List(); + + private XCutSceneData _cut_scene_data = null; + + private XCameraMotionData _camera = new XCameraMotionData(); + + private XEntity _target = null; + + private uint _token = 0u; + + private string _name = null; + + private XTimerMgr.ElapsedEventHandler _startCb = null; + + private XTimerMgr.ElapsedEventHandler _endCb = null; + + private XTimerMgr.ElapsedEventHandler _actorOnStageCb = null; + + private XTimerMgr.ElapsedEventHandler _playerOnStageCb = null; + + private XTimerMgr.ElapsedEventHandler _fxCb = null; + + private XTimerMgr.ElapsedEventHandler _audioCb = null; + + private XTimerMgr.ElapsedEventHandler _subTitleCb = null; + + private XTimerMgr.ElapsedEventHandler _slashCb = null; + + private XTimerMgr.ElapsedEventHandler _endShowCb = null; + + private XTimerMgr.ElapsedEventHandler _endSubTitleCb = null; + + private CommandCallback _findFxTransCb = null; + + private bool _bFadeAtEnd = true; + + private float farClipPlaneBackUP = 150f; + + public XCutScene() + { + this._camera.AutoSync_At_Begin = false; + this._camera.Coordinate = CameraMotionSpace.World; + this._camera.Follow_Position = false; + this._camera.LookAt_Target = false; + this._camera.At = 0f; + this._camera.MotionType = CameraMotionType.AnchorBased; + this._startCb = new XTimerMgr.ElapsedEventHandler(this.InnerStart); + this._endCb = new XTimerMgr.ElapsedEventHandler(this.InnerEnd); + this._actorOnStageCb = new XTimerMgr.ElapsedEventHandler(this.ActorOnStage); + this._playerOnStageCb = new XTimerMgr.ElapsedEventHandler(this.PlayerOnStage); + this._fxCb = new XTimerMgr.ElapsedEventHandler(this.Fx); + this._audioCb = new XTimerMgr.ElapsedEventHandler(this.Audio); + this._subTitleCb = new XTimerMgr.ElapsedEventHandler(this.SubTitle); + this._slashCb = new XTimerMgr.ElapsedEventHandler(this.Slash); + this._endShowCb = new XTimerMgr.ElapsedEventHandler(this.EndShow); + this._endSubTitleCb = new XTimerMgr.ElapsedEventHandler(this.EndSubTitle); + this._findFxTransCb = new CommandCallback(this.AttachFx); + } + + public void Start(string cutname, bool bFadeOut = true, bool bFadeAtEnd = true) + { + bool cut_scene = this._cut_scene; + if (cut_scene) + { + XSingleton.singleton.Stop(true); + } + this._bFadeAtEnd = bFadeAtEnd; + this._actors = new List(); + XSingleton.singleton.StopSoundForCutscene(); + XSingleton.singleton.DoScriptRecord(cutname); + XSingleton.singleton.MakeEffectEnable(XPostEffect.BlackWhite, false); + this._cut_scene = true; + this._name = cutname; + this._cut_scene_data = XSingleton.singleton.GetData(this._name, ".txt"); + XBillBoardDocument.SetAllBillBoardState(BillBoardHideType.CutScene, false); + bool flag = XSingleton.singleton.CurrentStage is XConcreteStage; + if (flag) + { + XSingleton.singleton.ShowBlock(true); + } + bool overrideBGM = this._cut_scene_data.OverrideBGM; + if (overrideBGM) + { + XSingleton.singleton.PauseBGM(); + } + bool flag2 = DlgBase.singleton.IsLoaded(); + if (flag2) + { + DlgBase.singleton.OnStopVoiceRecord(); + } + bool flag3 = DlgBase.singleton.IsLoaded(); + if (flag3) + { + DlgBase.singleton.OnStopVoiceRecord(); + } + XSingleton.singleton.TimeMagicBack(); + XSingleton.singleton.EnablePlayerAI(false); + List ally = XSingleton.singleton.GetAlly(XSingleton.singleton.Player); + for (int i = 0; i < ally.Count; i++) + { + bool flag4 = ally[i] != XSingleton.singleton.Player; + if (flag4) + { + XAIEnableAI @event = XEventPool.GetEvent(); + @event.Firer = ally[i]; + @event.Enable = false; + XSingleton.singleton.FireEvent(@event); + } + } + bool flag5 = string.IsNullOrEmpty(this._cut_scene_data.CameraClip); + if (flag5) + { + XAutoFade.FadeOut2In(1f, 2.5f); + this.AddedTimerToken(XSingleton.singleton.SetTimer(1f, this._endCb, null)); + } + else if (bFadeOut) + { + XAutoFade.FadeOut2In(0.5f, 0.5f); + this.AddedTimerToken(XSingleton.singleton.SetTimer(0.5f, this._startCb, null)); + } + else + { + this.InnerStart(this); + } + } + + public void Stop(bool bImmdiately = false) + { + bool isPlaying = this.IsPlaying; + if (isPlaying) + { + for (int i = 0; i < this._eventToken.Count; i++) + { + XSingleton.singleton.KillTimer(this._eventToken[i]); + } + this._eventToken.Clear(); + if (bImmdiately) + { + this.InnerEnd(null); + } + else + { + this.EndShow(null); + } + } + } + + public void ClearCommon() + { + for (int i = 0; i < this._common_fx.Count; i++) + { + bool flag = this._common_fx[i] != null; + if (flag) + { + XSingleton.singleton.DestroyFx(this._common_fx[i], true); + } + } + this._common_fx.Clear(); + foreach (XActor xactor in this._common_actors.Values) + { + xactor.Uninitilize(); + } + this._common_actors.Clear(); + } + + public void OnLeaveScene() + { + bool isPlaying = this.IsPlaying; + if (isPlaying) + { + this.Stop(true); + XAutoFade.FastFadeIn(); + } + } + + public void AddedTimerToken(uint token) + { + this._eventToken.Add(token); + } + + private void InnerStart(object o) + { + XSingleton.singleton.Freezed = true; + bool flag = o == null; + if (flag) + { + XAutoFade.MakeBlack(false); + } + this.farClipPlaneBackUP = XSingleton.singleton.GameCamera.UnityCamera.farClipPlane; + XSingleton.singleton.GameCamera.UnityCamera.farClipPlane = 150f; + XSingleton.singleton.GameCamera.UnityCamera.fieldOfView = this._cut_scene_data.FieldOfView; + this._camera.Motion = this._cut_scene_data.CameraClip; + this._camera.Follow_Position = this._cut_scene_data.GeneralShow; + this._camera.AutoSync_At_Begin = this._cut_scene_data.GeneralShow; + bool flag2 = XSingleton.singleton.GameCamera.CloseUp != null; + if (flag2) + { + XSingleton.singleton.GameCamera.CloseUp.Stop(null); + } + bool flag3 = XSingleton.singleton.GameCamera.Collision != null; + if (flag3) + { + XSingleton.singleton.GameCamera.Collision.Enabled = false; + } + bool flag4 = XSingleton.singleton.GameCamera.VAdjust != null; + if (flag4) + { + XSingleton.singleton.GameCamera.VAdjust.Enabled = false; + } + bool flag5 = XSingleton.singleton.GameCamera.Solo != null; + if (flag5) + { + XSingleton.singleton.GameCamera.Solo.Stop(); + } + foreach (XActorDataClip xactorDataClip in this._cut_scene_data.Actors) + { + this.AddedTimerToken(XSingleton.singleton.SetTimer(xactorDataClip.TimeLineAt / 30f - 0.016f, this._actorOnStageCb, xactorDataClip)); + } + bool generalShow = this._cut_scene_data.GeneralShow; + if (generalShow) + { + bool flag6 = XSingleton.singleton.Boss != null; + if (flag6) + { + this._target = XSingleton.singleton.Boss; + } + else + { + bool flag7 = this.GeneralMonsterID > 0u; + if (flag7) + { + Vector3 zero = Vector3.zero; + float angle = 0f; + bool flag8 = XSingleton.singleton.QueryMonsterStaticInfo(this.GeneralMonsterID, ref zero, ref angle); + if (flag8) + { + this._target = XSingleton.singleton.CreateDummy(this.GeneralMonsterID, zero, XSingleton.singleton.FloatToQuaternion(angle)); + } + else + { + XSingleton.singleton.AddErrorLog("QueryMonsterStaticInfo failed with id ", this.GeneralMonsterID.ToString(), " in cutscene ", this._cut_scene_data.Name, null, null); + } + } + else + { + XSingleton.singleton.AddErrorLog("Missing Boss id in general cutscene script with name ", this._cut_scene_data.Name, null, null, null, null); + } + } + } + XCameraMotionEventArgs @event = XEventPool.GetEvent(); + @event.Motion = this._camera; + @event.Target = this._target; + @event.Trigger = this._cut_scene_data.Trigger; + @event.Firer = XSingleton.singleton.GameCamera; + XSingleton.singleton.FireEvent(@event); + bool flag9 = !this._cut_scene_data.GeneralShow; + if (flag9) + { + foreach (XPlayerDataClip xplayerDataClip in this._cut_scene_data.Player) + { + this.AddedTimerToken(XSingleton.singleton.SetTimer(xplayerDataClip.TimeLineAt / 30f - 0.016f, this._playerOnStageCb, xplayerDataClip)); + } + foreach (XFxDataClip xfxDataClip in this._cut_scene_data.Fxs) + { + this.AddedTimerToken(XSingleton.singleton.SetTimer(xfxDataClip.TimeLineAt / 30f, this._fxCb, xfxDataClip)); + } + } + foreach (XAudioDataClip xaudioDataClip in this._cut_scene_data.Audios) + { + this.AddedTimerToken(XSingleton.singleton.SetTimer(xaudioDataClip.TimeLineAt / 30f, this._audioCb, xaudioDataClip)); + } + bool mourningborder = this._cut_scene_data.Mourningborder; + if (mourningborder) + { + DlgBase.singleton.SetVisible(true, true); + foreach (XSubTitleDataClip xsubTitleDataClip in this._cut_scene_data.SubTitle) + { + this.AddedTimerToken(XSingleton.singleton.SetTimer(xsubTitleDataClip.TimeLineAt / 30f, this._subTitleCb, xsubTitleDataClip)); + } + foreach (XSlashDataClip xslashDataClip in this._cut_scene_data.Slash) + { + this.AddedTimerToken(XSingleton.singleton.SetTimer(xslashDataClip.TimeLineAt / 30f, new XTimerMgr.ElapsedEventHandler(this.Slash), xslashDataClip)); + } + } + else + { + bool flag10 = XSingleton.singleton.CurrentStage.Stage == EXStage.World; + if (flag10) + { + } + } + bool autoEnd = this._cut_scene_data.AutoEnd; + if (autoEnd) + { + this.AddedTimerToken(XSingleton.singleton.SetTimer((this._cut_scene_data.TotalFrame - 30f) / 30f, this._endShowCb, null)); + } + this.Reflection(); + XSingleton.singleton.Dummilize(this._cut_scene_data.TypeMask); + bool flag11 = this.EndWithPos.sqrMagnitude > 0.1f; + if (flag11) + { + this.CorrectToEndPos(); + } + } + + public void Reflection() + { + bool flag = this._cut_scene_data != null; + if (flag) + { + bool flag2 = !string.IsNullOrEmpty(this._cut_scene_data.Script); + if (flag2) + { + XSingleton.singleton.ExecuteCutScene(this._cut_scene_data.Script, this._actors); + } + } + } + + private void ActorOnStage(object o) + { + XActorDataClip xactorDataClip = o as XActorDataClip; + XActor xactor = null; + bool flag = !string.IsNullOrEmpty(xactorDataClip.Tag); + if (flag) + { + int num = 0; + bool flag2 = int.TryParse(xactorDataClip.Tag, out num) && num > XGame.RoleCount; + if (flag2) + { + return; + } + } + Vector3 pos; + pos= new Vector3(xactorDataClip.AppearX, xactorDataClip.AppearY, xactorDataClip.AppearZ); + bool flag3 = xactorDataClip.bUsingID && xactorDataClip.bToCommonPool; + if (flag3) + { + bool flag4 = !this._common_actors.TryGetValue((uint)xactorDataClip.StatisticsID, out xactor); + if (flag4) + { + xactor = (xactorDataClip.bUsingID ? new XActor((uint)xactorDataClip.StatisticsID, pos, xactorDataClip.Clip) : new XActor(xactorDataClip.Prefab, pos, Quaternion.identity, xactorDataClip.Clip)); + xactor.Initilize(0); + bool flag5 = !string.IsNullOrEmpty(xactorDataClip.Tag); + if (flag5) + { + xactor.EngineObject.Tag = xactorDataClip.Tag; + } + this._common_actors.Add((uint)xactorDataClip.StatisticsID, xactor); + } + else + { + xactor.PlayAnimation(xactorDataClip.Clip); + } + } + else + { + xactor = (xactorDataClip.bUsingID ? new XActor((uint)xactorDataClip.StatisticsID, pos, xactorDataClip.Clip) : new XActor(xactorDataClip.Prefab, pos, Quaternion.identity, xactorDataClip.Clip)); + xactor.Initilize(0); + } + this._actors.Add(xactor); + this.Reflection(); + } + + private void PlayerOnStage(object o) + { + XPlayerDataClip xplayerDataClip = o as XPlayerDataClip; + Vector3 pos; + pos= new Vector3(xplayerDataClip.AppearX, xplayerDataClip.AppearY, xplayerDataClip.AppearZ); + XActor xactor; + switch (XSingleton.singleton.Player.BasicTypeID) + { + case 1u: + xactor = new XActor(pos, xplayerDataClip.Clip1); + break; + case 2u: + xactor = new XActor(pos, xplayerDataClip.Clip2); + break; + case 3u: + xactor = new XActor(pos, xplayerDataClip.Clip3); + break; + case 4u: + xactor = new XActor(pos, xplayerDataClip.Clip4); + break; + case 5u: + xactor = new XActor(pos, xplayerDataClip.Clip5); + break; + case 6u: + xactor = new XActor(pos, xplayerDataClip.Clip6); + break; + case 7u: + xactor = new XActor(pos, xplayerDataClip.Clip7); + break; + default: + xactor = new XActor(pos, null); + break; + } + xactor.Initilize(0); + this._actors.Add(xactor); + this.Reflection(); + } + + private void AttachFx(XGameObject go, object o, int commandID) + { + XFxDataClip xfxDataClip = o as XFxDataClip; + XFx xfx = XSingleton.singleton.CreateFx(xfxDataClip.Fx, null, false); + xfx.DelayDestroy = xfxDataClip.Destroy_Delay; + Transform transform = (go != null) ? go.Find(xfxDataClip.Bone) : null; + bool flag = transform != null; + if (flag) + { + xfx.Play(transform, Vector3.zero, xfxDataClip.Scale * Vector3.one, 1f, xfxDataClip.Follow, false); + bool flag2 = this._common_actors.ContainsValue(this._actors[xfxDataClip.BindIdx]); + if (flag2) + { + this._common_fx.Add(xfx); + } + } + else + { + xfx.Play(new Vector3(xfxDataClip.AppearX, xfxDataClip.AppearY, xfxDataClip.AppearZ), XSingleton.singleton.FloatToQuaternion(xfxDataClip.Face), Vector3.one, 1f); + } + this._fx.Add(xfx); + } + + private void Fx(object o) + { + XFxDataClip xfxDataClip = o as XFxDataClip; + bool flag = xfxDataClip.BindIdx >= 0; + if (flag) + { + XGameObject engineObject = this._actors[xfxDataClip.BindIdx].EngineObject; + engineObject.CallCommand(this._findFxTransCb, o, -1, false); + } + else + { + this.AttachFx(null, o, -1); + } + } + + private void Audio(object o) + { + XAudioDataClip xaudioDataClip = o as XAudioDataClip; + bool flag = xaudioDataClip.BindIdx < 0; + if (flag) + { + XSingleton.singleton.PlayUISound(xaudioDataClip.Clip, true, xaudioDataClip.Channel); + } + else + { + bool flag2 = XSingleton.singleton.Player != null; + if (flag2) + { + XSingleton.singleton.PlaySound(this._actors[xaudioDataClip.BindIdx], xaudioDataClip.Channel, xaudioDataClip.Clip, false, new XAudioExParam("PlayerClass", XSingleton.singleton.Player.PlayerAttributes.BasicTypeID)); + } + else + { + XSingleton.singleton.PlaySound(this._actors[xaudioDataClip.BindIdx], xaudioDataClip.Channel, xaudioDataClip.Clip); + } + } + } + + private void SubTitle(object o) + { + XSubTitleDataClip xsubTitleDataClip = o as XSubTitleDataClip; + DlgBase.singleton.SetText(xsubTitleDataClip.Context); + XSingleton.singleton.KillTimer(this._token); + this._token = XSingleton.singleton.SetTimer(xsubTitleDataClip.Duration / 30f, this._endSubTitleCb, null); + } + + private void Slash(object o) + { + XSlashDataClip xslashDataClip = o as XSlashDataClip; + bool generalShow = this._cut_scene_data.GeneralShow; + if (generalShow) + { + string name = ""; + bool flag = this._target != null && (this._target.IsDummy || XEntity.ValideEntity(this._target)); + if (flag) + { + XEntityStatistics.RowData byID = XSingleton.singleton.EntityStatistics.GetByID(this._target.TypeID); + bool flag2 = byID != null; + if (flag2) + { + name = byID.Name; + } + } + DlgBase.singleton.SetIntroText(true, name, xslashDataClip.Discription, xslashDataClip.AnchorX, xslashDataClip.AnchorY); + } + else + { + DlgBase.singleton.SetIntroText(true, xslashDataClip.Name, xslashDataClip.Discription, xslashDataClip.AnchorX, xslashDataClip.AnchorY); + } + this.AddedTimerToken(XSingleton.singleton.SetTimer(xslashDataClip.Duration, new XTimerMgr.ElapsedEventHandler(this.EndSlash), null)); + } + + private void EndShow(object o) + { + bool bFadeAtEnd = this._bFadeAtEnd; + if (bFadeAtEnd) + { + XAutoFade.FadeOut2In(1f, 1f); + } + this.AddedTimerToken(XSingleton.singleton.SetTimer(0.984f, this._endCb, null)); + } + + private void EndSlash(object o) + { + DlgBase.singleton.SetIntroText(false, "", "", 0f, 0f); + } + + private void EndSubTitle(object o) + { + DlgBase.singleton.SetText(""); + } + + private void InnerEnd(object o) + { + bool overrideBGM = this._cut_scene_data.OverrideBGM; + if (overrideBGM) + { + XSingleton.singleton.ResumeBGM(); + } + XSingleton.singleton.KillTimer(this._token); + for (int i = 0; i < this._eventToken.Count; i++) + { + XSingleton.singleton.KillTimer(this._eventToken[i]); + } + this._eventToken.Clear(); + XBillBoardDocument.SetAllBillBoardState(BillBoardHideType.CutScene, true); + for (int j = 0; j < this._fx.Count; j++) + { + bool flag = !this._common_fx.Contains(this._fx[j]); + if (flag) + { + XSingleton.singleton.DestroyFx(this._fx[j], true); + } + } + this._fx.Clear(); + for (int k = 0; k < this._actors.Count; k++) + { + bool flag2 = !this._common_actors.ContainsValue(this._actors[k]); + if (flag2) + { + this._actors[k].Uninitilize(); + } + } + this._actors.Clear(); + this._actors = null; + XSingleton.singleton.GameCamera.FovBack(); + this._cut_scene = false; + this._name = null; + XSingleton.singleton.Dedummilize(); + this.Reflection(); + bool mourningborder = this._cut_scene_data.Mourningborder; + if (mourningborder) + { + this.EndSubTitle(null); + DlgBase.singleton.SetVisible(false, true); + XSingleton.singleton.MakeEffectEnable(XPostEffect.BlackWhite, XSingleton.singleton.Player.IsDead); + } + bool flag3 = !string.IsNullOrEmpty(this._cut_scene_data.CameraClip); + if (flag3) + { + XCameraMotionEndEventArgs @event = XEventPool.GetEvent(); + @event.Target = this._target; + @event.Firer = XSingleton.singleton.GameCamera; + @event.CutSceneEnd = true; + XSingleton.singleton.FireEvent(@event); + } + bool flag4 = this._target != null && this._target.IsDummy; + if (flag4) + { + XSingleton.singleton.DestroyImmediate(this._target); + } + this._target = null; + XSingleton.singleton.Freezed = false; + bool flag5 = XSingleton.singleton.CurrentStage is XConcreteStage; + if (flag5) + { + XSingleton.singleton.ShowBlock(false); + } + bool flag6 = XSingleton.singleton.Player != null && !XSingleton.singleton.IsCurrentLevelFinished; + if (flag6) + { + XSingleton.singleton.EnablePlayerAI(true); + List ally = XSingleton.singleton.GetAlly(XSingleton.singleton.Player); + for (int l = 0; l < ally.Count; l++) + { + bool flag7 = ally[l] != XSingleton.singleton.Player; + if (flag7) + { + XAIEnableAI event2 = XEventPool.GetEvent(); + event2.Firer = ally[l]; + event2.Enable = true; + XSingleton.singleton.FireEvent(event2); + } + } + } + XSingleton.singleton.GameCamera.TrySolo(); + this.EndWithPos = Vector3.zero; + this.GeneralMonsterID = 0u; + XSingleton.singleton.GameCamera.UnityCamera.farClipPlane = this.farClipPlaneBackUP; + bool flag8 = !XSingleton.singleton.SyncMode && !XOperationData.Is3DMode() && XEntity.ValideEntity(XSingleton.singleton.Player); + if (flag8) + { + XSingleton.singleton.GameCamera.Root_R_Y = XSingleton.singleton.AngleToFloat(XSingleton.singleton.Player.MoveObj.Forward); + } + bool flag9 = DlgBase.singleton.IsVisible(); + if (flag9) + { + DlgBase.singleton.RefreshWelcomeBackFlow(); + } + } + + private void CorrectToEndPos() + { + bool syncMode = XSingleton.singleton.SyncMode; + if (!syncMode) + { + List ally = XSingleton.singleton.GetAlly(XSingleton.singleton.Player); + for (int i = 0; i < ally.Count; i++) + { + bool flag = ally[i].IsRole || (ally[i].MobbedBy != null && ally[i].MobbedBy.IsRole && ally[i].Attributes != null && ally[i].Attributes.RunSpeed > 0f); + if (flag) + { + XOnEntityTransferEventArgs @event = XEventPool.GetEvent(); + @event.Firer = ally[i]; + XSingleton.singleton.FireEvent(@event); + ally[i].CorrectMe(this.EndWithPos, XSingleton.singleton.FloatToAngle(this.EndWithDir), false, false); + } + } + } + } + } +} -- cgit v1.1-26-g67d0