using System; using Server.Network; using Server.Targeting; using Server.Custom; // Required for durability extension methods namespace Server.Items { public class PowderOfTemperament : Item, IUsesRemaining { private int m_UsesRemaining; [Constructable] public PowderOfTemperament() : this(10) { } [Constructable] public PowderOfTemperament(int charges) : base(4102) { Weight = 1.0; Hue = 2419; UsesRemaining = charges; } public PowderOfTemperament(Serial serial) : base(serial) { } [CommandProperty(AccessLevel.GameMaster)] public int UsesRemaining { get { return m_UsesRemaining; } set { m_UsesRemaining = value; InvalidateProperties(); } } public bool ShowUsesRemaining { get { return true; } set { } } public override int LabelNumber { get { return 1049082; } // powder of fortifying } public override void Serialize(GenericWriter writer) { base.Serialize(writer); writer.Write((int)0); writer.Write((int)m_UsesRemaining); } public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); if (version == 0) m_UsesRemaining = reader.ReadInt(); } public override void AddUsesRemainingProperties(ObjectPropertyList list) { list.Add(1060584, m_UsesRemaining.ToString()); } public override void OnDoubleClick(Mobile from) { if (IsChildOf(from.Backpack)) from.Target = new InternalTarget(this); else from.SendLocalizedMessage(1042001); // Must be in pack } private class InternalTarget : Target { private PowderOfTemperament m_Powder; public InternalTarget(PowderOfTemperament powder) : base(2, false, TargetFlags.None) { m_Powder = powder; } protected override void OnTarget(Mobile from, object targeted) { if (m_Powder.Deleted || m_Powder.UsesRemaining <= 0) { from.SendLocalizedMessage(1049086); // used up return; } Item item = targeted as Item; if (item == null) { from.SendLocalizedMessage(1042001); return; } // Jewelry cannot be fortified (OSI) if (item is BaseJewel) { from.SendLocalizedMessage(1049083); return; } // Brittle or Antique items cannot be fortified (OSI) if (IsBrittle(item) || IsAntique(item)) { from.SendLocalizedMessage(1049083); return; } IDurability wearable = targeted as IDurability; if (wearable == null || !wearable.CanFortify) { from.SendLocalizedMessage(1049083); return; } if (!(item.IsChildOf(from.Backpack) || (Core.ML && item.Parent == from)) || !m_Powder.IsChildOf(from.Backpack)) { from.SendLocalizedMessage(1049085); return; } // =============================== // HARD CAP CHECK — OSI ACCURATE // =============================== int oldMax = wearable.MaxHitPoints; if (oldMax >= 255) { from.SendMessage("This item cannot be fortified any further."); return; } // =============================== // APPLY +10 DURABILITY (CAPPED) // =============================== int delta = 10; if (oldMax + delta > 255) delta = 255 - oldMax; if (delta <= 0) { from.SendMessage("This item cannot be fortified any further."); return; } int newMax = oldMax + delta; wearable.MaxHitPoints = newMax; wearable.HitPoints += delta; if (wearable.HitPoints > wearable.MaxHitPoints) wearable.HitPoints = wearable.MaxHitPoints; // =============================================== // REMOVE SELF REPAIR ON FIRST PoF USE // =============================================== if (item is BaseWeapon bw) { bw.WeaponAttributes.SelfRepair = 0; } if (item is BaseArmor ba) { ba.ArmorAttributes.SelfRepair = 0; } if (item is BaseShield bs) { bs.ArmorAttributes.SelfRepair = 0; } if (item is BaseClothing bc) { bc.ClothingAttributes.SelfRepair = 0; } // =============================== // TRACK POF USES // =============================== item.SetPoFUses(item.GetPoFUses() + 1); // =============================== // APPLY REPAIR LOCK // =============================== item.SetRepairLocked(true); from.SendMessage("You successfully fortify the item."); from.PlaySound(0x247); m_Powder.UsesRemaining--; if (m_Powder.UsesRemaining <= 0) { from.SendLocalizedMessage(1049086); m_Powder.Delete(); } } private bool IsBrittle(Item item) { BaseWeapon bw = item as BaseWeapon; if (bw != null && (bw.Attributes.Brittle > 0 || bw.NegativeAttributes.Brittle > 0)) return true; BaseArmor ba = item as BaseArmor; if (ba != null && (ba.Attributes.Brittle > 0 || ba.NegativeAttributes.Brittle > 0)) return true; BaseClothing bc = item as BaseClothing; if (bc != null && (bc.Attributes.Brittle > 0 || bc.NegativeAttributes.Brittle > 0)) return true; BaseJewel bj = item as BaseJewel; if (bj != null && (bj.Attributes.Brittle > 0 || bj.NegativeAttributes.Brittle > 0)) return true; BaseTalisman bt = item as BaseTalisman; if (bt != null && bt.Attributes.Brittle > 0) return true; return false; } private bool IsAntique(Item item) { BaseWeapon bw = item as BaseWeapon; if (bw != null && bw.NegativeAttributes.Antique > 0) return true; BaseArmor ba = item as BaseArmor; if (ba != null && ba.NegativeAttributes.Antique > 0) return true; BaseClothing bc = item as BaseClothing; if (bc != null && bc.NegativeAttributes.Antique > 0) return true; BaseJewel bj = item as BaseJewel; if (bj != null && bj.NegativeAttributes.Antique > 0) return true; return false; } } } }