Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions APRandomizerMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
using Mod.Courier;
using Mod.Courier.Module;
using Mod.Courier.UI;
using static Mod.Courier.UI.TextEntryButtonInfo;
using MonoMod.Cil;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using WebSocketSharp;
using static Mod.Courier.UI.TextEntryButtonInfo;
using Object = UnityEngine.Object;

namespace MessengerRando
namespace MessengerRando
{
/// <summary>
/// Where it all begins! This class defines and injects all the necessary for the mod.
Expand Down Expand Up @@ -53,7 +53,7 @@ public override void Load()

//Initialize the randomizer state manager
randoStateManager = new RandomizerStateManager();

//Plug in my code :3
On.InventoryManager.AddItem += InventoryManager_AddItem;
On.ProgressionManager.SetChallengeRoomAsCompleted += ProgressionManager_SetChallengeRoomAsCompleted;
Expand Down Expand Up @@ -102,6 +102,8 @@ public override void Load()
On.ElementalSkylandsLevelInitializer.OnBeforeInitDone += RandoLevelManager.ElementalSkylandsInit;
// On.PortalOpeningCutscene.OnOpenPortalEvent += RandoPortalManager.OpenPortalEvent;
On.TotHQ.LeaveToLevel += RandoPortalManager.LeaveHQ;
// generator deactivation management
Hooks.ElementalSkylandGenerator.ApplyHooks();
//These functions let us override and manage power seals ourselves with 'fake' items
On.ProgressionManager.TotalPowerSealCollected += ProgressionManager_TotalPowerSealCollected;
On.ShopChestOpenCutscene.OnChestOpened += (orig, self) =>
Expand All @@ -121,12 +123,12 @@ public override void Load()
On.Cutscene.Play += Cutscene_Play;
On.PlayerController.Awake += OnPlayerController_Awake;
//temp add
#if DEBUG
#if DEBUG
On.PhantomIntroCutscene.OnEnterRoom += PhantomIntro_OnEnterRoom; //this lets us skip the phantom fight
On.UIManager.ShowView += UIManager_ShowView;
On.MusicBox.SetNotesState += MusicBox_SetNotesState;
On.PowerSeal.OnEnterRoom += PowerSeal_OnEnterRoom;
#endif
#endif

Console.WriteLine("Randomizer finished loading!");
}
Expand Down Expand Up @@ -171,17 +173,17 @@ private void OnOptionScreenEnable(On.OptionScreen.orig_OnEnable orig, OptionScre

public override void Initialize()
{
#if DEBUG
#if DEBUG
SceneManager.sceneLoaded += OnSceneLoadedRando;
#endif
#endif

//load config
Debug.Log("Loading config from APConfig.toml");
try
{
UserConfig.ReadConfig(ModPath);
}
catch (Exception e) {Console.Write(e);}
catch (Exception e) { Console.Write(e); }
ArchipelagoMenu.BuildArchipelagoMenu();
RandoMenu.BuildRandoMenu();
HintMenu.BuildHintMenu();
Expand Down Expand Up @@ -245,7 +247,7 @@ void InventoryManager_AddItem(On.InventoryManager.orig_AddItem orig, InventoryMa
}
//Call original add with items
orig(self, itemId, quantity);

}

void ProgressionManager_SetChallengeRoomAsCompleted(On.ProgressionManager.orig_SetChallengeRoomAsCompleted orig, ProgressionManager self, string roomKey)
Expand Down Expand Up @@ -277,7 +279,7 @@ bool HasItem_IsTrue(On.HasItem.orig_IsTrue orig, HasItem self)
//OLD WAY
//Don't actually check for the item i have, check to see if I have the item that was at it's location.
//int itemQuantity = Manager<InventoryManager>.Instance.GetItemQuantity(randoStateManager.CurrentLocationToItemMapping[check].Item);

//NEW WAY
//Don't actually check for the item I have, check to see if I have done this check before. We'll do this by seeing if the item at its location has been collected yet or not
int itemQuantity = RandomizerStateManager.HasCompletedCheck(check) ? 1 : 0;
Expand All @@ -290,7 +292,7 @@ bool HasItem_IsTrue(On.HasItem.orig_IsTrue orig, HasItem self)
? 1
: 0;
}

switch (self.conditionOperator)
{
case EConditionOperator.LESS_THAN:
Expand All @@ -314,9 +316,9 @@ bool HasItem_IsTrue(On.HasItem.orig_IsTrue orig, HasItem self)
Console.WriteLine("HasItem check was not randomized. Doing vanilla checks.");
Debug.Log($"Is randomized file : '{ArchipelagoClient.HasConnected}' | Is location '{self.item}' randomized: '{randoStateManager.IsLocationRandomized(self.item, out check)}' | Not in the special triggers list: '{!RandomizerConstants.GetSpecialTriggerNames().Contains(self.Owner.name)}'|");
return orig(self);

}

bool AwardNoteCutscene_ShouldPlay(On.AwardNoteCutscene.orig_ShouldPlay orig, AwardNoteCutscene self)
{
//Need to handle note cutscene triggers so they will play as long as I dont have the actual item it grants
Expand All @@ -338,7 +340,7 @@ bool CutsceneHasPlayed_IsTrue(On.CutsceneHasPlayed.orig_IsTrue orig, CutsceneHas
}
return orig(self);
}

void SaveGameSelectionScreen_OnLoadGame(On.SaveGameSelectionScreen.orig_OnLoadGame orig, SaveGameSelectionScreen self, int slotIndex)
{
//slotIndex is 0-based, going to increment it locally to keep things simple.
Expand Down Expand Up @@ -496,7 +498,7 @@ private void SaveGameSelectionScreen_OnDelete(On.SaveGameSelectionScreen.orig_On
}
orig(self, delete);
}

void PauseScreen_OnQuitToTitle(On.BackToTitleScreen.orig_GoBackToTitleScreen orig)
{
if (ArchipelagoClient.HasConnected)
Expand Down Expand Up @@ -524,7 +526,7 @@ void PauseScreen_OnQuitToTitle(On.BackToTitleScreen.orig_GoBackToTitleScreen ori
void CatacombLevelInitializer_OnBeforeInitDone(On.CatacombLevelInitializer.orig_OnBeforeInitDone orig, CatacombLevelInitializer self)
{
//check to see if we already have the item at Necro check
if(ArchipelagoClient.HasConnected)
if (ArchipelagoClient.HasConnected)
{
if (!RandomizerStateManager.HasCompletedCheck(
ItemsAndLocationsHandler.LocationsLookup[new LocationRO("Necro")]))
Expand All @@ -538,7 +540,7 @@ ItemsAndLocationsHandler.LocationsLookup[new LocationRO("Necro")]))
//we are not rando here, call orig method
orig(self);
}

}

// Breaking into Necro cutscene to fix things
Expand All @@ -554,11 +556,11 @@ void RuxxtinNoteAndAwardAmuletCutscene_Play(ILContext il)
{
ILCursor cursor = new ILCursor(il);

while(cursor.TryGotoNext(MoveType.After, instr => instr.MatchLdcI4(55)))
while (cursor.TryGotoNext(MoveType.After, instr => instr.MatchLdcI4(55)))
{
cursor.EmitDelegate<Func<EItems, EItems>>(GetRandoItemByItem);
}

}

void MegaTimeShard_OnBreakDone(On.MegaTimeShard.orig_OnBreakDone orig, MegaTimeShard self)
Expand Down Expand Up @@ -652,7 +654,7 @@ void MusicBox_SetNotesState(On.MusicBox.orig_SetNotesState orig, MusicBox self)
// this determines which notes should be shown present in the music box
orig(self);
}

public static void OnToggleWindmillShuriken()
{
Manager<ProgressionManager>.Instance.useWindmillShuriken = !Manager<ProgressionManager>.Instance.useWindmillShuriken;
Expand All @@ -663,7 +665,7 @@ public static void OnToggleWindmillShuriken()

public static void OnSelectTeleportToHq()
{
Console.WriteLine("Teleporting to HQ!");
Console.WriteLine("Teleporting to HQ!");
#if DEBUG
var position = Manager<PlayerManager>.Instance.Player.transform.position;
Console.WriteLine($"{position.x} {position.y} {position.z}");
Expand Down Expand Up @@ -753,7 +755,7 @@ public static void OnSelectArchipelagoConnect()
{
return;
}

ArchipelagoClient.ConnectAsync(ArchipelagoMenu.ArchipelagoConnectButton);
}

Expand Down Expand Up @@ -916,7 +918,7 @@ private void SaveManager_DoActualSave(On.SaveManager.orig_DoActualSaving orig, S
// just keep trying to solve it until it eventually works lmao
LostWoodsManager.SolveLostWoods();
}

// The game calls the save method after the ending cutscene before rolling credits
if (ArchipelagoClient.Authenticated
&& Manager<LevelManager>.Instance.GetCurrentLevelEnum().Equals(ELevel.Level_Ending))
Expand Down
11 changes: 4 additions & 7 deletions Archipelago/ArchipelagoData.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Archipelago.MultiClient.Net.Models;
using MessengerRando.GameOverrideManagers;
using MessengerRando.Utils;
using Newtonsoft.Json;
using UnityEngine;

namespace MessengerRando.Archipelago
{
Expand Down Expand Up @@ -37,7 +34,7 @@ public void StartNewSeed()
ReceivedItems = new Dictionary<long, int>();
AvailableTeleports = [false, false];
}

public override string ToString()
{
return JsonConvert.SerializeObject(this);
Expand Down Expand Up @@ -70,7 +67,7 @@ private bool loadData(int slot)
Index = tempServerData.Index;
PowerSealsCollected = tempServerData.PowerSealsCollected;
CheckedLocations = tempServerData.CheckedLocations ?? [];
RandoBossManager.DefeatedBosses = DefeatedBosses =
RandoBossManager.DefeatedBosses = DefeatedBosses =
tempServerData.DefeatedBosses ?? [];
ReceivedItems = tempServerData.ReceivedItems ?? [];
AvailableTeleports = tempServerData.AvailableTeleports ?? [false, false];
Expand Down Expand Up @@ -131,10 +128,10 @@ private bool loadData(int slot)
}
return ArchipelagoClient.HasConnected = true;
}
catch (Exception ex)
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return false;
return false;
}
}
}
Expand Down
48 changes: 35 additions & 13 deletions Archipelago/ItemsAndLocationsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class ItemsAndLocationsHandler
public static Dictionary<long, RandoItemRO> ItemsLookup;
public static Dictionary<LocationRO, long> LocationsLookup;
private static Dictionary<EItems, long> EItemsLocationsLookup;
private static Dictionary<long, LocationRO> IDtoLocationsLookup;
public static Dictionary<long, LocationRO> IDtoLocationsLookup;

public static RandomizerStateManager RandoStateManager;

Expand All @@ -39,13 +39,14 @@ public static void Initialize()
new RandoItemRO("Money Wrench", EItems.MONEY_WRENCH),
new RandoItemRO("Teleport Trap", EItems.NONE),
new RandoItemRO("Prophecy Trap", EItems.NONE),
new RandoItemRO("Progressive Generator Shutdown", EItems.NONE),
new RandoItemRO("Darkness Trap", EItems.NONE),
new RandoItemRO("Health", EItems.POTION),
new RandoItemRO("Mana", EItems.MANA),
new RandoItemRO("Feather", EItems.FEATHER),
new RandoItemRO("Mask Fragment", EItems.MASK_PIECE),
});

foreach (var item in ArchipelagoItems)
{
ItemsLookup.Add(offset, item);
Expand All @@ -58,15 +59,20 @@ public static void Initialize()
LocationsLookup = new Dictionary<LocationRO, long>();
EItemsLocationsLookup = new Dictionary<EItems, long>();
IDtoLocationsLookup = new Dictionary<long, LocationRO>();

var megaShards = RandoTimeShardManager.MegaShardLookup.Select(item => item.Loc).ToList();
ArchipelagoLocations.AddRange(megaShards);
ArchipelagoLocations.AddRange(BossLocations);
ArchipelagoLocations.AddRange(ShopLocations);
foreach (var figurine in Enum.GetValues(typeof(EFigurine)))
ArchipelagoLocations.Add(new LocationRO(figurine.ToString()));
ArchipelagoLocations.Add(new LocationRO("Money Wrench", EItems.MONEY_WRENCH));


ArchipelagoLocations.Add(new LocationRO("Elemental Skylands - Shutdown Air Generator"));
ArchipelagoLocations.Add(new LocationRO("Elemental Skylands - Shutdown Earth Generator"));
ArchipelagoLocations.Add(new LocationRO("Elemental Skylands - Shutdown Water Generator"));
ArchipelagoLocations.Add(new LocationRO("Elemental Skylands - Shutdown Fire Generator"));

foreach (var progLocation in ArchipelagoLocations)
{
LocationsLookup.Add(progLocation, offset);
Expand Down Expand Up @@ -228,7 +234,7 @@ public static void Initialize()
//Elemental Skylands
new LocationRO("-52-20420436", "Elemental Skylands Seal - Air Seal"),
new LocationRO("18361868372388", "Elemental Skylands Seal - Water Seal"),
new LocationRO("28602892356388", "Elemental Skylands Seal - Fire Seal")
new LocationRO("28602892356388", "Elemental Skylands Seal - Fire Seal"),
];

private static readonly List<LocationRO> BossLocations =
Expand Down Expand Up @@ -354,15 +360,20 @@ public static void Unlock(long itemToUnlock, int quantity = APQuantity)
case "Timeshard":
quantity = ArchipelagoClient.ServerData.SlotData.ContainsKey("shop") ? 1 : 100;
break;
case "Timeshard (10)": quantity = 10;
case "Timeshard (10)":
quantity = 10;
break;
case "Timeshard (50)": quantity = 50;
case "Timeshard (50)":
quantity = 50;
break;
case "Timeshard (100)": quantity = 100;
case "Timeshard (100)":
quantity = 100;
break;
case "Timeshard (300)": quantity = 300;
case "Timeshard (300)":
quantity = 300;
break;
case "Timeshard (500)": quantity = 500;
case "Timeshard (500)":
quantity = 500;
break;
}
Console.WriteLine($"Unlocking time shards... {quantity}");
Expand All @@ -379,6 +390,11 @@ public static void Unlock(long itemToUnlock, int quantity = APQuantity)
}
catch
{
if (randoItem.Name.EndsWith("Generator Shutdown"))
{
SkylandsGeneratorStateManager.ReceiveGeneratorShutdown(randoItem.Name);
break;
}
switch (randoItem.Name)
{
case "Darkness Trap":
Expand Down Expand Up @@ -430,6 +446,12 @@ public static void Unlock(long itemToUnlock, int quantity = APQuantity)
ArchipelagoClient.ServerData.ReceivedItems.Add(itemToUnlock, 1);
}

public static bool IsLocationChecked(LocationRO location)
{
LocationsLookup.TryGetValue(location, out var locationID);
return RandomizerStateManager.HasCompletedCheck(locationID);
}

public static void SendLocationCheck(LocationRO checkedLocation)
{
LocationsLookup.TryGetValue(checkedLocation, out var locationID);
Expand Down Expand Up @@ -460,7 +482,7 @@ public static void SendLocationCheck(long locationID)
else return;
}
ArchipelagoClient.ServerData.CheckedLocations.Add(locationID);

Console.WriteLine("Sending location checks");
if (ArchipelagoClient.Authenticated)
{
Expand Down Expand Up @@ -493,7 +515,7 @@ public static void SendLocationCheck(long locationID)
Unlock(itemToUnlock);
else
ArchipelagoClient.ItemQueue.Enqueue(itemToUnlock);

if (!HasDialog(locationID))
{
var dialog = SeedGenerator.GetOfflineDialog(locationID);
Expand All @@ -518,7 +540,7 @@ public static void UnlockItems()

Synced = false;
}

public static void ReSync()
{
Synced = true;
Expand Down
4 changes: 1 addition & 3 deletions GameOverrideManagers/RandoShopManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ public static void UpgradeButton_Refresh(On.UpgradeButton.orig_Refresh orig, Upg

public static string GetText(On.LocalizationManager.orig_GetText orig, LocalizationManager self, string locid)
{
// if (!InShop()) return orig(self, locid);
Console.WriteLine($"Requesting text for {locid}");
if (!ArchipelagoClient.HasConnected) return orig(self, locid);
var locType = TextType.None;
var lookupName = string.Empty;
Expand Down Expand Up @@ -190,7 +188,7 @@ public static string GetText(On.LocalizationManager.orig_GetText orig, Localizat
var itemOnLocation = RandomizerStateManager.Instance.ScoutedLocations[locationID];
if (locType.Equals(TextType.Name) && ArchipelagoClient.Authenticated)
{
if(!ArchipelagoClient.ServerData.CheckedLocations.Contains(locationID))
if (!ArchipelagoClient.ServerData.CheckedLocations.Contains(locationID))
{
ThreadPool.QueueUserWorkItem(_ =>
ArchipelagoClient.Session.Locations.ScoutLocationsAsync(
Expand Down
Loading