Skip to content

Commit

Permalink
Logic and Group Wall fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nerthul11 committed Jun 28, 2024
1 parent ad3e8f4 commit 61251c6
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 210 deletions.
2 changes: 1 addition & 1 deletion BreakableWallRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace BreakableWallRandomizer
public class BreakableWallRandomizer : Mod, IGlobalSettings<BWR_Settings>
{
new public string GetName() => "Breakable Wall Randomizer";
public override string GetVersion() => "3.0.0.0";
public override string GetVersion() => "3.0.0.1";
public BWR_Settings GS { get; set; } = new();
private static BreakableWallRandomizer _instance;
public BreakableWallRandomizer() : base()
Expand Down
4 changes: 2 additions & 2 deletions BreakableWallRandomizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<Product>BreakableWallRandomizer</Product>
<Description>A Randomizer add-on for wall and floor objects.</Description>
<Copyright>Copyright ©2023</Copyright>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion>
<AssemblyVersion>3.0.0.1</AssemblyVersion>
<FileVersion>3.0.0.1</FileVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
9 changes: 6 additions & 3 deletions IC/BreakableWallItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ private InteropTag BreakableWallItemTag()
sprite = "wood_plank_02";
if (name.StartsWith("Dive_Floor-"))
sprite = "break_floor_glass";
if (name.StartsWith("Wall_Group-"))
sprite = "mine_break_wall_03_0deg";

InteropTag tag = new();
tag.Properties["ModSource"] = "BreakableWallRandomizer";
Expand All @@ -62,8 +64,8 @@ public override void GiveImmediate(GiveInfo info)
{
foreach (CondensedWallObject wall in groupWalls)
{
if (!BreakableWallModule.Instance.UnlockedBreakableWalls.Contains(name))
BreakableWallModule.Instance.UnlockedBreakableWalls.Add(name);
if (!BreakableWallModule.Instance.UnlockedBreakableWalls.Contains(wall.name))
BreakableWallModule.Instance.UnlockedBreakableWalls.Add(wall.name);
if (wall.name.StartsWith("Wall") && !BreakableWallModule.Instance.UnlockedWalls.Contains(name))
BreakableWallModule.Instance.UnlockedWalls.Add(wall.name);
if (wall.name.StartsWith("Plank") && !BreakableWallModule.Instance.UnlockedPlanks.Contains(name))
Expand All @@ -78,7 +80,8 @@ public override void GiveImmediate(GiveInfo info)
}
else
{
BreakableWallModule.Instance.UnlockedBreakableWalls.Add(name);
if (!BreakableWallModule.Instance.UnlockedBreakableWalls.Contains(name))
BreakableWallModule.Instance.UnlockedBreakableWalls.Add(name);
if (name.StartsWith("Wall") && !BreakableWallModule.Instance.UnlockedWalls.Contains(name))
BreakableWallModule.Instance.UnlockedWalls.Add(name);
if (name.StartsWith("Plank") && !BreakableWallModule.Instance.UnlockedPlanks.Contains(name))
Expand Down
294 changes: 159 additions & 135 deletions IC/BreakableWallLocation.cs

Large diffs are not rendered by default.

54 changes: 15 additions & 39 deletions IC/ShopLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,61 +57,37 @@ protected override void OnUnload()

private void PreventMylaZombie(On.DeactivateIfPlayerdataFalse.orig_OnEnable orig, DeactivateIfPlayerdataFalse self)
{
bool AllObtained = true;
foreach (AbstractItem item in Placement.Items)
{
if (!item.WasEverObtained())
AllObtained = false;
}

if (AllObtained && (self.gameObject.name.Contains("Zombie Myla") || string.Equals(self.gameObject.name, "Myla Crazy NPC")))
bool AllObtained = Placement.Items.All(x => x.GetTag<CostTag>()?.Cost?.Paid ?? true);
if (!AllObtained && (self.gameObject.name.Contains("Zombie Myla") || string.Equals(self.gameObject.name, "Myla Crazy NPC")))
{
self.gameObject.SetActive(false);
return;
}
else if (self.gameObject.name.Contains("Zombie Myla") || string.Equals(self.gameObject.name, "Myla Crazy NPC"))
{
GameObject myla = self.gameObject;
if (Placement.CheckVisitedAny(VisitState.Accepted) && !Placement.AllObtained())
{
Container c = Container.GetContainer(Container.Shiny);

ContainerInfo info = new(c.Name, Placement, flingType, (Placement as ItemChanger.Placements.ISingleCostPlacement)?.Cost);
GameObject shiny = c.GetNewContainer(info);

c.ApplyTargetContext(shiny, myla.transform.position.x, myla.transform.position.y, 0f);
ShinyUtility.FlingShinyRandomly(shiny.LocateMyFSM("Shiny Control"));
}
}
else if (AllObtained && (self.gameObject.name.Contains("Zombie Myla") || string.Equals(self.gameObject.name, "Myla Crazy NPC")))
RespawnItems();
orig(self);
}

private void ForceMyla(On.DeactivateIfPlayerdataTrue.orig_OnEnable orig, DeactivateIfPlayerdataTrue self)
{
bool AllObtained = true;
foreach (AbstractItem item in Placement.Items)
{
if (!item.WasEverObtained())
AllObtained = false;
}

if (string.Equals(self.gameObject.name, "Miner") && GameManager.instance.sceneName == sceneName && AllObtained)
bool AllObtained = Placement.Items.All(x => x.GetTag<CostTag>()?.Cost?.Paid ?? true);
if (string.Equals(self.gameObject.name, "Miner") && !AllObtained)
return;

orig(self);
}

private void MakeShinyForRespawnedItems(GameObject myla)
private void RespawnItems()
{
if (Placement.CheckVisitedAny(VisitState.Accepted) && !Placement.AllObtained())
foreach (AbstractItem item in Placement.Items)
{
Container c = Container.GetContainer(Container.Shiny);

ContainerInfo info = new(c.Name, Placement, flingType, (Placement as ItemChanger.Placements.ISingleCostPlacement)?.Cost);
GameObject shiny = c.GetNewContainer(info);

c.ApplyTargetContext(shiny, myla.transform.position.x, myla.transform.position.y, 0f);
ShinyUtility.FlingShinyLeft(shiny.LocateMyFSM("Shiny Control"));
if (!item.IsObtained() && (item.GetTag<CostTag>()?.Cost?.Paid ?? true))
{
Container c = Container.GetContainer(Container.Shiny);
GameObject shiny = c.GetNewContainer(new(c.Name, Placement, flingType));
shiny.transform.position = new(Random.Range(28.0f, 42.0f), 3.4f);
shiny.SetActive(true);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Interop/MoreLocations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class WallCostProvider : ICostProvider

public LogicCost Next(LogicManager lm, Random rng)
{
int wallCount = 53;
int wallCount = BWR_Manager.TotalWalls;
int minCost = (int)(wallCount * BWR_Manager.Settings.MylaShop.MinimumCost);
int maxCost = (int)(wallCount * BWR_Manager.Settings.MylaShop.MaximumCost);
return new WallLogicCost(lm.GetTermStrict("Broken_Walls"), rng.Next(minCost, maxCost), amount => new WallCost(amount));
Expand All @@ -42,7 +42,7 @@ internal class PlankCostProvider : ICostProvider

public LogicCost Next(LogicManager lm, Random rng)
{
int wallCount = 49;
int wallCount = BWR_Manager.TotalPlanks;
int minCost = (int)(wallCount * BWR_Manager.Settings.MylaShop.MinimumCost);
int maxCost = (int)(wallCount * BWR_Manager.Settings.MylaShop.MaximumCost);
return new WallLogicCost(lm.GetTermStrict("Broken_Planks"), rng.Next(minCost, maxCost), amount => new PlankCost(amount));
Expand All @@ -57,7 +57,7 @@ internal class DiveCostProvider : ICostProvider

public LogicCost Next(LogicManager lm, Random rng)
{
int wallCount = 44;
int wallCount = BWR_Manager.TotalDives;
int minCost = (int)(wallCount * BWR_Manager.Settings.MylaShop.MinimumCost);
int maxCost = (int)(wallCount * BWR_Manager.Settings.MylaShop.MaximumCost);
return new WallLogicCost(lm.GetTermStrict("Broken_Dive_Floors"), rng.Next(minCost, maxCost), amount => new DiveCost(amount));
Expand Down
28 changes: 25 additions & 3 deletions Manager/ItemHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal static class ItemHandler
{
internal static void Hook()
{
ProgressionInitializer.OnCreateProgressionInitializer += AddTolerance;
RequestBuilder.OnUpdate.Subscribe(-500f, DefineShopRef);
RequestBuilder.OnUpdate.Subscribe(-400f, DefineGroups);
RequestBuilder.OnUpdate.Subscribe(-100f, RandomizeShopCost);
Expand Down Expand Up @@ -131,7 +132,7 @@ private static void RandomizeShopCost(RequestBuilder builder)
int termNo = rng.Next(3);
if (termNo == 0 && !usedTerms.Contains("Walls")) // Walls
{
int wallCount = 53;
int wallCount = BWR_Manager.TotalWalls;
int minCost = Math.Max((int)(wallCount * BWR_Manager.Settings.MylaShop.MinimumCost), 1);
int maxCost = Math.Max((int)(wallCount * BWR_Manager.Settings.MylaShop.MaximumCost), 1);
usedTerms.Add("Walls");
Expand All @@ -140,7 +141,7 @@ private static void RandomizeShopCost(RequestBuilder builder)

if (termNo == 1 && !usedTerms.Contains("Planks")) // Planks
{
int wallCount = 49;
int wallCount = BWR_Manager.TotalPlanks;
int minCost = Math.Max( (int)(wallCount * BWR_Manager.Settings.MylaShop.MinimumCost), 1);
int maxCost = Math.Max( (int)(wallCount * BWR_Manager.Settings.MylaShop.MaximumCost), 1);
usedTerms.Add("Planks");
Expand All @@ -149,7 +150,7 @@ private static void RandomizeShopCost(RequestBuilder builder)

if (termNo == 2 && !usedTerms.Contains("Dives")) // Dives
{
int wallCount = 44;
int wallCount = BWR_Manager.TotalDives;
int minCost = Math.Max( (int)(wallCount * BWR_Manager.Settings.MylaShop.MinimumCost), 1);
int maxCost = Math.Max( (int)(wallCount * BWR_Manager.Settings.MylaShop.MaximumCost), 1);
usedTerms.Add("Dives");
Expand Down Expand Up @@ -299,6 +300,27 @@ private static void AddWalls(RequestBuilder rb)
}
}

private static void AddTolerance(LogicManager lm, GenerationSettings gs, ProgressionInitializer pi)
{
if (!BWR_Manager.Settings.Enabled || !BWR_Manager.Settings.MylaShop.Enabled)
return;

int wallCount = BWR_Manager.TotalWalls;
int wallCost = Math.Max((int)(wallCount * BWR_Manager.Settings.MylaShop.MaximumCost), 1);
int wallTolerance = Math.Min((int)(wallCost * BWR_Manager.Settings.MylaShop.Tolerance), wallCount - wallCost);
pi.Setters.Add(new RandomizerCore.TermValue(lm.GetTermStrict("Broken_Walls"), -wallTolerance));

int plankCount = BWR_Manager.TotalPlanks;
int plankCost = Math.Max((int)(plankCount * BWR_Manager.Settings.MylaShop.MaximumCost), 1);
int plankTolerance = Math.Min((int)(plankCost * BWR_Manager.Settings.MylaShop.Tolerance), plankCount - plankCost);
pi.Setters.Add(new RandomizerCore.TermValue(lm.GetTermStrict("Broken_Planks"), -plankTolerance));

int diveCount = BWR_Manager.TotalDives;
int diveCost = Math.Max((int)(diveCount * BWR_Manager.Settings.MylaShop.MaximumCost), 1);
int diveTolerance = Math.Min((int)(diveCost * BWR_Manager.Settings.MylaShop.Tolerance), diveCount - diveCost);
pi.Setters.Add(new RandomizerCore.TermValue(lm.GetTermStrict("Broken_Dive_Floors"), -diveTolerance));
}

private static void AddFileSettings(LogArguments args, TextWriter tw)
{
// Log settings into the settings file
Expand Down
3 changes: 3 additions & 0 deletions Manager/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace BreakableWallRandomizer.Manager
internal static class BWR_Manager
{
public static BWR_Settings Settings => BreakableWallRandomizer.Instance.GS;
public static int TotalWalls = 53;
public static int TotalPlanks = 49;
public static int TotalDives = 44;
public static void Hook()
{
DefineObjects();
Expand Down
6 changes: 3 additions & 3 deletions Modules/BreakableWallModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ public void CompletedChallenges()
completed.Add("All Buried Geo Dives");
if (sanctumWallCount == 7)
completed.Add("All Inner Soul Sanctum Dives");
if (UnlockedWalls.Count == 53)
if (UnlockedWalls.Count == BWR_Manager.TotalWalls)
completed.Add("All Walls broken.");
if (UnlockedPlanks.Count == 49)
if (UnlockedPlanks.Count == BWR_Manager.TotalPlanks)
completed.Add("All Walls broken.");
if (UnlockedDives.Count == 44)
if (UnlockedDives.Count == BWR_Manager.TotalDives)
completed.Add("All Walls broken.");

OnAchievedBreakableWall?.Invoke(completed);
Expand Down
3 changes: 2 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ These are left out by design. Might add as an optional setting at some point.

### Myla Shop
- Enabled --> Boolean to define if the Godhome Shop should appear or not.
- Minimum/Maximum Cost --> A range from 0 to 1, where 0 is 0% and 1 is 100% (176) of all available wall objects. Default is 25% to 75%.
- Minimum/Maximum Cost --> A range from 0 to 1, where 0 is 0% and 1 is 100% of all available wall objects. Default is 25% to 75%.
- Include In Junk Shop --> Allows the defined costs to appear as currency in More Locations' Junk Shop, regardless of if Myla's Shop is enabled or not.
- Tolerance --> A range from 0 to 1, where 0 is no tolerance and 1 is 100% of the used maximum cost. If maximum cost + tolerance should be over the total existing walls, the tolerance will automatically be capped. For reference, most mods have tolerance be a 10-25% of the maximum costs.

## Dependencies:
- ItemChanger
Expand Down
41 changes: 25 additions & 16 deletions Resources/Data/BreakableWallObjects.json
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@
"alsoDestroy": [],
"exit": false,
"groupWalls": [],
"group": "",
"logic": "Deepnest_03[left2] | Deepnest_03 + (LEFTSUPERDASH | WINGS | LEFTCLAW + ($SHADESKIP | $SLOPEBALL[before:ROOMSOUL]))",
"logicOverrides": {
"Deepnest_03[left2]": "Deepnest_03[left2] | (ORIG) + Wall-Deepnest_Springs_Grub"
Expand Down Expand Up @@ -590,7 +591,7 @@
"exit": false,
"groupWalls": [],
"group": "Nosk_Walls",
"logic": "Deepnest_31[right1] + (LEFTSLASH | UPSLASH | SCREAM | LEFTFIREBALL | ANYCLAW | WINGS | LEFTDASH | (RIGHTSPELLAIRSTALL?SPELLAIRSTALL) + $CASTSPELL[3]) | Deepnest_31[right2] + ((RIGHTCLAW | LEFTCLAW + (WINGS | BACKGROUNDPOGOS)) + Plank-Nosk_Exit | (ANYCLAW | WINGS) + Wall-Nosk_Inner)",
"logic": "Deepnest_31[right1] + (LEFTSLASH | UPSLASH | SCREAM | LEFTFIREBALL | ANYCLAW | WINGS | LEFTDASH | (FIREBALLSKIPS + (RIGHTFIREBALL | SCREAM)) + $CASTSPELL[3]) | Deepnest_31[right2] + ((RIGHTCLAW | LEFTCLAW + (WINGS | BACKGROUNDPOGOS)) + Plank-Nosk_Exit | (ANYCLAW | WINGS) + Wall-Nosk_Inner)",
"logicOverrides": {},
"logicSubstitutions": {}
},
Expand All @@ -609,7 +610,7 @@
"exit": false,
"groupWalls": [],
"group": "Nosk_Walls",
"logic": "Deepnest_31[right1] + (ANYCLAW | WINGS | LEFTDASH | (RIGHTSPELLAIRSTALL?SPELLAIRSTALL) + $CASTSPELL[3]) + Wall-Nosk_Outer | Deepnest_31[right2] + (ANYCLAW | WINGS)",
"logic": "Deepnest_31[right1] + (ANYCLAW | WINGS | LEFTDASH | (FIREBALLSKIPS + (RIGHTFIREBALL | SCREAM)) + $CASTSPELL[3]) + Wall-Nosk_Outer | Deepnest_31[right2] + (ANYCLAW | WINGS)",
"logicOverrides": {},
"logicSubstitutions": {}
},
Expand Down Expand Up @@ -1094,7 +1095,7 @@
"exit": false,
"groupWalls": [],
"group": "",
"logic": "Deepnest_Spider_Town[left1] + WINGS + (RIGHTCLAW + (LEFTDASH | LEFTSUPERDASH | RIGHTSPELLAIRSTALL?SPELLAIRSTALL + $CASTSPELL[1]) | LEFTCLAW + RIGHTSUPERDASH) | Bench-Beast's_Den + ANYCLAW + Plank-Den_Secret_Entrance | Deepnest_Spider_Town[left1] + (WINGS + ANYCLAW | FULLCLAW + (COMBAT[Left_Devout] | COMBAT[Any_Devout])) + Plank-Den_Secret_Entrance",
"logic": "Deepnest_Spider_Town[left1] + WINGS + (RIGHTCLAW + (LEFTDASH | LEFTSUPERDASH | FIREBALLSKIPS + (RIGHTFIREBALL | SCREAM) + $CASTSPELL[1]) | LEFTCLAW + RIGHTSUPERDASH) | Bench-Beast's_Den + ANYCLAW + Plank-Den_Secret_Entrance | Deepnest_Spider_Town[left1] + (WINGS + ANYCLAW | FULLCLAW + (COMBAT[Left_Devout] | COMBAT[Any_Devout])) + Plank-Den_Secret_Entrance",
"logicOverrides": {},
"logicSubstitutions": {}
},
Expand Down Expand Up @@ -1142,8 +1143,8 @@
"gameObject": "/Break Floor 1",
"fsmType": "break_floor",
"sceneName": "Fungus2_29",
"x": 0.0,
"y": 0.0,
"x": 0.14,
"y": -0.02,
"persistentBool": "",
"sprite": "fungd_mush_01_0001_a_break_floor_270deg",
"alsoDestroy": [
Expand Down Expand Up @@ -1361,8 +1362,8 @@
"gameObject": "/One Way Wall",
"fsmType": "break_floor",
"sceneName": "Fungus3_05",
"x": 0.0,
"y": 0.0,
"x": 0.3,
"y": -0.15,
"persistentBool": "",
"sprite": "crumble_floor_fungus_270deg",
"alsoDestroy": [
Expand All @@ -1371,7 +1372,7 @@
"exit": true,
"groupWalls": [],
"group": "",
"logic": "(Fungus3_05[left1] | Fungus3_05[right1]) + ((WINGS | (LEFTDASH | RIGHTCLAW + LEFTSUPERDASH | RIGHTSPELLAIRSTALL?AIRSTALL + $CASTSPELL[2,before:ROOMSOUL,after:ROOMSOUL]) + (RIGHTDASH | RIGHTSUPERDASH | LEFTSPELLAIRSTALL?AIRSTALL + (LEFTCLAW + $CASTSPELL[1] | $CASTSPELL[2,1]))) + (RIGHTCLAW | LEFTCLAW + WINGS) | Plank-Petra_Arena)",
"logic": "(Fungus3_05[left1] | Fungus3_05[right1]) + ((WINGS | (LEFTDASH | RIGHTCLAW + LEFTSUPERDASH | FIREBALLSKIPS + (RIGHTFIREBALL | SCREAM) + $CASTSPELL[2,before:ROOMSOUL,after:ROOMSOUL]) + (RIGHTDASH | RIGHTSUPERDASH | FIREBALLSKIPS + (LEFTFIREBALL | SCREAM) + (LEFTCLAW + $CASTSPELL[1] | $CASTSPELL[2,1]))) + (RIGHTCLAW | LEFTCLAW + WINGS) | Plank-Petra_Arena)",
"logicOverrides": {},
"logicSubstitutions": {}
},
Expand All @@ -1380,8 +1381,8 @@
"gameObject": "/One Way Wall",
"fsmType": "break_floor",
"sceneName": "Fungus3_39",
"x": 0.0,
"y": 0.0,
"x": 0.04,
"y": -0.32,
"persistentBool": "",
"sprite": "one_way_fung_266deg",
"alsoDestroy": [],
Expand Down Expand Up @@ -1416,7 +1417,11 @@
"group": "",
"logic": "Fungus3_44[door1]",
"logicOverrides": {},
"logicSubstitutions": {}
"logicSubstitutions": {
"Fungus3_44": {
"Fungus3_44[door1]": "Fungus3_44[door1] + Plank-Outside_Overgrown_Mound"
}
}
},
{
"name": "Plank-Archives_Outer",
Expand All @@ -1435,7 +1440,11 @@
"logicOverrides": {
"Fungus3_47[left1]": "(ORIG) + Plank-Archives_Outer"
},
"logicSubstitutions": {}
"logicSubstitutions": {
"Fungus3_47": {
"Fungus3_47[left1]": "Fungus3_47[left1] + Plank-Archives_Outer"
}
}
},
{
"name": "Plank-Hive_Knight",
Expand Down Expand Up @@ -2037,8 +2046,8 @@
"gameObject": "/Quake Floor",
"fsmType": "quake_floor",
"sceneName": "Abyss_17",
"x": 0.0,
"y": 0.0,
"x": 0.5,
"y": -0.1,
"persistentBool": "",
"sprite": "break_floor",
"alsoDestroy": [
Expand All @@ -2058,8 +2067,8 @@
"gameObject": "/Quake Floor",
"fsmType": "quake_floor",
"sceneName": "Cliffs_04",
"x": 0.0,
"y": 0.0,
"x": 0.05,
"y": -0.05,
"persistentBool": "",
"sprite": "break_floor",
"alsoDestroy": [],
Expand Down
Loading

0 comments on commit 61251c6

Please sign in to comment.