ModernUO/Projects/UOContent/Items/Skill Items/Magical/Potions/Cure Potions/BaseCurePotion.cs
Kamron Batman 38731d98b6
fix: Fixes splitting potions before error (#1862)
### Summary

Most potions have various checks, such as a cooldown. This fixes an edge case where potions get split from their stack before erroring.
2024-07-06 16:39:47 -07:00

90 lines
2 KiB
C#

using ModernUO.Serialization;
using Server.Spells;
using Server.Spells.Necromancy;
namespace Server.Items;
public class CureLevelInfo
{
public CureLevelInfo(Poison poison, double chance)
{
Poison = poison;
Chance = chance;
}
public Poison Poison { get; }
public double Chance { get; }
}
[SerializationGenerator(0, false)]
public abstract partial class BaseCurePotion : BasePotion
{
public BaseCurePotion(PotionEffect effect) : base(0xF07, effect)
{
}
public abstract CureLevelInfo[] LevelInfo { get; }
public void DoCure(Mobile from)
{
var cure = false;
var info = LevelInfo;
for (var i = 0; i < info.Length; ++i)
{
var li = info[i];
if (li.Poison == from.Poison && Scale(from, li.Chance) > Utility.RandomDouble())
{
cure = true;
break;
}
}
if (cure && from.CurePoison(from))
{
from.SendLocalizedMessage(500231); // You feel cured of poison!
from.FixedEffect(0x373A, 10, 15);
from.PlaySound(0x1E0);
}
else if (!cure)
{
from.SendLocalizedMessage(500232); // That potion was not strong enough to cure your ailment!
}
}
public override bool CanDrink(Mobile from)
{
if (!base.CanDrink(from))
{
return false;
}
if (TransformationSpellHelper.UnderTransformation(from, typeof(VampiricEmbraceSpell)))
{
from.SendLocalizedMessage(1061652); // The garlic in the potion would surely kill you.
return false;
}
if (!from.Poisoned)
{
from.SendLocalizedMessage(1042000); // You are not poisoned.
return false;
}
return true;
}
public override void Drink(Mobile from)
{
DoCure(from);
PlayDrinkEffect(from);
from.FixedParticles(0x373A, 10, 15, 5012, EffectLayer.Waist);
from.PlaySound(0x1E0);
}
}