Skip to content

Commit 4622431

Browse files
committed
remove wood on pedestal when the 'rare wood' is purchased
Changes in the spritesheet: - removed the wood-without-glass pedestal; - created an empty pedestal based on the wood-with-glass one; - and rearranged that part of the spritesheet to fit the new pedestal.
1 parent dbd0c7f commit 4622431

File tree

8 files changed

+122
-45
lines changed

8 files changed

+122
-45
lines changed

CentralStation/Framework/Constants/MapSubActions.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ internal class MapSubActions
1212
/// <summary>The sub-action which checks the exit door.</summary>
1313
public const string ExitDoor = "ExitDoor";
1414

15+
/// <summary>The sub-action which opens the gift shop.</summary>
16+
public const string GiftShop = "GiftShop";
17+
18+
/// <summary>The sub-action which opens the pop-up shop.</summary>
19+
public const string PopUpShop = "PopUpShop";
20+
1521
/// <summary>The sub-action which opens a destination menu through the main Central Station ticket booth.</summary>
1622
public const string TicketBooth = "TicketBooth";
1723

1824
/// <summary>The sub-action which opens a destination menu through the main Central Station ticket machine.</summary>
1925
public const string TicketMachine = "TicketMachine";
2026

21-
/// <summary>The sub-action which opens the pop-up shop.</summary>
22-
public const string PopUpShop = "PopUpShop";
23-
2427
/// <summary>The sub-action which opens a destination menu.</summary>
2528
public const string TouristDialogue = "TouristDialogue";
2629
}

CentralStation/Framework/ContentManager.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
44
using System.Linq;
5+
using System.Reflection;
56
using Microsoft.Xna.Framework;
7+
using Netcode;
68
using Pathoschild.Stardew.CentralStation.Framework.Constants;
79
using Pathoschild.Stardew.CentralStation.Framework.ContentModels;
810
using Pathoschild.Stardew.Common;
@@ -13,7 +15,9 @@
1315
using StardewValley.Extensions;
1416
using StardewValley.GameData;
1517
using StardewValley.Locations;
18+
using StardewValley.Network;
1619
using StardewValley.TokenizableStrings;
20+
using StardewValley.Util;
1721
using xTile;
1822
using xTile.Layers;
1923
using xTile.Tiles;
@@ -381,6 +385,20 @@ public bool TryParseOptionalSpaceDelimitedNetworks(string[] args, int index, out
381385
return true;
382386
}
383387

388+
/// <summary>Update the Central Station map when the rare wood is sold.</summary>
389+
/// <param name="map">The map to edit.</param>
390+
public void OnRareWoodSold(Map map)
391+
{
392+
IAssetDataForMap editor = this.ContentHelper.GetPatchHelper(map, map.assetPath).AsMap();
393+
394+
editor.PatchMap(
395+
source: this.ContentHelper.Load<Map>($"Maps/{Constant.ModId}_EmptyWoodPedestal"),
396+
sourceArea: new Rectangle(0, 0, 2, 3),
397+
targetArea: new Rectangle(57, 25, 2, 3),
398+
PatchMapMode.ReplaceByLayer
399+
);
400+
}
401+
384402

385403
/*********
386404
** Private methods
@@ -457,8 +475,10 @@ private void AddTicketMachineForMapProperty(GameLocation location)
457475
/// <param name="assetData">The asset data.</param>
458476
private void EditCentralStationMap(IAssetData assetData)
459477
{
460-
var map = assetData.AsMap().Data;
478+
var editor = assetData.AsMap();
479+
var map = editor.Data;
461480

481+
// dark station
462482
if (this.StationDark.Value)
463483
{
464484
// make it darker
@@ -510,8 +530,16 @@ private void EditCentralStationMap(IAssetData assetData)
510530
}
511531
}
512532
}
513-
else
514-
this.AddCentralStationTourists(assetData.AsMap());
533+
534+
// empty wood pedestal if sold
535+
SynchronizedShopStock syncedShop = Game1.player.team.synchronizedShopStock;
536+
string woodSyncId = $"{Constant.ModId}_GiftShop/{Game1.player.UniqueMultiplayerID}/Wood";
537+
var syncedStock = syncedShop.GetType().GetField("stockDictionary", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)?.GetValue(syncedShop) as NetStringDictionary<int, NetInt>;
538+
if (syncedStock != null && syncedStock.TryGetValue(woodSyncId, out int stock) && stock <= 0)
539+
this.OnRareWoodSold(map);
540+
541+
// add tourists
542+
this.AddCentralStationTourists(editor);
515543
}
516544

517545
/// <summary>Add random tourist NPCs to the Central Station map.</summary>

CentralStation/ModEntry.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ private bool OnCentralAction(GameLocation location, string[] args, Farmer who, P
148148
case MapSubActions.ExitDoor:
149149
return this.OnCentralExitDoorAction();
150150

151+
case MapSubActions.GiftShop:
152+
return this.OnCentralGiftShopAction();
153+
151154
case MapSubActions.PopUpShop:
152155
return this.OnCentralPopupShopAction();
153156

@@ -266,6 +269,23 @@ private bool OnCentralExitDoorAction()
266269
return true;
267270
}
268271

272+
/// <summary>Handle the player activating a <see cref="MapSubActions.GiftShop"/> action in the Central Station.</summary>
273+
/// <returns>Returns whether the action was handled.</returns>
274+
private bool OnCentralGiftShopAction()
275+
{
276+
if (Utility.TryOpenShopMenu($"{Constant.ModId}_GiftShop", null as string) && Game1.activeClickableMenu is ShopMenu shop)
277+
shop.onPurchase = OnPurchase;
278+
return true;
279+
280+
bool OnPurchase(ISalable salable, Farmer who, int countTaken, ItemStockInformation stock)
281+
{
282+
if (salable.QualifiedItemId == "(O)388" && Game1.currentLocation.Name == Constant.CentralStationLocationId)
283+
this.ContentManager.OnRareWoodSold(Game1.currentLocation.Map);
284+
285+
return false;
286+
}
287+
}
288+
269289
/// <summary>Handle the player activating a <see cref="MapSubActions.PopUpShop"/> action in the Central Station.</summary>
270290
/// <returns>Returns whether the action was handled.</returns>
271291
private bool OnCentralPopupShopAction()
6.33 KB
Loading

0 commit comments

Comments
 (0)