Пример #1
0
 private void DropSupportedTriles(TrileInstance instance)
 {
     foreach (Vector3 vector3 in BombsHost.CornerNeighbors)
     {
         TrileInstance trileInstance = this.LevelManager.ActualInstanceAt(instance.Center + instance.TransformedSize * vector3);
         if (trileInstance != null && trileInstance.PhysicsState != null)
         {
             MultipleHits <TrileInstance> ground = trileInstance.PhysicsState.Ground;
             if (ground.NearLow == instance)
             {
                 trileInstance.PhysicsState.Ground = new MultipleHits <TrileInstance>()
                 {
                     FarHigh = ground.FarHigh
                 }
             }
             ;
             if (ground.FarHigh == instance)
             {
                 trileInstance.PhysicsState.Ground = new MultipleHits <TrileInstance>()
                 {
                     NearLow = ground.NearLow
                 }
             }
             ;
         }
     }
 }
Пример #2
0
 protected override bool Act(TimeSpan elapsed)
 {
     if (this.PlayerManager.CarriedInstance == null)
     {
         this.PlayerManager.Action = ActionType.Idle;
         return(false);
     }
     else
     {
         Vector3       vector3_1       = FezMath.RightVector(this.CameraManager.Viewpoint) * (float)FezMath.Sign(this.PlayerManager.LookingDirection);
         TrileInstance carriedInstance = this.PlayerManager.CarriedInstance;
         Vector3       vector3_2       = this.PlayerManager.Center + this.PlayerManager.Size / 2f * (Vector3.Down + vector3_1) - carriedInstance.TransformedSize / 2f * vector3_1 + carriedInstance.Trile.Size / 2f * (Vector3.UnitY + vector3_1) + 0.125f * vector3_1;
         bool          flag            = ActorTypeExtensions.IsLight(carriedInstance.Trile.ActorSettings.Type);
         Vector2[]     vector2Array    = flag ? Lift.LightTrilePositioning : Lift.HeavyTrilePositioning;
         int           index           = (flag ? 4 : 7) - this.PlayerManager.Animation.Timing.Frame;
         Vector3       vector3_3       = vector3_2 + (vector2Array[index].X * -vector3_1 + vector2Array[index].Y * Vector3.Up) * 1f / 16f;
         carriedInstance.PhysicsState.Center = vector3_3;
         carriedInstance.PhysicsState.UpdateInstance();
         this.PlayerManager.Position -= vector3_3 - carriedInstance.Center;
         this.PlayerManager.CarriedInstance.PhysicsState.UpdateInstance();
         if (this.PlayerManager.Animation.Timing.Ended)
         {
             Vector3 impulse = (float)(3.15000009536743 * (double)Math.Sign(this.CollisionManager.GravityFactor) * 0.150000005960464) * (float)elapsed.TotalSeconds * Vector3.Down;
             if ((double)this.PlayerManager.GroundMovement.Y < 0.0)
             {
                 impulse += this.PlayerManager.GroundMovement;
             }
             MultipleHits <CollisionResult> result = this.CollisionManager.CollideEdge(carriedInstance.PhysicsState.Center, impulse, carriedInstance.TransformedSize / 2f, Direction2D.Vertical);
             if (BoxCollisionResultExtensions.AnyCollided(result))
             {
                 carriedInstance.PhysicsState.Ground = new MultipleHits <TrileInstance>()
                 {
                     NearLow = result.NearLow.Collided ? result.NearLow.Destination : (TrileInstance)null,
                     FarHigh = result.FarHigh.Collided ? result.FarHigh.Destination : (TrileInstance)null
                 };
                 if (carriedInstance.PhysicsState.Ground.First.PhysicsState != null)
                 {
                     carriedInstance.PhysicsState.GroundMovement = carriedInstance.PhysicsState.Ground.First.PhysicsState.Velocity;
                     carriedInstance.PhysicsState.Center        += carriedInstance.PhysicsState.GroundMovement;
                 }
             }
             carriedInstance.PhysicsState.Velocity = impulse;
             carriedInstance.PhysicsState.UpdateInstance();
             if (flag)
             {
                 this.PlayerManager.Action = ActionType.Idle;
             }
             else
             {
                 this.PlayerManager.PushedInstance = this.PlayerManager.CarriedInstance;
                 this.PlayerManager.Action         = ActionType.Grabbing;
             }
             this.PlayerManager.CarriedInstance = (TrileInstance)null;
             this.PhysicsManager.HugWalls((IPhysicsEntity)this.PlayerManager, false, false, true);
         }
         return(true);
     }
 }
Пример #3
0
        private void TryPushHorizontalStack(PickupState state, float elapsedSeconds)
        {
            TrileInstance trileInstance1 = state.Instance;
            TrileGroup    trileGroup     = state.Group;

            if (!BoxCollisionResultExtensions.AnyCollided(trileInstance1.PhysicsState.WallCollision))
            {
                return;
            }
            Vector3 vector3_1 = -FezMath.Sign(trileInstance1.PhysicsState.WallCollision.First.Response);

            trileInstance1.PhysicsState.Velocity = Vector3.Zero;
            TrileInstance instance = trileInstance1;

            while (instance != null && BoxCollisionResultExtensions.AnyCollided(instance.PhysicsState.WallCollision))
            {
                MultipleHits <CollisionResult> wallCollision = instance.PhysicsState.WallCollision;
                TrileInstance trileInstance2 = wallCollision.First.Destination;
                if (trileInstance2.PhysicsState != null && ActorTypeExtensions.IsPickable(trileInstance2.Trile.ActorSettings.Type) && (trileGroup == null || !trileGroup.Triles.Contains(trileInstance2)))
                {
                    Vector3 vector = -wallCollision.First.Response;
                    if (FezMath.Sign(vector) != vector3_1 || vector == Vector3.Zero)
                    {
                        instance = (TrileInstance)null;
                    }
                    else
                    {
                        instance = trileInstance2;
                        Vector3 velocity = instance.PhysicsState.Velocity;
                        instance.PhysicsState.Velocity = vector;
                        Vector3 center = instance.PhysicsState.Center;
                        if (instance.PhysicsState.Grounded)
                        {
                            instance.PhysicsState.Velocity += (float)(3.15000009536743 * (double)Math.Sign(this.CollisionManager.GravityFactor) * 0.150000005960464) * elapsedSeconds * Vector3.Down;
                        }
                        this.PhysicsManager.Update((ISimplePhysicsEntity)instance.PhysicsState, false, false);
                        if (trileInstance1.PhysicsState.Grounded)
                        {
                            instance.PhysicsState.Velocity = velocity;
                        }
                        instance.PhysicsState.UpdateInstance();
                        this.LevelManager.UpdateInstance(instance);
                        foreach (PickupState pickupState in this.PickupStates)
                        {
                            if (pickupState.Instance.PhysicsState.Ground.NearLow == instance || pickupState.Instance.PhysicsState.Ground.FarHigh == instance)
                            {
                                Vector3 vector3_2 = (instance.PhysicsState.Center - center) / 0.85f;
                                pickupState.Instance.PhysicsState.Velocity = vector3_2;
                            }
                        }
                    }
                }
                else
                {
                    instance = (TrileInstance)null;
                }
            }
        }
Пример #4
0
 public void DetermineInBackground(IPhysicsEntity entity, bool allowEnterInBackground, bool postRotation, bool keepInFront)
 {
     if (allowEnterInBackground)
     {
         if (entity is IComplexPhysicsEntity)
         {
             IComplexPhysicsEntity complexPhysicsEntity = entity as IComplexPhysicsEntity;
             Vector3      impulse = 1.0 / 32.0 * Vector3.Down;
             QueryOptions options = QueryOptions.None;
             if (complexPhysicsEntity.Background)
             {
                 options |= QueryOptions.Background;
             }
             bool flag = BoxCollisionResultExtensions.AnyHit(this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options));
             if (!flag)
             {
                 flag = flag | BoxCollisionResultExtensions.AnyHit(this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options, 0.0f, FezMath.GetOpposite(this.CameraManager.Viewpoint)));
             }
             if (complexPhysicsEntity.Grounded && !flag)
             {
                 this.DebuggingBag.Add("zz. had to re-clamp to ground", (object)"POSITIF");
                 MultipleHits <CollisionResult> result = this.CollisionManager.CollideEdge(entity.Center, impulse, entity.Size / 2f, Direction2D.Vertical, options, 0.0f, this.CameraManager.LastViewpoint);
                 if (BoxCollisionResultExtensions.AnyCollided(result))
                 {
                     this.ClampToGround(entity, new Vector3?(BoxCollisionResultExtensions.First(result).NearestDistance), this.CameraManager.LastViewpoint);
                 }
             }
         }
         entity.Background = false;
         PhysicsManager.WallHuggingResult wallHuggingResult;
         do
         {
             this.DetermineOverlapsInternal(entity, this.CameraManager.Viewpoint);
             wallHuggingResult = this.HugWalls(entity, true, postRotation, keepInFront);
         }while (wallHuggingResult.Hugged);
         entity.Background = wallHuggingResult.Behind;
         this.DetermineOverlapsInternal(entity, this.CameraManager.Viewpoint);
         this.HugWalls(entity, false, false, keepInFront);
     }
     else
     {
         if (!entity.Background)
         {
             return;
         }
         bool flag = true;
         foreach (PointCollision pointCollision in entity.CornerCollision)
         {
             flag = flag & !this.IsHuggable(pointCollision.Instances.Deep, entity);
         }
         if (!flag)
         {
             return;
         }
         entity.Background = false;
     }
 }
Пример #5
0
 public static bool AnyHit(this MultipleHits <CollisionResult> result)
 {
     if (result.NearLow.Destination == null)
     {
         return(result.FarHigh.Destination != null);
     }
     else
     {
         return(true);
     }
 }
Пример #6
0
 public static bool AnyCollided(this MultipleHits <CollisionResult> result)
 {
     if (!result.NearLow.Collided)
     {
         return(result.FarHigh.Collided);
     }
     else
     {
         return(true);
     }
 }
Пример #7
0
 public void CollideRectangle(Vector3 position, Vector3 impulse, Vector3 size, QueryOptions options, float elasticity, Viewpoint viewpoint, out MultipleHits<CollisionResult> horizontalResults, out MultipleHits<CollisionResult> verticalResults)
 {
   Vector3 impulse1 = viewpoint == Viewpoint.Front || viewpoint == Viewpoint.Back ? new Vector3(impulse.X, 0.0f, 0.0f) : new Vector3(0.0f, 0.0f, impulse.Z);
   Vector3 impulse2 = new Vector3(0.0f, impulse.Y, 0.0f);
   Vector3 halfSize = size / 2f;
   horizontalResults = this.CollideEdge(position, impulse1, halfSize, Direction2D.Horizontal, options, elasticity, viewpoint);
   verticalResults = this.CollideEdge(position, impulse2, halfSize, Direction2D.Vertical, options, elasticity, viewpoint);
   if ((options & QueryOptions.Simple) == QueryOptions.Simple || BoxCollisionResultExtensions.AnyCollided(horizontalResults) || BoxCollisionResultExtensions.AnyCollided(verticalResults))
     return;
   horizontalResults = this.CollideEdge(position + impulse2, impulse1, halfSize, Direction2D.Horizontal, options, elasticity, viewpoint);
   verticalResults = this.CollideEdge(position + impulse1, impulse2, halfSize, Direction2D.Vertical, options, elasticity, viewpoint);
 }
Пример #8
0
 protected override void TestConditions()
 {
     switch (this.PlayerManager.Action)
     {
     case ActionType.Jumping:
     case ActionType.Falling:
         HorizontalDirection lookingDirection = this.PlayerManager.LookingDirection;
         if (lookingDirection == HorizontalDirection.None)
         {
             break;
         }
         Vector3 vector3_1 = FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint);
         Vector3 b         = FezMath.RightVector(this.CameraManager.Viewpoint) * (float)FezMath.Sign(lookingDirection);
         if ((double)FezMath.Dot(this.PlayerManager.Velocity, b) <= 0.025000000372529 && (double)(this.InputManager.Movement.X * (float)FezMath.Sign(lookingDirection)) <= 0.100000001490116)
         {
             break;
         }
         MultipleHits <CollisionResult> wallCollision = this.PlayerManager.WallCollision;
         FaceOrientation visibleOrientation           = this.CameraManager.VisibleOrientation;
         TrileInstance   trileInstance1 = wallCollision.NearLow.Destination ?? this.PlayerManager.CornerCollision[1 + (lookingDirection == HorizontalDirection.Left ? 2 : 0)].Instances.Deep;
         TrileInstance   trileInstance2 = wallCollision.FarHigh.Destination ?? this.PlayerManager.CornerCollision[lookingDirection == HorizontalDirection.Left ? 2 : 0].Instances.Deep;
         Trile           trile          = trileInstance1 == null ? (Trile)null : trileInstance1.Trile;
         if (trileInstance1 == null || trileInstance1.GetRotatedFace(visibleOrientation) == CollisionType.None || (trile.ActorSettings.Type == ActorType.Ladder || trileInstance1 == trileInstance2) || (trileInstance2 != null && trileInstance2.GetRotatedFace(visibleOrientation) == CollisionType.AllSides || !trileInstance1.Enabled))
         {
             break;
         }
         TrileInstance trileInstance3 = this.LevelManager.ActualInstanceAt(trileInstance1.Center - b);
         TrileInstance trileInstance4 = this.LevelManager.NearestTrile(trileInstance1.Center - b).Deep;
         if (trileInstance4 != null && trileInstance4.Enabled && trileInstance4.GetRotatedFace(this.CameraManager.VisibleOrientation) != CollisionType.None || trileInstance3 != null && trileInstance3.Enabled && !trileInstance3.Trile.Immaterial || this.PlayerManager.Action == ActionType.Jumping && (double)((trileInstance1.Center - this.PlayerManager.LeaveGroundPosition) * vector3_1).Length() < 1.25 || trileInstance1.GetRotatedFace(visibleOrientation) != CollisionType.AllSides && BoxCollisionResultExtensions.AnyHit(this.CollisionManager.CollideEdge(trileInstance1.Center, Vector3.Down * (float)Math.Sign(this.CollisionManager.GravityFactor), this.PlayerManager.Size * FezMath.XZMask / 2f, Direction2D.Vertical)))
         {
             break;
         }
         Vector3 vector3_2 = (-b + Vector3.UnitY * (float)Math.Sign(this.CollisionManager.GravityFactor)) * trileInstance1.TransformedSize / 2f;
         if ((double)(this.PlayerManager.Center * vector3_1 - trileInstance1.Center * vector3_1 + vector3_2).Length() >= 0.349999994039536)
         {
             break;
         }
         this.PlayerManager.HeldInstance = trileInstance1;
         this.PlayerManager.Action       = ActionType.GrabCornerLedge;
         Waiters.Wait(0.1, (Action)(() =>
         {
             if (this.PlayerManager.HeldInstance == null)
             {
                 return;
             }
             SoundEffectExtensions.EmitAt(this.sound, this.PlayerManager.Position);
             this.InputManager.ActiveGamepad.Vibrate(VibrationMotor.LeftLow, 0.100000001490116, TimeSpan.FromSeconds(0.200000002980232));
             this.InputManager.ActiveGamepad.Vibrate(VibrationMotor.RightHigh, 0.400000005960464, TimeSpan.FromSeconds(0.200000002980232));
         }));
         break;
     }
 }
Пример #9
0
        private int FindStackSize(TrileInstance instance, int stackSize)
        {
            Vector3 halfSize = instance.TransformedSize / 2f - new Vector3(0.004f);
            MultipleHits <CollisionResult> result = this.CollisionManager.CollideEdge(instance.Center, instance.Trile.Size.Y * Vector3.Up, halfSize, Direction2D.Vertical);

            if (BoxCollisionResultExtensions.AnyCollided(result))
            {
                TrileInstance instance1 = result.First.Destination;
                if (instance1.PhysicsState != null && instance1.PhysicsState.Grounded)
                {
                    return(this.FindStackSize(instance1, stackSize + 1));
                }
            }
            return(stackSize);
        }
Пример #10
0
 public static CollisionResult First(this MultipleHits <CollisionResult> result)
 {
     if (result.NearLow.Collided)
     {
         return(result.NearLow);
     }
     if (!result.FarHigh.Collided)
     {
         return(new CollisionResult());
     }
     else
     {
         return(result.FarHigh);
     }
 }
Пример #11
0
 protected override void TestConditions()
 {
     switch (this.PlayerManager.Action)
     {
     case ActionType.CarryIdle:
     case ActionType.CarryWalk:
     case ActionType.CarryJump:
     case ActionType.CarrySlide:
     case ActionType.CarryHeavyIdle:
     case ActionType.CarryHeavyWalk:
     case ActionType.CarryHeavyJump:
     case ActionType.CarryHeavySlide:
         if (this.PlayerManager.Background || this.InputManager.GrabThrow != FezButtonState.Pressed || (double)this.InputManager.Movement.Y >= -0.5 && (double)Math.Abs(this.InputManager.Movement.X) >= 0.25)
         {
             break;
         }
         TrileInstance carriedInstance = this.PlayerManager.CarriedInstance;
         this.PlayerManager.Action = ActorTypeExtensions.IsLight(carriedInstance.Trile.ActorSettings.Type) ? ActionType.DropTrile : ActionType.DropHeavyTrile;
         Vector3 vector3_1 = FezMath.SideMask(this.CameraManager.Viewpoint);
         Vector3 vector3_2 = FezMath.RightVector(this.CameraManager.Viewpoint) * (float)FezMath.Sign(this.PlayerManager.LookingDirection);
         Vector3 vector3_3 = this.PlayerManager.Center + this.PlayerManager.Size / 2f * (Vector3.Down + vector3_2) - carriedInstance.TransformedSize / 2f * vector3_2 + carriedInstance.Trile.Size / 2f * (Vector3.UnitY + vector3_2) + 0.125f * vector3_2;
         carriedInstance.Enabled = false;
         MultipleHits <CollisionResult> result = this.CollisionManager.CollideEdge(carriedInstance.Center, vector3_3 - carriedInstance.Center, carriedInstance.TransformedSize / 2f, Direction2D.Horizontal);
         if (BoxCollisionResultExtensions.AnyCollided(result))
         {
             CollisionResult collisionResult = result.NearLow;
             if (!collisionResult.Collided || collisionResult.Destination.GetRotatedFace(this.CameraManager.VisibleOrientation) != CollisionType.AllSides || (double)Math.Abs(collisionResult.Destination.Center.Y - vector3_3.Y) >= 1.0)
             {
                 collisionResult = result.FarHigh;
             }
             if (collisionResult.Collided && collisionResult.Destination.GetRotatedFace(this.CameraManager.VisibleOrientation) == CollisionType.AllSides && (double)Math.Abs(collisionResult.Destination.Center.Y - vector3_3.Y) < 1.0)
             {
                 TrileInstance trileInstance = collisionResult.Destination;
                 Vector3       vector3_4     = trileInstance.Center - vector3_2 * trileInstance.TransformedSize / 2f;
                 Vector3       vector3_5     = vector3_3 + vector3_2 * carriedInstance.TransformedSize / 2f;
                 this.PlayerManager.Position -= vector3_1 * (vector3_5 - vector3_4);
             }
         }
         carriedInstance.Enabled = true;
         IPlayerManager playerManager = this.PlayerManager;
         Vector3        vector3_6     = playerManager.Velocity * Vector3.UnitY;
         playerManager.Velocity = vector3_6;
         break;
     }
 }
Пример #12
0
        public MultipleHits <CollisionResult> CollideEdge(Vector3 position, Vector3 impulse, Vector3 halfSize, Direction2D direction, QueryOptions options, float elasticity, Viewpoint viewpoint)
        {
            MultipleHits <CollisionResult> multipleHits = new MultipleHits <CollisionResult>();

            if (impulse == Vector3.Zero)
            {
                return(multipleHits);
            }
            bool    flag      = (options & QueryOptions.Simple) == QueryOptions.Simple;
            Vector3 vector3_1 = new Vector3((float)Math.Sign(impulse.X), (float)Math.Sign(impulse.Y), (float)Math.Sign(impulse.Z));

            if (!flag)
            {
                Vector3 position1 = position;
                Vector3 position2 = position;
                switch (direction)
                {
                case Direction2D.Horizontal:
                    position1 += (vector3_1 + Vector3.Down) * halfSize;
                    position2 += (vector3_1 + Vector3.Up) * halfSize;
                    break;

                case Direction2D.Vertical:
                    Vector3 vector3_2 = FezMath.RightVector(viewpoint) * (float)FezMath.Sign(this.PlayerManager.LookingDirection);
                    position1 += (vector3_1 - vector3_2) * halfSize;
                    position2 += (vector3_1 + vector3_2) * halfSize;
                    break;
                }
                multipleHits.NearLow = this.CollidePoint(position1, impulse, options, elasticity, viewpoint);
                multipleHits.FarHigh = this.CollidePoint(position2, impulse, options, elasticity, viewpoint);
            }
            if (flag || !multipleHits.NearLow.Collided)
            {
                Vector3 position1 = position + vector3_1 * halfSize;
                multipleHits.NearLow = this.CollidePoint(position1, impulse, options, elasticity, viewpoint);
            }
            return(multipleHits);
        }
Пример #13
0
        public void RecordRespawnInformation(bool markCheckpoint)
        {
            if (!this.Grounded && !this.Climbing && (this.action != ActionType.GrabCornerLedge && !ActionTypeExtensions.IsSwimming(this.action)) && this.action != ActionType.EnteringPipe)
            {
                return;
            }
            TrileInstance first = this.Ground.First;

            if (this.Climbing)
            {
                Vector3 vector3 = FezMath.SideMask(this.CameraManager.Viewpoint);
                this.LeaveGroundPosition = vector3 * FezMath.Floor(this.Position) + vector3 * 0.5f + Vector3.UnitY * ((float)(int)Math.Ceiling((double)this.Position.Y) + 0.5f) + (Vector3.One - vector3 - Vector3.UnitY) * this.Position;
            }
            else
            {
                this.LeaveGroundPosition = this.action == ActionType.GrabCornerLedge || ActionTypeExtensions.IsSwimming(this.action) || this.action == ActionType.EnteringPipe ? this.Position : first.Center + (float)((double)first.TransformedSize.Y / 2.0 + (double)this.Size.Y / 2.0) * Vector3.UnitY * (float)Math.Sign(this.CollisionManager.GravityFactor);
            }
            if (!ActionTypeExtensions.DisallowsRespawn(this.Action) && this.CarriedInstance == null && !this.Background && (!this.Grounded || first.PhysicsState == null && !first.Unsafe) && (this.HeldInstance == null || this.HeldInstance.PhysicsState == null) && (this.Grounded && ActorTypeExtensions.IsSafe(first.Trile.ActorSettings.Type) || this.Action == ActionType.GrabCornerLedge && this.HeldInstance != null && (!this.HeldInstance.Unsafe && ActorTypeExtensions.IsSafe(this.HeldInstance.Trile.ActorSettings.Type))))
            {
                this.LastGroundedAction           = this.Action;
                this.LastGroundedView             = this.CameraManager.Viewpoint;
                this.LastGroundedLookingDirection = this.LookingDirection;
                this.RespawnPosition  = this.LeaveGroundPosition;
                this.lastGround       = this.Ground;
                this.lastHeldInstance = this.HeldInstance;
            }
            if (!markCheckpoint && this.LastGroundedView != Viewpoint.None)
            {
                return;
            }
            this.GameState.SaveData.View      = this.CameraManager.Viewpoint;
            this.GameState.SaveData.TimeOfDay = this.TimeManager.CurrentTime.TimeOfDay;
            this.CheckpointGround             = first;
            this.GameState.SaveData.Ground    = this.CheckpointGround.Center;
            this.GameState.SaveData.Level     = this.LevelManager.Name;
        }
Пример #14
0
 public bool Update(ISimplePhysicsEntity entity, bool simple, bool keepInFront)
 {
   QueryOptions queryOptions = QueryOptions.None;
   if (entity.Background)
     queryOptions |= QueryOptions.Background;
   if (simple)
     queryOptions |= QueryOptions.Simple;
   if (entity is InstancePhysicsState)
     (entity as InstancePhysicsState).UpdatingPhysics = true;
   if (!simple)
     this.MoveAlongWithGround((IPhysicsEntity) entity, queryOptions);
   Vector3? clampToGroundDistance = new Vector3?();
   bool grounded = entity.Grounded;
   MultipleHits<CollisionResult> horizontalResults;
   MultipleHits<CollisionResult> verticalResults;
   if (!entity.IgnoreCollision)
   {
     this.CollisionManager.CollideRectangle(entity.Center, entity.Velocity, entity.Size, queryOptions, entity.Elasticity, out horizontalResults, out verticalResults);
     bool flag = (double) this.CollisionManager.GravityFactor < 0.0;
     FaceOrientation faceOrientation = this.CameraManager.VisibleOrientation;
     if (entity.Background)
       faceOrientation = FezMath.GetOpposite(faceOrientation);
     if ((flag ? ((double) entity.Velocity.Y > 0.0 ? 1 : 0) : ((double) entity.Velocity.Y < 0.0 ? 1 : 0)) != 0 && BoxCollisionResultExtensions.AnyCollided(verticalResults))
     {
       MultipleHits<TrileInstance> ground = entity.Ground;
       CollisionResult collisionResult1 = verticalResults.NearLow;
       CollisionResult collisionResult2 = verticalResults.FarHigh;
       if (collisionResult2.Destination != null && collisionResult2.Destination.GetRotatedFace(faceOrientation) != CollisionType.None)
       {
         ground.FarHigh = collisionResult2.Destination;
         if (collisionResult2.Collided && collisionResult2.ShouldBeClamped)
           clampToGroundDistance = new Vector3?(collisionResult2.NearestDistance);
       }
       else
         ground.FarHigh = (TrileInstance) null;
       if (collisionResult1.Destination != null && collisionResult1.Destination.GetRotatedFace(faceOrientation) != CollisionType.None)
       {
         ground.NearLow = collisionResult1.Destination;
         if (collisionResult1.Collided && collisionResult1.ShouldBeClamped)
           clampToGroundDistance = new Vector3?(collisionResult1.NearestDistance);
       }
       else
         ground.NearLow = (TrileInstance) null;
       entity.Ground = ground;
     }
     else
       entity.Ground = new MultipleHits<TrileInstance>();
   }
   else
   {
     horizontalResults = new MultipleHits<CollisionResult>();
     verticalResults = new MultipleHits<CollisionResult>();
   }
   bool flag1 = this.UpdateInternal((IPhysicsEntity) entity, horizontalResults, verticalResults, clampToGroundDistance, grounded, keepInFront, false, simple);
   if (entity is InstancePhysicsState)
     (entity as InstancePhysicsState).UpdatingPhysics = false;
   return flag1;
 }
Пример #15
0
        private bool UpdateInternal(IPhysicsEntity entity, MultipleHits <CollisionResult> horizontalResults, MultipleHits <CollisionResult> verticalResults, Vector3?clampToGroundDistance, bool wasGrounded, bool hugWalls, bool velocityIrrelevant, bool simple)
        {
            Vector3 velocity = entity.Velocity;

            if (!simple)
            {
                MultipleHits <CollisionResult> multipleHits = new MultipleHits <CollisionResult>();
                if (BoxCollisionResultExtensions.AnyCollided(horizontalResults))
                {
                    if (horizontalResults.NearLow.Collided)
                    {
                        multipleHits.NearLow = horizontalResults.NearLow;
                    }
                    if (horizontalResults.FarHigh.Collided)
                    {
                        multipleHits.FarHigh = horizontalResults.FarHigh;
                    }
                }
                entity.WallCollision = multipleHits;
            }
            if (horizontalResults.NearLow.Collided)
            {
                velocity += horizontalResults.NearLow.Response;
            }
            else if (horizontalResults.FarHigh.Collided)
            {
                velocity += horizontalResults.FarHigh.Response;
            }
            if (verticalResults.NearLow.Collided)
            {
                velocity += verticalResults.NearLow.Response;
            }
            else if (verticalResults.FarHigh.Collided)
            {
                velocity += verticalResults.FarHigh.Response;
            }
            Vector3 vector3_1 = !(entity is IComplexPhysicsEntity) || !(entity as IComplexPhysicsEntity).Swimming ? (entity.Grounded || wasGrounded ? (entity.Sliding ? PhysicsManager.SlidingFrictionV : PhysicsManager.GroundFrictionV) : PhysicsManager.AirFrictionV) : PhysicsManager.WaterFrictionV;
            float   amount    = (float)((1.20000004768372 + (double)Math.Abs(this.CollisionManager.GravityFactor) * 0.800000011920929) / 2.0);
            Vector3 vector3_2 = FezMath.AlmostClamp(velocity * Vector3.Lerp(Vector3.One, vector3_1, amount), 1E-06f);

            if (!entity.NoVelocityClamping)
            {
                float max = entity is IComplexPhysicsEntity ? 0.4f : 0.38f;
                vector3_2.Y = MathHelper.Clamp(vector3_2.Y, -max, max);
            }
            Vector3 center = entity.Center;
            Vector3 a      = center + vector3_2;
            bool    flag   = !FezMath.AlmostEqual(a, center);

            entity.Velocity = vector3_2;
            if (flag)
            {
                entity.Center = a;
            }
            if (velocityIrrelevant || flag)
            {
                this.DetermineInBackground(entity, false, false, hugWalls);
                this.ClampToGround(entity, clampToGroundDistance, this.CameraManager.Viewpoint);
                if (hugWalls)
                {
                    this.HugWalls(entity, false, false, true);
                }
            }
            if (!simple && (!(entity is ISimplePhysicsEntity) || !(entity as ISimplePhysicsEntity).IgnoreCollision))
            {
                if (this.LevelManager.IsInvalidatingScreen)
                {
                    this.ScheduleRedefineCorners(entity);
                }
                else
                {
                    this.RedefineCorners(entity);
                }
            }
            return(flag);
        }
Пример #16
0
 public void CollideRectangle(Vector3 position, Vector3 impulse, Vector3 size, QueryOptions options, out MultipleHits <CollisionResult> horizontalResults, out MultipleHits <CollisionResult> verticalResults)
 {
     this.CollideRectangle(position, impulse, size, options, 0.0f, out horizontalResults, out verticalResults);
 }
Пример #17
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));
        }
Пример #18
0
        public bool Update(ISimplePhysicsEntity entity, bool simple, bool keepInFront)
        {
            QueryOptions queryOptions = QueryOptions.None;

            if (entity.Background)
            {
                queryOptions |= QueryOptions.Background;
            }
            if (simple)
            {
                queryOptions |= QueryOptions.Simple;
            }
            if (entity is InstancePhysicsState)
            {
                (entity as InstancePhysicsState).UpdatingPhysics = true;
            }
            if (!simple)
            {
                this.MoveAlongWithGround((IPhysicsEntity)entity, queryOptions);
            }
            Vector3?clampToGroundDistance = new Vector3?();
            bool    grounded = entity.Grounded;
            MultipleHits <CollisionResult> horizontalResults;
            MultipleHits <CollisionResult> verticalResults;

            if (!entity.IgnoreCollision)
            {
                this.CollisionManager.CollideRectangle(entity.Center, entity.Velocity, entity.Size, queryOptions, entity.Elasticity, out horizontalResults, out verticalResults);
                bool            flag            = (double)this.CollisionManager.GravityFactor < 0.0;
                FaceOrientation faceOrientation = this.CameraManager.VisibleOrientation;
                if (entity.Background)
                {
                    faceOrientation = FezMath.GetOpposite(faceOrientation);
                }
                if ((flag ? ((double)entity.Velocity.Y > 0.0 ? 1 : 0) : ((double)entity.Velocity.Y < 0.0 ? 1 : 0)) != 0 && BoxCollisionResultExtensions.AnyCollided(verticalResults))
                {
                    MultipleHits <TrileInstance> ground = entity.Ground;
                    CollisionResult collisionResult1    = verticalResults.NearLow;
                    CollisionResult collisionResult2    = verticalResults.FarHigh;
                    if (collisionResult2.Destination != null && collisionResult2.Destination.GetRotatedFace(faceOrientation) != CollisionType.None)
                    {
                        ground.FarHigh = collisionResult2.Destination;
                        if (collisionResult2.Collided && collisionResult2.ShouldBeClamped)
                        {
                            clampToGroundDistance = new Vector3?(collisionResult2.NearestDistance);
                        }
                    }
                    else
                    {
                        ground.FarHigh = (TrileInstance)null;
                    }
                    if (collisionResult1.Destination != null && collisionResult1.Destination.GetRotatedFace(faceOrientation) != CollisionType.None)
                    {
                        ground.NearLow = collisionResult1.Destination;
                        if (collisionResult1.Collided && collisionResult1.ShouldBeClamped)
                        {
                            clampToGroundDistance = new Vector3?(collisionResult1.NearestDistance);
                        }
                    }
                    else
                    {
                        ground.NearLow = (TrileInstance)null;
                    }
                    entity.Ground = ground;
                }
                else
                {
                    entity.Ground = new MultipleHits <TrileInstance>();
                }
            }
            else
            {
                horizontalResults = new MultipleHits <CollisionResult>();
                verticalResults   = new MultipleHits <CollisionResult>();
            }
            bool flag1 = this.UpdateInternal((IPhysicsEntity)entity, horizontalResults, verticalResults, clampToGroundDistance, grounded, keepInFront, false, simple);

            if (entity is InstancePhysicsState)
            {
                (entity as InstancePhysicsState).UpdatingPhysics = false;
            }
            return(flag1);
        }
Пример #19
0
 public void CollideRectangle(Vector3 position, Vector3 impulse, Vector3 size, QueryOptions options, float elasticity, out MultipleHits <CollisionResult> horizontalResults, out MultipleHits <CollisionResult> verticalResults)
 {
     this.CollideRectangle(position, impulse, size, options, elasticity, this.CameraManager.Viewpoint, out horizontalResults, out verticalResults);
 }
Пример #20
0
 private bool UpdateInternal(IPhysicsEntity entity, MultipleHits<CollisionResult> horizontalResults, MultipleHits<CollisionResult> verticalResults, Vector3? clampToGroundDistance, bool wasGrounded, bool hugWalls, bool velocityIrrelevant, bool simple)
 {
   Vector3 velocity = entity.Velocity;
   if (!simple)
   {
     MultipleHits<CollisionResult> multipleHits = new MultipleHits<CollisionResult>();
     if (BoxCollisionResultExtensions.AnyCollided(horizontalResults))
     {
       if (horizontalResults.NearLow.Collided)
         multipleHits.NearLow = horizontalResults.NearLow;
       if (horizontalResults.FarHigh.Collided)
         multipleHits.FarHigh = horizontalResults.FarHigh;
     }
     entity.WallCollision = multipleHits;
   }
   if (horizontalResults.NearLow.Collided)
     velocity += horizontalResults.NearLow.Response;
   else if (horizontalResults.FarHigh.Collided)
     velocity += horizontalResults.FarHigh.Response;
   if (verticalResults.NearLow.Collided)
     velocity += verticalResults.NearLow.Response;
   else if (verticalResults.FarHigh.Collided)
     velocity += verticalResults.FarHigh.Response;
   Vector3 vector3_1 = !(entity is IComplexPhysicsEntity) || !(entity as IComplexPhysicsEntity).Swimming ? (entity.Grounded || wasGrounded ? (entity.Sliding ? PhysicsManager.SlidingFrictionV : PhysicsManager.GroundFrictionV) : PhysicsManager.AirFrictionV) : PhysicsManager.WaterFrictionV;
   float amount = (float) ((1.20000004768372 + (double) Math.Abs(this.CollisionManager.GravityFactor) * 0.800000011920929) / 2.0);
   Vector3 vector3_2 = FezMath.AlmostClamp(velocity * Vector3.Lerp(Vector3.One, vector3_1, amount), 1E-06f);
   if (!entity.NoVelocityClamping)
   {
     float max = entity is IComplexPhysicsEntity ? 0.4f : 0.38f;
     vector3_2.Y = MathHelper.Clamp(vector3_2.Y, -max, max);
   }
   Vector3 center = entity.Center;
   Vector3 a = center + vector3_2;
   bool flag = !FezMath.AlmostEqual(a, center);
   entity.Velocity = vector3_2;
   if (flag)
     entity.Center = a;
   if (velocityIrrelevant || flag)
   {
     this.DetermineInBackground(entity, false, false, hugWalls);
     this.ClampToGround(entity, clampToGroundDistance, this.CameraManager.Viewpoint);
     if (hugWalls)
       this.HugWalls(entity, false, false, true);
   }
   if (!simple && (!(entity is ISimplePhysicsEntity) || !(entity as ISimplePhysicsEntity).IgnoreCollision))
   {
     if (this.LevelManager.IsInvalidatingScreen)
       this.ScheduleRedefineCorners(entity);
     else
       this.RedefineCorners(entity);
   }
   return flag;
 }
Пример #21
0
 public void CollideRectangle(Vector3 position, Vector3 impulse, Vector3 size, QueryOptions options, float elasticity, out MultipleHits<CollisionResult> horizontalResults, out MultipleHits<CollisionResult> verticalResults)
 {
   this.CollideRectangle(position, impulse, size, options, elasticity, this.CameraManager.Viewpoint, out horizontalResults, out verticalResults);
 }
Пример #22
0
 public MultipleHits<CollisionResult> CollideEdge(Vector3 position, Vector3 impulse, Vector3 halfSize, Direction2D direction, QueryOptions options, float elasticity, Viewpoint viewpoint)
 {
   MultipleHits<CollisionResult> multipleHits = new MultipleHits<CollisionResult>();
   if (impulse == Vector3.Zero)
     return multipleHits;
   bool flag = (options & QueryOptions.Simple) == QueryOptions.Simple;
   Vector3 vector3_1 = new Vector3((float) Math.Sign(impulse.X), (float) Math.Sign(impulse.Y), (float) Math.Sign(impulse.Z));
   if (!flag)
   {
     Vector3 position1 = position;
     Vector3 position2 = position;
     switch (direction)
     {
       case Direction2D.Horizontal:
         position1 += (vector3_1 + Vector3.Down) * halfSize;
         position2 += (vector3_1 + Vector3.Up) * halfSize;
         break;
       case Direction2D.Vertical:
         Vector3 vector3_2 = FezMath.RightVector(viewpoint) * (float) FezMath.Sign(this.PlayerManager.LookingDirection);
         position1 += (vector3_1 - vector3_2) * halfSize;
         position2 += (vector3_1 + vector3_2) * halfSize;
         break;
     }
     multipleHits.NearLow = this.CollidePoint(position1, impulse, options, elasticity, viewpoint);
     multipleHits.FarHigh = this.CollidePoint(position2, impulse, options, elasticity, viewpoint);
   }
   if (flag || !multipleHits.NearLow.Collided)
   {
     Vector3 position1 = position + vector3_1 * halfSize;
     multipleHits.NearLow = this.CollidePoint(position1, impulse, options, elasticity, viewpoint);
   }
   return multipleHits;
 }
Пример #23
0
        public void CollideRectangle(Vector3 position, Vector3 impulse, Vector3 size, QueryOptions options, float elasticity, Viewpoint viewpoint, out MultipleHits <CollisionResult> horizontalResults, out MultipleHits <CollisionResult> verticalResults)
        {
            Vector3 impulse1 = viewpoint == Viewpoint.Front || viewpoint == Viewpoint.Back ? new Vector3(impulse.X, 0.0f, 0.0f) : new Vector3(0.0f, 0.0f, impulse.Z);
            Vector3 impulse2 = new Vector3(0.0f, impulse.Y, 0.0f);
            Vector3 halfSize = size / 2f;

            horizontalResults = this.CollideEdge(position, impulse1, halfSize, Direction2D.Horizontal, options, elasticity, viewpoint);
            verticalResults   = this.CollideEdge(position, impulse2, halfSize, Direction2D.Vertical, options, elasticity, viewpoint);
            if ((options & QueryOptions.Simple) == QueryOptions.Simple || BoxCollisionResultExtensions.AnyCollided(horizontalResults) || BoxCollisionResultExtensions.AnyCollided(verticalResults))
            {
                return;
            }
            horizontalResults = this.CollideEdge(position + impulse2, impulse1, halfSize, Direction2D.Horizontal, options, elasticity, viewpoint);
            verticalResults   = this.CollideEdge(position + impulse1, impulse2, halfSize, Direction2D.Vertical, options, elasticity, viewpoint);
        }
Пример #24
0
        protected override bool Act(TimeSpan elapsed)
        {
            ClimbingApproach approach;
            TrileInstance    trileInstance1 = this.IsOnLadder(out approach);

            this.PlayerManager.HeldInstance = trileInstance1;
            if (trileInstance1 == null || this.currentApproach == ClimbingApproach.None)
            {
                this.PlayerManager.Action = ActionType.Idle;
                return(false);
            }
            else
            {
                this.lastGrabbed     = trileInstance1;
                this.sinceGrabbed    = TimeSpan.Zero;
                this.currentApproach = approach;
                this.RefreshPlayerAction();
                this.RefreshPlayerDirection();
                this.PlayerManager.Position = this.PlayerManager.Position * Vector3.UnitY + (trileInstance1.Position + FezMath.HalfVector) * FezMath.XZMask;
                Vector3 vector3_1 = (float)((double)this.InputManager.Movement.Y * 4.69999980926514 * 0.425000011920929) * (float)elapsed.TotalSeconds * Vector3.UnitY;
                Vector3 b         = FezMath.ForwardVector(this.CameraManager.Viewpoint) * (this.PlayerManager.Background ? -1f : 1f);
                if ((double)this.PlayerManager.Center.Y < (double)this.LevelManager.Size.Y - 1.0 && (double)this.PlayerManager.Center.Y > 1.0)
                {
                    QueryOptions  options        = this.PlayerManager.Background ? QueryOptions.Background : QueryOptions.None;
                    NearestTriles nearestTriles1 = this.LevelManager.NearestTrile(this.PlayerManager.Center + Vector3.Down, options);
                    NearestTriles nearestTriles2 = this.LevelManager.NearestTrile(this.PlayerManager.Center + vector3_1, options);
                    NearestTriles nearestTriles3 = this.LevelManager.NearestTrile(this.PlayerManager.Center + vector3_1 + FezMath.Sign(vector3_1) * new Vector3(0.0f, 0.5f, 0.0f), options);
                    bool          flag           = false;
                    if ((nearestTriles2.Surface == null || (flag = nearestTriles3.Deep != null && (double)FezMath.Dot(this.PlayerManager.Position, b) > (double)FezMath.Dot(nearestTriles3.Deep.Center, b))) && (nearestTriles1.Deep == null || nearestTriles1.Deep.GetRotatedFace(this.PlayerManager.Background ? this.CameraManager.VisibleOrientation : FezMath.GetOpposite(this.CameraManager.VisibleOrientation)) == CollisionType.None))
                    {
                        vector3_1 = Vector3.Zero;
                        if (!flag && (this.PlayerManager.LookingDirection == HorizontalDirection.Left && FezButtonStateExtensions.IsDown(this.InputManager.Left) || this.PlayerManager.LookingDirection == HorizontalDirection.Right && FezButtonStateExtensions.IsDown(this.InputManager.Right)))
                        {
                            if (nearestTriles2.Deep == null || nearestTriles1.Surface == null)
                            {
                                this.PlayerManager.Action = ActionType.ClimbOverLadder;
                                return(false);
                            }
                            else if ((double)FezMath.Dot(nearestTriles2.Deep.Center, b) > (double)FezMath.Dot(nearestTriles1.Surface.Center, b))
                            {
                                this.PlayerManager.Action = ActionType.ClimbOverLadder;
                                return(false);
                            }
                        }
                    }
                }
                float num1  = (float)((double)FezMath.Saturate(Math.Abs((float)((double)this.PlayerManager.Animation.Timing.NormalizedStep * 2.0 % 1.0 - 0.5))) * 1.39999997615814 + 0.25);
                int   frame = this.PlayerManager.Animation.Timing.Frame;
                if (this.lastFrame != frame)
                {
                    if (frame == 1 || frame == 4)
                    {
                        SoundEffectExtensions.EmitAt(this.climbSound, this.PlayerManager.Position);
                    }
                    this.lastFrame = frame;
                }
                this.PlayerManager.Velocity = vector3_1 * num1;
                if (trileInstance1.PhysicsState != null)
                {
                    IPlayerManager playerManager = this.PlayerManager;
                    Vector3        vector3_2     = playerManager.Velocity + trileInstance1.PhysicsState.Velocity;
                    playerManager.Velocity = vector3_2;
                }
                int num2 = Math.Sign(vector3_1.Y);
                this.PlayerManager.Animation.Timing.Update(elapsed, (float)num2);
                this.PlayerManager.GroundedVelocity = new Vector3?(this.PlayerManager.Velocity);
                MultipleHits <CollisionResult> multipleHits = this.CollisionManager.CollideEdge(this.PlayerManager.Center, vector3_1, this.PlayerManager.Size / 2f, Direction2D.Vertical);
                if ((double)vector3_1.Y < 0.0 && (multipleHits.NearLow.Collided || multipleHits.FarHigh.Collided))
                {
                    TrileInstance trileInstance2 = this.LevelManager.NearestTrile(multipleHits.First.Destination.Center).Surface;
                    if (trileInstance2 != null && trileInstance2.Trile.ActorSettings.Type == ActorType.Ladder && this.currentApproach == ClimbingApproach.Back)
                    {
                        IPlayerManager playerManager = this.PlayerManager;
                        Vector3        vector3_2     = playerManager.Center + vector3_1;
                        playerManager.Center = vector3_2;
                    }
                    else
                    {
                        this.lastGrabbed = (TrileInstance)null;
                        this.PlayerManager.HeldInstance = (TrileInstance)null;
                        this.PlayerManager.Action       = ActionType.Falling;
                    }
                }
                return(false);
            }
        }
Пример #25
0
        public void Update(TimeSpan elapsed)
        {
            if (!this.moving)
            {
                if (this.velocityNeedsReset)
                {
                    foreach (TrileInstance trileInstance in this.group.Triles)
                    {
                        trileInstance.PhysicsState.Velocity = Vector3.Zero;
                    }
                    this.velocityNeedsReset = false;
                }
                bool flag = false;
                foreach (TrileInstance trileInstance in this.bottomTriles)
                {
                    TrileInstance first = trileInstance.PhysicsState.Ground.First;
                    flag = ((flag ? 1 : 0) | (first == null || !first.Enabled ? 0 : (first.PhysicsState == null ? 1 : (first.PhysicsState.Grounded ? 1 : 0)))) != 0;
                }
                if (!flag)
                {
                    this.moving = true;
                    foreach (TrileInstance trileInstance in this.group.Triles)
                    {
                        trileInstance.PhysicsState.Ground = new MultipleHits <TrileInstance>();
                        trileInstance.IsMovingGroup       = true;
                    }
                }
            }
            if (!this.moving)
            {
                return;
            }
            Vector3 vector3_1 = 0.4725f * (float)elapsed.TotalSeconds * -Vector3.UnitY;

            foreach (TrileInstance trileInstance in this.group.Triles)
            {
                trileInstance.PhysicsState.UpdatingPhysics = true;
            }
            bool    flag1     = false;
            Vector3 vector3_2 = Vector3.Zero;

            foreach (TrileInstance trileInstance in this.bottomTriles)
            {
                MultipleHits <CollisionResult> multipleHits = this.CollisionManager.CollideEdge(trileInstance.Center, trileInstance.PhysicsState.Velocity + vector3_1, trileInstance.TransformedSize / 2f, Direction2D.Vertical);
                if (multipleHits.First.Collided)
                {
                    flag1     = true;
                    vector3_2 = Vector3.Max(vector3_2, multipleHits.First.Response);
                }
            }
            Vector3 vector3_3 = vector3_1 + vector3_2;

            foreach (TrileInstance instance in this.group.Triles)
            {
                instance.Position += instance.PhysicsState.Velocity += vector3_3;
                this.LevelManager.UpdateInstance(instance);
                instance.PhysicsState.UpdatingPhysics = false;
            }
            if (!flag1)
            {
                return;
            }
            this.MarkGrounds();
            this.moving             = false;
            this.velocityNeedsReset = true;
        }
Пример #26
0
 public void CollideRectangle(Vector3 position, Vector3 impulse, Vector3 size, QueryOptions options, out MultipleHits<CollisionResult> horizontalResults, out MultipleHits<CollisionResult> verticalResults)
 {
   this.CollideRectangle(position, impulse, size, options, 0.0f, out horizontalResults, out verticalResults);
 }
Пример #27
0
        protected override bool Act(TimeSpan elapsed)
        {
            ClimbingApproach approach;
            TrileInstance    trileInstance1 = this.IsOnVine(out approach);

            this.PlayerManager.HeldInstance = trileInstance1;
            if (trileInstance1 == null || this.currentApproach == ClimbingApproach.None)
            {
                this.PlayerManager.Action = ActionType.Idle;
                return(false);
            }
            else
            {
                this.lastGrabbed  = trileInstance1;
                this.sinceGrabbed = TimeSpan.Zero;
                if ((this.currentApproach == ClimbingApproach.Back || this.currentApproach == ClimbingApproach.Front) && (approach == ClimbingApproach.Right || approach == ClimbingApproach.Left))
                {
                    this.currentApproach = approach;
                }
                if (this.PlayerManager.Action == ActionType.SideClimbingVine && (double)Math.Abs(this.InputManager.Movement.X) > 0.5)
                {
                    Vector3       vector3       = (float)Math.Sign(this.InputManager.Movement.X) * FezMath.RightVector(this.CameraManager.Viewpoint);
                    NearestTriles nearestTriles = this.LevelManager.NearestTrile(this.PlayerManager.Position + vector3);
                    if (nearestTriles.Surface != null && nearestTriles.Surface.Trile.ActorSettings.Type == ActorType.Vine)
                    {
                        this.PlayerManager.Position += vector3 * 0.1f;
                        this.PlayerManager.ForceOverlapsDetermination();
                        trileInstance1 = this.IsOnVine(out this.currentApproach);
                        this.PlayerManager.HeldInstance = trileInstance1;
                    }
                }
                if (trileInstance1 == null || this.currentApproach == ClimbingApproach.None)
                {
                    this.PlayerManager.Action = ActionType.Idle;
                    return(false);
                }
                else
                {
                    this.RefreshPlayerAction(false);
                    this.RefreshPlayerDirection(false);
                    Vector3 vector3_1 = trileInstance1.Position + FezMath.HalfVector;
                    Vector3 vector3_2 = Vector3.Zero;
                    switch (this.currentApproach)
                    {
                    case ClimbingApproach.Right:
                    case ClimbingApproach.Left:
                        TrileInstance trileInstance2 = this.LevelManager.ActualInstanceAt(this.PlayerManager.Position);
                        vector3_2 = trileInstance2 == null || trileInstance2.Trile.ActorSettings.Type != ActorType.Vine ? FezMath.XZMask : FezMath.SideMask(this.CameraManager.Viewpoint);
                        break;

                    case ClimbingApproach.Back:
                    case ClimbingApproach.Front:
                        vector3_2 = FezMath.DepthMask(this.CameraManager.Viewpoint);
                        break;
                    }
                    this.PlayerManager.Position = this.PlayerManager.Position * (Vector3.One - vector3_2) + vector3_1 * vector3_2;
                    Vector2 vector2 = this.InputManager.Movement * 4.7f * 0.475f * (float)elapsed.TotalSeconds;
                    Vector3 vector  = Vector3.Zero;
                    if (this.PlayerManager.Action != ActionType.SideClimbingVine)
                    {
                        vector = Vector3.Transform(Vector3.UnitX * vector2.X * 0.75f, this.CameraManager.Rotation);
                    }
                    Vector3         impulse        = vector2.Y * Vector3.UnitY;
                    QueryOptions    options        = this.PlayerManager.Background ? QueryOptions.Background : QueryOptions.None;
                    FaceOrientation face           = this.PlayerManager.Background ? this.CameraManager.VisibleOrientation : FezMath.GetOpposite(this.CameraManager.VisibleOrientation);
                    NearestTriles   nearestTriles1 = this.LevelManager.NearestTrile(this.PlayerManager.Center + Vector3.Down * 1.5f + this.PlayerManager.Size / 2f * FezMath.Sign(vector), options);
                    NearestTriles   nearestTriles2 = this.LevelManager.NearestTrile(this.PlayerManager.Center + vector * 2f, options);
                    if ((nearestTriles2.Surface == null || nearestTriles2.Surface.Trile.ActorSettings.Type != ActorType.Vine) && (nearestTriles1.Deep == null || nearestTriles1.Deep.GetRotatedFace(face) == CollisionType.None))
                    {
                        vector = Vector3.Zero;
                    }
                    nearestTriles1 = this.LevelManager.NearestTrile(this.PlayerManager.Center + this.PlayerManager.Size / 2f * Vector3.Down, options);
                    NearestTriles nearestTriles3 = this.LevelManager.NearestTrile(this.PlayerManager.Center + impulse * 2f, options);
                    if ((nearestTriles3.Surface == null || nearestTriles3.Surface.Trile.ActorSettings.Type != ActorType.Vine) && (nearestTriles1.Deep == null || nearestTriles1.Deep.GetRotatedFace(face) == CollisionType.None))
                    {
                        impulse = Vector3.Zero;
                        if (FezButtonStateExtensions.IsDown(this.InputManager.Up))
                        {
                            Vector3       vector3_3      = FezMath.RightVector(this.CameraManager.Viewpoint) * (float)FezMath.Sign(this.PlayerManager.LookingDirection);
                            TrileInstance trileInstance3 = this.LevelManager.NearestTrile(trileInstance1.Center + vector3_3 * 0.5f + vector3_3 * trileInstance1.TransformedSize / 2f).Deep;
                            if (trileInstance3 != null && !trileInstance3.Trile.Immaterial && (trileInstance3.Enabled && trileInstance3.GetRotatedFace(face) != CollisionType.None))
                            {
                                TrileInstance trileInstance4 = this.LevelManager.ActualInstanceAt(trileInstance3.Position - vector3_3 + new Vector3(0.5f));
                                TrileInstance trileInstance5 = this.LevelManager.NearestTrile(trileInstance3.Position - vector3_3 + new Vector3(0.5f)).Deep;
                                if ((trileInstance5 == null || !trileInstance5.Enabled || trileInstance5.GetRotatedFace(this.CameraManager.VisibleOrientation) == CollisionType.None) && (trileInstance4 == null || !trileInstance4.Enabled || trileInstance4.Trile.Immaterial))
                                {
                                    this.PlayerManager.HeldInstance = trileInstance3;
                                    this.PlayerManager.Action       = ActionType.GrabCornerLedge;
                                    Vector3 vector3_4 = (-vector3_3 + Vector3.UnitY) * trileInstance3.TransformedSize / 2f;
                                    this.PlayerManager.Position = trileInstance3.Center + vector3_4;
                                    this.PlayerManager.ForceOverlapsDetermination();
                                    return(false);
                                }
                            }
                        }
                    }
                    float num1  = (float)((double)FezMath.Saturate(Math.Abs((float)((double)this.PlayerManager.Animation.Timing.NormalizedStep * 2.0 % 1.0 - 0.5))) * 1.39999997615814 + 0.25);
                    float num2  = FezMath.Saturate(Math.Abs((float)(((double)this.PlayerManager.Animation.Timing.NormalizedStep + 0.300000011920929) % 1.0))) + 0.2f;
                    int   frame = this.PlayerManager.Animation.Timing.Frame;
                    if (this.lastFrame != frame)
                    {
                        bool flag = (double)Math.Abs(this.InputManager.Movement.Y) < 0.5;
                        if (flag && frame == 0 || !flag && (frame == 1 || frame == 4))
                        {
                            SoundEffectExtensions.EmitAt(this.climbSound, this.PlayerManager.Position, RandomHelper.Between(-0.100000001490116, 0.100000001490116), RandomHelper.Between(0.899999976158142, 1.0));
                        }
                        this.lastFrame = frame;
                    }
                    this.PlayerManager.Velocity = vector * num2 + impulse * num1;
                    if (trileInstance1.PhysicsState != null)
                    {
                        IPlayerManager playerManager = this.PlayerManager;
                        Vector3        vector3_3     = playerManager.Velocity + trileInstance1.PhysicsState.Velocity;
                        playerManager.Velocity = vector3_3;
                    }
                    float timeFactor = impulse == Vector3.Zero ? 0.0f : Math.Abs(this.InputManager.Movement.Y);
                    if (this.PlayerManager.Action != ActionType.SideClimbingVine)
                    {
                        timeFactor = vector == Vector3.Zero ? timeFactor : FezMath.Saturate(timeFactor + Math.Abs(this.InputManager.Movement.X));
                    }
                    this.PlayerManager.Animation.Timing.Update(elapsed, timeFactor);
                    this.PlayerManager.GroundedVelocity = new Vector3?(this.PlayerManager.Velocity);
                    MultipleHits <CollisionResult> multipleHits = this.CollisionManager.CollideEdge(this.PlayerManager.Center, impulse, this.PlayerManager.Size / 2f, Direction2D.Vertical);
                    if ((double)impulse.Y < 0.0 && (multipleHits.NearLow.Collided || multipleHits.FarHigh.Collided) && multipleHits.First.Destination.GetRotatedFace(this.CameraManager.VisibleOrientation) != CollisionType.None)
                    {
                        this.lastGrabbed = (TrileInstance)null;
                        this.PlayerManager.HeldInstance = (TrileInstance)null;
                        this.PlayerManager.Action       = ActionType.Falling;
                    }
                    return(false);
                }
            }
        }
Пример #28
0
 public void RecordRespawnInformation(bool markCheckpoint)
 {
   if (!this.Grounded && !this.Climbing && (this.action != ActionType.GrabCornerLedge && !ActionTypeExtensions.IsSwimming(this.action)) && this.action != ActionType.EnteringPipe)
     return;
   TrileInstance first = this.Ground.First;
   if (this.Climbing)
   {
     Vector3 vector3 = FezMath.SideMask(this.CameraManager.Viewpoint);
     this.LeaveGroundPosition = vector3 * FezMath.Floor(this.Position) + vector3 * 0.5f + Vector3.UnitY * ((float) (int) Math.Ceiling((double) this.Position.Y) + 0.5f) + (Vector3.One - vector3 - Vector3.UnitY) * this.Position;
   }
   else
     this.LeaveGroundPosition = this.action == ActionType.GrabCornerLedge || ActionTypeExtensions.IsSwimming(this.action) || this.action == ActionType.EnteringPipe ? this.Position : first.Center + (float) ((double) first.TransformedSize.Y / 2.0 + (double) this.Size.Y / 2.0) * Vector3.UnitY * (float) Math.Sign(this.CollisionManager.GravityFactor);
   if (!ActionTypeExtensions.DisallowsRespawn(this.Action) && this.CarriedInstance == null && !this.Background && (!this.Grounded || first.PhysicsState == null && !first.Unsafe) && (this.HeldInstance == null || this.HeldInstance.PhysicsState == null) && (this.Grounded && ActorTypeExtensions.IsSafe(first.Trile.ActorSettings.Type) || this.Action == ActionType.GrabCornerLedge && this.HeldInstance != null && (!this.HeldInstance.Unsafe && ActorTypeExtensions.IsSafe(this.HeldInstance.Trile.ActorSettings.Type))))
   {
     this.LastGroundedAction = this.Action;
     this.LastGroundedView = this.CameraManager.Viewpoint;
     this.LastGroundedLookingDirection = this.LookingDirection;
     this.RespawnPosition = this.LeaveGroundPosition;
     this.lastGround = this.Ground;
     this.lastHeldInstance = this.HeldInstance;
   }
   if (!markCheckpoint && this.LastGroundedView != Viewpoint.None)
     return;
   this.GameState.SaveData.View = this.CameraManager.Viewpoint;
   this.GameState.SaveData.TimeOfDay = this.TimeManager.CurrentTime.TimeOfDay;
   this.CheckpointGround = first;
   this.GameState.SaveData.Ground = this.CheckpointGround.Center;
   this.GameState.SaveData.Level = this.LevelManager.Name;
 }
Пример #29
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();
        }