public static bool IsDying(Farmer who) { FarmerSprite sprite = who.FarmerSprite; int currentAnimaton = ModEntry.BRGame.Helper.Reflection.GetField <int>(sprite, "currentSingleAnimation").GetValue(); return(Patches.CustomDeathAnimation.customAnimations.Contains(currentAnimaton)); }
/// <summary>Draw the subject portrait (if available).</summary> /// <param name="spriteBatch">The sprite batch being drawn.</param> /// <param name="position">The position at which to draw.</param> /// <param name="size">The size of the portrait to draw.</param> /// <returns>Returns <c>true</c> if a portrait was drawn, else <c>false</c>.</returns> public override bool DrawPortrait(SpriteBatch spriteBatch, Vector2 position, Vector2 size) { SFarmer farmer = this.Target; FarmerSprite sprite = farmer.FarmerSprite; farmer.FarmerRenderer.draw(spriteBatch, sprite.CurrentAnimationFrame, sprite.CurrentFrame, sprite.SourceRect, position, Vector2.Zero, 0.8f, Color.White, 0, 1f, farmer); return(true); }
private GhostFarmer() : base(new FarmerSprite(null), Vector2.Zero, 1, "GhostFarmer", new List <Item>(), true) { ClearInventory(); uniqueMultiplayerID = Game1.player.uniqueMultiplayerID; professions = Game1.player.professions; FarmerSprite.setOwner(this); maxItems = 24; }
public override void tickUpdate(GameTime time, Farmer who) { // cancel save mode if (this.IsSaving) { TimeSpan savingTime = this.GetTimeSince(this.StartedSaving !.Value); if (savingTime > this.ResetDelay) { this.CancelUse(who); this.StartedSaving = null; return; } } // handle use mode if (this.IsUsing) { // animate FarmerSprite sprite = (FarmerSprite)who.Sprite; switch (who.FacingDirection) { case Game1.up: sprite.animate(112, time); break; case Game1.right: sprite.animate(104, time); break; case Game1.down: sprite.animate(96, time); break; case Game1.left: sprite.animate(120, time); break; } // save if done TimeSpan useTime = this.GetTimeSince(this.StartedUsing !.Value); if (useTime > TentTool.UseDelay) { this.CancelUse(who); this.StartedSaving = this.GetTicks(); Mod.Instance.RememberLocation(); Game1.player.isInBed.Value = true; Game1.NewDay(0); } } }
/********* ** Private methods *********/ /// <summary>The method invoked after the game updates (roughly 60 times per second).</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> /// <remarks> /// All times are shown in the game's internal format, which is essentially military time with support for /// times past midnight (e.g. 2400 is midnight, 2600 is 2am). /// /// The game's logic for collapsing the player mostly happens in <see cref="Game1.performTenMinuteClockUpdate"/>. /// It has three cases which affect staying up: /// - time = 2600: dismounts the player. /// - time ≥ 2600: sets the <see cref="Game1.farmerShouldPassOut"/> flag, which causes <see cref="Game1.UpdateOther"/> /// to initiate a player collapse (animation #293). /// - time = 2800: initiates a player collapse. /// </remarks> private void GameEvents_UpdateTick(object sender, EventArgs e) { if (!Context.IsWorldReady || Game1.timeOfDay < 2550) { return; } // get clock details bool clockWillChangeNextTick = this.WillClockChangeNextTick(); // 1. Right before the clock changes, freeze the player for interval + 1. That's too fast for the player to // notice, but long enough to bypass the farmerShouldPassOut check (which skips if the player is frozen). Game1.farmerShouldPassOut = false; if (clockWillChangeNextTick) { Game1.player.freezePause = Game1.currentGameTime.ElapsedGameTime.Milliseconds + 1; this.Monitor.Log($"Adding freeze for {this.GetNextTime(Game1.timeOfDay)} next tick ({Game1.player.freezePause}ms).", LogLevel.Trace); } // 2. Right before the game updates the clock to 2600/2800, change it to the upcoming time. The game will then // update to 2610/2810 instead, which has no special logic. Immediately afterwards, change the clock back to // 2600/2800. This happens faster than the player can see. if (clockWillChangeNextTick && (Game1.timeOfDay == 2550 || Game1.timeOfDay == 2750)) { Game1.timeOfDay += 50; this.Monitor.Log($"Skipping {Game1.timeOfDay} next tick.", LogLevel.Trace); this.JustSkipped = true; } else if (this.JustSkipped) { Game1.timeOfDay -= 10; this.Monitor.Log($"Skip done, reset time to {Game1.timeOfDay}.", LogLevel.Trace); this.JustSkipped = false; } // 3. As a failsafe, if the collapse animation starts immediately remove it. This prevents the attached // Farmer.passOutFromTired callback from being called. FarmerSprite sprite = (FarmerSprite)Game1.player.Sprite; var animation = sprite.CurrentAnimation; if (animation != null && animation.Any(frame => frame.frameBehavior == SFarmer.passOutFromTired)) { this.Monitor.Log("Cancelling player collapse.", LogLevel.Trace); Game1.player.freezePause = 0; Game1.player.canMove = true; sprite.PauseForSingleAnimation = false; sprite.StopAnimation(); } }
/// <summary>Draw the subject portrait (if available).</summary> /// <param name="spriteBatch">The sprite batch being drawn.</param> /// <param name="position">The position at which to draw.</param> /// <param name="size">The size of the portrait to draw.</param> /// <returns>Returns <c>true</c> if a portrait was drawn, else <c>false</c>.</returns> public override bool DrawPortrait(SpriteBatch spriteBatch, Vector2 position, Vector2 size) { SFarmer target = this.Target; if (this.IsLoadMenu) { target.FarmerRenderer.draw(spriteBatch, new FarmerSprite.AnimationFrame(0, 0, false, false), 0, new Rectangle(0, 0, 16, 32), position, Vector2.Zero, 0.8f, 2, Color.White, 0.0f, 1f, target); } else { FarmerSprite sprite = target.FarmerSprite; target.FarmerRenderer.draw(spriteBatch, sprite.CurrentAnimationFrame, sprite.CurrentFrame, sprite.SourceRect, position, Vector2.Zero, 0.8f, Color.White, 0, 1f, target); } return(true); }
private void GetAnimationCancelDetails(FarmerSprite sprite, out List <int> animationFrames, out List <Color> animationState) { animationFrames = new List <int>(); animationState = new List <Color>(); bool canAnimCancel = false; for (int i = 0; i < sprite.CurrentAnimation.Count; i++) { int frames = Math.Max(1, (int)((sprite.CurrentAnimation[i].milliseconds + FrameTimeSpan.Milliseconds - 1) / FrameTimeSpan.TotalMilliseconds)); animationFrames.Add(frames); if (sprite.CurrentAnimation[i].frameStartBehavior != null && sprite.CurrentAnimation[i].frameStartBehavior.Method.Name.Equals("useTool")) { canAnimCancel = true; } if (i > 0 && sprite.CurrentAnimation[i - 1].frameEndBehavior != null && sprite.CurrentAnimation[i - 1].frameEndBehavior.Method.Name.Equals("useTool")) { canAnimCancel = true; } animationState.Add(canAnimCancel ? ValidColor : TooEarlyColor); } }
public FarmerSpriteWrapper(FarmerSprite farmerSprite) : base(farmerSprite) { }
public void draw(SpriteBatch b, FarmerSprite farmerSprite, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, Color overrideColor, float rotation, Farmer who) { this.draw(b, farmerSprite.CurrentAnimationFrame, farmerSprite.CurrentFrame, sourceRect, position, origin, layerDepth, overrideColor, rotation, 1f, who); }
/// <summary> /// Sets a <see cref="FarmerSprite" /> next frame offset. /// </summary> /// <param name="farmerSprite">The <see cref="FarmerSprite" /> instance.</param> /// <param name="offset">The new offset.</param> public static void SetNextOffset(this FarmerSprite farmerSprite, int offset) { FarmerSpritePatcher.FarmerSpritesData.GetOrCreateValue(farmerSprite).NextOffset = offset; }
/// <summary> /// Gets a <see cref="FarmerSprite" /> next frame offset. /// </summary> /// <param name="farmerSprite">The <see cref="FarmerSprite" /> instance.</param> /// <returns></returns> public static int GetNextOffset(this FarmerSprite farmerSprite) { return(FarmerSpritePatcher.FarmerSpritesData.GetOrCreateValue(farmerSprite).NextOffset); }
public virtual void update(GameTime time, GameLocation location, long id, bool move) { if (this.yJumpOffset != 0) { this.yJumpVelocity -= 0.5f; this.yJumpOffset -= (int)this.yJumpVelocity; if (this.yJumpOffset >= 0) { this.yJumpOffset = 0; this.yJumpVelocity = 0f; if (!this.IsMonster && (location == null || location.Equals(Game1.currentLocation))) { FarmerSprite.checkForFootstep(this); } } } if (this.faceTowardFarmerTimer > 0) { this.faceTowardFarmerTimer -= time.ElapsedGameTime.Milliseconds; if (!this.faceTowardFarmer && this.faceTowardFarmerTimer > 0 && Utility.tileWithinRadiusOfPlayer((int)this.getTileLocation().X, (int)this.getTileLocation().Y, this.faceTowardFarmerRadius, this.whoToFace)) { this.faceTowardFarmer = true; } else if (!Utility.tileWithinRadiusOfPlayer((int)this.getTileLocation().X, (int)this.getTileLocation().Y, this.faceTowardFarmerRadius, this.whoToFace) || this.faceTowardFarmerTimer <= 0) { this.faceDirection(this.facingDirectionBeforeSpeakingToPlayer); if (this.faceTowardFarmerTimer <= 0) { this.facingDirectionBeforeSpeakingToPlayer = -1; this.faceTowardFarmer = false; this.faceAwayFromFarmer = false; this.faceTowardFarmerTimer = 0; } } } if (this.forceUpdateTimer > 0) { this.forceUpdateTimer -= time.ElapsedGameTime.Milliseconds; } this.updateGlow(); this.updateEmote(time); if (!Game1.IsMultiplayer || Game1.IsServer || this.ignoreMultiplayerUpdates) { if (this.faceTowardFarmer && this.whoToFace != null) { this.faceGeneralDirection(this.whoToFace.getStandingPosition(), 0); if (this.faceAwayFromFarmer) { this.faceDirection((this.facingDirection + 2) % 4); } } if ((this.controller == null & move) && !this.freezeMotion) { this.updateMovement(location, time); } if (this.controller != null && !this.freezeMotion && this.controller.update(time)) { this.controller = null; } if (Game1.IsServer && !Game1.isFestival() && Game1.random.NextDouble() < 0.2) { MultiplayerUtility.broadcastNPCMove((int)this.position.X, (int)this.position.Y, id, location); return; } } else if (!Game1.eventUp) { this.lerpPosition(this.positionToLerpTo); if (this.distanceFromLastServerPosition() >= 8f) { this.animateInFacingDirection(time); } } }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="farmer">The player's character sprite and animation manager.</param> public AnimationEvents(FarmerSprite farmer) { this.Farmer = farmer; }