private void ChooseIdle() { if (NpcActionExtensions.IsSpecialIdle(this.CurrentAction)) { this.CurrentAction = NpcAction.Idle; } else { float num1 = RandomHelper.Unit(); float num2 = (float) (1 + FezMath.AsNumeric(this.CanIdle2) + FezMath.AsNumeric(this.CanIdle3)); if ((double) num1 < 1.0 / (double) num2) this.CurrentAction = NpcAction.Idle; else if ((double) num2 > 1.0 && (double) num1 < 2.0 / (double) num2) { this.CurrentAction = this.CanIdle2 ? NpcAction.Idle2 : NpcAction.Idle3; } else { if ((double) num2 <= 2.0 || (double) num1 >= 3.0 / (double) num2) return; this.CurrentAction = NpcAction.Idle3; } } }
private void Turn() { this.LookingDirection = FezMath.GetOpposite(this.LookingDirection); this.UpdateRotation(); this.CurrentAction = this.CanWalk ? NpcAction.Walk : NpcAction.Idle; }
private void ToggleAction() { NpcAction npcAction = this.CurrentAction; if (this.initialized) this.RandomizeAction(); else this.CurrentAction = this.CanIdle ? NpcAction.Idle : NpcAction.Walk; this.TimeUntilActionChange = new TimeSpan(0, 0, RandomHelper.Random.Next(2, 5)); this.TimeSinceActionChange = TimeSpan.Zero; if (this.initialized && this.CurrentAction == npcAction) return; this.UpdateAction(); }
private void RandomizeAction() { switch (this.CurrentAction) { case NpcAction.Turn: this.Turn(); break; case NpcAction.Burrow: ServiceHelper.RemoveComponent<NpcState>(this); break; case NpcAction.TakeOff: this.CurrentAction = NpcAction.Fly; this.UpdateAction(); break; case NpcAction.Land: this.CurrentAction = NpcAction.Idle; this.UpdateAction(); break; default: if ((RandomHelper.Probability(0.5) || !this.CanWalk) && this.CanIdle) { if (this.CanWalk || RandomHelper.Probability(0.5)) { this.ChooseIdle(); break; } else if (this.CanTurn) { this.CurrentAction = NpcAction.Turn; break; } else { this.Turn(); break; } } else { if (!this.CanWalk) throw new InvalidOperationException("This NPC can't walk or idle!"); if ((double) this.WalkStep == 1.0 || (double) this.WalkStep == 0.0) { if (this.CanIdle && RandomHelper.Probability(0.5)) { this.ChooseIdle(); break; } else if (this.CanTurn) { this.CurrentAction = NpcAction.Turn; break; } else { this.Turn(); break; } } else if (this.CanTurn && RandomHelper.Probability(0.5)) { this.CurrentAction = NpcAction.Turn; break; } else { this.CurrentAction = NpcAction.Walk; break; } } } }
private void Fly(TimeSpan elapsed) { if (!this.flyRight.HasValue) this.flyRight = new Vector3?(Vector3.Transform(Vector3.Right, this.Group.Rotation)); if ((!this.FlyingBack || this.Npc.ActorType != ActorType.Owl) && FezMath.AlmostEqual(FezMath.Dot(FezMath.Abs(Vector3.Transform(Vector3.Right, this.Group.Rotation)), FezMath.Abs(this.flyRight.Value)), 0.0f, 0.1f)) { NpcState npcState = this; Vector3? nullable1 = npcState.flyRight; Vector3 vector3 = Vector3.Transform(Vector3.Right, this.Group.Rotation); Vector3? nullable2 = nullable1.HasValue ? new Vector3?(nullable1.GetValueOrDefault() + vector3) : new Vector3?(); npcState.flyRight = nullable2; } this.flySpeed = Vector2.Lerp(this.flySpeed, new Vector2(4f, 3f), 0.03333334f); Vector2 vector2 = this.flySpeed * ((1f - FezMath.Frac(this.CurrentTiming.Step + 0.75f)) * new Vector2(0.4f, 0.6f) + new Vector2(0.6f, 0.4f)); this.Position += (float) elapsed.TotalSeconds * (vector2.X * this.flyRight.Value + Vector3.Up * vector2.Y * (this.FlyingBack ? -1f : 1f)); if (FezMath.IsOrthographic(this.CameraManager.Viewpoint) && this.CameraManager.ViewTransitionReached) { Vector3 b = FezMath.ForwardVector(this.CameraManager.Viewpoint); if (this.InBackground) b *= -1f; NearestTriles nearestTriles = this.LevelManager.NearestTrile(this.Position, QueryOptions.Simple); TrileInstance trileInstance = nearestTriles.Surface ?? nearestTriles.Deep; if (trileInstance != null) { Vector3 a = trileInstance.Center + trileInstance.TransformedSize / 2f * -b; Vector3 vector3 = FezMath.DepthMask(this.CameraManager.Viewpoint); if ((double) FezMath.Dot(this.Position, b) > (double) FezMath.Dot(a, b)) this.Position = this.Position * FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint) + a * vector3 - b; } } if (this.CurrentTiming.Frame == 0 && this.lastFrame != 0) SoundEffectExtensions.EmitAt(this.flySound, this.Position); this.lastFrame = this.CurrentTiming.Frame; if (this.FlyingBack) { if ((double) this.Position.Y > (double) this.Npc.Position.Y) return; this.Position = this.Npc.Position; this.CurrentAction = NpcAction.Land; this.flySpeed = Vector2.Zero; this.UpdateAction(); this.FlyingBack = false; this.flyRight = new Vector3?(); } else { if (this.CameraManager.Frustum.Contains(new BoundingBox(this.Position - Vector3.One, this.Position + Vector3.One)) != ContainmentType.Disjoint) return; if (this.MayComeBack) { this.OwlInvisible = true; this.MayComeBack = false; this.CurrentAction = NpcAction.Idle; this.flySpeed = Vector2.Zero; this.flyRight = new Vector3?(); this.UpdateAction(); } else ServiceHelper.RemoveComponent<NpcState>(this); } }