Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Decompiled with JetBrains decompiler
- // Type: PatrolHelicopterAI
- // Assembly: Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
- // MVID: BE7294DA-F897-4599-AE8B-7F016E2E3E06
- // Assembly location: C:\Users\rust\Desktop\SteamCMD\steamapps\common\rust_dedicated\RustDedicated_Data\Managed\Assembly-CSharp.dll
- using Rust;
- using System.Collections.Generic;
- using UnityEngine;
- public class PatrolHelicopterAI : MonoBehaviour
- {
- private float destination_min_dist = 2f;
- public Vector3 currentOrbitTarget = Vector3.zero;
- private float maxOrbitDuration = 30f;
- private float timeBetweenRockets = 0.2f;
- private int numRocketsLeft = 12;
- private int maxRockets = 12;
- private float strafe_approach_range = 175f;
- private float strafe_firing_range = 150f;
- public float waitAtPoint = 10f;
- public float maxSpeed = 25f;
- public float windForce = 5f;
- public float windFrequency = 1f;
- public float maxRotationSpeed = 90f;
- public float terrainPushForce = 100f;
- public float obstaclePushForce = 100f;
- public float courseAdjustLerpTime = 2f;
- private Vector3 pushVec = Vector3.zero;
- public List<PatrolHelicopterAI.targetinfo> _targetList = new List<PatrolHelicopterAI.targetinfo>();
- public static PatrolHelicopterAI heliInstance;
- public BaseHelicopter helicopterBase;
- public Vector3 interestZoneOrigin;
- public bool hasInterestZone;
- public Vector3 destination;
- public Quaternion targetRotation;
- public int waypointIndex;
- public Transform[] waypoints;
- public float moveSpeed;
- public Vector3 windVec;
- public Vector3 targetWindVec;
- public float targetThrottleSpeed;
- public float throttleSpeed;
- public float rotationSpeed;
- private Vector3 _lastPos;
- private Vector3 _lastMoveDir;
- private bool movementLockingAiming;
- private bool hasAimTarget;
- private Vector3 _aimTarget;
- private bool aimDoorSide;
- public PatrolHelicopterAI.aiState _currentState;
- public HelicopterTurret leftGun;
- public HelicopterTurret rightGun;
- private bool isDead;
- private float spawnTime;
- private float lastDamageTime;
- private bool isRetiring;
- private float deathTimeout;
- private float currentOrbitDistance;
- private float currentOrbitTime;
- private bool hasEnteredOrbit;
- private float orbitStartTime;
- private bool breakingOrbit;
- public List<MonumentInfo> _visitedMonuments;
- public float arrivalTime;
- private bool leftTubeFiredLast;
- private float lastRocketTime;
- private Vector3 strafe_target_position;
- private bool puttingDistance;
- public GameObjectRef rocketProjectile;
- private float _lastThinkTime;
- public bool IsAlive()
- {
- return !this.isDead;
- }
- public void SetAimTarget(Vector3 aimTarg, bool isDoorSide)
- {
- if (this.movementLockingAiming)
- return;
- this.hasAimTarget = true;
- this._aimTarget = aimTarg;
- this.aimDoorSide = isDoorSide;
- }
- public void ClearAimTarget()
- {
- this.hasAimTarget = false;
- this._aimTarget = Vector3.zero;
- }
- public void SetInitialDestination(Vector3 dest, float mapScaleDistance = 0.25f)
- {
- this.hasInterestZone = true;
- this.interestZoneOrigin = dest;
- float num1 = TerrainMeta.Size.x;
- float num2 = dest.y + 25f;
- Vector3 vector3_1 = Vector3Ex.Range(-1f, 1f);
- vector3_1.y = 0.0f;
- vector3_1.Normalize();
- Vector3 vector3_2 = vector3_1 * (num1 * mapScaleDistance);
- vector3_2.y = num2;
- if ((double) mapScaleDistance == 0.0)
- vector3_2 = this.interestZoneOrigin + new Vector3(0.0f, 10f, 0.0f);
- this.transform.position = vector3_2;
- this.ExitCurrentState();
- this.State_Move_Enter(dest);
- }
- public List<BaseCombatEntity> EntitiesInRadius(Vector3 pos, float radius)
- {
- List<BaseCombatEntity> list = new List<BaseCombatEntity>();
- foreach (Component component in Physics.OverlapSphere(pos, radius))
- {
- BaseCombatEntity baseCombatEntity = UnityEngine.BaseEntityEx.ToBaseEntity(component.gameObject) as BaseCombatEntity;
- if ((Object) baseCombatEntity != (Object) null && !list.Contains(baseCombatEntity))
- list.Add(baseCombatEntity);
- }
- return list;
- }
- public List<BasePlayer> PlayersInRadius(Vector3 pos, float radius)
- {
- List<BasePlayer> list = new List<BasePlayer>();
- using (List<BasePlayer>.Enumerator enumerator = BasePlayer.activePlayerList.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- BasePlayer current = enumerator.Current;
- if ((double) Vector3Ex.Distance2D(pos, current.transform.position) <= (double) radius)
- list.Add(current);
- }
- }
- return list;
- }
- public void Awake()
- {
- this.InvokeRepeating("UpdateWind", 0.0f, 1f / this.windFrequency);
- this._lastPos = this.transform.position;
- this.InitializeAI();
- this.spawnTime = Time.realtimeSinceStartup;
- if ((double) heli.lifetimeMinutes != 0.0)
- return;
- this.Invoke("DestroyMe", 1f);
- }
- public void Retire()
- {
- if (this.isRetiring)
- return;
- this.isRetiring = true;
- this.Invoke("DestroyMe", 240f);
- float num1 = TerrainMeta.Size.x;
- float num2 = 200f;
- Vector3 newPos = Vector3Ex.Range(-1f, 1f);
- newPos.y = 0.0f;
- newPos.Normalize();
- newPos *= num1 * 20f;
- newPos.y = num2;
- this.ExitCurrentState();
- this.State_Move_Enter(newPos);
- }
- public void DestroyMe()
- {
- this.helicopterBase.Kill(BaseNetworkable.DestroyMode.None);
- }
- public Vector3 GetLastMoveDir()
- {
- return this._lastMoveDir;
- }
- public Vector3 GetMoveDirection()
- {
- return (this.destination - this.transform.position).normalized;
- }
- public float GetMoveSpeed()
- {
- return this.moveSpeed;
- }
- public void UpdateWind()
- {
- this.targetWindVec = Random.onUnitSphere;
- }
- public void MoveToDestination()
- {
- Vector3 vector3 = Vector3.Lerp(this._lastMoveDir, (this.destination - this.transform.position).normalized, Time.deltaTime / this.courseAdjustLerpTime);
- this._lastMoveDir = vector3;
- this.throttleSpeed = Mathf.Lerp(this.throttleSpeed, this.targetThrottleSpeed, Time.deltaTime / 3f);
- float num = this.throttleSpeed * this.maxSpeed;
- this.TerrainPushback();
- this.transform.position += vector3 * num * Time.deltaTime;
- this.windVec = Vector3.Lerp(this.windVec, this.targetWindVec, Time.deltaTime);
- this.transform.position += this.windVec * this.windForce * Time.deltaTime;
- this.moveSpeed = Mathf.Lerp(this.moveSpeed, Vector3.Distance(this._lastPos, this.transform.position) / Time.deltaTime, Time.deltaTime * 2f);
- this._lastPos = this.transform.position;
- }
- public void DoPushback()
- {
- if (this._currentState == PatrolHelicopterAI.aiState.DEATH)
- return;
- Vector3 zero = Vector3.zero;
- Vector3 rayOrigin = this.transform.position + new Vector3(0.0f, 2f, 0.0f);
- int mask = LayerMask.GetMask("Terrain", "World", "Construction");
- Vector3 normalized = (this.destination - rayOrigin).normalized;
- float b = Vector3.Distance(this.destination, this.transform.position);
- this.pushVec = Vector3.Lerp(this.pushVec, zero + this.DoPushBackDirection(rayOrigin, normalized, Mathf.Min(30f, b), 5f, mask, 1f, 0.0f), Time.deltaTime);
- this.transform.position += this.pushVec * Time.deltaTime;
- }
- public Vector3 DoPushBackDirection(Vector3 rayOrigin, Vector3 dir, float dist, float radius, int mask, float upScale = 1f, float reverseScale = 0.0f)
- {
- Ray ray = new Ray(rayOrigin, dir);
- float radius1 = 5f;
- Vector3 vector3 = Vector3.zero;
- RaycastHit hitInfo;
- if (Physics.SphereCast(ray, radius1, out hitInfo, dist - radius1 * 0.5f, mask))
- {
- float num = this.terrainPushForce * (float) (1.0 - (double) hitInfo.distance / (double) dist);
- vector3 = vector3 + this._lastMoveDir * num * -1f * reverseScale + Vector3.up * num * upScale;
- }
- return vector3;
- }
- public void TerrainPushback()
- {
- if (this._currentState == PatrolHelicopterAI.aiState.DEATH)
- return;
- Vector3 origin = this.transform.position + new Vector3(0.0f, 2f, 0.0f);
- Vector3 normalized = (this.destination - origin).normalized;
- float b1 = Vector3.Distance(this.destination, this.transform.position);
- Ray ray1 = new Ray(origin, normalized);
- float radius = 5f;
- float num1 = Mathf.Min(100f, b1);
- int mask = LayerMask.GetMask("Terrain", "World", "Construction");
- Vector3 b2 = Vector3.zero;
- RaycastHit hitInfo1;
- if (Physics.SphereCast(ray1, radius, out hitInfo1, num1 - radius * 0.5f, mask))
- b2 = Vector3.up * (this.terrainPushForce * (float) (1.0 - (double) hitInfo1.distance / (double) num1));
- Ray ray2 = new Ray(origin, this._lastMoveDir);
- float num2 = Mathf.Min(10f, b1);
- RaycastHit hitInfo2;
- if (Physics.SphereCast(ray2, radius, out hitInfo2, num2 - radius * 0.5f, mask))
- {
- float num3 = this.obstaclePushForce * (float) (1.0 - (double) hitInfo2.distance / (double) num2);
- b2 = b2 + this._lastMoveDir * num3 * -1f + Vector3.up * num3;
- }
- this.pushVec = Vector3.Lerp(this.pushVec, b2, Time.deltaTime);
- this.transform.position += this.pushVec * Time.deltaTime;
- }
- public void ObjectPushback()
- {
- Ray ray = new Ray(this.transform.position, this._lastMoveDir);
- float maxDistance = 5f;
- int layerMask = 1;
- RaycastHit hitInfo;
- if (!Physics.SphereCast(ray, 4f, out hitInfo, maxDistance, layerMask))
- ;
- if (Physics.SphereCast(ray, 4f, out hitInfo, maxDistance, layerMask))
- ;
- }
- public void UpdateRotation()
- {
- if (this.hasAimTarget)
- {
- Vector3 position = this.transform.position;
- position.y = 0.0f;
- Vector3 vector3 = this._aimTarget;
- vector3.y = 0.0f;
- Vector3 normalized = (vector3 - position).normalized;
- Vector3 forward = Vector3.Cross(normalized, Vector3.up);
- float num1 = Vector3.Angle(normalized, this.transform.right);
- float num2 = Vector3.Angle(normalized, -this.transform.right);
- this.targetRotation = !this.aimDoorSide ? Quaternion.LookRotation(normalized) : ((double) num1 >= (double) num2 ? Quaternion.LookRotation(-forward) : Quaternion.LookRotation(forward));
- }
- this.rotationSpeed = Mathf.Lerp(this.rotationSpeed, this.maxRotationSpeed, Time.deltaTime / 2f);
- this.transform.rotation = Quaternion.Lerp(this.transform.rotation, this.targetRotation, this.rotationSpeed * Time.deltaTime);
- }
- public void Update()
- {
- if (this.helicopterBase.isClient)
- return;
- PatrolHelicopterAI.heliInstance = this;
- this.UpdateTargetList();
- this.MoveToDestination();
- this.UpdateRotation();
- this.UpdateSpotlight();
- this.AIThink();
- this.DoMachineGuns();
- if (this.isRetiring || (double) Time.realtimeSinceStartup <= (double) Mathf.Max(this.spawnTime + heli.lifetimeMinutes * 60f, this.lastDamageTime + 120f))
- return;
- this.Retire();
- }
- public void WeakspotDamaged()
- {
- this.lastDamageTime = Time.realtimeSinceStartup;
- }
- public void UpdateSpotlight()
- {
- if (this.hasInterestZone)
- this.helicopterBase.spotlightTarget = this.interestZoneOrigin;
- else
- this.helicopterBase.spotlightTarget = Vector3.zero;
- }
- public bool PlayerVisible(BasePlayer ply)
- {
- Vector3 a = ply.eyes.position;
- if (TOD_Sky.Instance.IsNight && (double) Vector3.Distance(a, this.interestZoneOrigin) > 50.0)
- return false;
- Vector3 b = this.transform.position - Vector3.up * 6f;
- float num = Vector3.Distance(a, b);
- Vector3 normalized = (a - b).normalized;
- RaycastHit hitInfo;
- return Physics.Raycast(b + normalized * 5f, normalized, out hitInfo, num * 1.1f, -1063040255) && (Object) UnityEngine.BaseEntityEx.ToBaseEntity(hitInfo.collider.gameObject) == (Object) ply;
- }
- public void WasAttacked(HitInfo info)
- {
- BasePlayer initPly = info.Initiator as BasePlayer;
- if (!((Object) initPly != (Object) null))
- return;
- this._targetList.Add(new PatrolHelicopterAI.targetinfo((BaseEntity) initPly, initPly));
- }
- public void UpdateTargetList()
- {
- Vector3 strafePos = Vector3.zero;
- bool flag1 = false;
- for (int index = this._targetList.Count - 1; index >= 0; --index)
- {
- PatrolHelicopterAI.targetinfo targetinfo = this._targetList[index];
- if (targetinfo == null)
- {
- this._targetList.Remove(targetinfo);
- }
- else
- {
- if ((double) Time.realtimeSinceStartup > (double) targetinfo.nextLOSCheck)
- {
- targetinfo.nextLOSCheck = Time.realtimeSinceStartup + 1f;
- if (this.PlayerVisible(targetinfo.ply))
- {
- targetinfo.lastSeenTime = Time.realtimeSinceStartup;
- ++targetinfo.visibleFor;
- }
- else
- targetinfo.visibleFor = 0.0f;
- }
- bool flag2 = !(bool) ((Object) targetinfo.ply) ? (double) targetinfo.ent.Health() <= 0.0 : targetinfo.ply.IsDead();
- if ((double) targetinfo.TimeSinceSeen() >= 6.0 || flag2)
- {
- bool flag3 = (double) Random.Range(0.0f, 1f) >= 0.5;
- if (this.IsAlive() && !flag1 && !flag2 && (((Object) targetinfo.ply == (Object) this.leftGun._target || (Object) targetinfo.ply == (Object) this.rightGun._target) && (flag3 && targetinfo.ply.CanBuild())))
- {
- flag1 = true;
- strafePos = targetinfo.ply.transform.position;
- }
- this._targetList.Remove(targetinfo);
- }
- }
- }
- using (List<BasePlayer>.Enumerator enumerator1 = this.PlayersInRadius(this.transform.position, 150f).GetEnumerator())
- {
- while (enumerator1.MoveNext())
- {
- BasePlayer current = enumerator1.Current;
- bool flag2 = false;
- using (List<PatrolHelicopterAI.targetinfo>.Enumerator enumerator2 = this._targetList.GetEnumerator())
- {
- while (enumerator2.MoveNext())
- {
- if ((Object) enumerator2.Current.ply == (Object) current)
- {
- flag2 = true;
- break;
- }
- }
- }
- if (!flag2 && (double) current.GetThreatLevel() > 0.5 && this.PlayerVisible(current))
- this._targetList.Add(new PatrolHelicopterAI.targetinfo((BaseEntity) current, current));
- }
- }
- if (!flag1)
- return;
- this.ExitCurrentState();
- this.State_Strafe_Enter(strafePos);
- }
- public void UpdateInterestZone()
- {
- }
- public void FireGun(Vector3 targetPos, float aimCone, bool left)
- {
- if (heli.guns == 0)
- return;
- Vector3 position = (!left ? this.helicopterBase.right_gun_muzzle.transform : this.helicopterBase.left_gun_muzzle.transform).position;
- Vector3 normalized = (targetPos - position).normalized;
- Vector3 origin = position + normalized * 2f;
- float num = aimCone;
- Vector3 direction = Quaternion.Euler(Random.Range((float) (-(double) num * 0.5), num * 0.5f), Random.Range((float) (-(double) num * 0.5), num * 0.5f), Random.Range((float) (-(double) num * 0.5), num * 0.5f)) * normalized;
- RaycastHit hitInfo;
- if (Physics.Raycast(origin, direction, out hitInfo, 300f, -1063040255))
- {
- targetPos = hitInfo.point;
- if ((bool) ((Object) hitInfo.collider))
- {
- BaseEntity baseEntity = UnityEngine.BaseEntityEx.ToBaseEntity(hitInfo.collider.gameObject);
- if ((bool) ((Object) baseEntity) && (Object) baseEntity != (Object) this.helicopterBase)
- {
- BaseCombatEntity baseCombatEntity = baseEntity as BaseCombatEntity;
- HitInfo info = new HitInfo((BaseEntity) this.helicopterBase, DamageType.Bullet, this.helicopterBase.bulletDamage * heli.bulletDamageScale, hitInfo.point);
- if ((bool) ((Object) baseCombatEntity))
- {
- baseCombatEntity.OnAttacked(info);
- if (baseCombatEntity is BasePlayer)
- Effect.server.ImpactEffect(new HitInfo()
- {
- HitPositionWorld = hitInfo.point - direction * 0.25f,
- HitNormalWorld = -direction,
- HitMaterial = StringPool.Get("Flesh")
- });
- }
- else
- baseEntity.SendMessage("OnAttacked", (object) info, SendMessageOptions.DontRequireReceiver);
- }
- }
- }
- else
- targetPos = origin + direction * 300f;
- this.helicopterBase.ClientRPC((Network.Connection) null, "FireGun", (object) (bool) (left ? 1 : 0), (object) targetPos);
- }
- public void DoMachineGuns()
- {
- if (this._targetList.Count > 0)
- {
- if (this.leftGun.NeedsNewTarget())
- this.leftGun.UpdateTargetFromList(this._targetList);
- if (this.rightGun.NeedsNewTarget())
- this.rightGun.UpdateTargetFromList(this._targetList);
- }
- this.leftGun.TurretThink();
- this.rightGun.TurretThink();
- }
- public float GetMaxRotationSpeed()
- {
- return this.maxRotationSpeed;
- }
- public void SetIdealRotation(Quaternion newTargetRot, float rotationSpeedOverride = -1)
- {
- this.rotationSpeed = ((double) rotationSpeedOverride != -1.0 ? rotationSpeedOverride : Mathf.Clamp01(this.moveSpeed / (this.maxSpeed * 0.5f))) * this.maxRotationSpeed;
- this.targetRotation = newTargetRot;
- }
- public void CriticalDamage()
- {
- this.isDead = true;
- this.ExitCurrentState();
- this.State_Death_Enter();
- }
- public bool IsTargeting()
- {
- return this.hasAimTarget;
- }
- public Quaternion GetYawRotationTo(Vector3 targetDest)
- {
- Vector3 vector3 = targetDest;
- vector3.y = 0.0f;
- Vector3 position = this.transform.position;
- position.y = 0.0f;
- return Quaternion.LookRotation((vector3 - position).normalized);
- }
- public void SetTargetDestination(Vector3 targetDest, float minDist = 5f, float minDistForFacingRotation = 30f)
- {
- this.destination = targetDest;
- this.destination_min_dist = minDist;
- float distToTarget = Vector3.Distance(targetDest, this.transform.position);
- if ((double) distToTarget > (double) minDistForFacingRotation && !this.IsTargeting())
- this.SetIdealRotation(this.GetYawRotationTo(this.destination), -1f);
- this.targetThrottleSpeed = this.GetThrottleForDistance(distToTarget);
- }
- public bool AtDestination()
- {
- return (double) Vector3.Distance(this.transform.position, this.destination) < (double) this.destination_min_dist;
- }
- public void State_Death_Think(float timePassed)
- {
- float num = Time.realtimeSinceStartup * 0.25f;
- this.SetAimTarget(this.transform.position + new Vector3(Mathf.Sin(6.283185f * num) * 10f, 0.0f, Mathf.Cos(6.283185f * num) * 10f), true);
- Ray ray = new Ray(this.transform.position, this.GetLastMoveDir());
- int mask = LayerMask.GetMask("Terrain", "World", "Construction", "Water");
- RaycastHit hitInfo;
- if (!Physics.SphereCast(ray, 3f, out hitInfo, 5f, mask) && (double) Time.realtimeSinceStartup <= (double) this.deathTimeout)
- return;
- this.helicopterBase.Hurt(this.helicopterBase.health * 2f, DamageType.Generic, (BaseEntity) null, false);
- }
- public void State_Death_Enter()
- {
- this.maxRotationSpeed *= 8f;
- this._currentState = PatrolHelicopterAI.aiState.DEATH;
- Vector3 randomOffset = this.GetRandomOffset(this.transform.position, 20f, 60f, 20f, 30f);
- int num = -1063040255;
- Vector3 pos;
- Vector3 normal;
- TransformUtil.GetGroundInfo(randomOffset - Vector3.up * 2f, out pos, out normal, 500f, (LayerMask) num, (Transform) null);
- this.SetTargetDestination(pos, 5f, 30f);
- this.targetThrottleSpeed = 0.5f;
- this.deathTimeout = Time.realtimeSinceStartup + 10f;
- }
- public void State_Death_Leave()
- {
- }
- public void State_Idle_Think(float timePassed)
- {
- this.ExitCurrentState();
- this.State_Patrol_Enter();
- }
- public void State_Idle_Enter()
- {
- this._currentState = PatrolHelicopterAI.aiState.IDLE;
- }
- public void State_Idle_Leave()
- {
- }
- public void State_Move_Think(float timePassed)
- {
- this.targetThrottleSpeed = this.GetThrottleForDistance(Vector3.Distance(this.transform.position, this.destination));
- if (!this.AtDestination())
- return;
- this.ExitCurrentState();
- this.State_Idle_Enter();
- }
- public void State_Move_Enter(Vector3 newPos)
- {
- this._currentState = PatrolHelicopterAI.aiState.MOVE;
- this.destination_min_dist = 5f;
- this.SetTargetDestination(newPos, 5f, 30f);
- this.targetThrottleSpeed = this.GetThrottleForDistance(Vector3.Distance(this.transform.position, this.destination));
- }
- public void State_Move_Leave()
- {
- }
- public void State_Orbit_Think(float timePassed)
- {
- if (!this.breakingOrbit)
- {
- if ((double) Vector3Ex.Distance2D(this.transform.position, this.destination) > 15.0)
- return;
- if (!this.hasEnteredOrbit)
- {
- this.hasEnteredOrbit = true;
- this.orbitStartTime = Time.realtimeSinceStartup;
- }
- float num = 6.283185f * this.currentOrbitDistance / (0.5f * this.maxSpeed);
- this.currentOrbitTime += timePassed / (num * 1.01f);
- Vector3 orbitPosition = this.GetOrbitPosition(this.currentOrbitTime);
- this.ClearAimTarget();
- this.SetTargetDestination(orbitPosition, 0.0f, 1f);
- this.targetThrottleSpeed = 0.5f;
- }
- else if (this.AtDestination())
- {
- this.ExitCurrentState();
- this.State_Idle_Enter();
- }
- if ((double) Time.realtimeSinceStartup - (double) this.orbitStartTime <= (double) this.maxOrbitDuration || this.breakingOrbit)
- return;
- this.breakingOrbit = true;
- this.SetTargetDestination(this.GetAppropriatePosition(this.transform.position + this.transform.forward * 75f, 40f, 50f), 10f, 0.0f);
- }
- public Vector3 GetOrbitPosition(float rate)
- {
- return this.interestZoneOrigin + new Vector3(Mathf.Sin(6.283185f * rate) * this.currentOrbitDistance, 20f, Mathf.Cos(6.283185f * rate) * this.currentOrbitDistance);
- }
- public void State_Orbit_Enter(float orbitDistance)
- {
- this.breakingOrbit = false;
- this.hasEnteredOrbit = false;
- this.orbitStartTime = Time.realtimeSinceStartup;
- Vector3 vector3 = this.transform.position - this.interestZoneOrigin;
- this.currentOrbitTime = Mathf.Atan2(vector3.x, vector3.z);
- this.currentOrbitDistance = orbitDistance;
- this._currentState = PatrolHelicopterAI.aiState.ORBIT;
- this.ClearAimTarget();
- this.SetTargetDestination(this.GetOrbitPosition(this.currentOrbitTime), 20f, 0.0f);
- }
- public void State_Orbit_Leave()
- {
- this.breakingOrbit = false;
- this.hasEnteredOrbit = false;
- this.currentOrbitTime = 0.0f;
- this.ClearAimTarget();
- }
- public Vector3 GetRandomPatrolDestination()
- {
- Vector3 vector3_1 = Vector3.zero;
- if (TerrainMeta.Path.Monuments.Count > 0)
- {
- MonumentInfo monumentInfo = (MonumentInfo) null;
- if (this._visitedMonuments.Count > 0)
- {
- using (List<MonumentInfo>.Enumerator enumerator1 = TerrainMeta.Path.Monuments.GetEnumerator())
- {
- while (enumerator1.MoveNext())
- {
- MonumentInfo current1 = enumerator1.Current;
- bool flag = false;
- using (List<MonumentInfo>.Enumerator enumerator2 = this._visitedMonuments.GetEnumerator())
- {
- while (enumerator2.MoveNext())
- {
- MonumentInfo current2 = enumerator2.Current;
- if ((Object) current1 == (Object) current2)
- flag = true;
- }
- }
- if (!flag)
- {
- monumentInfo = current1;
- break;
- }
- }
- }
- }
- if ((Object) monumentInfo == (Object) null)
- {
- this._visitedMonuments.Clear();
- monumentInfo = TerrainMeta.Path.Monuments[Random.Range(0, TerrainMeta.Path.Monuments.Count)];
- }
- if ((bool) ((Object) monumentInfo))
- {
- vector3_1 = monumentInfo.transform.position;
- this._visitedMonuments.Add(monumentInfo);
- vector3_1.y = TerrainMeta.HeightMap.GetHeight(vector3_1) + 200f;
- RaycastHit hitOut;
- if (TransformUtil.GetGroundInfo(vector3_1, out hitOut, 300f, (LayerMask) -1063190527, (Transform) null))
- vector3_1.y = hitOut.point.y;
- vector3_1.y += 30f;
- }
- }
- else
- {
- float num1 = TerrainMeta.Size.x;
- float num2 = 30f;
- Vector3 vector3_2 = Vector3Ex.Range(-1f, 1f);
- vector3_2.y = 0.0f;
- vector3_2.Normalize();
- vector3_1 = vector3_2 * (num1 * Random.Range(0.0f, 0.75f));
- vector3_1.y = num2;
- }
- return vector3_1;
- }
- public void State_Patrol_Think(float timePassed)
- {
- float distToTarget = Vector3.Distance(this.transform.position, this.destination);
- this.targetThrottleSpeed = (double) distToTarget > 25.0 ? 0.5f : this.GetThrottleForDistance(distToTarget);
- if (this.AtDestination() && (double) this.arrivalTime == 0.0)
- {
- this.arrivalTime = Time.realtimeSinceStartup;
- this.ExitCurrentState();
- this.maxOrbitDuration = 20f;
- this.State_Orbit_Enter(75f);
- }
- if (this._targetList.Count <= 0)
- return;
- this.interestZoneOrigin = this._targetList[0].ply.transform.position + new Vector3(0.0f, 20f, 0.0f);
- this.ExitCurrentState();
- this.maxOrbitDuration = 10f;
- this.State_Orbit_Enter(75f);
- }
- public void State_Patrol_Enter()
- {
- this._currentState = PatrolHelicopterAI.aiState.PATROL;
- Vector3 patrolDestination = this.GetRandomPatrolDestination();
- this.SetTargetDestination(patrolDestination, 10f, 30f);
- this.interestZoneOrigin = patrolDestination;
- this.arrivalTime = 0.0f;
- }
- public void State_Patrol_Leave()
- {
- }
- public int ClipRocketsLeft()
- {
- return this.numRocketsLeft;
- }
- public void State_Strafe_Enter(Vector3 strafePos)
- {
- this._currentState = PatrolHelicopterAI.aiState.STRAFE;
- int mask = LayerMask.GetMask("Terrain", "World", "Construction", "Water");
- Vector3 pos;
- Vector3 normal;
- this.strafe_target_position = !TransformUtil.GetGroundInfo(strafePos, out pos, out normal, 100f, (LayerMask) mask, this.transform) ? strafePos : pos;
- this.numRocketsLeft = this.maxRockets;
- this.lastRocketTime = 0.0f;
- this.movementLockingAiming = true;
- Vector3 randomOffset = this.GetRandomOffset(strafePos, this.strafe_approach_range, this.strafe_approach_range * 1.1f, 20f, 30f);
- this.SetTargetDestination(randomOffset, 10f, 30f);
- this.SetIdealRotation(this.GetYawRotationTo(randomOffset), -1f);
- this.puttingDistance = true;
- }
- public void State_Strafe_Think(float timePassed)
- {
- if (this.puttingDistance)
- {
- if (!this.AtDestination())
- return;
- this.puttingDistance = false;
- this.SetTargetDestination(this.strafe_target_position + new Vector3(0.0f, 20f, 0.0f), 10f, 30f);
- this.SetIdealRotation(this.GetYawRotationTo(this.strafe_target_position), -1f);
- }
- else
- {
- this.SetIdealRotation(this.GetYawRotationTo(this.strafe_target_position), -1f);
- float num = Vector3Ex.Distance2D(this.strafe_target_position, this.transform.position);
- if ((double) num <= (double) this.strafe_firing_range && this.ClipRocketsLeft() > 0 && (double) Time.realtimeSinceStartup - (double) this.lastRocketTime > (double) this.timeBetweenRockets)
- {
- float maxDistance = Vector3.Distance(this.strafe_target_position, this.transform.position) - 10f;
- if ((double) maxDistance < 0.0)
- maxDistance = 0.0f;
- if (!Physics.Raycast(this.transform.position, (this.strafe_target_position - this.transform.position).normalized, maxDistance, LayerMask.GetMask("Terrain", "World")))
- this.FireRocket();
- }
- if (this.ClipRocketsLeft() > 0 && (double) num > 15.0)
- return;
- this.ExitCurrentState();
- this.State_Move_Enter(this.GetAppropriatePosition(this.strafe_target_position + this.transform.forward * 120f, 20f, 30f));
- }
- }
- public void State_Strafe_Leave()
- {
- this.movementLockingAiming = false;
- }
- public void FireRocket()
- {
- --this.numRocketsLeft;
- this.lastRocketTime = Time.realtimeSinceStartup;
- float num1 = 4f;
- bool flag = this.leftTubeFiredLast;
- this.leftTubeFiredLast = !this.leftTubeFiredLast;
- Transform transform = !flag ? this.helicopterBase.rocket_tube_right.transform : this.helicopterBase.rocket_tube_left.transform;
- Vector3 vector3 = transform.position + transform.forward * 1f;
- Vector3 direction = (this.strafe_target_position - vector3).normalized;
- if ((double) num1 > 0.0)
- direction = Quaternion.Euler(Random.Range((float) (-(double) num1 * 0.5), num1 * 0.5f), Random.Range((float) (-(double) num1 * 0.5), num1 * 0.5f), Random.Range((float) (-(double) num1 * 0.5), num1 * 0.5f)) * direction;
- float maxDistance = 1f;
- RaycastHit hitInfo;
- if (Physics.Raycast(vector3, direction, out hitInfo, maxDistance, -1063040255))
- {
- float num2 = hitInfo.distance - 0.1f;
- }
- Effect.server.Run(this.helicopterBase.rocket_fire_effect.resourcePath, (BaseEntity) this.helicopterBase, StringPool.Get(!flag ? "rocket_tube_right" : "rocket_tube_left"), Vector3.zero, Vector3.forward, (Network.Connection) null, true);
- BaseEntity entity = GameManager.server.CreateEntity(this.rocketProjectile.resourcePath, vector3, new Quaternion(), true);
- if ((Object) entity == (Object) null)
- return;
- entity.SendMessage("InitializeVelocity", (object) (direction * 1f));
- entity.Spawn(true);
- }
- public void InitializeAI()
- {
- this._lastThinkTime = Time.realtimeSinceStartup;
- }
- public void OnCurrentStateExit()
- {
- switch (this._currentState)
- {
- case PatrolHelicopterAI.aiState.MOVE:
- this.State_Move_Leave();
- break;
- case PatrolHelicopterAI.aiState.ORBIT:
- this.State_Orbit_Leave();
- break;
- case PatrolHelicopterAI.aiState.STRAFE:
- this.State_Strafe_Leave();
- break;
- case PatrolHelicopterAI.aiState.PATROL:
- this.State_Patrol_Leave();
- break;
- default:
- this.State_Idle_Leave();
- break;
- }
- }
- public void ExitCurrentState()
- {
- this.OnCurrentStateExit();
- this._currentState = PatrolHelicopterAI.aiState.IDLE;
- }
- public float GetTime()
- {
- return Time.realtimeSinceStartup;
- }
- public void AIThink()
- {
- float time = this.GetTime();
- float timePassed = time - this._lastThinkTime;
- this._lastThinkTime = time;
- switch (this._currentState)
- {
- case PatrolHelicopterAI.aiState.MOVE:
- this.State_Move_Think(timePassed);
- break;
- case PatrolHelicopterAI.aiState.ORBIT:
- this.State_Orbit_Think(timePassed);
- break;
- case PatrolHelicopterAI.aiState.STRAFE:
- this.State_Strafe_Think(timePassed);
- break;
- case PatrolHelicopterAI.aiState.PATROL:
- this.State_Patrol_Think(timePassed);
- break;
- case PatrolHelicopterAI.aiState.DEATH:
- this.State_Death_Think(timePassed);
- break;
- default:
- this.State_Idle_Think(timePassed);
- break;
- }
- }
- public Vector3 GetRandomOffset(Vector3 origin, float minRange, float maxRange = 0.0f, float minHeight = 20f, float maxHeight = 30f)
- {
- Vector3 onUnitSphere = Random.onUnitSphere;
- onUnitSphere.y = 0.0f;
- onUnitSphere.Normalize();
- maxRange = Mathf.Max(minRange, maxRange);
- return this.GetAppropriatePosition(origin + onUnitSphere * Random.Range(minRange, maxRange), minHeight, maxHeight);
- }
- public Vector3 GetAppropriatePosition(Vector3 origin, float minHeight = 20f, float maxHeight = 30f)
- {
- float y = 100f;
- Ray ray = new Ray(origin + new Vector3(0.0f, y, 0.0f), Vector3.down);
- float radius = 5f;
- int mask = LayerMask.GetMask("Terrain", "World", "Construction", "Water");
- RaycastHit hitInfo;
- if (Physics.SphereCast(ray, radius, out hitInfo, y * 2f - radius, mask))
- origin = hitInfo.point;
- origin.y += Random.Range(minHeight, maxHeight);
- return origin;
- }
- public float GetThrottleForDistance(float distToTarget)
- {
- return (double) distToTarget < 75.0 ? ((double) distToTarget < 50.0 ? ((double) distToTarget < 25.0 ? ((double) distToTarget < 5.0 ? (float) (0.0500000007450581 * (1.0 - (double) distToTarget / 5.0)) : 0.05f) : 0.33f) : 0.75f) : 1f;
- }
- public class targetinfo
- {
- public float lastSeenTime = float.PositiveInfinity;
- public BasePlayer ply;
- public BaseEntity ent;
- public float visibleFor;
- public float nextLOSCheck;
- public targetinfo(BaseEntity initEnt, BasePlayer initPly = null)
- {
- this.ply = initPly;
- this.ent = initEnt;
- this.lastSeenTime = float.PositiveInfinity;
- this.nextLOSCheck = Time.realtimeSinceStartup + 1.5f;
- }
- public bool IsVisible()
- {
- return (double) this.TimeSinceSeen() < 1.5;
- }
- public float TimeSinceSeen()
- {
- return Time.realtimeSinceStartup - this.lastSeenTime;
- }
- }
- public enum aiState
- {
- IDLE,
- MOVE,
- ORBIT,
- STRAFE,
- PATROL,
- GUARD,
- DEATH,
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement