Updatd timefreeze with multiplayer checks. Also surpressed NetAnimationManager glitch.

This commit is contained in:
2018-08-08 01:39:13 -07:00
parent 713ec38603
commit 298b7c4a24
4 changed files with 139 additions and 7 deletions

View File

@ -69,7 +69,7 @@ namespace StardustCore.NetCode
{ {
texture = new NetTexture2DExtended(); texture = new NetTexture2DExtended();
texture.ReadFull(reader, version); texture.ReadData(reader, version);
Value.setExtendedTexture(texture.Value); Value.setExtendedTexture(texture.Value);
which = new NetInt(); which = new NetInt();
@ -95,10 +95,11 @@ namespace StardustCore.NetCode
drawPosition = new NetVector2(); drawPosition = new NetVector2();
drawPosition.Read(reader, version); drawPosition.Read(reader, version);
Value.drawPosition = drawPosition.Value; Value.drawPosition = drawPosition.Value;
/*
animationManager = new NetAnimationManager(); animationManager = new NetAnimationManager();
animationManager.Read(reader, version); animationManager.Read(reader, version);
Value.animationManager = animationManager.Value; Value.animationManager = animationManager.Value;
*/
} }
@ -106,7 +107,7 @@ namespace StardustCore.NetCode
{ {
texture = new NetTexture2DExtended(Value.getExtendedTexture()); texture = new NetTexture2DExtended(Value.getExtendedTexture());
texture.Write(writer); texture.WriteData(writer);
which = new NetInt(Value.ParentSheetIndex); which = new NetInt(Value.ParentSheetIndex);
which.Write(writer); which.Write(writer);
@ -126,11 +127,13 @@ namespace StardustCore.NetCode
drawPosition = new NetVector2(Value.drawPosition); drawPosition = new NetVector2(Value.drawPosition);
drawPosition.Write(writer); drawPosition.Write(writer);
/*
if (Value.animationManager != null) if (Value.animationManager != null)
{ {
animationManager = new NetAnimationManager(Value.animationManager); animationManager = new NetAnimationManager(Value.animationManager);
animationManager.Write(writer); animationManager.Write(writer);
} }
*/
} }
} }
} }

View File

@ -8,5 +8,30 @@
/// <summary>Whether time should be unfrozen while the player is swimming in the vanilla bathhouse.</summary> /// <summary>Whether time should be unfrozen while the player is swimming in the vanilla bathhouse.</summary>
public bool PassTimeWhileSwimmingInBathhouse { get; set; } = true; public bool PassTimeWhileSwimmingInBathhouse { get; set; } = true;
/// <summary>
/// Whether time passes normally inside the mine.
/// </summary>
public bool PassTimeWhileInsideMine { get; set; } = true;
/// <summary>
/// Whether time passes normally inside the skull cavern.
/// </summary>
public bool PassTimeWhileInsideSkullCave { get; set; } = true;
/// <summary>
/// Checks if just one player meets the conditions to freeze time, and then freeze time.
/// </summary>
public bool freezeIfEvenOnePlayerMeetsTimeFreezeConditions { get; set; } = false;
/// <summary>
/// Checks if the majority of players can freeze time and then freeze time.
/// </summary>
public bool freezeIfMajorityPlayersMeetsTimeFreezeConditions { get; set; } = false;
/// <summary>
/// Checks if all players can freeze time and if so, do so.
/// </summary>
public bool freezeIfAllPlayersMeetTimeFreezeConditions { get; set; } = false;
} }
} }

View File

@ -16,6 +16,8 @@ namespace Omegasis.TimeFreeze
/// <summary>The mod configuration.</summary> /// <summary>The mod configuration.</summary>
private ModConfig Config; private ModConfig Config;
public int oldInterval;
/********* /*********
** Public methods ** Public methods
@ -40,8 +42,92 @@ namespace Omegasis.TimeFreeze
if (!Context.IsWorldReady) if (!Context.IsWorldReady)
return; return;
if (this.ShouldFreezeTime(Game1.player, Game1.player.currentLocation)) if (Game1.gameTimeInterval != 0)
{
oldInterval = Game1.gameTimeInterval;
}
if (Game1.IsMultiplayer)
{
if (Config.freezeIfEvenOnePlayerMeetsTimeFreezeConditions)
{
bool isAnyFarmerSuitable = false;
foreach (Farmer farmer in Game1.getAllFarmers())
{
if (this.ShouldFreezeTime(farmer, farmer.currentLocation))
{
Game1.gameTimeInterval = 0; Game1.gameTimeInterval = 0;
isAnyFarmerSuitable = true;
}
}
if (isAnyFarmerSuitable == false)
{
Game1.gameTimeInterval = oldInterval;
}
}
else if (Config.freezeIfMajorityPlayersMeetsTimeFreezeConditions)
{
int freezeCount = 0;
int playerCount = 0;
foreach (Farmer farmer in Game1.getAllFarmers())
{
playerCount++;
if (this.ShouldFreezeTime(farmer, farmer.currentLocation))
{
//Game1.gameTimeInterval = 0;
freezeCount++;
}
}
if (freezeCount >= (playerCount / 2))
{
Game1.gameTimeInterval = 0;
}
else
{
Game1.gameTimeInterval = oldInterval;
}
}
else if (Config.freezeIfAllPlayersMeetTimeFreezeConditions)
{
int freezeCount = 0;
int playerCount = 0;
foreach (Farmer farmer in Game1.getAllFarmers())
{
playerCount++;
if (this.ShouldFreezeTime(farmer, farmer.currentLocation))
{
//Game1.gameTimeInterval = 0;
freezeCount++;
}
}
if (freezeCount >= playerCount)
{
Game1.gameTimeInterval = 0;
}
else
{
Game1.gameTimeInterval = oldInterval;
}
}
}
else
{
Farmer player = Game1.player;
if (this.ShouldFreezeTime(player, player.currentLocation))
{
Game1.gameTimeInterval = 0;
}
else
{
Game1.gameTimeInterval = oldInterval;
}
}
} }
/// <summary>Get whether time should be frozen for the player at the given location.</summary> /// <summary>Get whether time should be frozen for the player at the given location.</summary>
@ -49,8 +135,26 @@ namespace Omegasis.TimeFreeze
/// <param name="location">The location to check.</param> /// <param name="location">The location to check.</param>
private bool ShouldFreezeTime(StardewValley.Farmer player, GameLocation location) private bool ShouldFreezeTime(StardewValley.Farmer player, GameLocation location)
{ {
if (location.Name == "Mine" || location.Name == "SkullCave"|| location.Name.StartsWith("SkullCave") || location.Name.StartsWith("UndergroundMine") || location.IsOutdoors)
if (Config.PassTimeWhileInsideMine==false)
{
if(location.Name == "Mine" || location.Name.StartsWith("UndergroundMine"))
{
return true;
}
}
if (Config.PassTimeWhileInsideSkullCave==false)
{
if (location.Name == "SkullCave" || location.Name.StartsWith("SkullCave"))
{
return true;
}
}
if (location.IsOutdoors)
return false; return false;
if (player.swimming.Value) if (player.swimming.Value)
{ {
if (this.Config.PassTimeWhileSwimmingInBathhouse && location is BathHousePool) if (this.Config.PassTimeWhileSwimmingInBathhouse && location is BathHousePool)

View File

@ -1,7 +1,7 @@
{ {
"Name": "Time Freeze", "Name": "Time Freeze",
"Author": "Alpha_Omegasis", "Author": "Alpha_Omegasis",
"Version": "1.4.0", "Version": "1.5.0",
"Description": "Emulates old Harvest Moon-style games where time is frozen inside.", "Description": "Emulates old Harvest Moon-style games where time is frozen inside.",
"UniqueID": "Omegasis.TimeFreeze", "UniqueID": "Omegasis.TimeFreeze",
"EntryDll": "TimeFreeze.dll", "EntryDll": "TimeFreeze.dll",