ServUO Version
Publish 57
Ultima Expansion
None
C#:
using System;
using Server;
using Server.Mobiles;
using Server.Network;
using Server.Spells;
using Server.Targeting;
using Server.Items;
using Server.Spells.Chivalry;
using Server.Gumps;

namespace Server.Spells.Chivalry
{
    public class PaladinStatBoostSpell : PaladinSpell
    {
        public static new readonly SpellInfo Info = new SpellInfo(
            "Divine Power", "Divinus Potentia",
            221, // SpellID or Icon ID
            9002, // Cast animation
            221, // Icon ID for the spell
            Reagent.BlackPearl, Reagent.MandrakeRoot); // Reagents used for the spell

        public override TimeSpan CastDelayBase => TimeSpan.FromSeconds(2.0);
        public override bool ClearHandsOnCast => false;
        public override double RequiredSkill => 60.0; // Required skill level to cast
        public override int RequiredMana => 20;       // Mana cost for the spell
        public override int RequiredTithing => 15;    // Tithing cost for the spell
        public override int MantraNumber => 1060724;  // "Divinus Potentia"

        private const int HitPointBonus = 20;
        private const int StatBonus = 10;
        private const double BonusDuration = 2.0; // Duration in minutes

        public PaladinStatBoostSpell(Mobile caster, Item scroll)
            : base(caster, scroll, Info)
        {
        }

        public static void Initialize()
        {
            // Register the spell in the Paladin spell list
            SpellRegistry.Register(Info.Name, typeof(PaladinStatBoostSpell));
        }

        private void RevertStats(object state)
        {
            Mobile caster = (Mobile)state;

            // Safely revert the stat bonuses, ensure no negative stats or hits
            caster.Hits = Math.Max(caster.Hits - HitPointBonus, 1);
            caster.Str = Math.Max(caster.Str - StatBonus, 1);
            caster.Dex = Math.Max(caster.Dex - StatBonus, 1);
            caster.Int = Math.Max(caster.Int - StatBonus, 1);

            caster.SendMessage("The divine power fades away.");
        }

        public override void OnCast()
        {
            Mobile caster = Caster;

            if (caster.HitsMax + HitPointBonus > 0 && caster.Str + StatBonus > 0 && caster.Dex + StatBonus > 0 && caster.Int + StatBonus > 0)
            {
                // Apply the bonuses
                caster.Hits += HitPointBonus;
                caster.Str += StatBonus;
                caster.Dex += StatBonus;
                caster.Int += StatBonus;

                caster.SendMessage("You feel a surge of divine power!");

                // Set up the timer to revert the stats after the duration ends
                object value = Timer(TimeSpan.FromMinutes(BonusDuration),
                                               RevertStats,
                                               caster);

                FinishSequence();
            }
            else
            {
                caster.SendMessage("You are already too powerful to benefit from this spell.");
                FinishSequence();
            }
        }

        private object Timer(TimeSpan timeSpan, Action<object> revertStats, Mobile caster)
        {
            throw new NotImplementedException();
        }
    }

    public class PaladinSpellGump : Gump
    {
        public PaladinSpellGump(Mobile from) : base(100, 100)
        {
            // Existing spell buttons...

            AddButton(100, 100, 2103, 2104, 1, GumpButtonType.Reply, 0); // Button for "Divine Power" spell
            AddLabel(130, 100, 0, "Divine Power"); // Label for the spell name
        }

        public override void OnResponse(NetState sender, RelayInfo info)
        {
            Mobile from = sender.Mobile;

            if (info.ButtonID == 1)
            {
                // Cast the Divine Power spell when the button is pressed
                from.SendMessage("You cast Divine Power.");
                new PaladinStatBoostSpell(from, null).Cast();
            }
        }
    }
}
And the magic that raises the paladin's stats a bit like world of warcraft, serveruo works and then crashes I don't understand
 

Attachments

  • paladinblessing.cs
    4 KB · Views: 2
Your timer logic is missing on line 87, this crash happens because the code that was generated reminds you to fill it in by throwing an exception.

Line 72 needs to use Timer.DelayCall() instead of this erroneous Timer() method, which can be completely removed.
 
Your timer logic is missing on line 87, this crash happens because the code that was generated reminds you to fill it in by throwing an exception.

Line 72 needs to use Timer.DelayCall() instead of this erroneous Timer() method, which can be completely removed.
Good catch, debugging AI generated code is fun
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back