Skip to content

Commit

Permalink
Add handling to repair fragile charm when upgraded to unbreakable.
Browse files Browse the repository at this point in the history
  • Loading branch information
homothetyhk committed Jan 17, 2022
1 parent 855acac commit 995fef3
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions ItemChanger/Items/UnbreakableCharmItem.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
namespace ItemChanger.Items
using Newtonsoft.Json;

namespace ItemChanger.Items
{
/// <summary>
/// CharmItem which gives the unbreakable version of the charm.
/// </summary>
public class UnbreakableCharmItem : CharmItem
{
public string unbreakableBool
public string GetUnbreakableBool() => charmNum switch
{
get
{
switch (charmNum)
{
case 23:
return nameof(PlayerData.fragileHealth_unbreakable);
case 24:
return nameof(PlayerData.fragileGreed_unbreakable);
case 25:
return nameof(PlayerData.fragileStrength_unbreakable);
default:
throw new ArgumentException("CharmNum out of range.");
}
}
}
23 => nameof(PlayerData.fragileHealth_unbreakable),
24 => nameof(PlayerData.fragileGreed_unbreakable),
25 => nameof(PlayerData.fragileStrength_unbreakable),
_ => throw new ArgumentException("CharmNum out of range."),
};

public string GetBrokenBool() => charmNum switch
{
23 => nameof(PlayerData.brokenCharm_23),
24 => nameof(PlayerData.brokenCharm_24),
25 => nameof(PlayerData.brokenCharm_25),
_ => throw new ArgumentException("CharmNum out of range."),
};

public override void GiveImmediate(GiveInfo info)
{
base.GiveImmediate(info);
PlayerData.instance.SetBool(unbreakableBool, true);
if (PlayerData.instance.GetBool(GetBrokenBool())) PlayerData.instance.SetBool(GetBrokenBool(), false);
PlayerData.instance.SetBool(GetUnbreakableBool(), true);
}

public override bool Redundant()
{
return base.Redundant() && PlayerData.instance.GetBool(unbreakableBool);
return base.Redundant() && PlayerData.instance.GetBool(GetUnbreakableBool());
}
}
}

0 comments on commit 995fef3

Please sign in to comment.