/// <summary> /// Returns the intensity of the given prop on the given item. /// </summary> /// <param name="checkHold">true if we want to ensure CanHold( item ) is checked, false if we have checked it before.</param> public static int ComputeIntensity(Item item, BaseAttrInfo prop, bool checkHold) { if (checkHold && !prop.CanHold(item)) { return(0); } int propVal = prop.GetValue(item); int total = GetIntensitySteps(prop); int relative = Math.Max(0, 1 + (int)((propVal - prop.MinIntensity) / prop.IntensityInterval)); int intensity = (int)(100 * ((double)relative / total)); return(intensity); }
public ConfirmationGump(Mobile from, Item itemToImbue, PropCollection itemProperties, BaseAttrInfo propToImbue, BaseAttrInfo propToReplace, int intensityStep, int totalSteps) : base(50, 50) { // Var declarations int intensity; // intensity of the prop we are imbuing int wIntensity; // weighted intensity of the prop we are imbuing int totalIntensity; // total intensity of all props, weighted int wTotalIntensity; // total intensity of all props, weighted int totalProperties; // total number of properties the item will possess when imbued string newValueString; // the new value of the prop we are imbuing // Save the parameters. m_ItemToImbue = itemToImbue; m_Imbuable = m_ItemToImbue as IImbuable; m_ItemProperties = itemProperties; m_PropToImbue = propToImbue; m_PropToReplace = propToReplace; m_IntensityStep = intensityStep; m_TotalIntensitySteps = totalSteps; // Make sure we don't perverse the intensities. Utility.FixMinMax(ref m_IntensityStep, 1, m_TotalIntensitySteps); // Gets info about the prop that we are going to imbue. intensity = (int)(100 * ((double)m_IntensityStep / m_TotalIntensitySteps)); wIntensity = (int)(intensity * m_PropToImbue.Weight); totalIntensity = m_ItemProperties.Intensity + intensity; wTotalIntensity = m_ItemProperties.WeightedIntensity + wIntensity; totalProperties = m_ItemProperties.Count; m_ValueToImbue = ComputeValue(m_IntensityStep, m_TotalIntensitySteps, m_PropToImbue.MinIntensity, m_PropToImbue.MaxIntensity); newValueString = FormatValue(m_PropToImbue.Modify(m_ItemToImbue, m_ValueToImbue), m_PropToImbue); // ********************** // Gump Structure // ********************** AddPage(0); AddBackground(0, 0, 520, 440, 0x13BE); AddImageTiled(10, 10, 500, 20, 0xA40); AddImageTiled(10, 40, 245, 140, 0xA40); AddImageTiled(265, 40, 245, 140, 0xA40); AddImageTiled(10, 190, 245, 140, 0xA40); AddImageTiled(265, 190, 245, 140, 0xA40); AddImageTiled(10, 340, 500, 60, 0xA40); AddImageTiled(10, 410, 500, 20, 0xA40); AddAlphaRegion(10, 10, 500, 420); AddHtmlLocalized(10, 12, 500, 20, 1079717, 0x7FFF, false, false); // <CENTER>IMBUING CONFIRMATION</CENTER> // ********************** // Property Info // ********************** AddHtmlLocalized(50, 50, 250, 20, 1114269, 0x7FFF, false, false); // PROPERTY INFORMATION AddHtmlLocalized(25, 80, 390, 20, 1114270, 0x7FFF, false, false); // Property: AddHtmlLocalized(95, 80, 150, 20, m_PropToImbue.Name, 0x7FFF, false, false); AddHtmlLocalized(25, 100, 390, 20, 1114271, 0x7FFF, false, false); // Replaces: if (m_PropToReplace != null) { m_ValueToReplace = m_PropToReplace.GetValue(m_ItemToImbue); AddHtmlLocalized(95, 100, 150, 20, m_PropToReplace.Name, 0x7FFF, false, false); // The intensity of the property replaced may not count in the total. int replaceIntensity = Imbuing.ComputeIntensity(m_ItemToImbue, m_PropToReplace); totalIntensity -= replaceIntensity; wTotalIntensity -= (int)(m_PropToReplace.Weight * replaceIntensity); } else { // Since we are not replacing any prop, it means we are adding one ^^u totalProperties++; } m_WTotalIntensity = wTotalIntensity; AddHtmlLocalized(25, 120, 200, 20, 1114272, 0x7FFF, false, false); // Weight: AddLabel(95, 120, 0x481, String.Format("{0:0.0}x", m_PropToImbue.Weight)); AddHtmlLocalized(25, 140, 200, 20, 1114273, 0x7FFF, false, false); // Intensity: AddLabel(95, 140, 0x481, String.Format("{0}%", wIntensity)); AddHtmlLocalized(280, 55, 205, 115, m_PropToImbue.Description, 0x7FFF, false, false); // ********************** // Material Info // ********************** AddHtmlLocalized(100, 200, 80, 20, 1044055, 0x7FFF, false, false); // <CENTER>MATERIALS</CENTER> m_Resources1 = Math.Max(1, (int)(intensity / 20)); m_Resources2 = Math.Max(1, (int)(intensity / 10)); m_Resources3 = Math.Max(0, (intensity - 90)); AddHtmlLocalized(40, 220, 390, 20, (int)m_PropToImbue.PrimaryResource, 0x7FFF, false, false); AddLabel(210, 220, 0x481, m_Resources1.ToString()); AddHtmlLocalized(40, 240, 390, 20, (int)m_PropToImbue.SecondaryResource, 0x7FFF, false, false); AddLabel(210, 240, 0x481, m_Resources2.ToString()); if (m_Resources3 > 0) { AddHtmlLocalized(40, 260, 390, 20, (int)m_PropToImbue.FullResource, 0x7FFF, false, false); AddLabel(210, 260, 0x481, m_Resources3.ToString()); } // ********************** // Results // ********************** AddHtmlLocalized(350, 200, 65, 20, 1113650, 0x7FFF, false, false); // RESULTS AddHtmlLocalized(280, 220, 140, 20, 1113645, 0x7FFF, false, false); // Properties: AddFractionLabel(430, 220, totalProperties, 5); AddHtmlLocalized(280, 240, 260, 20, 1113646, 0x7FFF, false, false); // Total Property Weight: AddFractionLabel(430, 240, wTotalIntensity, m_Imbuable.MaxIntensity); AddHtmlLocalized(280, 260, 200, 20, 1113647, 0x7FFF, false, false); // Times Imbued: AddFractionLabel(430, 260, m_Imbuable.TimesImbued, 20); // ********************** // Choose Intensity // ********************** if (m_PropToImbue.MinIntensity != m_PropToImbue.MaxIntensity) { AddHtmlLocalized(235, 350, 200, 20, 1062300, 0x7FFF, false, false); // New Value: AddLabel(256, 370, 0x481, newValueString); AddButton(179, 372, 0x1464, 0x1464, 310, GumpButtonType.Reply, 0); AddButton(187, 372, 0x1466, 0x1466, 310, GumpButtonType.Reply, 0); AddLabel(181, 370, 0x0, "<"); AddLabel(185, 370, 0x0, "<"); AddLabel(189, 370, 0x0, "<"); AddButton(199, 372, 0x1464, 0x1464, 314, GumpButtonType.Reply, 0); AddButton(207, 372, 0x1466, 0x1466, 314, GumpButtonType.Reply, 0); AddLabel(202, 370, 0x0, "<"); AddLabel(207, 370, 0x0, "<"); AddButton(221, 372, 0x1464, 0x1464, 311, GumpButtonType.Reply, 0); AddButton(229, 372, 0x1466, 0x1466, 311, GumpButtonType.Reply, 0); AddLabel(224, 370, 0x0, "<"); AddButton(280, 372, 0x1464, 0x1464, 312, GumpButtonType.Reply, 0); AddButton(288, 372, 0x1466, 0x1466, 312, GumpButtonType.Reply, 0); AddLabel(286, 370, 0x0, ">"); AddButton(300, 372, 0x1464, 0x1464, 315, GumpButtonType.Reply, 0); AddButton(308, 372, 0x1466, 0x1466, 315, GumpButtonType.Reply, 0); AddLabel(304, 370, 0x0, ">"); AddLabel(308, 370, 0x0, ">"); AddButton(320, 372, 0x1464, 0x1464, 313, GumpButtonType.Reply, 0); AddButton(328, 372, 0x1466, 0x1466, 313, GumpButtonType.Reply, 0); AddLabel(322, 370, 0x0, ">"); AddLabel(326, 370, 0x0, ">"); AddLabel(330, 370, 0x0, ">"); } // ********************** // Self Repair Warning // ********************** bool selfRepair = (m_ItemToImbue is IArmor && ((IArmor)m_ItemToImbue).ArmorAttributes.SelfRepair != 0) || (m_ItemToImbue is ICloth && ((ICloth)m_ItemToImbue).ClothingAttributes.SelfRepair != 0) || (m_ItemToImbue is IWeapon && ((IWeapon)m_ItemToImbue).WeaponAttributes.SelfRepair != 0); if (selfRepair) { AddHtmlLocalized(20, 330, 390, 20, 1080417, 0x7FFF, false, false); // WARNING! Imbuing will remove Self Repair from this item. } // ********************** // Success Chance // ********************** m_SuccessChance = Imbuing.GetSuccessChance(from, m_ItemToImbue, totalIntensity); AddHtmlLocalized(300, 300, 250, 20, 1044057, 0x7FFF, false, false); // Success Chance: AddLabel(420, 300, GetSuccessChanceHue(), String.Format("{0:0.0}%", Math.Max(0, (m_SuccessChance * 100)))); // ********************** // Are we ready to rock? // ********************** AddButton(15, 410, 0xFA5, 0xFA6, 301, GumpButtonType.Reply, 0); AddHtmlLocalized(50, 412, 100, 20, 1114268, 0x7FFF, false, false); // Back AddButton(390, 410, 0xFA5, 0xFA6, 302, GumpButtonType.Reply, 0); AddHtmlLocalized(425, 412, 100, 20, 1114267, 0x7FFF, false, false); // Imbue Item }
/// <summary> /// Do the imbuing stuff. /// </summary> public static void Do(Mobile from, Item item, BaseAttrInfo propToImbue, BaseAttrInfo propToReplace, int value, int wTotalIntensity, int r1, int r2, int r3, double successChance) { IImbuable imbuable = item as IImbuable; int curValue = propToImbue.GetValue(item); if (curValue == value) { from.SendLocalizedMessage(1113473); // The item already has that property imbued at that intensity. } else if (wTotalIntensity > imbuable.MaxIntensity) { from.SendLocalizedMessage(1113364); // You can not imbue this property on this item at the selected intensity because it will make the item unstable. } else if (!Check(from, item)) { } else if (!Resources.ConsumeResources(from, propToImbue, r1, r2, r3)) { from.SendLocalizedMessage(1079773); // You do not have enough resources to imbue this item. } else { bool success; if (imbuable.TimesImbued >= 20) { from.SendLocalizedMessage(1113377); // Your chance to learn while imbuing this item is diminished, as it has been imbued many times before. success = successChance > Utility.RandomDouble(); } else { success = from.CheckSkill(SkillName.Imbuing, successChance); } Effects.SendPacket(from, from.Map, new GraphicalEffect(EffectType.FixedFrom, from.Serial, Server.Serial.Zero, 0x375A, from.Location, from.Location, 1, 17, true, false)); Effects.SendTargetParticles(from, 0, 1, 0, 0x1593, EffectLayer.Waist); if (success) { if (propToReplace != null) { propToReplace.SetValue(item, 0); } propToImbue.SetValue(item, value); if (item is IArmor) { ((IArmor)item).ArmorAttributes.SelfRepair = 0; } else if (item is ICloth) { ((ICloth)item).ClothingAttributes.SelfRepair = 0; } else if (item is IWeapon) { ((IWeapon)item).WeaponAttributes.SelfRepair = 0; } imbuable.OnImbued(); imbuable.TimesImbued++; from.SendLocalizedMessage(1079775); // You successfully imbue the item! from.PlaySound(0x1EB); } else { from.SendLocalizedMessage(1079774); // You attempt to imbue the item, but fail. from.PlaySound(0x1E4); } Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerCallback( delegate { from.SendGump(new ImbuingMainGump()); } )); return; } from.EndAction(typeof(Imbuing)); }
/// <summary> /// Do the imbuing stuff. /// </summary> public static void Do( Mobile from, Item item, BaseAttrInfo propToImbue, BaseAttrInfo propToReplace, int value, int wTotalIntensity, int r1, int r2, int r3, double successChance ) { IImbuable imbuable = item as IImbuable; int curValue = propToImbue.GetValue( item ); if ( curValue == value ) from.SendLocalizedMessage( 1113473 ); // The item already has that property imbued at that intensity. else if ( wTotalIntensity > imbuable.MaxIntensity ) from.SendLocalizedMessage( 1113364 ); // You can not imbue this property on this item at the selected intensity because it will make the item unstable. else if ( !Check( from, item ) ) { } else if ( !Resources.ConsumeResources( from, propToImbue, r1, r2, r3 ) ) from.SendLocalizedMessage( 1079773 ); // You do not have enough resources to imbue this item. else { bool success; if ( imbuable.TimesImbued >= 20 ) { from.SendLocalizedMessage( 1113377 ); // Your chance to learn while imbuing this item is diminished, as it has been imbued many times before. success = successChance > Utility.RandomDouble(); } else { success = from.CheckSkill( SkillName.Imbuing, successChance ); } Effects.SendPacket( from, from.Map, new GraphicalEffect( EffectType.FixedFrom, from.Serial, Server.Serial.Zero, 0x375A, from.Location, from.Location, 1, 17, true, false ) ); Effects.SendTargetParticles( from, 0, 1, 0, 0x1593, EffectLayer.Waist ); if ( success ) { if ( propToReplace != null ) propToReplace.SetValue( item, 0 ); propToImbue.SetValue( item, value ); if ( item is IArmor ) ( (IArmor) item ).ArmorAttributes.SelfRepair = 0; else if ( item is ICloth ) ( (ICloth) item ).ClothingAttributes.SelfRepair = 0; else if ( item is IWeapon ) ( (IWeapon) item ).WeaponAttributes.SelfRepair = 0; imbuable.OnImbued(); imbuable.TimesImbued++; from.SendLocalizedMessage( 1079775 ); // You successfully imbue the item! from.PlaySound( 0x1EB ); } else { from.SendLocalizedMessage( 1079774 ); // You attempt to imbue the item, but fail. from.PlaySound( 0x1E4 ); } Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( delegate { from.SendGump( new ImbuingMainGump() ); } ) ); return; } from.EndAction( typeof( Imbuing ) ); }
/// <summary> /// Returns the intensity of the given prop on the given item. /// </summary> /// <param name="checkHold">true if we want to ensure CanHold( item ) is checked, false if we have checked it before.</param> public static int ComputeIntensity( Item item, BaseAttrInfo prop, bool checkHold ) { if ( checkHold && !prop.CanHold( item ) ) return 0; int propVal = prop.GetValue( item ); int total = GetIntensitySteps( prop ); int relative = Math.Max( 0, 1 + (int) ( ( propVal - prop.MinIntensity ) / prop.IntensityInterval ) ); int intensity = (int) ( 100 * ( (double) relative / total ) ); return intensity; }