Skip to content

Commit da7e709

Browse files
committed
improve rewriters for Stardew Valley 1.6
1 parent 21abd0f commit da7e709

32 files changed

+1091
-23
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.Xna.Framework;
3+
using StardewModdingAPI.Framework.ModLoading.Framework;
4+
using StardewValley;
5+
using StardewValley.Projectiles;
6+
7+
#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.
8+
9+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
10+
{
11+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BasicProjectile"/> methods to their newer form to avoid breaking older mods.</summary>
12+
/// <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>
13+
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)]
14+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
15+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
16+
public class BasicProjectileFacade : BasicProjectile, IRewriteFacade
17+
{
18+
/*********
19+
** Public methods
20+
*********/
21+
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)
22+
{
23+
var projectile = new BasicProjectile(
24+
damageToFarmer: damageToFarmer,
25+
spriteIndex: parentSheetIndex,
26+
bouncesTillDestruct: bouncesTillDestruct,
27+
tailLength: tailLength,
28+
rotationVelocity: rotationVelocity,
29+
xVelocity: xVelocity,
30+
yVelocity: yVelocity,
31+
startingPosition: startingPosition
32+
);
33+
34+
projectile.explode.Value = explode;
35+
projectile.collisionSound.Value = collisionSound;
36+
projectile.damagesMonsters.Value = damagesMonsters;
37+
projectile.theOneWhoFiredMe.Set(location, firer);
38+
projectile.itemId.Value = spriteFromObjectSheet ? parentSheetIndex.ToString() : null;
39+
projectile.collisionBehavior = collisionBehavior;
40+
41+
if (!string.IsNullOrWhiteSpace(firingSound) && location != null)
42+
location.playSound(firingSound);
43+
44+
return projectile;
45+
}
46+
47+
public static BasicProjectile Constructor(int damageToFarmer, int parentSheetIndex, int bouncesTillDestruct, int tailLength, float rotationVelocity, float xVelocity, float yVelocity, Vector2 startingPosition)
48+
{
49+
return Constructor(damageToFarmer, parentSheetIndex, bouncesTillDestruct, tailLength, rotationVelocity, xVelocity, yVelocity, startingPosition, "flameSpellHit", "flameSpell", true);
50+
}
51+
52+
53+
/*********
54+
** Private methods
55+
*********/
56+
private BasicProjectileFacade()
57+
{
58+
RewriteHelper.ThrowFakeConstructorCalled();
59+
}
60+
}
61+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using StardewModdingAPI.Framework.ModLoading.Framework;
3+
using StardewValley.Locations;
4+
5+
#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.
6+
7+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
8+
{
9+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BoatTunnel"/> methods to their newer form to avoid breaking older mods.</summary>
10+
/// <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>
11+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
12+
public class BoatTunnelFacade : BoatTunnel, IRewriteFacade
13+
{
14+
/*********
15+
** Public methods
16+
*********/
17+
public int GetTicketPrice()
18+
{
19+
return base.TicketPrice;
20+
}
21+
22+
23+
/*********
24+
** Private methods
25+
*********/
26+
private BoatTunnelFacade()
27+
{
28+
RewriteHelper.ThrowFakeConstructorCalled();
29+
}
30+
}
31+
}

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BootsFacade.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics.CodeAnalysis;
22
using StardewModdingAPI.Framework.ModLoading.Framework;
3+
using StardewValley;
34
using StardewValley.Objects;
45

56
#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.
@@ -8,6 +9,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
89
{
910
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Boots"/> methods to their newer form to avoid breaking older mods.</summary>
1011
/// <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>
12+
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)]
13+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
1114
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
1215
public class BootsFacade : Boots, IRewriteFacade
1316
{
@@ -19,6 +22,16 @@ public static Boots Constructor(int which)
1922
return new Boots(which.ToString());
2023
}
2124

25+
public virtual void onEquip()
26+
{
27+
base.onEquip(Game1.player);
28+
}
29+
30+
public virtual void onUnequip()
31+
{
32+
base.onUnequip(Game1.player);
33+
}
34+
2235

2336
/*********
2437
** Private methods

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/BreakableContainer.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.Xna.Framework;
23
using StardewModdingAPI.Framework.ModLoading.Framework;
34
using StardewValley;
5+
using StardewValley.Locations;
46
using StardewValley.Objects;
57

68
#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.
@@ -16,6 +18,25 @@ public class BreakableContainerFacade : BreakableContainer, IRewriteFacade
1618
/*********
1719
** Public methods
1820
*********/
21+
public static BreakableContainer Constructor(Vector2 tile, int type, MineShaft mine)
22+
{
23+
var container = BreakableContainer.GetBarrelForMines(tile, mine);
24+
25+
if (type.ToString() != BreakableContainer.barrelId)
26+
{
27+
#pragma warning disable CS0618 // obsolete code -- it's used for its intended purpose here
28+
container.SetIdAndSprite(type);
29+
#pragma warning restore CS0618
30+
}
31+
32+
return container;
33+
}
34+
35+
public static BreakableContainer Constructor(Vector2 tile, bool isVolcano)
36+
{
37+
return BreakableContainer.GetBarrelForVolcanoDungeon(tile);
38+
}
39+
1940
public void releaseContents(GameLocation location, Farmer who)
2041
{
2142
base.releaseContents(who);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using StardewModdingAPI.Framework.ModLoading.Framework;
3+
using StardewValley;
4+
using StardewValley.Menus;
5+
6+
#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.
7+
8+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
9+
{
10+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BuffsDisplayFacade"/> methods to their newer form to avoid breaking older mods.</summary>
11+
/// <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>
12+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
13+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
14+
public class BuffsDisplayFacade : BuffsDisplay, IRewriteFacade
15+
{
16+
/*********
17+
** Public methods
18+
*********/
19+
public bool hasBuff(int which)
20+
{
21+
return Game1.player.hasBuff(which.ToString());
22+
}
23+
24+
25+
/*********
26+
** Private methods
27+
*********/
28+
private BuffsDisplayFacade()
29+
{
30+
RewriteHelper.ThrowFakeConstructorCalled();
31+
}
32+
}
33+
}

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/CharacterFacade.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public class CharacterFacade : Character, IRewriteFacade
1717
/*********
1818
** Public methods
1919
*********/
20+
public new int addedSpeed
21+
{
22+
get => (int)base.addedSpeed;
23+
set => base.addedSpeed = value;
24+
}
25+
2026
public int getStandingX()
2127
{
2228
return base.StandingPixel.X;

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/ChestFacade.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ public static Chest Constructor(Vector2 location)
4343
return new Chest { TileLocation = location };
4444
}
4545

46-
public ChestFacade(int parent_sheet_index, Vector2 tile_location, int starting_lid_frame, int lid_frame_count)
47-
: base(parent_sheet_index.ToString(), tile_location, starting_lid_frame, lid_frame_count) { }
46+
public static Chest Constructor(int parent_sheet_index, Vector2 tile_location, int starting_lid_frame, int lid_frame_count)
47+
{
48+
return new Chest(parent_sheet_index.ToString(), tile_location, starting_lid_frame, lid_frame_count);
49+
}
4850

49-
public ChestFacade(int coins, List<Item> items, Vector2 location, bool giftbox = false, int giftboxIndex = 0)
50-
: base(items, location, giftbox, giftboxIndex) { }
51+
public static Chest Constructor(int coins, List<Item> items, Vector2 location, bool giftbox = false, int giftboxIndex = 0)
52+
{
53+
return new Chest(items, location, giftbox, giftboxIndex);
54+
}
5155

5256
public void destroyAndDropContents(Vector2 pointToDropAt, GameLocation location)
5357
{
@@ -59,6 +63,11 @@ public void dumpContents(GameLocation location)
5963
base.dumpContents();
6064
}
6165

66+
public void updateWhenCurrentLocation(GameTime time, GameLocation environment)
67+
{
68+
base.updateWhenCurrentLocation(time);
69+
}
70+
6271

6372
/*********
6473
** Private methods
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.Xna.Framework;
3+
using StardewModdingAPI.Framework.ModLoading.Framework;
4+
using StardewValley;
5+
using StardewValley.Projectiles;
6+
7+
#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.
8+
9+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
10+
{
11+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="DebuffingProjectile"/> methods to their newer form to avoid breaking older mods.</summary>
12+
/// <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>
13+
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = SuppressReasons.MatchesOriginal)]
14+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
15+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
16+
public class DebuffingProjectileFacade : DebuffingProjectile, IRewriteFacade
17+
{
18+
/*********
19+
** Public methods
20+
*********/
21+
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)
22+
{
23+
return new DebuffingProjectile(
24+
debuff: debuff.ToString(),
25+
spriteIndex: parentSheetIndex,
26+
bouncesTillDestruct: bouncesTillDestruct,
27+
tailLength: tailLength,
28+
rotationVelocity: rotationVelocity,
29+
xVelocity: xVelocity,
30+
yVelocity: yVelocity,
31+
startingPosition: startingPosition,
32+
location: location,
33+
owner: owner
34+
);
35+
}
36+
37+
38+
/*********
39+
** Private methods
40+
*********/
41+
private DebuffingProjectileFacade()
42+
{
43+
RewriteHelper.ThrowFakeConstructorCalled();
44+
}
45+
}
46+
}

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/DelayedActionFacade.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Diagnostics.CodeAnalysis;
23
using StardewModdingAPI.Framework.ModLoading.Framework;
34
using StardewValley;
@@ -15,6 +16,11 @@ public class DelayedActionFacade : DelayedAction, IRewriteFacade
1516
/*********
1617
** Public methods
1718
*********/
19+
public new static void functionAfterDelay(Action func, int timer)
20+
{
21+
DelayedAction.functionAfterDelay(func, timer);
22+
}
23+
1824
public static void playSoundAfterDelay(string soundName, int timer, GameLocation? location = null, int pitch = -1)
1925
{
2026
DelayedAction.playSoundAfterDelay(soundName, timer, location, pitch: pitch);

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_6/FarmerFacade.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public class FarmerFacade : Farmer, IRewriteFacade
2323
*********/
2424
public NetObjectList<Item> items => InventoryToNetObjectList.GetCachedWrapperFor(base.Items);
2525

26+
public int attack => base.buffs.Attack;
27+
public int immunity => base.buffs.Immunity;
28+
public int resilience => base.buffs.Defense;
29+
30+
public float attackIncreaseModifier => base.buffs.AttackMultiplier;
31+
public float critChanceModifier => base.buffs.CriticalChanceMultiplier;
32+
public float critPowerModifier => base.buffs.CriticalPowerMultiplier;
33+
public float knockbackModifier => base.buffs.KnockbackMultiplier;
34+
public float weaponPrecisionModifier => base.buffs.WeaponPrecisionMultiplier;
35+
public float weaponSpeedModifier => base.buffs.WeaponSpeedMultiplier;
36+
2637
public new IList<Item> Items
2738
{
2839
get => base.Items;
@@ -107,11 +118,21 @@ public bool hasQuest(int id)
107118
return base.hasQuest(id.ToString());
108119
}
109120

121+
public bool isMarried()
122+
{
123+
return base.isMarriedOrRoommates();
124+
}
125+
110126
public bool isWearingRing(int ringIndex)
111127
{
112128
return base.isWearingRing(ringIndex.ToString());
113129
}
114130

131+
public void removeFirstOfThisItemFromInventory(int parentSheetIndexOfItem)
132+
{
133+
base.removeFirstOfThisItemFromInventory(parentSheetIndexOfItem.ToString());
134+
}
135+
115136
public bool removeItemsFromInventory(int index, int stack)
116137
{
117138
if (this.hasItemInInventory(index, stack))

0 commit comments

Comments
 (0)