Skip to content

Commit

Permalink
improve rewriters for Stardew Valley 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Feb 22, 2024
1 parent 21abd0f commit da7e709
Show file tree
Hide file tree
Showing 32 changed files with 1,091 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Projectiles;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BasicProjectile"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BasicProjectileFacade : BasicProjectile, IRewriteFacade
{
/*********
** Public methods
*********/
public static BasicProjectile Constructor(int damageToFarmer, int parentSheetIndex, int bouncesTillDestruct, int tailLength, float rotationVelocity, float xVelocity, float yVelocity, Vector2 startingPosition, string collisionSound, string firingSound, bool explode, bool damagesMonsters = false, GameLocation? location = null, Character? firer = null, bool spriteFromObjectSheet = false, onCollisionBehavior? collisionBehavior = null)
{
var projectile = new BasicProjectile(
damageToFarmer: damageToFarmer,
spriteIndex: parentSheetIndex,
bouncesTillDestruct: bouncesTillDestruct,
tailLength: tailLength,
rotationVelocity: rotationVelocity,
xVelocity: xVelocity,
yVelocity: yVelocity,
startingPosition: startingPosition
);

projectile.explode.Value = explode;
projectile.collisionSound.Value = collisionSound;
projectile.damagesMonsters.Value = damagesMonsters;
projectile.theOneWhoFiredMe.Set(location, firer);
projectile.itemId.Value = spriteFromObjectSheet ? parentSheetIndex.ToString() : null;
projectile.collisionBehavior = collisionBehavior;

if (!string.IsNullOrWhiteSpace(firingSound) && location != null)
location.playSound(firingSound);

return projectile;
}

public static BasicProjectile Constructor(int damageToFarmer, int parentSheetIndex, int bouncesTillDestruct, int tailLength, float rotationVelocity, float xVelocity, float yVelocity, Vector2 startingPosition)
{
return Constructor(damageToFarmer, parentSheetIndex, bouncesTillDestruct, tailLength, rotationVelocity, xVelocity, yVelocity, startingPosition, "flameSpellHit", "flameSpell", true);
}


/*********
** Private methods
*********/
private BasicProjectileFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley.Locations;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BoatTunnel"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BoatTunnelFacade : BoatTunnel, IRewriteFacade
{
/*********
** Public methods
*********/
public int GetTicketPrice()
{
return base.TicketPrice;
}


/*********
** Private methods
*********/
private BoatTunnelFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Objects;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.
Expand All @@ -8,6 +9,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Boots"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BootsFacade : Boots, IRewriteFacade
{
Expand All @@ -19,6 +22,16 @@ public static Boots Constructor(int which)
return new Boots(which.ToString());
}

public virtual void onEquip()
{
base.onEquip(Game1.player);
}

public virtual void onUnequip()
{
base.onUnequip(Game1.player);
}


/*********
** Private methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Locations;
using StardewValley.Objects;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.
Expand All @@ -16,6 +18,25 @@ public class BreakableContainerFacade : BreakableContainer, IRewriteFacade
/*********
** Public methods
*********/
public static BreakableContainer Constructor(Vector2 tile, int type, MineShaft mine)
{
var container = BreakableContainer.GetBarrelForMines(tile, mine);

if (type.ToString() != BreakableContainer.barrelId)
{
#pragma warning disable CS0618 // obsolete code -- it's used for its intended purpose here
container.SetIdAndSprite(type);
#pragma warning restore CS0618
}

return container;
}

public static BreakableContainer Constructor(Vector2 tile, bool isVolcano)
{
return BreakableContainer.GetBarrelForVolcanoDungeon(tile);
}

public void releaseContents(GameLocation location, Farmer who)
{
base.releaseContents(who);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Menus;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BuffsDisplayFacade"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BuffsDisplayFacade : BuffsDisplay, IRewriteFacade
{
/*********
** Public methods
*********/
public bool hasBuff(int which)
{
return Game1.player.hasBuff(which.ToString());
}


/*********
** Private methods
*********/
private BuffsDisplayFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class CharacterFacade : Character, IRewriteFacade
/*********
** Public methods
*********/
public new int addedSpeed
{
get => (int)base.addedSpeed;
set => base.addedSpeed = value;
}

public int getStandingX()
{
return base.StandingPixel.X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ public static Chest Constructor(Vector2 location)
return new Chest { TileLocation = location };
}

public ChestFacade(int parent_sheet_index, Vector2 tile_location, int starting_lid_frame, int lid_frame_count)
: base(parent_sheet_index.ToString(), tile_location, starting_lid_frame, lid_frame_count) { }
public static Chest Constructor(int parent_sheet_index, Vector2 tile_location, int starting_lid_frame, int lid_frame_count)
{
return new Chest(parent_sheet_index.ToString(), tile_location, starting_lid_frame, lid_frame_count);
}

public ChestFacade(int coins, List<Item> items, Vector2 location, bool giftbox = false, int giftboxIndex = 0)
: base(items, location, giftbox, giftboxIndex) { }
public static Chest Constructor(int coins, List<Item> items, Vector2 location, bool giftbox = false, int giftboxIndex = 0)
{
return new Chest(items, location, giftbox, giftboxIndex);
}

public void destroyAndDropContents(Vector2 pointToDropAt, GameLocation location)
{
Expand All @@ -59,6 +63,11 @@ public void dumpContents(GameLocation location)
base.dumpContents();
}

public void updateWhenCurrentLocation(GameTime time, GameLocation environment)
{
base.updateWhenCurrentLocation(time);
}


/*********
** Private methods
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Projectiles;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="DebuffingProjectile"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class DebuffingProjectileFacade : DebuffingProjectile, IRewriteFacade
{
/*********
** Public methods
*********/
public static DebuffingProjectile Constructor(int debuff, int parentSheetIndex, int bouncesTillDestruct, int tailLength, float rotationVelocity, float xVelocity, float yVelocity, Vector2 startingPosition, GameLocation? location = null, Character? owner = null)
{
return new DebuffingProjectile(
debuff: debuff.ToString(),
spriteIndex: parentSheetIndex,
bouncesTillDestruct: bouncesTillDestruct,
tailLength: tailLength,
rotationVelocity: rotationVelocity,
xVelocity: xVelocity,
yVelocity: yVelocity,
startingPosition: startingPosition,
location: location,
owner: owner
);
}


/*********
** Private methods
*********/
private DebuffingProjectileFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
Expand All @@ -15,6 +16,11 @@ public class DelayedActionFacade : DelayedAction, IRewriteFacade
/*********
** Public methods
*********/
public new static void functionAfterDelay(Action func, int timer)
{
DelayedAction.functionAfterDelay(func, timer);
}

public static void playSoundAfterDelay(string soundName, int timer, GameLocation? location = null, int pitch = -1)
{
DelayedAction.playSoundAfterDelay(soundName, timer, location, pitch: pitch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ public class FarmerFacade : Farmer, IRewriteFacade
*********/
public NetObjectList<Item> items => InventoryToNetObjectList.GetCachedWrapperFor(base.Items);

public int attack => base.buffs.Attack;
public int immunity => base.buffs.Immunity;
public int resilience => base.buffs.Defense;

public float attackIncreaseModifier => base.buffs.AttackMultiplier;
public float critChanceModifier => base.buffs.CriticalChanceMultiplier;
public float critPowerModifier => base.buffs.CriticalPowerMultiplier;
public float knockbackModifier => base.buffs.KnockbackMultiplier;
public float weaponPrecisionModifier => base.buffs.WeaponPrecisionMultiplier;
public float weaponSpeedModifier => base.buffs.WeaponSpeedMultiplier;

public new IList<Item> Items
{
get => base.Items;
Expand Down Expand Up @@ -107,11 +118,21 @@ public bool hasQuest(int id)
return base.hasQuest(id.ToString());
}

public bool isMarried()
{
return base.isMarriedOrRoommates();
}

public bool isWearingRing(int ringIndex)
{
return base.isWearingRing(ringIndex.ToString());
}

public void removeFirstOfThisItemFromInventory(int parentSheetIndexOfItem)
{
base.removeFirstOfThisItemFromInventory(parentSheetIndexOfItem.ToString());
}

public bool removeItemsFromInventory(int index, int stack)
{
if (this.hasItemInInventory(index, stack))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;

Expand All @@ -15,6 +16,11 @@ public class FenceFacade : Fence, IRewriteFacade
/*********
** Public methods
*********/
public static Fence Constructor(Vector2 tileLocation, int whichType, bool isGate)
{
return new Fence(tileLocation, whichType.ToString(), isGate);
}

public void toggleGate(GameLocation location, bool open, bool is_toggling_counterpart = false, Farmer? who = null)
{
base.toggleGate(open, is_toggling_counterpart, who);
Expand Down
Loading

0 comments on commit da7e709

Please sign in to comment.