using Microsoft.Xna.Framework;
using Revitalize.Framework.Objects;
using StardewValley;
namespace Revitalize.Framework.Player.Managers
{
// TODO:
// - Make chair
// - animate player better
public class SittingInfo
{
/// If the player is currently sitting.
public bool isSitting;
/// How long a Farmer has sat (in milliseconds)
private int elapsedTime;
/// Gets how long the farmer has sat (in milliseconds).
public int ElapsedTime => this.elapsedTime;
/// Keeps trck of time elapsed.
GameTime timer;
/// How long a player has to sit to recover energy/health;
public int SittingSpan { get; }
StardewValley.Object sittingObject;
public StardewValley.Object SittingObject
{
get
{
return this.sittingObject;
}
}
/// Construct an instance.
public SittingInfo()
{
this.timer = Game1.currentGameTime;
this.SittingSpan = 10000;
}
/// Update the sitting info.
public void update()
{
if (Game1.activeClickableMenu != null) return;
if (Game1.player.isMoving())
{
this.isSitting = false;
this.elapsedTime = 0;
if(this.sittingObject is MultiTiledObject)
{
(this.sittingObject as MultiTiledObject).setAllAnimationsToDefault();
}
this.sittingObject = null;
}
if (this.isSitting && Game1.player.CanMove)
{
this.showSitting();
if (this.timer == null) this.timer = Game1.currentGameTime;
this.elapsedTime += this.timer.ElapsedGameTime.Milliseconds;
}
if (this.elapsedTime >= this.SittingSpan)
{
this.elapsedTime %= this.SittingSpan;
Game1.player.health++;
Game1.player.Stamina++;
}
}
///
/// Display the farmer actually sitting.
///
public void showSitting()
{
if (this.sittingObject == null)
{
switch (Game1.player.FacingDirection)
{
case 0:
Game1.player.FarmerSprite.setCurrentSingleFrame(113);
break;
case 1:
Game1.player.FarmerSprite.setCurrentSingleFrame(106);
break;
case 2:
Game1.player.FarmerSprite.setCurrentSingleFrame(107);
break;
case 3:
Game1.player.FarmerSprite.setCurrentSingleFrame(106);
break;
}
}
else
{
if(this.sittingObject is CustomObject)
{
Game1.player.faceDirection((int)(this.sittingObject as CustomObject).info.facingDirection);
switch ((this.sittingObject as CustomObject).info.facingDirection)
{
case Enums.Direction.Up:
Game1.player.FarmerSprite.setCurrentSingleFrame(113);
break;
case Enums.Direction.Right:
Game1.player.FarmerSprite.setCurrentSingleFrame(106);
break;
case Enums.Direction.Down:
Game1.player.FarmerSprite.setCurrentSingleFrame(107);
break;
case Enums.Direction.Left:
Game1.player.FarmerSprite.setCurrentSingleFrame(106,32000,false,true);
break;
}
}
}
}
///
/// Make the player sit.
///
///
///
public void sit(StardewValley.Object obj, Vector2 offset)
{
this.isSitting = true;
Game1.player.Position = (obj.TileLocation * Game1.tileSize + offset);
Game1.player.position.Y += Game1.tileSize / 2;
this.sittingObject = obj;
}
}
}