Hello, I am trying to create a Hit weapon property (like to HitLightning, or HitCurse), that provides a buff effect. I've created a couple custom Hit properties thus far, but I'm struggling with a buffing one.

(For Example in addition to "Hit Lightning 50%" on a weapon, it could also have "Hit Buff 50%" as well.)

Ideally I would like this "Hit" buff to provide the wielder (attacker) with 10% flat damage reduction for 10 seconds. I've looked at some similar damage reduction code like Perseverance, Block, and others but I'm unable to get it to work as an OnHitEffect.

Here is what I have so far:

public virtual void DoBuffhit(Mobile attacker, Mobile defender, int damage) // GOAL = 10% Damage Reduction Buff "OnHit" Effect for 10seconds duration
{
if (!attacker.CanBeHarmful(defender, false))
{
return;
}

attacker.FixedParticles(0x1153, 75, 35, 5044, EffectLayer.Waist);
attacker.PlaySound(0x0FB);

AbsorbDamage(attacker, defender, damage);
{
damage -= AOS.Scale(damage, 50); //I can't get the damage reduction to work
}

TimeSpan duration = TimeSpan.FromSeconds(10.0); // I can't get the timer to work
BuffInfo.AddBuff(attacker, new BuffInfo(BuffIcon.Resilience, 1075647, 1075648, TimeSpan.FromSeconds(10), attacker));

if (ProcessingMultipleHits)
BlockHitEffects = true;
}




Any ideas or suggestions by chance?
 
XmlAttachment can be attached to your weapon using the OnWeaponHit method?
C#:
public override void OnWeaponHit(Mobile attacker, Mobile defender, BaseWeapon weapon, int damageGiven)
The XmlLifeDrain does it pretty well and simulates the Life Leech property. The same way, you can script your own property giving it your own % to activate.
C#:
if (attachment !=null && (0.5 >= Utility.RandomDouble()) ) /50%
{
    //do your stuff
}
 
Hmm. I can't figure out how to put that in to create a "10% damage reduction buff for 10 seconds", can you help show where? Also I'm struggling linking the to link the timer to make the buff time out after 10 seconds as well.

C#:
        public virtual void DoBUFF(Mobile attacker, Mobile defender, int damage)  // GOAL = 10% Damage Reduction Buff "OnHit" Effect for 10seconds duration
        {
            if (!attacker.CanBeHarmful(defender, false))
            {
                return;
            }

            attacker.FixedParticles(0x1153, 75, 35, 5044, EffectLayer.Waist);
            attacker.PlaySound(0x0FB);

            AbsorbDamage(attacker, defender, damage);
            {
                damage -= AOS.Scale(damage, 50);   //I can't get the damage reduction to work
            }

            TimeSpan duration = TimeSpan.FromSeconds(10.0);   // I can't get the timer to work

            BuffInfo.AddBuff(attacker, new BuffInfo(BuffIcon.Resilience, 1075647, 1075648, TimeSpan.FromSeconds(10), attacker));

            if (ProcessingMultipleHits)
                BlockHitEffects = true;
        }
 
You need XmlSpawner for it to work. You should not need to do your "public virtual void DoBUFF" but using "OnWeaponHit" instead, as shown in XmlLifeDrain, XmlLightning, XmlManaDrain, XmlStamDrain, etc. (all contained in XmlAttachments folder)

Im not sure about the absorb damage part, which needs to be tested on my side to know what should be written to make it work properly...
but an attachment could look like this : (it needs to be polished but you'll get something to dig in)

also...

(0.5 >= Utility.RandomDouble()) ---> This would be 50%.
(0.1 >= Utility.RandomDouble()) ---> This would be 10%

Attachment Absorb Test:
using System;
using System.IO;
using System.Xml;
using Server;
using Server.Items;
using Server.Network;
using Server.Mobiles;
using System.Collections;
using System.Collections.Generic;
using Server.Targeting;
using Server.Gumps;
using System.Text;
using Server.Regions;
using Server.Spells;
using Server.Commands;
using Server.Commands.Generic;
using Server.Multis;
using Server.Misc;
using Server.Engines.XmlSpawner2;

namespace Server.Engines.XmlSpawner2
{
    public class XmlAbsorbDamage : XmlAttachment
    {
        private int m_Absorb = 0;
        private DateTime m_EndTime;

        [CommandProperty( AccessLevel.GameMaster )]
        public int Absorb { get{ return m_Absorb; } set { m_Absorb = value; } }

        // These are the various ways in which the message attachment can be constructed.
        // These can be called via the [addatt interface, via scripts, via the spawner ATTACH keyword.
        // Other overloads could be defined to handle other types of arguments

        // a serial constructor is REQUIRED
        public XmlAbsorbDamage(ASerial serial) :  base(serial)
        {
        }
        
        [Attachable]
        public XmlAbsorbDamage(int absorb)
        {
            m_Absorb = absorb;
        }

        [Attachable]
        public XmlAbsorbDamage(int absorb, double expiresin)
        {
            m_Absorb = absorb;
            Expiration = TimeSpan.FromMinutes(expiresin);
        }
        
        public override void OnWeaponHit(Mobile attacker, Mobile defender, BaseWeapon weapon, int damageGiven)
        {
            XmlBuff buff = XmlAttach.FindAttachment(attacker, typeof(XmlBuff)) as XmlBuff;

            if ( buff != null defender != null && attacker != null && (0.1 >= Utility.RandomDouble()) )//If attachment/attacker/defender is not null and 10% to activate
            {
                attacker.FixedParticles(0x1153, 75, 35, 5044, EffectLayer.Waist);
                attacker.PlaySound(0x0FB);
        
                //Absorb code
            }
        }
    
        public override void Serialize( GenericWriter writer )
        {
                base.Serialize(writer);
                writer.Write( (int) 1 );
                writer.Write(m_Absorb);
                writer.Write(m_EndTime - DateTime.Now);
        }

        public override void Deserialize(GenericReader reader)
        {
                base.Deserialize(reader);
                int version = reader.ReadInt();
                m_Absorb = reader.ReadInt();
                m_EndTime = DateTime.Now + remaining;   
        }
            
        public override void OnAttach()
        {
            XmlBuff buff = XmlAttach.FindAttachment(attacker, typeof(XmlBuff)) as XmlBuff;
            base.OnAttach();
            
            if (this.AttachedTo is Item)
            {
                GetProperties(list); //Can this work?
            }
        }
    
        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);   
            list.Add("<basefont color=#ffff00><center><b>Absorb Damage 10%</b>"); // Not sure?
        }
        
    }
}
 
Back