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); } } } }