Skip to content

Commit

Permalink
- Error message when loading a save fails to connect
Browse files Browse the repository at this point in the history
- New connect_override command
- Daily quest rework
- Fix Prairie king shop I hope
  • Loading branch information
agilbert1412 committed Jan 30, 2023
1 parent 9a2ec5d commit b043c85
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 41 deletions.
25 changes: 24 additions & 1 deletion StardewArchipelago/GameModifications/InformationDialog.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using StardewValley;
using StardewValley.Menus;

Expand All @@ -12,14 +13,17 @@ public class InformationDialog : IClickableMenu
protected string message;
public ClickableTextureComponent okButton;
protected ConfirmationDialog.behavior onClickOk;
protected ConfirmationDialog.behavior onClose;
private bool active = true;

public InformationDialog(
string message,
ConfirmationDialog.behavior onClickOkBehavior = null)
ConfirmationDialog.behavior onClickOkBehavior = null,
ConfirmationDialog.behavior onCloseBehavior = null)
: base(Game1.uiViewport.Width / 2 - (int)Game1.dialogueFont.MeasureString(message).X / 2 - borderWidth, Game1.uiViewport.Height / 2 - (int)Game1.dialogueFont.MeasureString(message).Y / 2, (int)Game1.dialogueFont.MeasureString(message).X + borderWidth * 2, (int)Game1.dialogueFont.MeasureString(message).Y + borderWidth * 2 + 160)
{
onClickOk = onClickOkBehavior ?? CloseDialog;
onClose = onCloseBehavior;
var titleSafeArea = Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea();
this.message = Game1.parseText(message, Game1.dialogueFont, Math.Min(titleSafeArea.Width - 64, width));
okButton = new ClickableTextureComponent("OK", new Rectangle(xPositionOnScreen + width - borderWidth - spaceToClearSideBorder - 128 - 4, yPositionOnScreen + height - borderWidth - spaceToClearTopBorder + 21, 64, 64), (string)null, (string)null, Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 46), 1f);
Expand All @@ -39,8 +43,27 @@ public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBou
okButton.setPosition(xPositionOnScreen + width - borderWidth - spaceToClearSideBorder - 128 - 4, yPositionOnScreen + height - borderWidth - spaceToClearTopBorder + 21);
}

public override void receiveKeyPress(Keys key)
{
if (key == Keys.None)
return;
if (Game1.options.doesInputListContain(Game1.options.menuButton, key) && this.readyToClose())
{
CloseDialog(Game1.player);
return;
}

base.receiveKeyPress(key);
}

public virtual void CloseDialog(Farmer who)
{
if (onClose != null)
{
onClose(who);
return;
}

if (Game1.activeClickableMenu is TitleMenu titleMenu)
{
titleMenu.backButtonPressed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public static class ArcadeMachineInjections
private static int _bootsLevel;
private static int _gunLevel;
private static int _ammoLevel;
private static int _bootsItemOffered;
private static int _gunItemOffered;
private static int _ammoItemOffered;
private static int _bootsItemOffered = -1;
private static int _gunItemOffered = -1;
private static int _ammoItemOffered = -1;

public static void Initialize(IMonitor monitor, IModHelper helper, ArchipelagoClient archipelago, LocationChecker locationChecker)
{
Expand Down Expand Up @@ -249,7 +249,7 @@ public static void Tick_Shopping_PostFix(AbigailGame __instance, GameTime time,
{
try
{
if (__instance.runSpeedLevel > _bootsLevel)
if (__instance.runSpeedLevel != _bootsLevel)
{
switch (_bootsItemOffered)
{
Expand All @@ -264,7 +264,9 @@ public static void Tick_Shopping_PostFix(AbigailGame __instance, GameTime time,
AssignStartingEquipment(__instance);
return;
}
if (__instance.fireSpeedLevel > _gunLevel || __instance.spreadPistol && _gunLevel < 4)

var instanceGun = __instance.fireSpeedLevel + (__instance.spreadPistol ? 1 : 0);
if (instanceGun != _gunLevel)
{
switch (_gunItemOffered)
{
Expand All @@ -285,7 +287,8 @@ public static void Tick_Shopping_PostFix(AbigailGame __instance, GameTime time,
AssignStartingEquipment(__instance);
return;
}
if (__instance.ammoLevel > _ammoLevel)

if (__instance.ammoLevel != _ammoLevel)
{
switch (_ammoItemOffered)
{
Expand Down Expand Up @@ -350,6 +353,10 @@ private static void AssignStartingEquipment(AbigailGame __instance)
__instance.spreadPistol = _gunLevel == 4;
__instance.ammoLevel = _ammoLevel;
__instance.bulletDamage = 1 + _ammoLevel;

_bootsItemOffered = -1;
_gunItemOffered = -1;
_ammoItemOffered = -1;
}

private static int GetBootsItemToOffer()
Expand Down
15 changes: 10 additions & 5 deletions StardewArchipelago/Locations/CodeInjections/QuestInjections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ public static bool QuestComplete_LocationInsteadOfReward_Prefix(Quest __instance
switch (__instance.questType.Value)
{
case (int)QuestType.ItemDelivery:
CheckDailyQuestLocation("Item Delivery");
CheckDailyQuestLocationOfType("Item Delivery");
break;
case (int)QuestType.SlayMonsters:
CheckDailyQuestLocation("Slay Monsters");
CheckDailyQuestLocationOfType("Slay Monsters");
break;
case (int)QuestType.Fishing:
CheckDailyQuestLocation("Fishing");
CheckDailyQuestLocationOfType("Fishing");
break;
case (int)QuestType.ResourceCollection:
CheckDailyQuestLocation("Gathering");
CheckDailyQuestLocationOfType("Gathering");
break;
}

Expand All @@ -102,9 +102,14 @@ public static bool QuestComplete_LocationInsteadOfReward_Prefix(Quest __instance
}
}

private static void CheckDailyQuestLocation(string typeApName)
private static void CheckDailyQuestLocationOfType(string typeApName)
{
var locationName = $"Help Wanted: {typeApName}";
CheckDailyQuestLocation(locationName);
}

public static void CheckDailyQuestLocation(string locationName)
{
var nextLocationNumber = 1;
while (true)
{
Expand Down
60 changes: 31 additions & 29 deletions StardewArchipelago/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using StardewValley;
using StardewValley.Buildings;
using StardewValley.Locations;
using StardewValley.Menus;
using StardewValley.Objects;

namespace StardewArchipelago
Expand Down Expand Up @@ -51,6 +52,7 @@ public class ModEntry : Mod
private Tester _tester;

private ArchipelagoStateDto _state;
private ArchipelagoConnectionInfo _apConnectionOverride;

public ModEntry() : base()
{
Expand All @@ -63,6 +65,8 @@ public ModEntry() : base()
/// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper)
{
_apConnectionOverride = null;

_helper = helper;
_harmony = new Harmony(this.ModManifest.UniqueID);

Expand All @@ -80,6 +84,9 @@ public override void Entry(IModHelper helper)
_helper.Events.GameLoop.DayEnding += this.OnDayEnding;
_helper.Events.GameLoop.ReturnedToTitle += this.OnReturnedToTitle;


_helper.ConsoleCommands.Add("connect_override", $"Overrides your next connection to Archipelago. {CONNECT_SYNTAX}", this.OnCommandConnectToArchipelago);

#if DEBUG
_helper.ConsoleCommands.Add("connect", $"Connect to Archipelago. {CONNECT_SYNTAX}", this.OnCommandConnectToArchipelago);
_helper.ConsoleCommands.Add("disconnect", $"Disconnects from Archipelago. {CONNECT_SYNTAX}", this.OnCommandDisconnectFromArchipelago);
Expand Down Expand Up @@ -163,16 +170,26 @@ private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
_logicPatcher = new RandomizedLogicPatcher(Monitor, _harmony, _archipelago, _locationChecker);
_jojaDisabler = new JojaDisabler(Monitor, _helper, _harmony);

if (_state.APConnectionInfo != null && !_archipelago.IsConnected)
if (_state.APConnectionInfo == null)
{
_archipelago.Connect(_state.APConnectionInfo, out _);
return;
}

if (!_archipelago.IsConnected)
{
Monitor.Log("You are not allowed to load a save without connecting to Archipelago", LogLevel.Error);
Game1.ExitToTitle();
return;
if (_apConnectionOverride != null)
{
_state.APConnectionInfo = _apConnectionOverride;
_apConnectionOverride = null;
}
_archipelago.Connect(_state.APConnectionInfo, out var errorMessage);

if (!_archipelago.IsConnected)
{
_state.APConnectionInfo = null;
Game1.activeClickableMenu = new InformationDialog(errorMessage, onCloseBehavior: (_) => OnCloseBehavior());
return;
}
}

_logicPatcher.PatchAllGameLogic();
Expand All @@ -195,6 +212,13 @@ private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
FixDailyQuestLocations("Gathering");
}

private void OnCloseBehavior()
{
Monitor.Log("You are not allowed to load a save without connecting to Archipelago", LogLevel.Error);
// TitleMenu.subMenu = previousMenu;
Game1.ExitToTitle();
}

private void FixDailyQuestLocations(string typeApName)
{
var locationName = $"Help Wanted: {typeApName}";
Expand All @@ -209,34 +233,12 @@ private void FixDailyQuestLocations(string typeApName)

for (var i = 0; i < numberOfCheckedLocationsNotResolved; i++)
{
CheckDailyQuestLocation(locationName);
QuestInjections.CheckDailyQuestLocation(locationName);
}

_locationChecker.ForgetLocations(checkedLocationsNotResolved);
}

private void CheckDailyQuestLocation(string locationName)
{
var nextLocationNumber = 1;
while (true)
{
var fullName = $"{locationName} {nextLocationNumber}";
var id = _archipelago.GetLocationId(fullName);
if (id < 1)
{
return;
}

if (_locationChecker.IsLocationChecked(fullName))
{
nextLocationNumber++;
continue;
}

_locationChecker.AddCheckedLocation(fullName);
}
}

private void ReadPersistentArchipelagoData()
{
var state = _helper.Data.ReadSaveData<ArchipelagoStateDto>(AP_DATA_KEY);
Expand Down Expand Up @@ -310,7 +312,7 @@ private void OnCommandConnectToArchipelago(string arg1, string[] arg2)
var port = int.Parse(ipAndPort[1]);
var slot = arg2[1];
var password = arg2.Length >= 3 ? arg2[2] : "";
ArchipelagoConnect(ip, port, slot, password, out _);
_apConnectionOverride = new ArchipelagoConnectionInfo(ip, port, slot, false, password);
}

private void OnCommandDisconnectFromArchipelago(string arg1, string[] arg2)
Expand Down

0 comments on commit b043c85

Please sign in to comment.