Skip to content

Commit

Permalink
Added config
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurocosh committed Sep 17, 2022
1 parent dc134d1 commit a60ddfe
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 60 deletions.
67 changes: 62 additions & 5 deletions Config/SpellwrightServerConfig.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
using System.ComponentModel;
using Newtonsoft.Json;
using Spellwright.Core.Spells;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.RegularExpressions;
using Terraria;
using Terraria.ModLoader.Config;

namespace Spellwright.Config
{
[Label("$Mods.Spellwright.Config.ConfigName")]
class SpellwrightServerConfig : ModConfig
{
public override ConfigScope Mode => ConfigScope.ServerSide;

public static SpellwrightServerConfig Instance;

[Range(1, 10000000)]
[DefaultValue(10)]
[Header("$Mods.Spellwright.Config.SpellReagentCosts.Header")]
[Label("$Mods.Spellwright.Config.SpellReagentCosts.Common.Label")]
[Tooltip("$Mods.Spellwright.Config.SpellReagentCosts.Common.Tooltip")]
public int CommonReagentCost { get; set; }

[Range(1, 10000000)]
[DefaultValue(1000)]
[Label("$Mods.Spellwright.Config.SpellReagentCosts.Rare.Label")]
[Tooltip("$Mods.Spellwright.Config.SpellReagentCosts.Rare.Tooltip")]
public int RareReagentCost { get; set; }

[Range(1, 10000000)]
[DefaultValue(100000)]
[Label("$Mods.Spellwright.Config.SpellReagentCosts.Mythical.Label")]
[Tooltip("$Mods.Spellwright.Config.SpellReagentCosts.Mythical.Tooltip")]
public int MythicalReagentCost { get; set; }

[DefaultValue(true)]
[Label("Test")]
[Tooltip("Test")]
public bool Test { get; set; }
[Header("$Mods.Spellwright.Config.SpellCosts.Header")]
[Label("$Mods.Spellwright.Config.SpellCosts.CastCostEnabled.Label")]
[Tooltip("$Mods.Spellwright.Config.SpellCosts.CastCostEnabled.Tooltip")]
public bool CastCostEnabled { get; set; }

[DefaultValue(true)]
[Label("$Mods.Spellwright.Config.SpellCosts.UnlockCostEnabled.Label")]
[Tooltip("$Mods.Spellwright.Config.SpellCosts.UnlockCostEnabled.Tooltip")]
public bool UnlockCostEnabled { get; set; }

[Header("$Mods.Spellwright.Config.Spells.Header")]
[Label("$Mods.Spellwright.Config.Spells.DisabledSpells.Label")]
[Tooltip("$Mods.Spellwright.Config.Spells.DisabledSpells.Tooltip")]
public readonly HashSet<string> DisabledSpells = new();
[JsonIgnore]
public readonly HashSet<int> DisabledSpellIds = new();

public override bool AcceptClientChanges(ModConfig pendingConfig, int whoAmI, ref string message)
{
if (!Spellwright.IsPlayerServerOwner(Main.LocalPlayer))
{
message = "You are not the server owner";
message = Spellwright.GetTranslation("Config", "Errors", "NotServerOwner").ToString();
return false;
}

return base.AcceptClientChanges(pendingConfig, whoAmI, ref message);
}

public override void OnChanged()
{
ReloadDisabledSpells();
}

private void ReloadDisabledSpells()
{
DisabledSpellIds.Clear();
foreach (string spellIncantation in DisabledSpells)
{
var incantation = Regex.Replace(spellIncantation, @"\s+", " ").Trim();
var spell = SpellLibrary.GetSpellByIncantation(incantation);
if (spell != null)
DisabledSpellIds.Add(spell.Type);
}
}
}
}
4 changes: 3 additions & 1 deletion Content/Items/Reagents/CommonSpellReagent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Spellwright.Config;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
Expand All @@ -21,7 +22,8 @@ public override void SetDefaults()
{
Item.maxStack = 999;
Item.ammo = Item.type;
Item.value = Item.buyPrice(0, 0, 0, 10);
//Item.value = Item.buyPrice(0, 0, 0, 10);
Item.value = SpellwrightServerConfig.Instance.CommonReagentCost;
Item.rare = ItemRarityID.Green;
}
public override void AddRecipes()
Expand Down
4 changes: 3 additions & 1 deletion Content/Items/Reagents/MythicalSpellReagent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Spellwright.Config;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
Expand All @@ -20,7 +21,8 @@ public override void SetDefaults()
{
Item.maxStack = 999;
Item.ammo = Item.type;
Item.value = Item.buyPrice(0, 10, 0, 0);
//Item.value = Item.buyPrice(0, 10, 0, 0);
Item.value = SpellwrightServerConfig.Instance.MythicalReagentCost;
Item.rare = ItemRarityID.Red;
}
public override void AddRecipes()
Expand Down
4 changes: 3 additions & 1 deletion Content/Items/Reagents/RareSpellReagent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Spellwright.Config;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
Expand All @@ -20,7 +21,8 @@ public override void SetDefaults()
{
Item.maxStack = 999;
Item.ammo = Item.type;
Item.value = Item.buyPrice(0, 0, 10, 0);
//Item.value = Item.buyPrice(0, 0, 10, 0);
Item.value = SpellwrightServerConfig.Instance.RareReagentCost;
Item.rare = ItemRarityID.LightPurple;
}
public override void AddRecipes()
Expand Down
73 changes: 73 additions & 0 deletions Content/Items/SpellTomes/BeginnerSpellTome.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
using Spellwright.Content.Items.SpellTomes.Base;
using Spellwright.Content.Spells.BuffSpells;
using Spellwright.Content.Spells.BuffSpells.Defensive;
using Spellwright.Content.Spells.BuffSpells.Sigils;
using Spellwright.Content.Spells.BuffSpells.Utility;
using Spellwright.Content.Spells.BuffSpells.Vanilla;
using Spellwright.Content.Spells.Enchant;
using Spellwright.Content.Spells.Explosive;
using Spellwright.Content.Spells.Healing;
using Spellwright.Content.Spells.Herbs;
using Spellwright.Content.Spells.Items;
using Spellwright.Content.Spells.LiquidSpawn;
using Spellwright.Content.Spells.Minions;
using Spellwright.Content.Spells.Movement;
using Spellwright.Content.Spells.Other;
using Spellwright.Content.Spells.Projectiles;
using Spellwright.Content.Spells.SpellRelated;
using Spellwright.Content.Spells.Storage;
using Spellwright.Content.Spells.TileBreak;
using Spellwright.Content.Spells.TileSpawn;
using Spellwright.Content.Spells.Warp;
using Spellwright.Content.Spells.WorldEvents;
using Terraria;
using Terraria.ID;

Expand All @@ -29,6 +37,12 @@ public override void SetStaticDefaults()
content.AddCount(3, .25);
content.AddCount(4, .05);

// Level 0
content.AddSpell<AscendSpell>();
content.AddSpell<MendSpell>();
content.AddSpell<ReturnSpell>();
content.AddSpell<SparkCasterSpell>();

// Level 1
content.AddSpell<FireballSpell>(3);
content.AddSpell<ForceOfCreationSpell>(2);
Expand Down Expand Up @@ -70,6 +84,65 @@ public override void SetStaticDefaults()
content.AddSpell<SurgeOfLifeSpell>(2);
content.AddSpell<WarpMirrorSpell>();

// Level 4
content.AddSpell<BewitchSpell>();
content.AddSpell<BlockSpitterSpell>(2);
content.AddSpell<BloodArrowSpell>();
content.AddSpell<BoltOfConfusionSpell>();
content.AddSpell<HellGateSpell>(3);
content.AddSpell<HolyShoesSpell>(2);
content.AddSpell<PiggySpell>(3);
content.AddSpell<PotionVoidSpell>();
content.AddSpell<RainCallSpell>();
content.AddSpell<SkyGateSpell>(2);
content.AddSpell<TileRollerSpell>();

// Level 5
content.AddSpell<BurningSoulSpell>();
content.AddSpell<CallOfTheDepthsSpell>(3);
content.AddSpell<ClearMindSpell>();
content.AddSpell<DesertRiteSpell>();
content.AddSpell<EyesOfProfitSpell>(3);
content.AddSpell<GlassCannonSpell>();
content.AddSpell<ObsidianSkinSpell>(2);
content.AddSpell<ShadowStepSpell>(2);
content.AddSpell<VoidMarkSpell>(2);

// Level 6
content.AddSpell<DungeonGateSpell>(3);
content.AddSpell<FortressStanceSpell>();
content.AddSpell<ItemVoidSpell>(3);
content.AddSpell<PulseHealingSpell>();
content.AddSpell<RitualOfHarvestSpell>(2);
content.AddSpell<SelfDefenseHexSpell>();
content.AddSpell<ShapedChargeSpell>(2);

// Level 7
content.AddSpell<ManaShieldSpell>();
content.AddSpell<PurifySpell>();
content.AddSpell<SigilOfBerserkerSpell>(3);
content.AddSpell<SigilOfLegionSpell>(3);
content.AddSpell<SigilOfSageSpell>(3);
content.AddSpell<SigilOfSniperSpell>(3);
//content.AddSpell<SoulNibblerSpell>();

// Level 8
content.AddSpell<GravityDashSpell>(3);
content.AddSpell<LavaSplashSpell>();
content.AddSpell<ReactiveArmorSpell>();
content.AddSpell<StateLockSpell>(2);
content.AddSpell<VortexHandsSpell>();

// Level 9
content.AddSpell<AdventOfSummerSpell>(3);
content.AddSpell<BindMirrorSpell>(2);
content.AddSpell<GreedyVortexSpell>();

// Level 10
content.AddSpell<HymnOfDiscordSpell>(3);
content.AddSpell<MagickaFairySpell>();
content.AddSpell<MetabolicBoostSpell>(2);

Add(Type, content);
}

Expand Down
25 changes: 22 additions & 3 deletions Content/Spells/Base/ModSpell.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Spellwright.Config;
using Spellwright.Content.Spells.Base.CostModifiers;
using Spellwright.Content.Spells.Base.Description;
using Spellwright.Content.Spells.Base.Modifiers;
Expand Down Expand Up @@ -37,11 +38,28 @@ public abstract class ModSpell : ModType
protected SoundStyle? castSound;
protected SoundStyle? useSound;
protected float costModifier;
protected bool costIsImportant;
private SpellCost castCost;
private SpellCost useCost;
private SpellCost unlockCost;

public virtual int SpellLevel { get; protected set; }
public SpellType UseType { get; protected set; }
public SpellCost CastCost { get; protected set; }
public SpellCost UseCost { get; protected set; }
public SpellCost UnlockCost { get; protected set; }
public SpellCost CastCost
{
get => SpellwrightServerConfig.Instance.CastCostEnabled || costIsImportant ? castCost : null;
protected set => castCost = value;
}
public SpellCost UseCost
{
get => SpellwrightServerConfig.Instance.CastCostEnabled || costIsImportant ? useCost : null;
protected set => useCost = value;
}
public SpellCost UnlockCost
{
get => SpellwrightServerConfig.Instance.UnlockCostEnabled ? unlockCost : null;
protected set => unlockCost = value;
}
public SpellModifier AppplicableModifiers { get; protected set; }
private readonly Dictionary<SpellModifier, ICostModifier> spellCostModifiers;

Expand Down Expand Up @@ -73,6 +91,7 @@ protected ModSpell()
CastCost = null;
damageType = DamageClass.Generic;
costModifier = 1f;
costIsImportant = false;
AppplicableModifiers = SpellModifier.None;
spellCostModifiers = new Dictionary<SpellModifier, ICostModifier>();
castSound = SoundID.Item4;
Expand Down
1 change: 1 addition & 0 deletions Content/Spells/Base/SpellCastResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ internal enum SpellCastResult
{
Success,
IncantationInvalid,
SpellIsDisabled,
ModifiersInvalid,
ArgumentInvalid,
LevelTooLow,
Expand Down
4 changes: 4 additions & 0 deletions Content/Spells/SpellProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Spellwright.Common.Players;
using Spellwright.Config;
using Spellwright.Content.Items;
using Spellwright.Content.Spells.Base;
using Spellwright.Content.Spells.Base.Modifiers;
Expand Down Expand Up @@ -27,6 +28,9 @@ public static SpellCastResult ProcessCast(string incantationText)
if (!spellPlayer.KnownSpells.Contains(spell.Type))
return SpellCastResult.IncantationInvalid;

if (SpellwrightServerConfig.Instance.DisabledSpellIds.Contains(spell.Type))
return SpellCastResult.SpellIsDisabled;

var unlockResult = CheckUnlock(spellStructure, spell, spellPlayer);
if (unlockResult != SpellCastResult.Success)
return unlockResult;
Expand Down
1 change: 1 addition & 0 deletions Content/Spells/SpellRelated/AscendSpell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public override void SetStaticDefaults()
SpellLevel = 0;
UseType = SpellType.Invocation;
castSound = SoundID.Item4;
costIsImportant = true;

mappedSpellCost.ClearCosts();
mappedSpellCost.SetSpellCost(0, new SingleItemSpellCost(ItemID.FallenStar, 30));
Expand Down
4 changes: 4 additions & 0 deletions Core/Links/SpellListPageHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Spellwright.Common.Players;
using Spellwright.Config;
using Spellwright.Content.Spells.Base;
using Spellwright.Content.Spells.SpellRelated;
using Spellwright.Core.Links.Base;
Expand Down Expand Up @@ -130,6 +131,9 @@ private static MultiValueDictionary<int, ModSpell> PrepareSpellList(SpellwrightP
{
if (typeCategory != null && typeCategory != spell.UseType)
continue;
if (SpellwrightServerConfig.Instance.DisabledSpellIds.Contains(spell.Type))
continue;

if (showFavorite)
{
if (!spellPlayer.FavoriteSpells.Contains(spellId))
Expand Down
10 changes: 7 additions & 3 deletions Core/Markers/TomeSpellListMarkerProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Spellwright.Content.Items.SpellTomes.Base;
using Spellwright.Config;
using Spellwright.Content.Items.SpellTomes.Base;
using Spellwright.Content.Spells.Base;
using Spellwright.Lib;
using Spellwright.UI.Components.TextBox.MarkerProcessors.Base;
Expand Down Expand Up @@ -54,8 +55,11 @@ private static MultiValueDictionary<int, ModSpell> PrepareSpellList(List<ModSpel
var spellsByLevel = new MultiValueDictionary<int, ModSpell>();
foreach (var spell in spells)
{
int spellLevel = spell.SpellLevel;
spellsByLevel.Add(spellLevel, spell);
if (!SpellwrightServerConfig.Instance.DisabledSpellIds.Contains(spell.Type))
{
int spellLevel = spell.SpellLevel;
spellsByLevel.Add(spellLevel, spell);
}
}

foreach (var item in spellsByLevel.Values)
Expand Down
Loading

0 comments on commit a60ddfe

Please sign in to comment.