Discussion in   Coding Corner   started     10 years ago   September 09, 2013, 10:01:43 PM   by   Keldon

Hidden weapon procs

Keldon
Offline
223 Posts
Topic :   Hidden weapon procs
10 years ago  September 09, 2013, 10:01:43 PM

So this week I played around with the OnHit function for weapons.  With Tokuno's Karate belt additions we have seen a lot of mobs gaining the ability to drain our hit points, stamina points, or mana points as well as stunning us.  I decided I would play around with a weapon that is a really gimp weapon.  It's damage range is 1-2 and it has a 5 second swing delay but its hidden procs are the real gems:


I am only going to explain the on hit portion since all the other stuff is covered very well elsewhere:


I started off with adding a 1% chance for the weapon to set the defenders hit points to 0

Code: [Select]

        public override void OnHit(Mobile attacker, Mobile defender, double damageBonus)//adding hidden weapon procs to an otherwise gimp weapon
        {
            base.OnHit(attacker, defender, damageBonus);


            if (0.01 > Utility.RandomDouble())//1% of the time this weapon will set a defenders hit points to 0 almost killing it
            {
                defender.Hits -= defender.HitsMax;
                attacker.Say("*almost kills their opponent in one swing*");
            }
        }


While this is interesting I wanted to add something extra.  I added an else to this if incase the 1% chance doesnt go off.  I decided that I would add an additional 10% chance for something else to happen.
Code: [Select]

            if (0.01 > Utility.RandomDouble())//1% of the time this weapon will set a defenders hit points to 0 almost killing it
            {
                defender.Hits -= defender.HitsMax;
                attacker.Say("*almost kills their opponent in one swing*");
            }
            else
            {
                if (0.1 > Utility.RandomDouble())
            }


Now I am set up for an OnHit 1% chance to just about kill my opponent and failing that I have a 10% chance for something else to happen.


I decided that I would give a chance for one of 4 things to happen using a switch.  I wanted to steal hit points, mana, or stamina from my target but I also wanted a chance to stun.  I took the code form the golem's stun and modified it a little bit to work as a weapon proc.


Here is the code from my switch.  Each of the steals takes 33% off of the target and gives half of that value back to the attacker.
Code: [Select]

                if (0.1 > Utility.RandomDouble())//if the 1% chance does not fire there is a 10% chance of one of the following to happen
                {
                    switch (Utility.Random(4))
                    {
                        default:
                        case 0://this case decreases the defenders hit points by 33% and gives half of that amount to the attacker.
                            {
                                int hitpointstosteal = (int)(defender.HitsMax * 0.33);
                                defender.Hits -= hitpointstosteal;
                                attacker.Hits += (int)(hitpointstosteal * 0.5);
                                attacker.Say("*steals life from their victum*");
                            };
                            break;
                        case 1://this case decreases the defenders mana points by 33% and gives half of that amount to the attacker.
                            {
                                int manapointstosteal = (int)(defender.ManaMax * 0.33);
                                defender.Mana -= manapointstosteal;
                                attacker.Mana += (int)(manapointstosteal * 0.5);
                                attacker.Say("*steals mana from their victum*");
                            };
                            break;
                        case 2://this case decreases the defenders stamina points by 33% and gives half of that amount to the attacker.
                            {
                                int stampointstosteal = (int)(defender.StamMax * 0.33);
                                defender.Stam -= stampointstosteal;
                                attacker.Stam += (int)(stampointstosteal * 0.5);
                                attacker.Say("*steals stamina from their victum*");
                            };
                            break;
                        case 3://this adds the golem stun
                            {
                                m_Stunning = true;
                                defender.Animate(21, 6, 1, true, false, 0);
                                attacker.Say("*has stunned their victum with a mighty blow*");
                                if (defender.Alive)
                                {
                                    defender.Frozen = true;
                                    Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(Recover_Callback), defender);
                                }
                            }
                            break;
                    }


This is over powered at these values but I wanted to go large and exaggerate the results for my play testing.


Here is the completed code for the weapon and I have attacked the .cs file in case anyone wishes to view it that way.
Code: [Select]

using System;
using Server.Network;
using Server.Items;
using Server.Targeting;


namespace Server.Items
{
    public class HeavyHandedAxe : DoubleAxe
    {
        public override int OldMinDamage { get { return 1; } }
        public override int AosMinDamage { get { return 1; } }
        public override int OldMaxDamage { get { return 2; } }
        public override int AosMaxDamage { get { return 2; } }
        public override int AosSpeed { get { return 5; } }
        public override int OldSpeed { get { return 6; } }
        public override float MlSpeed { get { return 5.0f; } }


        public override int InitMinHits { get { return 255; } }
        public override int InitMaxHits { get { return 255; } }


        [Constructable]
        public HeavyHandedAxe()
        {
            Weight = 25;
            Name = "Heavy Handed Axe";
        }
        bool m_Stunning;


        public override void OnHit(Mobile attacker, Mobile defender, double damageBonus)//adding hidden weapon procs to an otherwise gimp weapon
        {
            base.OnHit(attacker, defender, damageBonus);


            if (0.01 > Utility.RandomDouble())//1% of the time this weapon will set a defenders hit points to 0 almost killing it
            {
                defender.Hits -= defender.HitsMax;
                attacker.Say("*almost kills their opponent in one swing*");
            }
            else
            {
                if (0.1 > Utility.RandomDouble())//if the 1% chance does not fire there is a 10% chance of one of the following to happen
                {
                    switch (Utility.Random(4))
                    {
                        default:
                        case 0://this case decreases the defenders hit points by 33% and gives half of that amount to the attacker.
                            {
                                int hitpointstosteal = (int)(defender.HitsMax * 0.33);
                                defender.Hits -= hitpointstosteal;
                                attacker.Hits += (int)(hitpointstosteal * 0.5);
                                attacker.Say("*steals life from their victum*");
                            };
                            break;
                        case 1://this case decreases the defenders mana points by 33% and gives half of that amount to the attacker.
                            {
                                int manapointstosteal = (int)(defender.ManaMax * 0.33);
                                defender.Mana -= manapointstosteal;
                                attacker.Mana += (int)(manapointstosteal * 0.5);
                                attacker.Say("*steals mana from their victum*");
                            };
                            break;
                        case 2://this case decreases the defenders stamina points by 33% and gives half of that amount to the attacker.
                            {
                                int stampointstosteal = (int)(defender.StamMax * 0.33);
                                defender.Stam -= stampointstosteal;
                                attacker.Stam += (int)(stampointstosteal * 0.5);
                                attacker.Say("*steals stamina from their victum*");
                            };
                            break;
                        case 3://this adds the golem stun
                            {
                                m_Stunning = true;
                                defender.Animate(21, 6, 1, true, false, 0);
                                attacker.Say("*has stunned their victum with a mighty blow*");
                                if (defender.Alive)
                                {
                                    defender.Frozen = true;
                                    Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerStateCallback(Recover_Callback), defender);
                                }
                            }
                            break;
                    }
                }
            }
        }


        private void Recover_Callback(object state)//this is the timer for the golem stun that was added to the on hit
        {
            Mobile defender = state as Mobile;


            if (defender != null)
            {
                defender.Frozen = false;
                defender.Combatant = null;
                defender.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You recover your senses.");
            }


            m_Stunning = false;
        }


        public HeavyHandedAxe( Serial serial ) : base( serial )
{
}


public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );


writer.Write( (int) 0 ); // version
}


public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );


int version = reader.ReadInt();
}
    }
}

Kyn
Offline
336 Posts
#1 Re :   Hidden weapon procs
10 years ago  September 10, 2013, 06:17:57 AM

Interesting concept. Possibly usable depending on the context.

Keldon
Offline
223 Posts
#2 Re :   Hidden weapon procs
10 years ago  September 10, 2013, 06:33:58 AM

that's what I was thinking.  I have been making outlandish things for my personal test server so I have a code base to refer back to later.  As this sits right now it would destroy a lot of the content.  Numbers adjusted and spread across some weapons it could be interesting.


My personal favorite so far is the earring that adds extra hit properties to your weapon.  tested and works well.  That is another thing that might have use in the right context.