From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/AI/AIRuntimeSetDest.cs | 170 +++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/AI/AIRuntimeSetDest.cs (limited to 'Client/Assets/Scripts/XMainClient/AI/AIRuntimeSetDest.cs') diff --git a/Client/Assets/Scripts/XMainClient/AI/AIRuntimeSetDest.cs b/Client/Assets/Scripts/XMainClient/AI/AIRuntimeSetDest.cs new file mode 100644 index 00000000..dcb0fee0 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/AI/AIRuntimeSetDest.cs @@ -0,0 +1,170 @@ +using System; +using System.Xml; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class AIRuntimeSetDest : AIRunTimeNodeAction + { + private string _final_dest_name; + + private string _target_name; + + private string _nav_name; + + private string _born_pos_name; + + private Vector3 _born_pos; + + private string _tick_count_name; + + private float _random_max; + + private float _adjust_angle; + + private string _adjust_length_name; + + private float _adjust_value; + + private int _adjust_dir; + + private int _set_dest_type; + + public AIRuntimeSetDest(XmlElement node) : base(node) + { + this._final_dest_name = node.GetAttribute("Shared_FinalDestName"); + this._target_name = node.GetAttribute("Shared_TargetName"); + this._nav_name = node.GetAttribute("Shared_NavName"); + this._born_pos_name = node.GetAttribute("Shared_BornPosName"); + this._tick_count_name = node.GetAttribute("Shared_TickCountName"); + this._random_max = float.Parse(node.GetAttribute("RandomMax")); + this._adjust_angle = float.Parse(node.GetAttribute("AdjustAngle")); + this._adjust_length_name = node.GetAttribute("Shared_AdjustLengthName"); + this._adjust_value = float.Parse(node.GetAttribute("Shared_AdjustLengthmValue")); + this._adjust_dir = int.Parse(node.GetAttribute("AdjustDir")); + this._set_dest_type = int.Parse(node.GetAttribute("SetDestType")); + string attribute = node.GetAttribute("Shared_BornPosmValue"); + float num = float.Parse(attribute.Split(new char[] + { + ':' + })[0]); + float num2 = float.Parse(attribute.Split(new char[] + { + ':' + })[1]); + float num3 = float.Parse(attribute.Split(new char[] + { + ':' + })[2]); + this._born_pos = new Vector3(num, num2, num3); + } + + public override bool Update(XEntity entity) + { + Vector3 vector = entity.AI.AIData.GetVector3ByName(this._final_dest_name, Vector3.zero); + XGameObject xgameObjectByName = entity.AI.AIData.GetXGameObjectByName(this._target_name); + Transform transformByName = entity.AI.AIData.GetTransformByName(this._nav_name); + Vector3 vector2 = entity.AI.AIData.GetVector3ByName(this._born_pos_name, Vector3.zero); + int intByName = entity.AI.AIData.GetIntByName(this._tick_count_name, 0); + float floatByName = entity.AI.AIData.GetFloatByName(this._adjust_length_name, this._adjust_value); + bool flag = string.IsNullOrEmpty(this._born_pos_name); + if (flag) + { + vector2 = this._born_pos; + } + Vector3 vector3 = new Vector3(1f, 0f, 1f); + //vector3= new Vector3(1f, 0f, 1f); + int num = XFastEnumIntEqualityComparer.ToInt(SetDestWay.Target); + bool flag2 = this._set_dest_type == XFastEnumIntEqualityComparer.ToInt(SetDestWay.Target); + if (flag2) + { + bool flag3 = xgameObjectByName == null; + if (flag3) + { + return false; + } + vector = xgameObjectByName.Position; + } + else + { + bool flag4 = this._set_dest_type == XFastEnumIntEqualityComparer.ToInt(SetDestWay.BornPos); + if (flag4) + { + vector = vector2; + } + else + { + bool flag5 = this._set_dest_type == XFastEnumIntEqualityComparer.ToInt(SetDestWay.NavPos); + if (flag5) + { + bool flag6 = transformByName == null; + if (flag6) + { + return false; + } + vector = transformByName.position; + } + } + } + bool flag7 = floatByName != 0f; + if (flag7) + { + Vector3 vector4 = Vector3.zero; + bool flag8 = this._adjust_dir == XFastEnumIntEqualityComparer.ToInt(AdjustDirection.TargetDir); + if (flag8) + { + vector4 = entity.EngineObject.Position - vector; + } + else + { + bool flag9 = this._adjust_dir == XFastEnumIntEqualityComparer.ToInt(AdjustDirection.TargetFace) && xgameObjectByName != null; + if (flag9) + { + vector4 = xgameObjectByName.Forward.normalized; + } + else + { + bool flag10 = this._adjust_dir == XFastEnumIntEqualityComparer.ToInt(AdjustDirection.SelfFace); + if (flag10) + { + vector4 = entity.EngineObject.Forward.normalized; + } + } + } + Vector3 vector5 = vector + (Quaternion.Euler(new Vector3(0f, (float)(intByName % 2) * this._adjust_angle * 2f - this._adjust_angle, 0f)) * vector4).normalized * floatByName; + bool flag11 = !XSingleton.singleton.IsPointInMap(vector5); + if (flag11) + { + for (int i = 0; i < 18; i++) + { + float num2 = this._adjust_angle + (float)(i * 10); + vector5 = vector + (Quaternion.Euler(new Vector3(0f, (float)(intByName % 2) * num2 * 2f - num2, 0f)) * vector4).normalized * floatByName; + bool flag12 = XSingleton.singleton.IsPointInMap(vector5); + if (flag12) + { + break; + } + num2 = this._adjust_angle - (float)(i * 10); + vector5 = vector + (Quaternion.Euler(new Vector3(0f, (float)(intByName % 2) * num2 * 2f - num2, 0f)) * vector4).normalized * floatByName; + bool flag13 = XSingleton.singleton.IsPointInMap(vector5); + if (flag13) + { + break; + } + } + } + vector = vector5; + } + bool flag14 = this._random_max > 0f; + if (flag14) + { + vector3.x = XSingleton.singleton.RandomFloat(-0.5f, 0.5f); + vector3.z = XSingleton.singleton.RandomFloat(-0.5f, 0.5f); + vector += this._random_max * vector3.normalized; + } + entity.AI.AIData.SetVector3ByName(this._final_dest_name, vector); + return true; + } + } +} -- cgit v1.1-26-g67d0