From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/XFishingComponent.cs | 176 +++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XFishingComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XFishingComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XFishingComponent.cs b/Client/Assets/Scripts/XMainClient/XFishingComponent.cs new file mode 100644 index 00000000..27cf8dd9 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XFishingComponent.cs @@ -0,0 +1,176 @@ +using System; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XFishingComponent : XComponent + { + public override uint ID + { + get + { + return XFishingComponent.uuID; + } + } + + public new static readonly uint uuID = XSingleton.singleton.XHash("FishingComponent"); + + private static uint fishing_present_id = 50001u; + + private bool _haveFish; + + private HomeFishingState _currState; + + private uint _timerToken; + + private XEntityPresentation.RowData _fishingRodPresentation; + + public override void OnAttachToHost(XObject host) + { + base.OnAttachToHost(host); + this._fishingRodPresentation = XSingleton.singleton.EntityInfo.GetByPresentID(50001u); + } + + public override void Attached() + { + this._entity.Equipment.EquipFishing(true, XFishingComponent.fishing_present_id); + XSingleton.singleton.AddGreenLog("Equip FishingRod.", null, null, null, null, null); + bool isPlayer = this._entity.IsPlayer; + if (isPlayer) + { + XCameraActionEventArgs @event = XEventPool.GetEvent(); + @event.XRotate = XSingleton.singleton.GameCamera.Root_R_X_Default; + float angle = float.Parse(XSingleton.singleton.GetValue("FishingCameraDesdir")); + float degree = float.Parse(XSingleton.singleton.GetValue("FishingCameraDegree")); + @event.YRotate = XSingleton.singleton.AngleToFloat(XSingleton.singleton.HorizontalRotateVetor3(XSingleton.singleton.FloatToAngle(angle), degree, true)); + @event.Firer = XSingleton.singleton.GameCamera; + XSingleton.singleton.FireEvent(@event); + } + } + + public override void OnDetachFromHost() + { + this._entity.Equipment.EquipFishing(false, 0u); + XSingleton.singleton.AddGreenLog("delete FishingRod.", null, null, null, null, null); + bool isPlayer = this._entity.IsPlayer; + if (isPlayer) + { + bool flag = XSingleton.singleton.Player != null; + if (flag) + { + XSingleton.singleton.Player.PlayStateBack(); + XCameraMotionEndEventArgs @event = XEventPool.GetEvent(); + @event.Target = this._entity; + @event.Firer = XSingleton.singleton.GameCamera; + XSingleton.singleton.FireEvent(@event); + } + } + else + { + XSingleton.singleton.KillTimer(this._timerToken); + } + base.OnDetachFromHost(); + } + + public void PlayAnimationWithResult(bool haveFish) + { + this._haveFish = haveFish; + this._currState = HomeFishingState.WAITSERVER; + XRole xrole = this._entity as XRole; + xrole.PlaySpecifiedAnimation(this._entity.Present.PresentLib.FishingIdle); + this._entity.Equipment.PlayFishingRodAnimation(this._fishingRodPresentation.FishingIdle); + XSingleton.singleton.KillTimer(this._timerToken); + this._timerToken = XSingleton.singleton.SetTimer(0.5f, new XTimerMgr.ElapsedEventHandler(this.OnFishingStateChange), null); + } + + private void OnFishingStateChange(object o = null) + { + float num = 5f; + XRole xrole = this._entity as XRole; + switch (this._currState) + { + case HomeFishingState.CAST: + { + this._currState = HomeFishingState.WAIT; + num = xrole.PlaySpecifiedAnimationGetLength(this._entity.Present.PresentLib.FishingWait); + bool flag = num < 0f; + if (flag) + { + return; + } + this._entity.Equipment.PlayFishingRodAnimation(this._fishingRodPresentation.FishingWait); + num = 1f; + break; + } + case HomeFishingState.WAIT: + { + this._currState = HomeFishingState.PULL; + num = xrole.PlaySpecifiedAnimationGetLength(this._entity.Present.PresentLib.FishingPull); + bool flag2 = num < 0f; + if (flag2) + { + return; + } + this._entity.Equipment.PlayFishingRodAnimation(this._fishingRodPresentation.FishingPull); + break; + } + case HomeFishingState.WAITSERVER: + { + this._currState = HomeFishingState.CAST; + num = xrole.PlaySpecifiedAnimationGetLength(this._entity.Present.PresentLib.FishingCast); + bool flag3 = num < 0f; + if (flag3) + { + return; + } + this._entity.Equipment.PlayFishingRodAnimation(this._fishingRodPresentation.FishingCast); + break; + } + case HomeFishingState.PULL: + { + this._currState = HomeFishingState.GET; + bool haveFish = this._haveFish; + if (haveFish) + { + num = xrole.PlaySpecifiedAnimationGetLength(this._entity.Present.PresentLib.FishingWin); + bool flag4 = num < 0f; + if (flag4) + { + return; + } + this._entity.Equipment.PlayFishingRodAnimation(this._fishingRodPresentation.FishingWin); + } + else + { + num = xrole.PlaySpecifiedAnimationGetLength(this._entity.Present.PresentLib.FishingLose); + bool flag5 = num < 0f; + if (flag5) + { + return; + } + this._entity.Equipment.PlayFishingRodAnimation(this._fishingRodPresentation.FishingLose); + } + break; + } + case HomeFishingState.GET: + { + this._currState = HomeFishingState.WAITSERVER; + num = xrole.PlaySpecifiedAnimationGetLength(this._entity.Present.PresentLib.FishingIdle); + bool flag6 = num < 0f; + if (flag6) + { + return; + } + this._entity.Equipment.PlayFishingRodAnimation(this._fishingRodPresentation.FishingIdle); + num = -1f; + break; + } + } + bool flag7 = num > 0f; + if (flag7) + { + this._timerToken = XSingleton.singleton.SetTimer(num, new XTimerMgr.ElapsedEventHandler(this.OnFishingStateChange), null); + } + } + } +} -- cgit v1.1-26-g67d0