Пример #1
0
        public static void ring_onMonsterSlay(Farmer who, StardewValley.Monsters.Monster target)
        {
            if (who == null)
            {
                return;
            }
            ActualRings ar = actualdata.GetValue(who, FarmerNotFound);

            who.leftRing.Value?.onMonsterSlay(target);
            who.rightRing.Value?.onMonsterSlay(target);
            ar.ring1.Value?.onMonsterSlay(target);
            ar.ring2.Value?.onMonsterSlay(target);
            ar.ring3.Value?.onMonsterSlay(target);
            ar.ring4.Value?.onMonsterSlay(target);
        }
Пример #2
0
        internal static StardewValley.Monsters.Monster GetMonsterForThisLevel(
            [UseOutputBind] ref bool useOutput,
            [InputBind(typeof(int), "level")] int level,
            [InputBind(typeof(int), "xTile")] int xTile,
            [InputBind(typeof(int), "yTile")] int yTile)
        {
            // Create the spawning location vector the same way it's handled in the hooked method
            Vector2 vector = new Vector2(xTile, yTile) * StardewValley.Game1.tileSize;

            // Create a new sub-list of spawn chances that apply to this level
            var ApplicableChances = MonsterSpawnChances.Where(c => c.MinLevel <= level && c.MaxLevel >= level);
            // Get the sum of all chance weights that apply. Starts at 1 for the default value's weight
            double weightSum = 1.0;

            foreach (MineshaftMonsterSpawnChance chance in ApplicableChances)
            {
                weightSum += chance.SpawnWeight;
            }

            // Get a random double between 0 and 1
            double randomValue = Random.NextDouble();
            // Current Evaluated Weight for the following loop
            double currentWeight = 0.0;

            // Loop through the applicable chances, and determine if luck has shined upon the monster it contains
            foreach (MineshaftMonsterSpawnChance chance in ApplicableChances)
            {
                if (currentWeight < (randomValue * weightSum) && (currentWeight + chance.SpawnWeight) >= (randomValue * weightSum))
                {
                    // Create the monster object and pass it back to be used
                    StardewValley.Monsters.Monster newMonsterObject = (StardewValley.Monsters.Monster)Activator.CreateInstance(chance.MonsterType, chance.Information, vector);

                    useOutput = true;
                    return(newMonsterObject);
                }

                currentWeight += chance.SpawnWeight;
            }

            // Luck did not shine on any custom spawn chances, use the default
            useOutput = false;
            return(null);
        }
Пример #3
0
        public void TakeDamage(int damage, long?damagerID = null)
        {
            if (ModEntry.BRGame.IsGameInProgress)
            {
                dummyMonster = dummyMonster ?? new StardewValley.Monsters.Monster();

                try
                {
                    bool oldIsEating = Game1.player.isEating;
                    Game1.player.isEating = false;                        //Prevent invincibility

                    Game1.player.takeDamage(damage, false, dummyMonster); //If you pass in null as monster the player won't take damage

                    Game1.player.isEating = oldIsEating;
                }catch (Exception)
                {
                    Console.WriteLine("Ignoring exception in takeDamage");
                }

                Farmer damager = null;
                if (Game1.currentLocation != null && Game1.currentLocation.farmers != null)
                {
                    foreach (Farmer player in Game1.currentLocation?.farmers)
                    {
                        //Hit shake timer / Invincibility frames
                        if (player != Game1.player && player != null)
                        {
                            var objects = new object[] { (int)NetworkUtility.MessageTypes.TELL_PLAYER_HIT_SHAKE_TIMER, 1200 };                            //Hard coded in Farmer.MovePosition
                            if (Game1.IsServer)
                            {
                                Game1.server.sendMessage(player.UniqueMultiplayerID, new OutgoingMessage(NetworkUtility.uniqueMessageType, Game1.player, objects));
                            }
                            else
                            {
                                NetworkUtility.RelayMessageFromClientToAnotherPlayer(player.UniqueMultiplayerID, objects);
                            }

                            if (player.UniqueMultiplayerID == damagerID)
                            {
                                damager = player;
                            }
                        }
                    }
                }

                //Knockback (knock the player)
                if (damager != null && damage > 0 && (DateTime.Now - knockbackImmunityTimeActivated).TotalMilliseconds >= knockbackImmunityMilliseconds)
                {
                    double amount = 10 + 8 * (-1 + 2 / (1 + Math.Pow(Math.E, -0.03 * damage)));
                    amount = Math.Min(18, amount);                    //Just in case

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

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

                        Console.WriteLine($"setting trajectory to {displacement.X},{displacement.Y}");

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

                if (Game1.player.health <= 0)
                {
                    //They are dead now
                    Console.WriteLine($"I AM DEAD!");

                    Random random = new Random();

                    //Spawn their items onto the floor
                    foreach (var item in Game1.player.Items)
                    {
                        if (item != null)
                        {
                            if (!(item is Tool) || item is StardewValley.Tools.MeleeWeapon || item is StardewValley.Tools.Slingshot)
                            {
                                Debris debris = new Debris(item, Game1.player.getStandingPosition(), Game1.player.getStandingPosition() + new Microsoft.Xna.Framework.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);

                    Game1.player.clearBackpack();
                    Game1.player.health = maxHealth;                    //Otherwise they will go the the Doctor on the next update tick
                    //Game1.player.warpFarmer(new TileLocation("Forest", 100, 20).CreateWarp());//Marnie's cow pen

                    SpectatorMode.EnterSpectatorMode(oldLocation, oldPosition);

                    if (Game1.IsServer)
                    {
                        ModEntry.BRGame.HandleDeath(Game1.player, damagerID);
                    }
                    else
                    {
                        if (damagerID.HasValue)
                        {
                            Game1.client.sendMessage(new OutgoingMessage(NetworkUtility.uniqueMessageType, Game1.player,
                                                                         (int)NetworkUtility.MessageTypes.TELL_SERVER_I_DIED, Game1.player.UniqueMultiplayerID, damagerID.Value));
                        }
                        else
                        {
                            Game1.client.sendMessage(new OutgoingMessage(NetworkUtility.uniqueMessageType, Game1.player,
                                                                         (int)NetworkUtility.MessageTypes.TELL_SERVER_I_DIED, Game1.player.UniqueMultiplayerID));
                        }
                    }
                }
            }
        }