Ejemplo n.º 1
0
 private void OnTick(object sender, UpdateTickingEventArgs e)
 {
     if (e.IsMultipleOf(120))
     {
         client.SetPresence(GenerateRichPresence());
     }
 }
 private void OnUpdateTicking(object sender, UpdateTickingEventArgs e)
 {
     if (!Context.IsMainPlayer)
     {
         return;
     }
     if (e.IsMultipleOf(this.Config.UpdateInterval))
     {
         configureAllMachines();
     }
 }
Ejemplo n.º 3
0
 /// <summary>Raised before the game state is updated (≈60 times per second).</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void GameLoop_UpdateTicking(object sender, UpdateTickingEventArgs e)
 {
     if (Game1.player.usingSlingshot && Game1.player.CurrentTool is Slingshot slingshot &&
         this.isActionButtonDown &&
         this.nameToConfigName.TryGetValue(slingshot.BaseName, out string configName) &&
         this.Config.AutomaticSlingshots.Contains(configName) &&
         this.configNameToFireRate.TryGetValue(configName, out int rate) && e.IsMultipleOf((uint)(this.Config.RapidFire ? rate / 2 : rate)) &&
         slingshot.attachments[0] != null)
     {
         this.IsAutoFire = true;
         SlingshotFinishPatch.ShouldRun(slingshot, false);
         slingshot.DoFunction(Game1.currentLocation, Game1.getMouseX(), Game1.getMouseY(), 1, slingshot.getLastFarmerToUse());
         SlingshotFinishPatch.ShouldRun(slingshot, true);
         this.IsAutoFire = false;
     }
 }
Ejemplo n.º 4
0
        /*********
        ** Private methods
        *********/
        /// <summary>Raised before the game state is updated</summary>
        private void OnUpdateTicking(object sender, UpdateTickingEventArgs e)
        {
            if (Game1.getFarm() is null)
            {
                return;
            }

            // Create a smoke sprite
            if (smokeAnimationData.Enabled && e.IsMultipleOf(smokeAnimationData.SpawnFrequency * 60 / 1000))
            {
                GameLocation location = Game1.player.currentLocation;

                if (location != null && location.IsFarm && location.IsOutdoors)
                {
                    for (int i = 0; i < furnaces.Count; i++)
                    {
                        if (!furnaces[i].CurrentlyOn)
                        {
                            continue;
                        }

                        int x = furnaces[i].furnace.tileX.Value;
                        int y = furnaces[i].furnace.tileY.Value;

                        TemporaryAnimatedSprite sprite;

                        // See if we should do a custom sprite, or use the default
                        if (customSmokeSpriteExists)
                        {
                            sprite = new TemporaryAnimatedSprite(smokeAnimationSpritePath,
                                                                 new Rectangle(0, 0, smokeAnimationData.SpriteSizeX, smokeAnimationData.SpriteSizeY),
                                                                 new Vector2(x * 64 + smokeAnimationData.SpawnXOffset, y * 64 + smokeAnimationData.SpawnYOffset),
                                                                 false, 1f / 500f, Color.Gray)
                            {
                                alpha          = 0.75f,
                                motion         = new Vector2(0.0f, -0.5f),
                                acceleration   = new Vector2(1f / 500f, 0.0f),
                                interval       = 99999f,
                                layerDepth     = 1f,
                                scale          = smokeAnimationData.SmokeScale,
                                scaleChange    = smokeAnimationData.SmokeScaleChange,
                                rotationChange = (float)(Game1.random.Next(-5, 6) * 3.14159274101257 / 256.0)
                            };
                        }
                        else
                        {
                            sprite = new TemporaryAnimatedSprite(Path.Combine("LooseSprites", "Cursors"),
                                                                 new Rectangle(372, 1956, 10, 10),
                                                                 new Vector2(x * 64 + smokeAnimationData.SpawnXOffset, y * 64 + smokeAnimationData.SpawnYOffset),
                                                                 false, 1f / 500f, Color.Gray)
                            {
                                alpha          = 0.75f,
                                motion         = new Vector2(0.0f, -0.5f),
                                acceleration   = new Vector2(1f / 500f, 0.0f),
                                interval       = 99999f,
                                layerDepth     = 1f,
                                scale          = smokeAnimationData.SmokeScale,
                                scaleChange    = smokeAnimationData.SmokeScaleChange,
                                rotationChange = (float)(Game1.random.Next(-5, 6) * 3.14159274101257 / 256.0)
                            };
                        }

                        // Add smoke sprite
                        location.temporarySprites.Add(sprite);
                    }
                }
            }
            // Create a fire sprite
            if (fireAnimationData.Enabled && e.IsMultipleOf(fireAnimationData.SpawnFrequency * 60 / 1000))
            {
                GameLocation location = Game1.player.currentLocation;

                if (location != null && location.IsFarm && location.IsOutdoors)
                {
                    for (int i = 0; i < furnaces.Count; i++)
                    {
                        if (!furnaces[i].CurrentlyOn)
                        {
                            continue;
                        }

                        int x = furnaces[i].furnace.tileX.Value;
                        int y = furnaces[i].furnace.tileY.Value;

                        TemporaryAnimatedSprite sprite;

                        if (customFireSpriteExists)
                        {
                            // Spark only randomly
                            if (Game1.random.NextDouble() >= fireAnimationData.SpawnChance)
                            {
                                continue;
                            }

                            double randomX = 2 * Game1.random.NextDouble() * fireAnimationData.SpawnXRandomOffset - fireAnimationData.SpawnXRandomOffset;
                            double randomY = 2 * Game1.random.NextDouble() * fireAnimationData.SpawnYRandomOffset - fireAnimationData.SpawnYRandomOffset;

                            Vector2 pos = new Vector2(x * 64f + fireAnimationData.SpawnXOffset + (float)randomX,
                                                      y * 64f + fireAnimationData.SpawnYOffset + (float)randomY);

                            sprite = new TemporaryAnimatedSprite(fireAnimationSpritePath,
                                                                 new Rectangle(0, 0, fireAnimationData.SpriteSizeX, fireAnimationData.SpriteSizeY),
                                                                 fireAnimationData.AnimationSpeed, fireAnimationData.AnimationLength, 10, pos, false,
                                                                 false,
                                                                 (float)((y + 1.0) * 64.0 / 10000.0 + 9.99999974737875E-05 + (x + 1.0) * 64.0 / 10000.0),
                                                                 0.005f, Color.White, 1f, 0f, 0f, 0f)
                            {
                                light      = true,
                                lightcolor = Color.Black
                            };

                            // Puff only randomlierly
                            if (Game1.random.NextDouble() < fireAnimationData.SoundEffectChance)
                            {
                                Game1.playSound("fireball");
                            }
                        }
                        else
                        {
                            // Spark only randomly
                            if (Game1.random.NextDouble() >= 0.2)
                            {
                                continue;
                            }

                            double randomX = 2 * Game1.random.NextDouble() * fireAnimationData.SpawnXRandomOffset - fireAnimationData.SpawnXRandomOffset;
                            double randomY = 2 * Game1.random.NextDouble() * fireAnimationData.SpawnYRandomOffset - fireAnimationData.SpawnYRandomOffset;

                            Vector2 pos = new Vector2(x * 64f + fireAnimationData.SpawnXOffset + (float)randomX,
                                                      y * 64f + fireAnimationData.SpawnYOffset + (float)randomY);

                            sprite = new TemporaryAnimatedSprite(30, pos, Color.White, fireAnimationData.AnimationLength,
                                                                 false, fireAnimationData.AnimationSpeed, 10, 64,
                                                                 (float)((y + 1.0) * 64.0 / 10000.0 + 9.99999974737875E-05 + (x + 1.0) * 64.0 / 10000.0),
                                                                 -1, 0)
                            {
                                alphaFade  = 0.005f,
                                light      = true,
                                lightcolor = Color.Black
                            };

                            // Puff only randomlierly
                            if (Game1.random.NextDouble() < fireAnimationData.SoundEffectChance)
                            {
                                Game1.playSound("fireball");
                            }
                        }

                        location.temporarySprites.Add(sprite);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void OnUpdateTicking(object sender, UpdateTickingEventArgs e)
        {
            if (!Context.IsWorldReady || !IsPlayerOnTrawler() || _isTripEnding.Value)
            {
                return;
            }

            if (Game1.activeClickableMenu != null && !Context.IsMultiplayer)
            {
                // Allow pausing in singleplayer via menu
                return;
            }

            if (_isNotificationFading)
            {
                _notificationAlpha -= 0.1f;
            }

            if (_notificationAlpha < 0f)
            {
                _activeNotification   = String.Empty;
                _isNotificationFading = false;
                _notificationAlpha    = 1f;
            }

            if (IsMainDeckhand())
            {
                if (e.IsMultipleOf(150))
                {
                    // Update water level (from leaks) every second
                    _trawlerHull.Value.RecaculateWaterLevel();
                    SyncTrawler(SyncType.WaterLevel, _trawlerHull.Value.GetWaterLevel(), GetFarmersOnTrawler());
                }
            }

            // Every quarter of a second play leaking sound, if there is a leak
            if (e.IsMultipleOf(15))
            {
                if (Game1.player.currentLocation is TrawlerHull && _trawlerHull.Value.HasLeak())
                {
                    Game1.playSoundPitched("wateringCan", Game1.random.Next(1, 5) * 100);
                }
            }

            if (e.IsMultipleOf(150))
            {
                if (!String.IsNullOrEmpty(_activeNotification))
                {
                    _isNotificationFading = true;
                }
            }

            if (_trawlerHull.Value.GetWaterLevel() == 100)
            {
                Monitor.Log($"Ending trip due to flooding for: {Game1.player.Name}", LogLevel.Trace);
                _trawlerSurface.Value.fishCaughtQuantity /= 4;

                // Set the status as failed
                Game1.player.modData[MURPHY_WAS_TRIP_SUCCESSFUL_KEY] = "false";
                Game1.player.modData[MURPHY_SAILED_TODAY_KEY]        = "true";

                // End trip due to flooding
                Game1.player.currentLocation.playSound("fishEscape");
                Game1.player.CanMove = false;
                Game1.addHUDMessage(new HUDMessage(i18n.Get("game_message.trip_failed"), null));

                EndTrip();
            }
        }