diff --git a/Scripts/Commands/Player/BandSelf.cs b/Scripts/Commands/Player/BandSelf.cs index b3a2c79..2b4240a 100644 --- a/Scripts/Commands/Player/BandSelf.cs +++ b/Scripts/Commands/Player/BandSelf.cs @@ -26,12 +26,39 @@ namespace Server.Commands return; } - // 2. Search for a bandage in the backpack + // 2. Search for the custom Enchanted Bandage first + EnchantedBandage enchanted = from.Backpack.FindItemByType(); + + if (enchanted != null && enchanted.Charges > 0) + { + // The 50% chance check + if (Utility.RandomDouble() < 0.50) + { + from.Poison = null; + from.Hits = from.HitsMax; + + from.PlaySound(0x1F2); + from.FixedParticles(0x376A, 9, 32, 5030, EffectLayer.Waist); + from.SendMessage(63, "The enchanted bandage glows brightly, instantly curing and fully healing you!"); + } + else + { + // Failed 50% check. Trigger normal heal using the custom charges. + if (BandageContext.BeginHeal(from, from) != null) + { + enchanted.Charges--; + } + } + + // Return here so we don't accidentally consume a regular bandage below + return; + } + + // 3. Fallback: Search for a standard bandage in the backpack Bandage bandage = from.Backpack.FindItemByType(); if (bandage != null) { - // 3. Trigger the healing attempt directly using the established Context logic // We call BeginHeal which handles the timer, skill checks, and target logic if (BandageContext.BeginHeal(from, from) != null) { diff --git a/Scripts/Quests/Rewards/EnchantedBandage.cs b/Scripts/Quests/Rewards/EnchantedBandage.cs new file mode 100644 index 0000000..9c2dbd1 --- /dev/null +++ b/Scripts/Quests/Rewards/EnchantedBandage.cs @@ -0,0 +1,188 @@ +using System; +using System.Collections.Generic; +using Server; +using Server.Items; +using Server.Mobiles; +using Server.Targeting; + +namespace Server.Items +{ + public class EnchantedBandage : Item + { + public static Dictionary CooldownTable = new Dictionary(); + + private int m_Charges; + + [CommandProperty( AccessLevel.GameMaster )] + public int Charges + { + get { return m_Charges; } + set { m_Charges = value; InvalidateProperties(); } + } + + public int MaxCharges { get { return 200; } } + + [Constructable] + public EnchantedBandage() : base( 0xE21 ) + { + Name = "an enchanted bandage roll"; + Hue = 1150; + Weight = 1.0; + m_Charges = 0; + } + + public override void OnDoubleClick( Mobile from ) + { + if ( !IsChildOf( from.Backpack ) ) + { + from.SendLocalizedMessage( 1042001 ); + return; + } + + if ( m_Charges <= 0 ) + { + from.SendMessage( 33, "There are no bandages stored in this roll." ); + return; + } + + if ( BandageContext.GetContext( from ) != null ) + { + from.SendMessage( 33, "You are already applying a bandage." ); + return; + } + + if ( CooldownTable.ContainsKey( from ) && CooldownTable[from] > DateTime.UtcNow ) + { + from.SendMessage( 33, "You must wait a moment before using the enchanted roll again." ); + return; + } + + from.SendMessage( "Who do you wish to heal?" ); + from.Target = new InternalTarget( this ); + } + + public override bool OnDragDrop( Mobile from, Item dropped ) + { + if ( dropped is Bandage ) + { + int amount = dropped.Amount; + int room = MaxCharges - m_Charges; + + if ( room <= 0 ) + { + from.SendMessage( 33, "This enchanted roll is already full." ); + return false; + } + + if ( amount > room ) + { + m_Charges += room; + dropped.Consume( room ); + from.SendMessage( 63, String.Format( "You add {0} bandages to the roll. It is now completely full.", room ) ); + from.PlaySound( 0x249 ); + return false; + } + else + { + m_Charges += amount; + dropped.Delete(); + from.SendMessage( 63, String.Format( "You add {0} bandages to the roll. It now holds {1}.", amount, m_Charges ) ); + from.PlaySound( 0x249 ); + return true; + } + } + + from.SendMessage( 33, "You can only add standard bandages to this roll." ); + return false; + } + + public override void OnSingleClick( Mobile from ) + { + base.OnSingleClick( from ); + this.LabelTo( from, String.Format( "[Charges: {0}/{1}]", m_Charges, MaxCharges ) ); + } + + public override void GetProperties( ObjectPropertyList list ) + { + base.GetProperties( list ); + list.Add( 1049644, "Charges: {0} / {1}", m_Charges, MaxCharges ); + } + + private class InternalTarget : Target + { + private EnchantedBandage m_Item; + + public InternalTarget( EnchantedBandage item ) : base( 1, false, TargetFlags.Beneficial ) + { + m_Item = item; + } + + protected override void OnTarget( Mobile from, object targeted ) + { + if ( m_Item.Deleted || m_Item.Charges <= 0 ) return; + + if ( !m_Item.IsChildOf( from.Backpack ) ) + { + from.SendLocalizedMessage( 1042001 ); + return; + } + + if ( BandageContext.GetContext( from ) != null ) + { + from.SendMessage( 33, "You are already applying a bandage." ); + return; + } + + if ( targeted is Mobile ) + { + Mobile m = (Mobile)targeted; + + if ( Utility.RandomDouble() < 0.30 ) + { + m.Poison = null; + m.Hits = m.HitsMax; + + m.PlaySound( 0x1F2 ); + m.FixedParticles( 0x376A, 9, 32, 5030, EffectLayer.Waist ); + + if ( m == from ) + from.SendMessage( 63, "The enchanted bandage glows brightly, instantly curing and fully healing you!" ); + else + from.SendMessage( 63, "The enchanted bandage glows brightly, instantly curing and fully healing them!" ); + + CooldownTable[from] = DateTime.UtcNow + TimeSpan.FromSeconds( 5 ); + } + else + { + if ( BandageContext.BeginHeal( from, m ) != null ) + { + m_Item.Charges--; + } + } + } + else + { + from.SendMessage( "You cannot heal that." ); + } + } + } + + public EnchantedBandage( Serial serial ) : base( serial ) + { + } + + public override void Serialize( GenericWriter writer ) + { + base.Serialize( writer ); + writer.Write( (int) 0 ); + writer.Write( (int) m_Charges ); + } + + public override void Deserialize( GenericReader reader ) + { + base.Deserialize( reader ); + int version = reader.ReadInt(); + m_Charges = reader.ReadInt(); + } + } +}