コード例 #1
0
        private static int Player_DreamDashUpdate(On.Celeste.Player.orig_DreamDashUpdate orig, Player self)
        {
            CustomDreamBlockV2 currentDreamBlock = self.CollideFirst <CustomDreamBlockV2>();

            if (currentDreamBlock != null)
            {
                var dyn = new DynData <Player>(self);

                if (!currentDreamBlock.ConserveSpeed)
                {
                    float lastDreamSpeed = dyn.Get <float>("lastDreamSpeed");
                    if (lastDreamSpeed != currentDreamBlock.DashSpeed)
                    {
                        self.Speed = self.DashDir * currentDreamBlock.DashSpeed;
                        dyn.Set("lastDreamSpeed", currentDreamBlock.DashSpeed * 1f);
                    }
                }

                // Redirects
                if (currentDreamBlock.AllowRedirects && self.CanDash)
                {
                    Vector2 aimVector = Input.GetAimVector(Facings.Right);
                    bool    sameDir   = aimVector == self.DashDir;
                    if (!sameDir || currentDreamBlock.AllowRedirectsInSameDir)
                    {
                        self.DashDir = aimVector;
                        self.Speed   = self.DashDir * self.Speed.Length();
                        self.Dashes  = Math.Max(0, self.Dashes - 1);
                        Audio.Play("event:/char/madeline/dreamblock_enter");
                        if (sameDir)
                        {
                            self.Speed   *= currentDreamBlock.SameDirectionSpeedMultiplier;
                            self.DashDir *= Math.Sign(currentDreamBlock.SameDirectionSpeedMultiplier);
                        }
                        Input.Dash.ConsumeBuffer();
                        Input.Dash.ConsumePress();
                        Input.CrouchDash.ConsumeBuffer();
                        Input.CrouchDash.ConsumePress();
                    }
                }
            }
            return(orig(self));
        }
コード例 #2
0
        private static void Player_DreamDashBegin(ILContext il)
        {
            ILCursor cursor = new ILCursor(il);

            while (cursor.TryGotoNext(MoveType.After, instr => instr.MatchStfld <Player>("Speed")))
            {
                cursor.Index--;
                cursor.Emit(OpCodes.Ldarg_0);
                cursor.EmitDelegate <Func <Vector2, Player, Vector2> >((origSpeed, player) =>
                {
                    CustomDreamBlockV2 currentDreamBlock = player.CollideFirst <CustomDreamBlockV2>(player.Position + Vector2.UnitX * Math.Sign(player.Speed.X)) ?? player.CollideFirst <CustomDreamBlockV2>(player.Position + Vector2.UnitY * Math.Sign(player.Speed.Y));
                    if (currentDreamBlock != null && currentDreamBlock.ConserveSpeed)
                    {
                        var newSpeed = player.Speed * Math.Sign(currentDreamBlock.DashSpeed);
                        //player.DashDir = newSpeed.SafeNormalize();
                        return(newSpeed);
                    }
                    return(origSpeed);
                });

                break;
            }
        }