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
7 changes: 7 additions & 0 deletions SolastaUnfinishedBusiness/Displays/CraftingAndItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ private static void DisplayGeneral()
CustomItemsContext.SwitchAllowClubsToBeThrown();
}

toggle = Main.Settings.AllMagicThrownReturn;
if (UI.Toggle(Gui.Localize("ModUi/&AllMagicThrownReturn"), ref toggle, UI.AutoWidth()))
{
Main.Settings.AllMagicThrownReturn = toggle;
CustomItemsContext.SwitchAllMagicThrownReturn();
}

toggle = Main.Settings.UseOfficialFoodRationsWeight;
if (UI.Toggle(Gui.Localize("ModUi/&UseOfficialFoodRationsWeight"), ref toggle, UI.AutoWidth()))
{
Expand Down
42 changes: 41 additions & 1 deletion SolastaUnfinishedBusiness/Models/CustomItemsContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using SolastaUnfinishedBusiness.Api.GameExtensions;
using SolastaUnfinishedBusiness.Behaviors.Specific;
using SolastaUnfinishedBusiness.Builders;
using SolastaUnfinishedBusiness.Builders.Features;
using SolastaUnfinishedBusiness.Interfaces;
Expand All @@ -10,14 +11,22 @@
using static SolastaUnfinishedBusiness.Api.DatabaseHelper.CharacterClassDefinitions;
using static SolastaUnfinishedBusiness.Api.DatabaseHelper.ItemDefinitions;


namespace SolastaUnfinishedBusiness.Models;

internal static class CustomItemsContext
{
private static readonly Dictionary<string, TagsDefinitions.Criticity> Tags = [];
private static ItemDefinition _helmOfAwareness;
private static ItemDefinition _glovesOfThievery;

private static readonly FeatureDefinitionAttributeModifier featureAllMagicThrownReturn = FeatureDefinitionAttributeModifierBuilder
.Create($"AttributeModifierAllMagicThrownReturn")
.SetGuiPresentationNoContent()
.AddCustomSubFeatures(ReturningWeapon.AlwaysValid)
.AddToDB();
private static readonly ItemPropertyDescription itemPropertyAllMagicThrownReturn = ItemPropertyDescriptionBuilder
.From(featureAllMagicThrownReturn, true)
.Build();
internal static ItemDefinition HelmOfAwareness => _helmOfAwareness ??= BuildHelmOfAwareness();
internal static ItemDefinition GlovesOfThievery => _glovesOfThievery ??= BuildGlovesOfThievery();

Expand All @@ -31,6 +40,7 @@ internal static void Load()
SwitchAllowClubsToBeThrown();
SwitchUniversalSylvanArmorAndLightbringer();
SwitchMagicStaffFoci();
SwitchAllMagicThrownReturn();
}

private static ItemDefinition BuildHelmOfAwareness()
Expand Down Expand Up @@ -215,6 +225,36 @@ internal static void SwitchMagicStaffFoci()
}
}

internal static void SwitchAllMagicThrownReturn()
{
foreach (var item in DatabaseRepository.GetDatabase<ItemDefinition>()
.Where(x => x.IsWeapon &&
x.Magical &&
x.WeaponDescription.WeaponTags.Contains("Thrown")))
{
bool hasProperty = item.StaticProperties
.Exists(p => p.FeatureDefinition.Name.Contains("AttributeModifierAllMagicThrownReturn"));

if (Main.Settings.AllMagicThrownReturn)
{
// ENABLED → add if missing
if (!hasProperty)
{
item.staticProperties.Add(itemPropertyAllMagicThrownReturn);
}
}
else
{
// DISABLED → remove if present
if (hasProperty)
{
item.staticProperties
.RemoveAll(p => p.FeatureDefinition.Name.Contains("AttributeModifierAllMagicThrownReturn"));
}
}
}
}

internal static bool IsAttackModeInvalid(RulesetCharacter character, RulesetAttackMode mode)
{
if (character is not RulesetCharacterHero hero)
Expand Down
1 change: 1 addition & 0 deletions SolastaUnfinishedBusiness/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public class Settings : UnityModManager.ModSettings
public bool RemoveAttunementRequirements { get; set; }
public bool AllowAnyClassToWearSylvanArmor { get; set; }
public bool AllowClubsToBeThrown { get; set; }
public bool AllMagicThrownReturn { get; set; }
[Tag(Type = TagType.T2014)] public bool UseOfficialFoodRationsWeight { get; set; }
public bool MakeAllMagicStaveArcaneFoci { get; set; }
[Tag(Type = TagType.T2014)] public bool FixRingOfRegenerationHealRate { get; set; }
Expand Down
1 change: 1 addition & 0 deletions SolastaUnfinishedBusiness/Translations/en/Settings-en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ModUi/&EnemySpellcastersDropScribedSpellbooks=Enemy spellcasters drop scribed sp
ModUi/&AddToStore=Add {0}
ModUi/&Advanced=<color=#F0DAA0>Advanced:</color> <b><i><color=#C04040E0>[Requires Restart]</color></i></b>
ModUi/&AdvancedHelp=• <b><color=#C04040E0>ATTENTION:</color></b> These settings will require the player to have this mod installed
ModUi/&AllMagicThrownReturn=All magic thrown weapons return to the thrower <b><i><color=#C04040E0>[Requires Restart To Remove]</color></i></b>
ModUi/&AllowAllPlayersOnNarrativeSequences=<i>+ Allow all players on narrative sequences</i>
ModUi/&AllowAlliesToPerceiveRangerGloomStalkerInNaturalDarkness=Allow allies to perceive <b>GloomStalker</b> when in natural darkness
ModUi/&AllowAnyClassToWearSylvanArmor=Allow any class to wear <color=#D89555>Sylvan Armor</color> or <color=#D89555>Lightbringer Clothes</color>
Expand Down