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/XActionSender.cs | 174 +++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XActionSender.cs (limited to 'Client/Assets/Scripts/XMainClient/XActionSender.cs') diff --git a/Client/Assets/Scripts/XMainClient/XActionSender.cs b/Client/Assets/Scripts/XMainClient/XActionSender.cs new file mode 100644 index 00000000..a49ac763 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XActionSender.cs @@ -0,0 +1,174 @@ +using System; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XActionSender : XSingleton + { + private PtcC2G_MoveOperationReq _dir_movePtc = new PtcC2G_MoveOperationReq(); + + private PtcC2G_MoveOperationReq _des_movePtc = new PtcC2G_MoveOperationReq(); + + private PtcC2G_CastSkill skillPtc = new PtcC2G_CastSkill(); + + private long _dir_tick = 0L; + + private long _des_tick = 0L; + + private long _stub = 0L; + + public void SendMoveAction(XEntity entity, float face, float speed, bool inertia) + { + bool flag = !entity.IsPlayer || XSingleton.singleton.Freezed; + if (!flag) + { + bool flag2 = face < 0f; + if (flag2) + { + face += 360f; + } + uint num = (uint)Mathf.Floor(face + 0.5f); + uint num2 = (uint)Mathf.Floor(speed * 10f + 0.5f); + num |= num2 << 16; + if (inertia) + { + num |= 2147483648u; + } + this._dir_movePtc.Data.PosXZ = (int)Mathf.Floor(entity.MoveObj.Position.z * 100f + 0.5f); + this._dir_movePtc.Data.PosXZ |= (int)Mathf.Floor(entity.MoveObj.Position.x * 100f + 0.5f) << 16; + this._dir_movePtc.Data.Common = (int)num; + long num3 = this._stub + 1L; + this._stub = num3; + this._dir_tick = num3; + } + } + + public void SendMoveAction(XEntity entity, Vector3 des, float speed, bool inertia, bool force2server = false) + { + bool flag = !entity.IsPlayer || (!force2server && XSingleton.singleton.Freezed); + if (!flag) + { + Vector3 dir = XSingleton.singleton.Horizontal(des - entity.MoveObj.Position); + dir.y = 0f; + float num = (dir.sqrMagnitude > 0f) ? XSingleton.singleton.AngleToFloat(dir) : XSingleton.singleton.AngleToFloat(entity.MoveObj.Forward); + bool flag2 = num < 0f; + if (flag2) + { + num += 360f; + } + uint num2 = (uint)Mathf.Floor(num + 0.5f); + uint num3 = (uint)Mathf.Floor(speed * 10f + 0.5f); + num2 |= num3 << 16; + if (inertia) + { + num2 |= 2147483648u; + } + this._des_movePtc.Data.PosXZ = (int)Mathf.Floor(entity.MoveObj.Position.z * 100f + 0.5f); + this._des_movePtc.Data.PosXZ |= (int)Mathf.Floor(entity.MoveObj.Position.x * 100f + 0.5f) << 16; + this._des_movePtc.Data.DesXZ = (int)Mathf.Floor(des.z * 100f + 0.5f); + this._des_movePtc.Data.DesXZ |= (int)Mathf.Floor(des.x * 100f + 0.5f) << 16; + this._des_movePtc.Data.Common = (int)num2; + long num4 = this._stub + 1L; + this._stub = num4; + this._des_tick = num4; + } + } + + public void Empty() + { + this._des_tick = 0L; + this._dir_tick = 0L; + } + + public void Flush(bool immediately = false) + { + bool flag = immediately || this.SyncPass(); + if (flag) + { + bool flag2 = this._des_tick != 0L && this._dir_tick != 0L; + if (flag2) + { + bool flag3 = this._des_tick < this._dir_tick; + if (flag3) + { + XSingleton.singleton.Send(this._des_movePtc); + XSingleton.singleton.Send(this._dir_movePtc); + } + else + { + XSingleton.singleton.Send(this._dir_movePtc); + XSingleton.singleton.Send(this._des_movePtc); + } + } + else + { + bool flag4 = this._des_tick != 0L; + if (flag4) + { + XSingleton.singleton.Send(this._des_movePtc); + } + bool flag5 = this._dir_tick != 0L; + if (flag5) + { + XSingleton.singleton.Send(this._dir_movePtc); + } + } + this.Empty(); + } + } + + public void SendSkillAction(XEntity entity, XEntity target, uint id, int slot) + { + bool flag = !entity.IsPlayer; + if (!flag) + { + XSkillCore skill = entity.SkillMgr.GetSkill(id); + this.ResetSkillPtc(); + this.skillPtc.Data.SkillID = id; + this.skillPtc.Data.Target = (XEntity.ValideEntity(target) ? target.ID : 0UL); + bool flag2 = slot != -1; + if (flag2) + { + this.skillPtc.Data.Slot = slot; + } + bool feeding = XSingleton.singleton.Feeding; + if (feeding) + { + this.skillPtc.Data.ManualFace = (int)(XSingleton.singleton.AngleToFloat(XSingleton.singleton.Direction) * 10f); + } + XSingleton.singleton.Send(this.skillPtc); + } + } + + public void SendSkillAction(XEntity entity, XEntity target, int slot) + { + bool flag = !entity.IsPlayer; + if (!flag) + { + this.ResetSkillPtc(); + this.skillPtc.Data.Target = (XEntity.ValideEntity(target) ? target.ID : 0UL); + this.skillPtc.Data.Slot = slot; + bool feeding = XSingleton.singleton.Feeding; + if (feeding) + { + this.skillPtc.Data.ManualFace = (int)(XSingleton.singleton.AngleToFloat(XSingleton.singleton.Direction) * 10f); + } + XSingleton.singleton.Send(this.skillPtc); + } + } + + private bool SyncPass() + { + return XSingleton.singleton.IsViewGridScene ? (Time.frameCount % (Application.targetFrameRate / 10) == 0) : ((Time.frameCount & 1) == 0); + } + + private void ResetSkillPtc() + { + this.skillPtc.Data.SkillIDSpecified = false; + this.skillPtc.Data.SlotSpecified = false; + this.skillPtc.Data.TargetSpecified = false; + this.skillPtc.Data.ManualFaceSpecified = false; + } + } +} -- cgit v1.1-26-g67d0