Skip to content

Commit

Permalink
Fixed help wanted algorithm in relation to !collect
Browse files Browse the repository at this point in the history
  • Loading branch information
agilbert1412 committed Jan 29, 2023
1 parent f5e3278 commit 9a2ec5d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 deletions.
18 changes: 13 additions & 5 deletions StardewArchipelago/Locations/CodeInjections/QuestInjections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,25 @@ public static bool QuestComplete_LocationInsteadOfReward_Prefix(Quest __instance
private static void CheckDailyQuestLocation(string typeApName)
{
var locationName = $"Help Wanted: {typeApName}";
var alreadyCheckedLocations = _locationChecker.GetAllLocationsAlreadyChecked();
var nextLocationNumber = 1;
foreach (var checkedLocation in alreadyCheckedLocations)
while (true)
{
if (checkedLocation.StartsWith(locationName))
var fullName = $"{locationName} {nextLocationNumber}";
var id = _archipelago.GetLocationId(fullName);
if (id < 1)
{
return;
}

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

_locationChecker.AddCheckedLocation($"{locationName} {nextLocationNumber}");
_locationChecker.AddCheckedLocation(fullName);
return;
}
}

public static void Command_RemoveQuest_CheckLocation_Postfix(Event __instance, GameLocation location, GameTime time, string[] split)
Expand Down
13 changes: 13 additions & 0 deletions StardewArchipelago/Locations/LocationChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,18 @@ private void TryToIdentifyUnknownLocationNames()
_checkedLocations[locationName] = locationId;
}
}

public void ForgetLocations(IEnumerable<string> locations)
{
foreach (var location in locations)
{
if (!_checkedLocations.ContainsKey(location))
{
continue;
}

_checkedLocations.Remove(location);
}
}
}
}
64 changes: 56 additions & 8 deletions StardewArchipelago/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using Microsoft.Xna.Framework;
using StardewArchipelago.Archipelago;
Expand Down Expand Up @@ -38,7 +39,7 @@ public class ModEntry : Mod
private ItemManager _itemManager;
private RandomizedLogicPatcher _logicPatcher;
private MailPatcher _mailPatcher;
private LocationChecker _locationsChecker;
private LocationChecker _locationChecker;
private LocationPatcher _locationsPatcher;
private ItemPatcher _itemPatcher;
private GoalManager _goalManager;
Expand Down Expand Up @@ -133,7 +134,7 @@ private void OnSaveCreated(object sender, SaveCreatedEventArgs e)
private void OnSaving(object sender, SavingEventArgs e)
{
_state.ItemsReceived = _itemManager.GetAllItemsAlreadyProcessed();
_state.LocationsChecked = _locationsChecker.GetAllLocationsAlreadyChecked();
_state.LocationsChecked = _locationChecker.GetAllLocationsAlreadyChecked();
_state.LocationsScouted = _archipelago.ScoutedLocations;
_state.LettersGenerated = _mail.GetAllLettersGenerated();
_helper.Data.WriteSaveData(AP_DATA_KEY, _state);
Expand All @@ -155,11 +156,11 @@ private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
_unlockManager = new UnlockManager();
_itemManager = new ItemManager(_archipelago, _stardewItemManager, _unlockManager, _mail, _state.ItemsReceived);
_mailPatcher = new MailPatcher(Monitor, new LetterActions(_mail), _harmony);
_locationsChecker = new LocationChecker(Monitor, _archipelago, _state.LocationsChecked);
_locationsPatcher = new LocationPatcher(Monitor, _archipelago, _bundleReader, _helper, _harmony, _locationsChecker);
_locationChecker = new LocationChecker(Monitor, _archipelago, _state.LocationsChecked);
_locationsPatcher = new LocationPatcher(Monitor, _archipelago, _bundleReader, _helper, _harmony, _locationChecker);
_itemPatcher = new ItemPatcher(Monitor, _helper, _harmony, _archipelago);
_goalManager = new GoalManager(Monitor, _helper, _harmony, _archipelago, _locationsChecker);
_logicPatcher = new RandomizedLogicPatcher(Monitor, _harmony, _archipelago, _locationsChecker);
_goalManager = new GoalManager(Monitor, _helper, _harmony, _archipelago, _locationChecker);
_logicPatcher = new RandomizedLogicPatcher(Monitor, _harmony, _archipelago, _locationChecker);
_jojaDisabler = new JojaDisabler(Monitor, _helper, _harmony);

if (_state.APConnectionInfo != null && !_archipelago.IsConnected)
Expand Down Expand Up @@ -187,6 +188,53 @@ private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
{
GivePlayerStartingResources();
}

FixDailyQuestLocations("Item Delivery");
FixDailyQuestLocations("Slay Monsters");
FixDailyQuestLocations("Fishing");
FixDailyQuestLocations("Gathering");
}

private void FixDailyQuestLocations(string typeApName)
{
var locationName = $"Help Wanted: {typeApName}";
var checkedLocationOfType =
_locationChecker.GetAllLocationsAlreadyChecked().Where(x => x.StartsWith(locationName));
var checkedLocationsNotResolved = checkedLocationOfType.Where(x => _archipelago.GetLocationId(x) < 1);
var numberOfCheckedLocationsNotResolved = checkedLocationsNotResolved.Count();
if (numberOfCheckedLocationsNotResolved < 1)
{
return;
}

for (var i = 0; i < numberOfCheckedLocationsNotResolved; i++)
{
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()
Expand Down Expand Up @@ -218,8 +266,8 @@ private void OnDayStarted(object sender, DayStartedEventArgs e)

FarmInjections.DeleteStartingDebris();
_mail.SendToday();
_locationsChecker.VerifyNewLocationChecksWithArchipelago();
_locationsChecker.SendAllLocationChecks();
_locationChecker.VerifyNewLocationChecksWithArchipelago();
_locationChecker.SendAllLocationChecks();
_itemManager.ReceiveAllNewItems();
_goalManager.CheckGoalCompletion();
_mail.SendTomorrow();
Expand Down

0 comments on commit 9a2ec5d

Please sign in to comment.