Skip to content

Commit

Permalink
Refactored #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarno458 committed Jan 22, 2022
1 parent c0e0353 commit 8b834a5
Show file tree
Hide file tree
Showing 25 changed files with 359 additions and 471 deletions.
2 changes: 1 addition & 1 deletion TsRandomizer/ItemTracker/ItemTrackerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal static ItemTrackerState FromItemLocationMap(IEnumerable<ItemLocation> i

static void SetMemberForItem(ItemTrackerState trackerState, ItemIdentifier itemInfo)
{
if (!ItemToMemberMap.TryGetValue(itemInfo, out Expression<Func<ItemTrackerState, bool>> expression))
if (!ItemToMemberMap.TryGetValue(itemInfo, out var expression))
return;

var memberExpression = (MemberExpression)expression.Body;
Expand Down
2 changes: 1 addition & 1 deletion TsRandomizer/LevelObjects/ItemManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TsRandomizer.LevelObjects
{
abstract class ItemManipulator<T> : ItemManipulator where T : Mobile
{
public readonly T TypedObject;
public readonly new T TypedObject;

protected ItemManipulator(T typedObject, ItemLocation itemLocation) : base(typedObject, itemLocation)
{
Expand Down
11 changes: 6 additions & 5 deletions TsRandomizer/LevelObjects/LevelObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
using TsRandomizer.Randomisation;
using TsRandomizer.ReplacementObjects;
using TsRandomizer.Screens;
using TsRandomizer.Screens.Settings;
using TsRandomizer.Settings;

namespace TsRandomizer.LevelObjects
{
abstract class LevelObject<T> : LevelObject where T : Mobile
{
public readonly T TypedObject;
public readonly new T TypedObject;

protected LevelObject(T typedObject) : base(typedObject)
{
Expand Down Expand Up @@ -104,7 +104,7 @@ public static void AwardFirstFrameItem(Dictionary<int, Item> itemDictionary, Pro

public static void Update(
Level level, GameplayScreen gameplayScreen, ItemLocationMap itemLocations,
bool roomChanged, SeedOptions seedOptions, GameSettingsCollection gameSettings,
bool roomChanged, SeedOptions seedOptions, SettingCollection gameSettings,
ScreenManager screenManager)
{
if (roomChanged)
Expand Down Expand Up @@ -138,7 +138,7 @@ public static void AwardFirstFrameItem(Dictionary<int, Item> itemDictionary, Pro
var lunais = level.MainHero;
if (roomChanged || newItems.Any()) AwardFirstFrameItem(itemsDictionary, lunais);

if ((bool)gameSettings.DamageRando.CurrentValue)
if (gameSettings.DamageRando.Value)
OrbDamageManager.UpdateOrbDamage(level.GameSave, level.MainHero);

KnownItemIds.Clear();
Expand All @@ -151,7 +151,8 @@ public static void AwardFirstFrameItem(Dictionary<int, Item> itemDictionary, Pro
level.GameSave.AddConcussion();
}

static void OnChangeRoom(Level level, ItemLocationMap itemLocations, SeedOptions seedOptions, GameSettingsCollection gameSettings, ScreenManager screenManager)
static void OnChangeRoom(Level level, ItemLocationMap itemLocations, SeedOptions seedOptions,
SettingCollection gameSettings, ScreenManager screenManager)
{
#if DEBUG
level.GameSave.AddItem(level, new ItemIdentifier(EInventoryRelicType.Dash));
Expand Down
43 changes: 21 additions & 22 deletions TsRandomizer/LevelObjects/Other/MerchantCrowNPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,74 @@
using Timespinner.GameObjects.BaseClasses;
using TsRandomizer.Extensions;
using TsRandomizer.IntermediateObjects;
using TsRandomizer.Screens.Settings;
using TsRandomizer.Settings;

namespace TsRandomizer.LevelObjects.Other
{
[TimeSpinnerType("Timespinner.GameObjects.NPCs.MerchantCrowNPC")]
class MerchantCrowNpc : LevelObject
{
readonly MerchantInventory merchandiseInventory = new MerchantInventory();

MerchantInventory _merchandiseInventory = new MerchantInventory();
public MerchantCrowNpc(Mobile typedObject) : base(typedObject)
{

}

protected override void Initialize(SeedOptions options)
{
GameSettingsCollection gameSettings = new GameSettingsCollection();
gameSettings.LoadSettingsFromFile();
string fillType = (string)gameSettings.ShopFill.CurrentValue;
var gameSettings = GameSettingsLoader.LoadSettingsFromFile();
var fillType = gameSettings.ShopFill.Value;
if (fillType == "Vanilla")
return;

PlayerInventory inventory = Dynamic._level.GameSave.Inventory;

// Only sell warp shards if Pyramid Key is aquired (and allowed in settings)
if ((bool)gameSettings.ShopWarpShards.CurrentValue && inventory.RelicInventory.IsRelicActive(EInventoryRelicType.PyramidsKey))
_merchandiseInventory.AddItem(EInventoryUseItemType.WarpCard);
if (gameSettings.ShopWarpShards.Value && inventory.RelicInventory.IsRelicActive(EInventoryRelicType.PyramidsKey))
merchandiseInventory.AddItem(EInventoryUseItemType.WarpCard);

if (fillType == "Empty")
{
Dynamic._merchandiseInventory = _merchandiseInventory;
Dynamic._merchandiseInventory = merchandiseInventory;
return;
}
if (fillType == "Random")
{
Random random = new Random((int)options.Flags);
for (int i = 0; i < 8; i++)
var random = new Random((int)options.Flags);
for (var i = 0; i < 8; i++)
{
var item = Helper.GetAllLoot().SelectRandom(random);
// Give half of the items to each era. Needs to be done after the random advances
// to keep the inventory consistent for the seed
if ((Dynamic._isInPresent && (i % 2 == 0) || !Dynamic._isInPresent && (i % 2 != 0)))
continue;
if (item.LootType == LootType.Equipment)
_merchandiseInventory.AddItem((EInventoryEquipmentType)item.ItemId);
merchandiseInventory.AddItem((EInventoryEquipmentType)item.ItemId);
else
_merchandiseInventory.AddItem((EInventoryUseItemType)item.ItemId);
merchandiseInventory.AddItem((EInventoryUseItemType)item.ItemId);
}
Dynamic._merchandiseInventory = _merchandiseInventory;
Dynamic._merchandiseInventory = merchandiseInventory;
return;
}

// Default case, streamlined inventory for randomizer players
if (Dynamic._isInPresent)
{
_merchandiseInventory.AddItem(EInventoryUseItemType.FuturePotion);
_merchandiseInventory.AddItem(EInventoryUseItemType.FutureEther);
merchandiseInventory.AddItem(EInventoryUseItemType.FuturePotion);
merchandiseInventory.AddItem(EInventoryUseItemType.FutureEther);
}
else
{
_merchandiseInventory.AddItem(EInventoryUseItemType.Potion);
_merchandiseInventory.AddItem(EInventoryUseItemType.Ether);
merchandiseInventory.AddItem(EInventoryUseItemType.Potion);
merchandiseInventory.AddItem(EInventoryUseItemType.Ether);
}
_merchandiseInventory.AddItem(EInventoryUseItemType.Biscuit);
_merchandiseInventory.AddItem(EInventoryUseItemType.Antidote);
_merchandiseInventory.AddItem(EInventoryUseItemType.SandBottle);
_merchandiseInventory.AddItem(EInventoryUseItemType.ChaosHeal);
merchandiseInventory.AddItem(EInventoryUseItemType.Biscuit);
merchandiseInventory.AddItem(EInventoryUseItemType.Antidote);
merchandiseInventory.AddItem(EInventoryUseItemType.SandBottle);
merchandiseInventory.AddItem(EInventoryUseItemType.ChaosHeal);

Dynamic._merchandiseInventory = _merchandiseInventory;
Dynamic._merchandiseInventory = merchandiseInventory;
}
}
}
8 changes: 4 additions & 4 deletions TsRandomizer/LevelObjects/RoomTriggers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using TsRandomizer.Randomisation;
using TsRandomizer.Randomisation.ItemPlacers;
using TsRandomizer.Screens;
using TsRandomizer.Screens.Settings;
using TsRandomizer.Settings;

namespace TsRandomizer.LevelObjects
{
Expand Down Expand Up @@ -293,16 +293,16 @@ static RoomTrigger()
}

readonly RoomItemKey key;
readonly Action<Level, ItemLocation, SeedOptions, GameSettingsCollection, ScreenManager> trigger;
readonly Action<Level, ItemLocation, SeedOptions, SettingCollection, ScreenManager> trigger;

public RoomTrigger(int levelId, int roomId, Action<Level, ItemLocation, SeedOptions, GameSettingsCollection, ScreenManager> triggerMethod)
public RoomTrigger(int levelId, int roomId, Action<Level, ItemLocation, SeedOptions, SettingCollection, ScreenManager> triggerMethod)
{
key = new RoomItemKey(levelId, roomId);
trigger = triggerMethod;
}

public static void OnChangeRoom(
Level level, SeedOptions seedOptions, GameSettingsCollection gameSettings, ItemLocationMap itemLocations, ScreenManager screenManager,
Level level, SeedOptions seedOptions, SettingCollection gameSettings, ItemLocationMap itemLocations, ScreenManager screenManager,
int levelId, int roomId)
{
var roomKey = new RoomItemKey(levelId, roomId);
Expand Down
2 changes: 0 additions & 2 deletions TsRandomizer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Text;
using SDL2;
using TsRandomizer.Extensions;
using TsRandomizer.Screens.Settings;
using TsRandomizer.Screens.Settings.GameSettingObjects;

namespace TsRandomizer
{
Expand Down
26 changes: 9 additions & 17 deletions TsRandomizer/Randomisation/ItemPlacers/ItemLocationRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Timespinner.GameAbstractions.Inventory;
using TsRandomizer.Extensions;
using TsRandomizer.IntermediateObjects;
using TsRandomizer.Screens.Settings;
using TsRandomizer.Settings;
using R = TsRandomizer.Randomisation.Requirement;

namespace TsRandomizer.Randomisation.ItemPlacers
Expand All @@ -13,7 +13,7 @@ abstract class ItemLocationRandomizer
{
protected readonly Seed Seed;
protected readonly SeedOptions SeedOptions;
protected readonly GameSettingsCollection GameSettings;
protected readonly SettingCollection settings;
protected readonly ItemInfoProvider ItemInfoProvider;
protected readonly ItemUnlockingMap UnlockingMap;

Expand All @@ -27,10 +27,7 @@ protected ItemLocationRandomizer(Seed seed, ItemInfoProvider itemInfoProvider, I
SeedOptions = seed.Options;
ItemInfoProvider = itemInfoProvider;
UnlockingMap = unlockingMap;
GameSettings = new GameSettingsCollection();
GameSettings.LoadSettingsFromFile();


settings = GameSettingsLoader.LoadSettingsFromFile();

itemsToRemoveFromGame = new List<ItemInfo>
{
Expand Down Expand Up @@ -141,11 +138,9 @@ void PutStarterProgressionItemInReachableLocation(Random random, ItemLocationMap
PutItemAtLocation(starterProgressionItem, location);
}

static bool ShouldGiveLightwall(Random random, ItemInfo starterProgressionItem)
{
return (starterProgressionItem.Identifier == new ItemIdentifier(EInventoryOrbType.Barrier, EOrbSlot.Spell))
&& random.Next(1, 5) == 1;
}
static bool ShouldGiveLightwall(Random random, ItemInfo starterProgressionItem) =>
(starterProgressionItem.Identifier == new ItemIdentifier(EInventoryOrbType.Barrier, EOrbSlot.Spell))
&& random.Next(1, 5) == 1;

protected void GiveOrbsToMom(Random random, ItemLocationMap itemLocations, bool useLightwallAsSpell)
{
Expand All @@ -166,7 +161,7 @@ protected void GiveOrbsToMom(Random random, ItemLocationMap itemLocations, bool
protected void PlaceGassMaskInALegalSpot(Random random, ItemLocationMap itemLocations)
{
var levelIdsToAvoid = new List<int>(3) { 1 };
R minimalMawRequirements = R.None;
var minimalMawRequirements = R.None;

if (!SeedOptions.Inverted)
{
Expand Down Expand Up @@ -228,7 +223,7 @@ void FixProgressiveNonProgressionItemsInSameRoom(Random random, ItemLocationMap
.Where(l => l.ItemInfo is ProgressiveItemInfo)
.GroupBy(l => l.ItemInfo);

foreach (IGrouping<ItemInfo, ItemLocation> progressiveItemLocations in progressiveItemLocationsPerType)
foreach (var progressiveItemLocations in progressiveItemLocationsPerType)
{
RoomItemKey roomkey = null;

Expand Down Expand Up @@ -283,10 +278,7 @@ List<ItemInfo> GenerateItemList(ItemLocationMap itemLocations)
return itemlist;
}

void AddExtraItems(List<ItemInfo> itemlist)
{
itemlist.AddRange(itemsToAddToGame);
}
void AddExtraItems(List<ItemInfo> itemlist) => itemlist.AddRange(itemsToAddToGame);

void AddFamiliars(List<ItemInfo> itemlist)
{
Expand Down
Loading

0 comments on commit 8b834a5

Please sign in to comment.