2018-12-30 18:00:05 +08:00
|
|
|
using Microsoft.Xna.Framework;
|
2019-01-06 14:25:22 +08:00
|
|
|
using Revitalize.Framework.Objects;
|
2019-01-14 06:46:31 +08:00
|
|
|
using Revitalize.Framework.Objects.Furniture;
|
2018-12-29 15:28:21 +08:00
|
|
|
using StardewValley;
|
|
|
|
|
|
|
|
namespace Revitalize.Framework.Player.Managers
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
// TODO:
|
|
|
|
// - Make chair
|
|
|
|
// - animate player better
|
2018-12-29 15:28:21 +08:00
|
|
|
public class SittingInfo
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>If the player is currently sitting.</summary>
|
2018-12-29 15:28:21 +08:00
|
|
|
public bool isSitting;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>How long a Farmer has sat (in milliseconds)</summary>
|
2018-12-29 15:28:21 +08:00
|
|
|
private int elapsedTime;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Gets how long the farmer has sat (in milliseconds).</summary>
|
|
|
|
public int ElapsedTime => this.elapsedTime;
|
2018-12-29 15:28:21 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Keeps trck of time elapsed.</summary>
|
2018-12-29 15:28:21 +08:00
|
|
|
GameTime timer;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
/// <summary>How long a player has to sit to recover energy/health;</summary>
|
|
|
|
public int SittingSpan { get; }
|
2018-12-29 15:28:21 +08:00
|
|
|
|
2019-01-06 14:25:22 +08:00
|
|
|
StardewValley.Object sittingObject;
|
|
|
|
|
|
|
|
public StardewValley.Object SittingObject
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.sittingObject;
|
|
|
|
}
|
|
|
|
}
|
2018-12-29 15:28:21 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
2018-12-29 15:28:21 +08:00
|
|
|
public SittingInfo()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.timer = Game1.currentGameTime;
|
|
|
|
this.SittingSpan = 10000;
|
2018-12-29 15:28:21 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Update the sitting info.</summary>
|
2018-12-29 15:28:21 +08:00
|
|
|
public void update()
|
|
|
|
{
|
|
|
|
if (Game1.activeClickableMenu != null) return;
|
|
|
|
|
|
|
|
if (Game1.player.isMoving())
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.isSitting = false;
|
|
|
|
this.elapsedTime = 0;
|
2019-01-14 06:46:31 +08:00
|
|
|
if(this.sittingObject is MultiTiledObject && (this.sittingObject.GetType()!=typeof(Bench)))
|
2019-01-09 14:15:58 +08:00
|
|
|
{
|
|
|
|
(this.sittingObject as MultiTiledObject).setAllAnimationsToDefault();
|
2019-01-14 06:46:31 +08:00
|
|
|
this.sittingObject = null;
|
|
|
|
}
|
|
|
|
else if(this.sittingObject is Bench)
|
|
|
|
{
|
|
|
|
(this.sittingObject as Bench).playersSittingHere.Remove(Game1.player.uniqueMultiplayerID);
|
|
|
|
if((this.sittingObject as Bench).playersSittingHere.Count == 0)
|
|
|
|
{
|
|
|
|
(this.sittingObject as MultiTiledObject).setAllAnimationsToDefault();
|
|
|
|
}
|
2019-01-09 14:15:58 +08:00
|
|
|
}
|
2019-01-06 14:25:22 +08:00
|
|
|
this.sittingObject = null;
|
2019-01-14 06:46:31 +08:00
|
|
|
|
|
|
|
|
2018-12-29 15:28:21 +08:00
|
|
|
}
|
2018-12-30 18:00:05 +08:00
|
|
|
if (this.isSitting && Game1.player.CanMove)
|
2018-12-29 15:28:21 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.showSitting();
|
|
|
|
if (this.timer == null) this.timer = Game1.currentGameTime;
|
|
|
|
this.elapsedTime += this.timer.ElapsedGameTime.Milliseconds;
|
2018-12-29 15:28:21 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
if (this.elapsedTime >= this.SittingSpan)
|
2018-12-29 15:28:21 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.elapsedTime %= this.SittingSpan;
|
2018-12-29 15:28:21 +08:00
|
|
|
Game1.player.health++;
|
|
|
|
Game1.player.Stamina++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-06 15:29:17 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Display the farmer actually sitting.
|
|
|
|
/// </summary>
|
2018-12-29 15:28:21 +08:00
|
|
|
public void showSitting()
|
|
|
|
{
|
2019-01-06 14:25:22 +08:00
|
|
|
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
|
2018-12-29 15:28:21 +08:00
|
|
|
{
|
2019-01-06 14:25:22 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-12-29 15:28:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-06 15:29:17 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Make the player sit.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
/// <param name="offset"></param>
|
2018-12-30 18:00:05 +08:00
|
|
|
public void sit(StardewValley.Object obj, Vector2 offset)
|
2018-12-29 15:28:21 +08:00
|
|
|
{
|
|
|
|
this.isSitting = true;
|
|
|
|
Game1.player.Position = (obj.TileLocation * Game1.tileSize + offset);
|
2018-12-30 18:00:05 +08:00
|
|
|
Game1.player.position.Y += Game1.tileSize / 2;
|
2019-01-06 14:25:22 +08:00
|
|
|
this.sittingObject = obj;
|
2018-12-29 15:28:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|