Beispiel #1
0
 private void RefreshPlayerDirection(bool force)
 {
     if (!force && this.InputManager.Movement == Vector2.Zero)
     {
         return;
     }
     if (this.PlayerManager.Action == ActionType.SideClimbingVine)
     {
         this.PlayerManager.LookingDirection = ClimbingApproachExtensions.AsDirection(this.currentApproach);
     }
     else
     {
         this.PlayerManager.LookingDirection = FezMath.DirectionFromMovement(this.InputManager.Movement.X);
     }
 }
Beispiel #2
0
        protected override bool TryStopTalking()
        {
            bool flag = this.SpeechManager.Hidden || !this.PlayerManager.Grounded;

            if (flag)
            {
                if (this.Npc.CustomSpeechLine == null && !this.Npc.RandomizeSpeech && (!this.Npc.SayFirstSpeechLineOnce && this.SequentialLineIndex != 0))
                {
                    this.Talk();
                    return(false);
                }
                else
                {
                    if (this.talkWaiter != null && this.talkWaiter.Alive)
                    {
                        this.talkWaiter.Cancel();
                    }
                    if (this.talkEmitter != null && !this.talkEmitter.Dead)
                    {
                        this.talkEmitter.FadeOutAndPause(0.1f);
                    }
                    if (!this.SpeechManager.Hidden)
                    {
                        this.SpeechManager.Hide();
                    }
                    this.Npc.CustomSpeechLine = (SpeechLine)null;
                    if (this.Npc.ActorType == ActorType.Owl)
                    {
                        this.LookingDirection = FezMath.DirectionFromMovement(FezMath.Dot(-(this.PlayerManager.Position - this.Position) * FezMath.Sign(this.Npc.DestinationOffset), FezMath.SideMask(this.CameraManager.Viewpoint)));
                        this.CurrentAction    = NpcAction.TakeOff;
                        this.UpdateAction();
                        ++this.GameState.SaveData.CollectedOwls;
                        this.OwlService.OnOwlCollected();
                        this.GameState.SaveData.ThisLevel.InactiveNPCs.Add(this.Npc.Id);
                        this.LevelService.ResolvePuzzle();
                    }
                }
            }
            return(flag);
        }
Beispiel #3
0
 protected override void TestConditions()
 {
     if (!FezMath.In <ActionType>(this.PlayerManager.Action, ActionType.Sliding, ActionType.GrabCornerLedge, ActionType.Running, ActionType.RunTurnAround, ActionType.Walking, ActionType.Landing, ActionType.WalkingTo, ActionType.GrabTombstone, (IEqualityComparer <ActionType>)ActionTypeComparer.Default) && !this.PlayerManager.Climbing && (!this.PlayerManager.Swimming && !ActionTypeExtensions.IsIdle(this.PlayerManager.Action)) && (this.PlayerManager.Action != ActionType.Falling || !this.PlayerManager.CanDoubleJump) && (this.PlayerManager.Action != ActionType.Grabbing && this.PlayerManager.Action != ActionType.Pushing && !ActionTypeExtensions.IsLookingAround(this.PlayerManager.Action)) || this.InputManager.Jump != FezButtonState.Pressed && (!this.PlayerManager.Grounded && !ActionTypeExtensions.IsOnLedge(this.PlayerManager.Action) || (double)this.PlayerManager.Velocity.Y * (double)Math.Sign(this.CollisionManager.GravityFactor) <= 0.1))
     {
         return;
     }
     this.PlayerManager.PushedInstance = (TrileInstance)null;
     if (this.PlayerManager.CanDoubleJump)
     {
         this.PlayerManager.CanDoubleJump = false;
     }
     if (FezButtonStateExtensions.IsDown(this.InputManager.Down) && (this.PlayerManager.Grounded && this.PlayerManager.Ground.First.GetRotatedFace(FezMath.VisibleOrientation(this.CameraManager.Viewpoint)) == CollisionType.TopOnly || this.PlayerManager.Climbing))
     {
         return;
     }
     if (this.PlayerManager.Action == ActionType.GrabCornerLedge)
     {
         HorizontalDirection horizontalDirection = FezMath.DirectionFromMovement(this.InputManager.Movement.X);
         if (horizontalDirection == HorizontalDirection.None || horizontalDirection == this.PlayerManager.LookingDirection)
         {
             return;
         }
         Vector3 position = this.PlayerManager.Position;
         this.PlayerManager.Position += FezMath.RightVector(this.CameraManager.Viewpoint) * (float)-FezMath.Sign(this.PlayerManager.LookingDirection);
         this.PhysicsManager.DetermineInBackground((IPhysicsEntity)this.PlayerManager, true, false, false);
         this.PlayerManager.Position = position;
     }
     if (this.InputManager.Jump == FezButtonState.Pressed)
     {
         this.sinceJumped  = TimeSpan.Zero;
         this.scheduleJump = true;
     }
     else
     {
         this.DoJump();
     }
     this.PlayerManager.Action = ActionType.Jumping;
 }
Beispiel #4
0
        public bool Update(IComplexPhysicsEntity entity)
        {
            QueryOptions queryOptions = QueryOptions.None;

            if (entity.Background)
            {
                queryOptions |= QueryOptions.Background;
            }
            this.MoveAlongWithGround((IPhysicsEntity)entity, queryOptions);
            MultipleHits <CollisionResult> horizontalResults;
            MultipleHits <CollisionResult> verticalResults;

            this.CollisionManager.CollideRectangle(entity.Center, entity.Velocity, entity.Size, queryOptions, entity.Elasticity, out horizontalResults, out verticalResults);
            bool grounded = entity.Grounded;
            MultipleHits <TrileInstance> ground1  = entity.Ground;
            Vector3?        clampToGroundDistance = new Vector3?();
            FaceOrientation visibleOrientation    = this.CameraManager.VisibleOrientation;
            bool            flag1 = (double)this.CollisionManager.GravityFactor < 0.0;

            if (BoxCollisionResultExtensions.AnyCollided(verticalResults) && (flag1 ? ((double)entity.Velocity.Y > 0.0 ? 1 : 0) : ((double)entity.Velocity.Y < 0.0 ? 1 : 0)) != 0)
            {
                MultipleHits <TrileInstance> ground2 = entity.Ground;
                CollisionResult collisionResult1     = verticalResults.NearLow;
                CollisionResult collisionResult2     = verticalResults.FarHigh;
                if (collisionResult2.Destination != null && collisionResult2.Destination.GetRotatedFace(visibleOrientation) != CollisionType.None)
                {
                    ground2.FarHigh = collisionResult2.Destination;
                    if (collisionResult2.Collided && (collisionResult2.ShouldBeClamped || entity.MustBeClampedToGround))
                    {
                        clampToGroundDistance = new Vector3?(collisionResult2.NearestDistance);
                    }
                }
                else
                {
                    ground2.FarHigh = (TrileInstance)null;
                }
                if (collisionResult1.Destination != null && collisionResult1.Destination.GetRotatedFace(visibleOrientation) != CollisionType.None)
                {
                    ground2.NearLow = collisionResult1.Destination;
                    if (collisionResult1.Collided && (collisionResult1.ShouldBeClamped || entity.MustBeClampedToGround))
                    {
                        clampToGroundDistance = new Vector3?(collisionResult1.NearestDistance);
                    }
                }
                else
                {
                    ground2.NearLow = (TrileInstance)null;
                }
                entity.Ground = ground2;
            }
            else
            {
                entity.Ground = new MultipleHits <TrileInstance>();
            }
            entity.Ceiling = (double)entity.Velocity.Y <= 0.0 || !BoxCollisionResultExtensions.AnyCollided(verticalResults) ? new MultipleHits <CollisionResult>() : verticalResults;
            bool flag2 = (this.PlayerManager.Action == ActionType.Grabbing || this.PlayerManager.Action == ActionType.Pushing || (this.PlayerManager.Action == ActionType.GrabCornerLedge || this.PlayerManager.Action == ActionType.LowerToCornerLedge) || this.PlayerManager.Action == ActionType.SuckedIn || this.PlayerManager.Action == ActionType.Landing) | entity.MustBeClampedToGround;

            entity.MustBeClampedToGround = false;
            bool velocityIrrelevant = ((flag2 ? 1 : 0) | (!entity.Grounded ? 0 : (entity.Ground.First.ForceClampToGround ? 1 : 0))) != 0;

            if (grounded && !entity.Grounded)
            {
                entity.GroundedVelocity = new Vector3?(entity.Velocity);
            }
            else if (!grounded && entity.Grounded)
            {
                entity.GroundedVelocity = new Vector3?();
            }
            Vector3 vector2 = FezMath.RightVector(this.CameraManager.Viewpoint);

            entity.MovingDirection = FezMath.DirectionFromMovement(Vector3.Dot(entity.Velocity, vector2));
            bool flag3 = this.PlayerManager.Action == ActionType.FrontClimbingLadder || this.PlayerManager.Action == ActionType.FrontClimbingVine;

            if (entity.GroundMovement != Vector3.Zero || flag3)
            {
                this.DetermineInBackground((IPhysicsEntity)entity, true, false, !this.PlayerManager.Climbing);
            }
            return(this.UpdateInternal((IPhysicsEntity)entity, horizontalResults, verticalResults, clampToGroundDistance, grounded, !entity.HandlesZClamping, velocityIrrelevant, false));
        }
Beispiel #5
0
        public override void Update(GameTime gameTime)
        {
            if (this.GameState.Loading || this.PlayerManager.Hidden || this.GameState.InCutscene)
            {
                return;
            }
            Vector3 position = this.PlayerManager.Position;

            if (!this.PlayerManager.CanControl)
            {
                this.InputManager.SaveState();
                this.InputManager.Reset();
            }
            if (this.CameraManager.Viewpoint != Viewpoint.Perspective && this.CameraManager.ActionRunning && (!this.GameState.InMenuCube && !this.GameState.Paused) && (this.CameraManager.RequestedViewpoint == Viewpoint.None && !this.GameState.InMap && !this.LevelManager.IsInvalidatingScreen))
            {
                if (ActionTypeExtensions.AllowsLookingDirectionChange(this.PlayerManager.Action) && !FezMath.AlmostEqual(this.InputManager.Movement.X, 0.0f))
                {
                    this.oldLookDir = this.PlayerManager.LookingDirection;
                    this.PlayerManager.LookingDirection = FezMath.DirectionFromMovement(this.InputManager.Movement.X);
                }
                Vector3 velocity = this.PlayerManager.Velocity;
                this.PhysicsManager.Update((IComplexPhysicsEntity)this.PlayerManager);
                if (this.PlayerManager.Grounded && this.PlayerManager.Ground.NearLow == null)
                {
                    TrileInstance trileInstance = this.PlayerManager.Ground.FarHigh;
                    Vector3       b             = FezMath.RightVector(this.CameraManager.Viewpoint) * (float)FezMath.Sign(this.PlayerManager.LookingDirection);
                    float         num           = FezMath.Dot(trileInstance.Center - trileInstance.TransformedSize / 2f * b - this.PlayerManager.Center + this.PlayerManager.Size / 2f * b, b);
                    if ((double)num > -0.25)
                    {
                        this.PlayerManager.Position -= Vector3.UnitY * 0.01f * (float)Math.Sign(this.CollisionManager.GravityFactor);
                        if (trileInstance.GetRotatedFace(FezMath.VisibleOrientation(this.CameraManager.Viewpoint)) == CollisionType.AllSides)
                        {
                            this.PlayerManager.Position += num * b;
                            this.PlayerManager.Velocity  = velocity * Vector3.UnitY;
                        }
                        else
                        {
                            this.PlayerManager.Velocity = velocity;
                        }
                        this.PlayerManager.Ground = new MultipleHits <TrileInstance>();
                    }
                }
                this.PlayerManager.RecordRespawnInformation();
                if (!ActionTypeExtensions.HandlesZClamping(this.PlayerManager.Action) && (this.oldLookDir != this.PlayerManager.LookingDirection || this.PlayerManager.LastAction == ActionType.RunTurnAround) && (this.PlayerManager.Action != ActionType.Dropping && this.PlayerManager.Action != ActionType.GrabCornerLedge && (this.PlayerManager.Action != ActionType.SuckedIn && this.PlayerManager.Action != ActionType.CrushVertical)) && this.PlayerManager.Action != ActionType.CrushHorizontal)
                {
                    this.CorrectWallOverlap(false);
                }
            }
            if (this.PlayerManager.CarriedInstance != null && this.PlayerManager.Action != ActionType.Suffering)
            {
                this.PlayerManager.CarriedInstance.Position += this.PlayerManager.Position - position;
                this.LevelManager.UpdateInstance(this.PlayerManager.CarriedInstance);
            }
            if (this.PlayerManager.Grounded)
            {
                this.PlayerManager.IgnoreFreefall = false;
            }
            if (this.PlayerManager.Animation != null && this.lastFrame != this.PlayerManager.Animation.Timing.Frame)
            {
                if (this.PlayerManager.Grounded)
                {
                    SurfaceType surfaceType = this.PlayerManager.Ground.First.Trile.SurfaceType;
                    if (this.PlayerManager.Action == ActionType.Landing && this.PlayerManager.Animation.Timing.Frame == 0)
                    {
                        this.PlaySurfaceHit(surfaceType, false);
                    }
                    else if ((this.PlayerManager.Action == ActionType.PullUpBack || this.PlayerManager.Action == ActionType.PullUpFront || this.PlayerManager.Action == ActionType.PullUpCornerLedge) && this.PlayerManager.Animation.Timing.Frame == 5)
                    {
                        this.PlaySurfaceHit(surfaceType, false);
                    }
                    else if (ActionTypeExtensions.GetAnimationPath(this.PlayerManager.Action) == "Walk")
                    {
                        if (this.PlayerManager.Animation.Timing.Frame == 1 || this.PlayerManager.Animation.Timing.Frame == 4)
                        {
                            if (this.PlayerManager.Action != ActionType.Sliding)
                            {
                                SoundEffectExtensions.EmitAt(this.isLeft ? this.LeftStep : this.RightStep, this.PlayerManager.Position, RandomHelper.Between(-0.100000001490116, 0.100000001490116), RandomHelper.Between(0.899999976158142, 1.0));
                                this.isLeft = !this.isLeft;
                            }
                            this.PlaySurfaceHit(surfaceType, false);
                        }
                    }
                    else if (this.PlayerManager.Action == ActionType.Running)
                    {
                        if (this.PlayerManager.Animation.Timing.Frame == 0 || this.PlayerManager.Animation.Timing.Frame == 3)
                        {
                            this.PlaySurfaceHit(surfaceType, true);
                        }
                    }
                    else if (this.PlayerManager.CarriedInstance != null)
                    {
                        if (ActionTypeExtensions.GetAnimationPath(this.PlayerManager.Action) == "CarryHeavyWalk")
                        {
                            if (this.PlayerManager.Animation.Timing.Frame == 0 || this.PlayerManager.Animation.Timing.Frame == 4)
                            {
                                this.PlaySurfaceHit(surfaceType, true);
                            }
                        }
                        else if (ActionTypeExtensions.GetAnimationPath(this.PlayerManager.Action) == "CarryWalk" && (this.PlayerManager.Animation.Timing.Frame == 3 || this.PlayerManager.Animation.Timing.Frame == 7))
                        {
                            this.PlaySurfaceHit(surfaceType, true);
                        }
                    }
                    else
                    {
                        this.isLeft = false;
                    }
                }
                else
                {
                    this.isLeft = false;
                }
                this.lastFrame = this.PlayerManager.Animation.Timing.Frame;
            }
            if (this.PlayerManager.CanControl)
            {
                return;
            }
            this.InputManager.RecoverState();
        }
Beispiel #6
0
        private void Talk()
        {
            if (this.Npc.CustomSpeechLine != null)
            {
                this.CurrentLine = this.Npc.CustomSpeechLine;
            }
            else
            {
                SpeechLine speechLine = this.CurrentLine;
                if (this.Npc.Speech.Count <= 1 || this.Npc.SayFirstSpeechLineOnce && !this.SaidFirstLine)
                {
                    this.CurrentLine = Enumerable.FirstOrDefault <SpeechLine>((IEnumerable <SpeechLine>) this.Npc.Speech);
                }
                else
                {
                    do
                    {
                        if (this.Npc.RandomizeSpeech)
                        {
                            this.CurrentLine = RandomHelper.InList <SpeechLine>(this.Npc.Speech);
                        }
                        else
                        {
                            this.CurrentLine = this.Npc.Speech[this.SequentialLineIndex];
                            ++this.SequentialLineIndex;
                            if (this.SequentialLineIndex == this.Npc.Speech.Count)
                            {
                                this.SequentialLineIndex = 0;
                            }
                        }
                    }while (speechLine == this.CurrentLine || this.Npc.SayFirstSpeechLineOnce && this.SaidFirstLine && this.CurrentLine == this.Npc.Speech[0]);
                }
                this.SaidFirstLine = true;
            }
            IPlayerManager playerManager1 = this.PlayerManager;
            Vector3        vector3_1      = playerManager1.Velocity * Vector3.UnitY;

            playerManager1.Velocity   = vector3_1;
            this.PlayerManager.Action = ActionType.ReadingSign;
            Vector3 a = this.PlayerManager.Position - this.Position;

            this.SpeechManager.Origin = this.Position + Vector3.UnitY * 0.5f;
            string s;

            if (this.LevelManager.SongName == "Majesty")
            {
                this.SpeechManager.Font = SpeechFont.Zuish;
                string stringRaw = GameText.GetStringRaw(this.CurrentLine.Text);
                this.SpeechManager.Origin       = this.Position + Vector3.UnitY * 0.5f + FezMath.RightVector(this.CameraManager.Viewpoint);
                this.SpeechManager.ChangeText(s = stringRaw);
            }
            else
            {
                this.SpeechManager.ChangeText(s = GameText.GetString(this.CurrentLine.Text));
            }
            this.LookingDirection = FezMath.DirectionFromMovement(FezMath.Dot(a * FezMath.Sign(this.Npc.DestinationOffset), FezMath.SideMask(this.CameraManager.Viewpoint)));
            this.PlayerManager.LookingDirection = FezMath.DirectionFromMovement(-FezMath.Dot(a, FezMath.RightVector(this.CameraManager.Viewpoint)));
            float num = FezMath.Dot(a, FezMath.SideMask(this.CameraManager.Viewpoint));

            if ((double)Math.Abs(num) < 1.0)
            {
                Vector3 center   = this.PlayerManager.Center;
                Vector3 velocity = this.PlayerManager.Velocity;
                MultipleHits <TrileInstance> ground = this.PlayerManager.Ground;
                IPlayerManager playerManager2       = this.PlayerManager;
                Vector3        vector3_2            = playerManager2.Center + (float)Math.Sign(num) * (1.25f - Math.Abs(num)) * FezMath.SideMask(this.CameraManager.Viewpoint);
                playerManager2.Center = vector3_2;
                this.PhysicsManager.Update((IComplexPhysicsEntity)this.PlayerManager);
                this.PlayerManager.Velocity = velocity;
                if (!this.PlayerManager.Grounded)
                {
                    this.PlayerManager.Center = center;
                    this.PlayerManager.Ground = ground;
                }
                else
                {
                    this.PlayerManager.Center = center + (float)Math.Sign(num) * (1f - Math.Abs(num)) * FezMath.SideMask(this.CameraManager.Viewpoint);
                }
            }
            this.CurrentAction = NpcAction.Talk;
            this.Npc.Talking   = true;
            if (this.Npc.ActorType == ActorType.LightningGhost)
            {
                this.Group.Material.Opacity = 0.0f;
            }
            this.talkWaiter = Waiters.Wait(0.100000001490116 + 0.0750000029802322 * (double)Util.StripPunctuation(s).Length *(Culture.IsCJK ? 2.0 : 1.0), (Action)(() =>
            {
                if (this.talkEmitter == null)
                {
                    return;
                }
                this.talkEmitter.FadeOutAndPause(0.1f);
            }));
            this.talkWaiter.AutoPause = true;
            this.UpdateAction();
        }
Beispiel #7
0
        protected override void TryFlee()
        {
            if (this.PlayerManager.Action == ActionType.IdleSleep)
            {
                return;
            }
            float num1 = FezMath.Dot(FezMath.Abs(this.Position - this.PlayerManager.Position), FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint));

            this.Npc.WalkSpeed = this.originalSpeed * (float)(1.0 + (1.0 - (double)FezMath.Saturate(num1 / 3f)));
            switch (this.CurrentAction)
            {
            case NpcAction.Turn:
                break;

            case NpcAction.Burrow:
                break;

            case NpcAction.ComeOut:
                break;

            case NpcAction.TakeOff:
                break;

            case NpcAction.Fly:
                break;

            default:
                Vector3 vector3 = Vector3.UnitY + FezMath.SideMask(this.CameraManager.Viewpoint) * 3f + FezMath.DepthMask(this.CameraManager.Viewpoint) * float.MaxValue;
                if (new BoundingBox(this.Position - vector3, this.Position + vector3).Contains(this.PlayerManager.Position) == ContainmentType.Disjoint)
                {
                    if (this.CurrentAction != NpcAction.Hide)
                    {
                        break;
                    }
                    this.CurrentAction = NpcAction.ComeOut;
                    this.UpdateAction();
                    break;
                }
                else
                {
                    float     num2      = FezMath.Dot(this.PlayerManager.Position - this.Position, FezMath.RightVector(this.CameraManager.Viewpoint)) * (float)Math.Sign(FezMath.Dot(this.Npc.DestinationOffset, FezMath.RightVector(this.CameraManager.Viewpoint)));
                    NpcAction npcAction = this.CurrentAction;
                    if ((double)num1 < 1.0)
                    {
                        this.Hide();
                    }
                    else if (this.CurrentAction == NpcAction.Hide)
                    {
                        this.CurrentAction = NpcAction.ComeOut;
                        SoundEffectExtensions.EmitAt(this.comeOutSound, this.Position);
                        this.UpdateAction();
                        break;
                    }
                    else
                    {
                        HorizontalDirection horizontalDirection = FezMath.DirectionFromMovement(-num2);
                        if (this.LookingDirection != horizontalDirection)
                        {
                            if (this.CanTurn)
                            {
                                this.CurrentAction = NpcAction.Turn;
                            }
                            else
                            {
                                this.LookingDirection = horizontalDirection;
                                this.CurrentAction    = this.CanWalk ? NpcAction.Walk : NpcAction.Idle;
                            }
                        }
                        else
                        {
                            this.CurrentAction = this.CanWalk ? NpcAction.Walk : NpcAction.Idle;
                        }
                    }
                    if (npcAction == this.CurrentAction)
                    {
                        break;
                    }
                    this.UpdateAction();
                    break;
                }
            }
        }