protected override void Update() { if (this.timeAttackAnimationPlaying > 0f) { this.timeAttackAnimationPlaying -= Time.deltaTime; } if (this.timeUseAnimationPlaying > 0f) { this.timeUseAnimationPlaying -= Time.deltaTime; } if (this.timeHarestingAnimationPlaying > 0f) { this.timeHarestingAnimationPlaying -= Time.deltaTime; if (this.timeHarestingAnimationPlaying <= 0f && this.anim != null) { this.SetBool("Harvesting", false); } } if (this.timeSpecialAttack2Playing > 0f) { this.timeSpecialAttack2Playing -= Time.deltaTime; } if (this.hitDuration > 0f) { this.hitDuration -= Time.deltaTime; if (this.hitDuration <= 0f) { this.SetTrigger("HitEndTrigger"); } } if (!this.m_bVisible && (this.entity == null || !this.entity.RootMotion || this.entity.isEntityRemote)) { Debug.Log("No Root Motion / Entity is Remote "); return; } if (this.bipedTransform == null || !this.bipedTransform.gameObject.activeInHierarchy) { Log("BipedTransform is null, or inactive"); return; } if (!(this.anim == null) && this.anim.avatar.isValid && this.anim.enabled) { this.updateLayerStateInfo(); this.setLayerWeights(); int value = this.entity.inventory.holdingItem.HoldType.Value; this.SetInt("WeaponHoldType", value); Log("Last Distance: " + this.lastDistance); float playerDistanceX = 0.0f; float playerDistanceZ = 0.0f; float encroached = this.lastDistance; Log("Position X: " + this.entity.position.x); Log("Position Z: " + this.entity.position.z); // Calculates how far away the entity is playerDistanceX = Mathf.Abs(this.entity.position.x - this.entity.lastTickPos[0].x) * 6f; playerDistanceZ = Mathf.Abs(this.entity.position.z - this.entity.lastTickPos[0].z) * 6f; if (!this.entity.isEntityRemote) { if (Mathf.Abs(playerDistanceX - this.lastPlayerX) > 0.00999999977648258 || Mathf.Abs(playerDistanceZ - this.lastPlayerZ) > 0.00999999977648258) { encroached = Mathf.Sqrt(playerDistanceX * playerDistanceX + playerDistanceZ * playerDistanceZ); this.lastPlayerX = playerDistanceX; this.lastPlayerZ = playerDistanceZ; this.lastDistance = encroached; } } else if (playerDistanceX <= this.lastPlayerX && playerDistanceZ <= this.lastPlayerZ) { this.lastPlayerX *= 0.9f; this.lastPlayerZ *= 0.9f; this.lastDistance *= 0.9f; } else { encroached = Mathf.Sqrt((playerDistanceX * playerDistanceX + playerDistanceZ * playerDistanceZ)); this.lastPlayerX = playerDistanceX; this.lastPlayerZ = playerDistanceZ; this.lastDistance = encroached; } Debug.Log("encroached: " + encroached); if (encroached > 0.05) { // Running if above 1.0 if (encroached > 1.0) { SetInt(MovementState, 2); } else { SetInt(MovementState, 1); } } else { SetInt(MovementState, 0); } Log("Movement State on Animation: " + this.anim.GetInteger("MovementState")); this.SetFloat("IdleTime", this.idleTime); this.idleTime += Time.deltaTime; this.SetFloat("RotationPitch", this.entity.rotation.x); this.animSyncWaitTime -= Time.deltaTime; if (this.animSyncWaitTime <= 0f) { this.animSyncWaitTime = 0.05f; if (this.ChangedAnimationParameters.Count > 0) { if (!this.entity.isEntityRemote) { List <global::AnimParamData> list = new List <global::AnimParamData>(this.ChangedAnimationParameters.Count); this.ChangedAnimationParameters.CopyValuesTo(list); if (global::Steam.Network.IsServer) { global::ConnectionManager instance = global::SingletonMonoBehaviour <global::ConnectionManager> .Instance; global::NetPackageEntityAnimationData package = new global::NetPackageEntityAnimationData(this.entity.entityId, list); int entityId = this.entity.entityId; instance.SendPackage(package, false, -1, entityId, -1, -1); } else { global::SingletonMonoBehaviour <global::ConnectionManager> .Instance.SendToServer(new global::NetPackageEntityAnimationData(this.entity.entityId, list), false); } } this.ChangedAnimationParameters.Clear(); } } return; } }
// Main Update method protected virtual void Update() { if (this.timeAttackAnimationPlaying > 0f) { this.timeAttackAnimationPlaying -= Time.deltaTime; } // No need to proceed if the model isn't initialized. if (this.bipedTransform == null || !this.bipedTransform.gameObject.activeInHierarchy) { return; } if (!(this.anim == null) && this.anim.avatar.isValid && this.anim.enabled) { // Logic to handle our movements float num = 0f; float num2 = 0f; if (!this.entity.IsFlyMode.Value) { num = this.entity.speedForward; num2 = this.entity.speedStrafe; } float num3 = num2; if (num3 >= 1234f) { num3 = 0f; } this.SetFloat("Forward", num); this.SetFloat("Strafe", num3); if (!this.entity.IsDead()) { if (this.movementStateOverride != -1) { this.SetInt("MovementState", this.movementStateOverride); this.movementStateOverride = -1; } else if (num2 >= 1234f) { this.SetInt("MovementState", 4); } else { float num4 = num * num + num3 * num3; int intMovementState = (num4 <= this.entity.moveSpeedAggro * this.entity.moveSpeedAggro) ? ((num4 <= this.entity.moveSpeed * this.entity.moveSpeed) ? ((num4 <= 0.001f) ? 0 : 1) : 2) : 3; this.SetInt("MovementState", intMovementState); } } if (Mathf.Abs(num) <= 0.01f && Mathf.Abs(num2) <= 0.01f) { this.SetBool("IsMoving", false); } else { this.idleTime = 0f; this.SetBool("IsMoving", true); } if (nextCheck == 0.0f || nextCheck < Time.time) { nextCheck = Time.time + CheckDelay; SetRandomIndex("RandomIndex"); SetRandomIndex("WalkIndex"); SetRandomIndex("RunIndex"); SetRandomIndex("IdleIndex"); } this.SetFloat("IdleTime", this.idleTime); this.idleTime += Time.deltaTime; this.SetFloat("RotationPitch", this.entity.rotation.x); // if the entity is in water, flag it, so we'll do the swiming conditions before the movement. this.SetBool("IsInWater", this.entity.IsInWater()); //Log("Entity is in Water: " + this.entity.IsInWater()); // This logic handles distributing the attack animations to clients and servers, and keeps them in sync this.animSyncWaitTime -= Time.deltaTime; if (this.animSyncWaitTime <= 0f) { this.animSyncWaitTime = 0.05f; if (this.ChangedAnimationParameters.Count > 0) { Log("Changed Animation Paramters: " + ChangedAnimationParameters.Count); foreach (var each in ChangedAnimationParameters) { Log(each.Value.ToString()); } if (!this.entity.isEntityRemote) { Log("Preparing package"); List <global::AnimParamData> list = new List <global::AnimParamData>(this.ChangedAnimationParameters.Count); this.ChangedAnimationParameters.CopyValuesTo(list); if (global::Steam.Network.IsServer) { global::ConnectionManager instance = global::SingletonMonoBehaviour <global::ConnectionManager> .Instance; global::NetPackageEntityAnimationData package = new global::NetPackageEntityAnimationData(this.entity.entityId, list); int entityId = this.entity.entityId; instance.SendPackage(package, false, -1, entityId, -1, -1); } else { global::SingletonMonoBehaviour <global::ConnectionManager> .Instance.SendToServer(new global::NetPackageEntityAnimationData(this.entity.entityId, list), false); } } Log("Clearing Parameter List"); this.ChangedAnimationParameters.Clear(); } else { Log("No Parameters"); } } return; } }