Skip to content

Commit

Permalink
Added missing cost to the Heart Thrower spell
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurocosh committed Mar 17, 2024
1 parent 0c346a0 commit 55c710b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
42 changes: 42 additions & 0 deletions Content/Spells/Base/SpellCosts/Stats/TotalManaPercentSpellCost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using Terraria;

namespace Spellwright.Content.Spells.Base.SpellCosts.Stats
{
internal class TotalManaPercentSpellCost : SpellCost
{
public float CostPercent { get; }

public TotalManaPercentSpellCost(float cost)
{
CostPercent = Math.Clamp(cost, 0, 1);
}

public override bool Consume(Player player, int playerLevel, SpellData spellData)
{
float costPercent = CostPercent * spellData.CostModifier;
int realCost = (int)Math.Floor(player.statManaMax * costPercent);
if (realCost <= 0)
return true;

if (player.statMana < realCost)
{
LastError = Spellwright.GetTranslation("SpellCost", "NotEnoughMana").Format(realCost);
return false;
}

player.statMana -= realCost;
return true;
}

public override string GetDescription(Player player, int playerLevel, SpellData spellData)
{
float costPercent = CostPercent * spellData.CostModifier;
int realCost = (int)Math.Floor(player.statManaMax * costPercent);
if (realCost <= 0)
return null;

return Spellwright.GetTranslation("SpellCost", "ManaCost").Format(realCost);
}
}
}
2 changes: 2 additions & 0 deletions Content/Spells/Projectiles/HeartThrowerSpell.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Spellwright.Content.Projectiles;
using Spellwright.Content.Spells.Base;
using Spellwright.Content.Spells.Base.SpellCosts.Items;
using Spellwright.Content.Spells.Base.SpellCosts.Stats;
using Spellwright.Content.Spells.Base.Types;
using Spellwright.Util;
using Terraria.ID;
Expand Down Expand Up @@ -29,6 +30,7 @@ public override void SetStaticDefaults()
minSpeedChange = .2f;
maxSpeedChange = .35f;

UseCost = new TotalManaPercentSpellCost(0.5f);
UnlockCost = new SingleItemSpellCost(ItemID.HeartLantern);
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
displayName = Spellwright
author = Aurocosh
version = 0.8.2.8
version = 0.8.2.9
dllReferences = NetSerializer
languageVersion = 7
buildIgnore = *.csproj, *.sln, *.user, *.md, obj\*, bin\*, .vs\*, .git\*, .gitignore
Expand Down

0 comments on commit 55c710b

Please sign in to comment.