| using System; |
| using System; |
| . | |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| . | public class RandomFlyingBird : MonoBehaviour |
| public class RandomFlyingBird : MonoBehaviour, IMonoUpdater |
| { |
| { |
| . | private void Start() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_anim = base.GetComponentInChildren<ZSyncAnimation>(); |
| this.m_anim = base.GetComponentInChildren<ZSyncAnimation>(); |
| this.m_lodGroup = base.GetComponent<LODGroup>(); |
| this.m_lodGroup = base.GetComponent<LODGroup>(); |
| . | this.m_landedModel.SetActive(true); |
| if (!this.m_singleModel) |
| this.m_flyingModel.SetActive(true); |
| { |
| |
| this.m_landedModel.SetActive(true); |
| |
| this.m_flyingModel.SetActive(true); |
| |
| } |
| |
| else |
| |
| { |
| |
| this.m_flyingModel.SetActive(true); |
| |
| } |
| |
| this.m_idleTargetTime = UnityEngine.Random.Range(this.m_randomIdleTimeMin, this.m_randomIdleTimeMax); |
| this.m_spawnPoint = this.m_nview.GetZDO().GetVec3(ZDOVars.s_spawnPoint, base.transform.position); |
| this.m_spawnPoint = this.m_nview.GetZDO().GetVec3(ZDOVars.s_spawnPoint, base.transform.position); |
| if (this.m_nview.IsOwner()) |
| if (this.m_nview.IsOwner()) |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnPoint, this.m_spawnPoint); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnPoint, this.m_spawnPoint); |
| } |
| } |
| this.m_randomNoiseTimer = UnityEngine.Random.Range(this.m_randomNoiseIntervalMin, this.m_randomNoiseIntervalMax); |
| this.m_randomNoiseTimer = UnityEngine.Random.Range(this.m_randomNoiseIntervalMin, this.m_randomNoiseIntervalMax); |
| if (this.m_nview.IsOwner()) |
| if (this.m_nview.IsOwner()) |
| { |
| { |
| this.RandomizeWaypoint(false); |
| this.RandomizeWaypoint(false); |
| } |
| } |
| if (this.m_lodGroup) |
| if (this.m_lodGroup) |
| { |
| { |
| this.m_originalLocalRef = this.m_lodGroup.localReferencePoint; |
| this.m_originalLocalRef = this.m_lodGroup.localReferencePoint; |
| } |
| } |
| } |
| } |
| |
| |
| . | private void FixedUpdate() |
| private void OnEnable() |
| |
| { |
| |
| if (this.m_nview != null) |
| |
| { |
| |
| RandomFlyingBird.Instances.Add(this); |
| |
| } |
| |
| } |
| |
| |
| |
| private void OnDisable() |
| |
| { |
| |
| RandomFlyingBird.Instances.Remove(this); |
| |
| } |
| |
| |
| |
| public void CustomFixedUpdate(float dt) |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| . | float fixedDeltaTime = Time.fixedDeltaTime; |
| bool flag = EnvMan.IsDaylight(); |
| bool flag = EnvMan.instance.IsDaylight(); |
| this.m_randomNoiseTimer -= dt; |
| this.m_randomNoiseTimer -= fixedDeltaTime; |
| |
| if (this.m_randomNoiseTimer <= 0f) |
| if (this.m_randomNoiseTimer <= 0f) |
| { |
| { |
| if (flag || !this.m_noNoiseAtNight) |
| if (flag || !this.m_noNoiseAtNight) |
| { |
| { |
| this.m_randomNoise.Create(base.transform.position, Quaternion.identity, base.transform, 1f, -1); |
| this.m_randomNoise.Create(base.transform.position, Quaternion.identity, base.transform, 1f, -1); |
| } |
| } |
| this.m_randomNoiseTimer = UnityEngine.Random.Range(this.m_randomNoiseIntervalMin, this.m_randomNoiseIntervalMax); |
| this.m_randomNoiseTimer = UnityEngine.Random.Range(this.m_randomNoiseIntervalMin, this.m_randomNoiseIntervalMax); |
| } |
| } |
| bool @bool = this.m_nview.GetZDO().GetBool(ZDOVars.s_landed, false); |
| bool @bool = this.m_nview.GetZDO().GetBool(ZDOVars.s_landed, false); |
| . | this.m_landedModel.SetActive(@bool); |
| if (!this.m_singleModel) |
| this.m_flyingModel.SetActive(!@bool); |
| { |
| |
| this.m_landedModel.SetActive(@bool); |
| |
| this.m_flyingModel.SetActive(!@bool); |
| |
| } |
| this.SetVisible(this.m_nview.HasOwner()); |
| this.SetVisible(this.m_nview.HasOwner()); |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| . | this.m_flyTimer += fixedDeltaTime; |
| this.m_flyTimer += dt; |
| this.m_modeTimer += fixedDeltaTime; |
| this.m_modeTimer += dt; |
| |
| if (this.m_singleModel) |
| |
| { |
| |
| this.m_anim.SetBool(RandomFlyingBird.s_flying, !@bool); |
| |
| } |
| if (@bool) |
| if (@bool) |
| { |
| { |
| Vector3 forward = base.transform.forward; |
| Vector3 forward = base.transform.forward; |
| forward.y = 0f; |
| forward.y = 0f; |
| forward.Normalize(); |
| forward.Normalize(); |
| base.transform.rotation = Quaternion.LookRotation(forward, Vector3.up); |
| base.transform.rotation = Quaternion.LookRotation(forward, Vector3.up); |
| . | this.m_landedTimer += fixedDeltaTime; |
| if (this.m_randomIdles > 0) |
| |
| { |
| |
| this.m_idleTimer += Time.fixedDeltaTime; |
| |
| if (this.m_idleTimer > this.m_idleTargetTime) |
| |
| { |
| |
| this.m_idleTargetTime = UnityEngine.Random.Range(this.m_randomIdleTimeMin, this.m_randomIdleTimeMax); |
| |
| this.m_idleTimer = 0f; |
| |
| this.m_anim.SetFloat(RandomFlyingBird.s_idle, (float)UnityEngine.Random.Range(0, this.m_randomIdles)); |
| |
| } |
| |
| } |
| |
| this.m_landedTimer += dt; |
| if (((flag || !this.m_noRandomFlightAtNight) && this.m_landedTimer > this.m_landDuration) || this.DangerNearby(base.transform.position)) |
| if (((flag || !this.m_noRandomFlightAtNight) && this.m_landedTimer > this.m_landDuration) || this.DangerNearby(base.transform.position)) |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_landed, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_landed, false); |
| this.RandomizeWaypoint(false); |
| this.RandomizeWaypoint(false); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| if (this.m_flapping) |
| if (this.m_flapping) |
| { |
| { |
| if (this.m_modeTimer > this.m_flapDuration) |
| if (this.m_modeTimer > this.m_flapDuration) |
| { |
| { |
| this.m_modeTimer = 0f; |
| this.m_modeTimer = 0f; |
| this.m_flapping = false; |
| this.m_flapping = false; |
| } |
| } |
| } |
| } |
| else if (this.m_modeTimer > this.m_sailDuration) |
| else if (this.m_modeTimer > this.m_sailDuration) |
| { |
| { |
| this.m_flapping = true; |
| this.m_flapping = true; |
| this.m_modeTimer = 0f; |
| this.m_modeTimer = 0f; |
| } |
| } |
| this.m_anim.SetBool(RandomFlyingBird.s_flapping, this.m_flapping); |
| this.m_anim.SetBool(RandomFlyingBird.s_flapping, this.m_flapping); |
| Vector3 vector = Vector3.Normalize(this.m_waypoint - base.transform.position); |
| Vector3 vector = Vector3.Normalize(this.m_waypoint - base.transform.position); |
| float num = (this.m_groundwp ? (this.m_turnRate * 4f) : this.m_turnRate); |
| float num = (this.m_groundwp ? (this.m_turnRate * 4f) : this.m_turnRate); |
| . | Vector3 vector2 = Vector3.RotateTowards(base.transform.forward, vector, num * 0.017453292f * fixedDeltaTime, 1f); |
| Vector3 vector2 = Vector3.RotateTowards(base.transform.forward, vector, num * 0.017453292f * dt, 1f); |
| float num2 = Vector3.SignedAngle(base.transform.forward, vector, Vector3.up); |
| float num2 = Vector3.SignedAngle(base.transform.forward, vector, Vector3.up); |
| Vector3 vector3 = Vector3.Cross(vector2, Vector3.up); |
| Vector3 vector3 = Vector3.Cross(vector2, Vector3.up); |
| Vector3 vector4 = Vector3.up; |
| Vector3 vector4 = Vector3.up; |
| if (num2 > 0f) |
| if (num2 > 0f) |
| { |
| { |
| vector4 += -vector3 * 1.5f * Utils.LerpStep(0f, 45f, num2); |
| vector4 += -vector3 * 1.5f * Utils.LerpStep(0f, 45f, num2); |
| } |
| } |
| else |
| else |
| { |
| { |
| vector4 += vector3 * 1.5f * Utils.LerpStep(0f, 45f, -num2); |
| vector4 += vector3 * 1.5f * Utils.LerpStep(0f, 45f, -num2); |
| } |
| } |
| float num3 = this.m_speed; |
| float num3 = this.m_speed; |
| bool flag2 = false; |
| bool flag2 = false; |
| if (this.m_groundwp) |
| if (this.m_groundwp) |
| { |
| { |
| float num4 = Vector3.Distance(base.transform.position, this.m_waypoint); |
| float num4 = Vector3.Distance(base.transform.position, this.m_waypoint); |
| if (num4 < 5f) |
| if (num4 < 5f) |
| { |
| { |
| num3 *= Mathf.Clamp(num4 / 5f, 0.2f, 1f); |
| num3 *= Mathf.Clamp(num4 / 5f, 0.2f, 1f); |
| vector2.y = 0f; |
| vector2.y = 0f; |
| vector2.Normalize(); |
| vector2.Normalize(); |
| vector4 = Vector3.up; |
| vector4 = Vector3.up; |
| flag2 = true; |
| flag2 = true; |
| } |
| } |
| if (num4 < 0.2f) |
| if (num4 < 0.2f) |
| { |
| { |
| base.transform.position = this.m_waypoint; |
| base.transform.position = this.m_waypoint; |
| this.m_nview.GetZDO().Set(ZDOVars.s_landed, true); |
| this.m_nview.GetZDO().Set(ZDOVars.s_landed, true); |
| this.m_landedTimer = 0f; |
| this.m_landedTimer = 0f; |
| this.m_flapping = true; |
| this.m_flapping = true; |
| this.m_modeTimer = 0f; |
| this.m_modeTimer = 0f; |
| } |
| } |
| } |
| } |
| else if (this.m_flyTimer >= this.m_wpDuration) |
| else if (this.m_flyTimer >= this.m_wpDuration) |
| { |
| { |
| bool flag3 = UnityEngine.Random.value < this.m_landChance; |
| bool flag3 = UnityEngine.Random.value < this.m_landChance; |
| this.RandomizeWaypoint(flag3); |
| this.RandomizeWaypoint(flag3); |
| } |
| } |
| Quaternion quaternion = Quaternion.LookRotation(vector2, vector4.normalized); |
| Quaternion quaternion = Quaternion.LookRotation(vector2, vector4.normalized); |
| . | base.transform.rotation = Quaternion.RotateTowards(base.transform.rotation, quaternion, 200f * fixedDeltaTime); |
| base.transform.rotation = Quaternion.RotateTowards(base.transform.rotation, quaternion, 200f * dt); |
| if (flag2) |
| if (flag2) |
| { |
| { |
| . | base.transform.position += vector * num3 * fixedDeltaTime; |
| base.transform.position += vector * num3 * dt; |
| return; |
| return; |
| } |
| } |
| . | base.transform.position += base.transform.forward * num3 * fixedDeltaTime; |
| base.transform.position += base.transform.forward * num3 * dt; |
| } |
| } |
| } |
| } |
| |
| |
| private void RandomizeWaypoint(bool ground) |
| private void RandomizeWaypoint(bool ground) |
| { |
| { |
| this.m_flyTimer = 0f; |
| this.m_flyTimer = 0f; |
| Vector3 vector; |
| Vector3 vector; |
| if (ground && this.FindLandingPoint(out vector)) |
| if (ground && this.FindLandingPoint(out vector)) |
| { |
| { |
| this.m_waypoint = vector; |
| this.m_waypoint = vector; |
| this.m_groundwp = true; |
| this.m_groundwp = true; |
| return; |
| return; |
| } |
| } |
| Vector2 vector2 = UnityEngine.Random.insideUnitCircle * this.m_flyRange; |
| Vector2 vector2 = UnityEngine.Random.insideUnitCircle * this.m_flyRange; |
| this.m_waypoint = this.m_spawnPoint + new Vector3(vector2.x, 0f, vector2.y); |
| this.m_waypoint = this.m_spawnPoint + new Vector3(vector2.x, 0f, vector2.y); |
| float num; |
| float num; |
| if (ZoneSystem.instance.GetSolidHeight(this.m_waypoint, out num, 1000)) |
| if (ZoneSystem.instance.GetSolidHeight(this.m_waypoint, out num, 1000)) |
| { |
| { |
| . | float num2 = ZoneSystem.instance.m_waterLevel + 2f; |
| float num2 = 32f; |
| if (num < num2) |
| if (num < num2) |
| { |
| { |
| num = num2; |
| num = num2; |
| } |
| } |
| this.m_waypoint.y = num + UnityEngine.Random.Range(this.m_minAlt, this.m_maxAlt); |
| this.m_waypoint.y = num + UnityEngine.Random.Range(this.m_minAlt, this.m_maxAlt); |
| } |
| } |
| this.m_groundwp = false; |
| this.m_groundwp = false; |
| } |
| } |
| |
| |
| private bool FindLandingPoint(out Vector3 waypoint) |
| private bool FindLandingPoint(out Vector3 waypoint) |
| { |
| { |
| waypoint = new Vector3(0f, -999f, 0f); |
| waypoint = new Vector3(0f, -999f, 0f); |
| bool flag = false; |
| bool flag = false; |
| for (int i = 0; i < 10; i++) |
| for (int i = 0; i < 10; i++) |
| { |
| { |
| Vector2 vector = UnityEngine.Random.insideUnitCircle * this.m_flyRange; |
| Vector2 vector = UnityEngine.Random.insideUnitCircle * this.m_flyRange; |
| Vector3 vector2 = this.m_spawnPoint + new Vector3(vector.x, 0f, vector.y); |
| Vector3 vector2 = this.m_spawnPoint + new Vector3(vector.x, 0f, vector.y); |
| float num; |
| float num; |
| . | if (ZoneSystem.instance.GetSolidHeight(vector2, out num, 1000) && num > ZoneSystem.instance.m_waterLevel && num > waypoint.y) |
| if (ZoneSystem.instance.GetSolidHeight(vector2, out num, 1000) && num > 30f && num > waypoint.y) |
| { |
| { |
| vector2.y = num; |
| vector2.y = num; |
| if (!this.DangerNearby(vector2)) |
| if (!this.DangerNearby(vector2)) |
| { |
| { |
| waypoint = vector2; |
| waypoint = vector2; |
| flag = true; |
| flag = true; |
| } |
| } |
| } |
| } |
| } |
| } |
| return flag; |
| return flag; |
| } |
| } |
| |
| |
| private bool DangerNearby(Vector3 p) |
| private bool DangerNearby(Vector3 p) |
| { |
| { |
| return Player.IsPlayerInRange(p, this.m_avoidDangerDistance); |
| return Player.IsPlayerInRange(p, this.m_avoidDangerDistance); |
| } |
| } |
| |
| |
| private void SetVisible(bool visible) |
| private void SetVisible(bool visible) |
| { |
| { |
| if (this.m_lodGroup == null) |
| if (this.m_lodGroup == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_lodVisible == visible) |
| if (this.m_lodVisible == visible) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_lodVisible = visible; |
| this.m_lodVisible = visible; |
| if (this.m_lodVisible) |
| if (this.m_lodVisible) |
| { |
| { |
| this.m_lodGroup.localReferencePoint = this.m_originalLocalRef; |
| this.m_lodGroup.localReferencePoint = this.m_originalLocalRef; |
| return; |
| return; |
| } |
| } |
| this.m_lodGroup.localReferencePoint = new Vector3(999999f, 999999f, 999999f); |
| this.m_lodGroup.localReferencePoint = new Vector3(999999f, 999999f, 999999f); |
| } |
| } |
| |
| |
| . | |
| public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>(); |
| |
| |
| public float m_flyRange = 20f; |
| public float m_flyRange = 20f; |
| |
| |
| public float m_minAlt = 5f; |
| public float m_minAlt = 5f; |
| |
| |
| public float m_maxAlt = 20f; |
| public float m_maxAlt = 20f; |
| |
| |
| public float m_speed = 10f; |
| public float m_speed = 10f; |
| |
| |
| public float m_turnRate = 10f; |
| public float m_turnRate = 10f; |
| |
| |
| public float m_wpDuration = 4f; |
| public float m_wpDuration = 4f; |
| |
| |
| public float m_flapDuration = 2f; |
| public float m_flapDuration = 2f; |
| |
| |
| public float m_sailDuration = 4f; |
| public float m_sailDuration = 4f; |
| |
| |
| public float m_landChance = 0.5f; |
| public float m_landChance = 0.5f; |
| |
| |
| public float m_landDuration = 2f; |
| public float m_landDuration = 2f; |
| |
| |
| public float m_avoidDangerDistance = 4f; |
| public float m_avoidDangerDistance = 4f; |
| |
| |
| public bool m_noRandomFlightAtNight = true; |
| public bool m_noRandomFlightAtNight = true; |
| |
| |
| public float m_randomNoiseIntervalMin = 3f; |
| public float m_randomNoiseIntervalMin = 3f; |
| |
| |
| public float m_randomNoiseIntervalMax = 6f; |
| public float m_randomNoiseIntervalMax = 6f; |
| |
| |
| public bool m_noNoiseAtNight = true; |
| public bool m_noNoiseAtNight = true; |
| |
| |
| public EffectList m_randomNoise = new EffectList(); |
| public EffectList m_randomNoise = new EffectList(); |
| |
| |
| . | |
| public int m_randomIdles; |
| |
| |
| |
| public float m_randomIdleTimeMin = 1f; |
| |
| |
| |
| public float m_randomIdleTimeMax = 4f; |
| |
| |
| |
| public bool m_singleModel; |
| |
| |
| public GameObject m_flyingModel; |
| public GameObject m_flyingModel; |
| |
| |
| public GameObject m_landedModel; |
| public GameObject m_landedModel; |
| |
| |
| private Vector3 m_spawnPoint; |
| private Vector3 m_spawnPoint; |
| |
| |
| private Vector3 m_waypoint; |
| private Vector3 m_waypoint; |
| |
| |
| private bool m_groundwp; |
| private bool m_groundwp; |
| |
| |
| private float m_flyTimer; |
| private float m_flyTimer; |
| |
| |
| private float m_modeTimer; |
| private float m_modeTimer; |
| |
| |
| . | |
| private float m_idleTimer; |
| |
| |
| |
| private float m_idleTargetTime = 1f; |
| |
| |
| private float m_randomNoiseTimer; |
| private float m_randomNoiseTimer; |
| |
| |
| private ZSyncAnimation m_anim; |
| private ZSyncAnimation m_anim; |
| |
| |
| private bool m_flapping = true; |
| private bool m_flapping = true; |
| |
| |
| private float m_landedTimer; |
| private float m_landedTimer; |
| |
| |
| private static readonly int s_flapping = ZSyncAnimation.GetHash("flapping"); |
| private static readonly int s_flapping = ZSyncAnimation.GetHash("flapping"); |
| . | |
| |
| |
| private static readonly int s_flying = ZSyncAnimation.GetHash("flying"); |
| |
| |
| |
| private static readonly int s_idle = ZSyncAnimation.GetHash("idle"); |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| protected LODGroup m_lodGroup; |
| protected LODGroup m_lodGroup; |
| |
| |
| private Vector3 m_originalLocalRef; |
| private Vector3 m_originalLocalRef; |
| |
| |
| private bool m_lodVisible = true; |
| private bool m_lodVisible = true; |
| } |
| } |
| |
| |