예제 #1
0
        public override void Receive(Farmer source, List <object> data)
        {
            for (int i = 0; i < Game1.player.items.Count; i++)
            {
                if (Game1.player.items[i] is not StardewValley.Objects.Hat)
                {
                    Game1.player.items[i] = null;
                }
            }

            DelayedAction.functionAfterDelay(() =>
            {
                if (!ModEntry.BRGame.InProgress)
                {
                    return;
                }

                var oldLocation = Game1.player.currentLocation;
                var oldPosition = new xTile.Dimensions.Location(
                    (int)Game1.player.Position.X - Game1.viewport.Width / 2,
                    (int)Game1.player.Position.Y - Game1.viewport.Height / 2
                    );

                SpectatorMode.EnterSpectatorMode(oldLocation, oldPosition);
            }, 1000);
        }
예제 #2
0
        public static void TakeDamage(Farmer who, DamageSource source, int damage, long?damagerID = null, string monster = "")
        {
            if (!ModEntry.BRGame.InProgress)
            {
                damage = 0;
            }

            if (who != Game1.player)
            {
                NetworkUtils.SendDamageToPlayer(who, source, damage, damagerID);
                return;
            }

            if (IsDying(Game1.player))
            {
                return;
            }

            Round round = ModEntry.BRGame.GetActiveRound();

            Game1.currentMinigame = null;

            Farmer damager = null;

            if (damagerID != null)
            {
                damager = Game1.getFarmer((long)damagerID);
            }

            if (damager != null && Game1.player != damager && IsOnSameTeamAs(Game1.player, damager))
            {
                return;
            }

            if (source != DamageSource.MONSTER)
            {
                bool oldIsEating = Game1.player.isEating;
                Game1.player.isEating = false; // Prevent invincibility
                Game1.player.takeDamage(source, damage, false, damager);
                Game1.player.isEating = oldIsEating;
            }

            bool wasInvincible = Game1.player.temporarilyInvincible;

            //Hit shake timer / Invincibility frames
            if (source != DamageSource.THORNS && !round.IsSpecialRoundType(SpecialRoundType.SLUGFEST) && !Game1.player.temporarilyInvincible)
            {
                int invincibilityDuration = 1200;
                int multiplier            = Game1.player.GetEffectsOfRingMultiplier(861);
                invincibilityDuration += 1000 * multiplier;

                NetworkMessage.Send(
                    NetworkUtils.MessageTypes.TELL_PLAYER_HIT_SHAKE_TIMER,
                    NetworkMessageDestination.ALL,
                    new List <object>()
                {
                    invincibilityDuration
                }
                    );
            }

            if (Game1.player.health <= 0)
            {
                ResetStatistics();

                Game1.player.CanMove = false;
                NetworkMessage.Send(
                    NetworkUtils.MessageTypes.SEND_DEATH_ANIMATION,
                    NetworkMessageDestination.ALL,
                    new List <object>()
                    );

                DelayedAction.functionAfterDelay(() =>
                {
                    Random random = new();

                    //Spawn their items onto the floor
                    foreach (var item in Game1.player.Items)
                    {
                        if (item != null)
                        {
                            if (item is not Tool || item is MeleeWeapon || item is Slingshot)
                            {
                                Debris debris = new(item, Game1.player.getStandingPosition(), Game1.player.getStandingPosition() + new Vector2(64 * (float)(random.NextDouble() * 2 - 1), 64 * (float)(random.NextDouble() * 2 - 1)));
                                Game1.currentLocation.debris.Add(debris);
                            }
                        }
                    }

                    var oldLocation = Game1.player.currentLocation;
                    var oldPosition = new xTile.Dimensions.Location(
                        (int)Game1.player.Position.X - Game1.viewport.Width / 2,
                        (int)Game1.player.Position.Y - Game1.viewport.Height / 2);

                    ClearInventory();

                    SpectatorMode.EnterSpectatorMode(oldLocation, oldPosition);

                    NetworkUtils.AnnounceClientDeath(source, monster, damagerID);
                }, 1800);
            }
            else if (source == DamageSource.PLAYER && damage > 0 && canBeKnockedBack && damager != null && !wasInvincible) // Knockback
            {
                double amount = 10 + 8 * (-1 + 2 / (1 + Math.Pow(Math.E, -0.03 * damage)));
                amount = Math.Min(18, amount); //Just in case

                if (damager.leftRing.Value != null && damager.leftRing.Value.GetsEffectOfRing(529))
                {
                    amount *= 1.5;
                }
                if (damager.rightRing.Value != null && damager.rightRing.Value.GetsEffectOfRing(529))
                {
                    amount *= 1.5;
                }

                Vector2 displacement = Vector2.Subtract(Game1.player.Position, damager.Position);
                if (displacement.LengthSquared() != 0)
                {
                    displacement.Normalize();

                    displacement.Y *= -1;
                    displacement    = Vector2.Multiply(displacement, (float)amount);

                    Game1.player.setTrajectory((int)displacement.X, (int)displacement.Y);
                }
            }
        }