Kamras

Member
This is my OnDamage section from basecreature.cs .

Desired Results. Equipment reaches X Level. Once X Level is reached, the code does a check against the players current level. If players current level is lower then the equipment level , equipment will not gain anymore exp. If players level is higher then the equipment then the equipment will gain exp.

So far the below code works as intended with one flaw. Once a layer of equipment reaches it's max level (first sequence in order from top to bottom, two handed sword, one handed sword) all the layers below that code does not gain exp. So ultimately the check comes in, and once equipment reaching max level is detected everything else below is ignored.

I'm sure this is something simple and my return method is wrong... I just cant put my finger on it.


Code:
        public override void OnDamage(int amount, Mobile from, bool willKill)
        {
            if (BardPacified && (HitsMax - Hits) * 0.001 > Utility.RandomDouble())
            {
                Unpacify();
            }

            int disruptThreshold;
            //NPCs can use bandages too!
            if (!Core.AOS)
            {
                disruptThreshold = 0;
            }
            else if (from != null && from.Player)
            {
                disruptThreshold = 18;
            }
            else
            {
                disruptThreshold = 25;
            }

            if (amount > disruptThreshold)
            {
                BandageContext c = BandageContext.GetContext(this);

                if (c != null)
                {
                    c.Slip();
                }
            }

            if (Confidence.IsRegenerating(this))
            {
                Confidence.StopRegenerating(this);
            }

            WeightOverloading.FatigueOnDamage(this, amount);

            InhumanSpeech speechType = SpeechType;

            if (speechType != null && !willKill)
            {
                speechType.OnDamage(this, amount);
            }

            if (m_ReceivedHonorContext != null)
            {
                m_ReceivedHonorContext.OnTargetDamaged(from, amount);
            }
           
            //Level System
            if (willKill && En.Enabled)
            LevelHandler.Set(from, this);
            //End Level System

            if (!willKill)
            {
                if (CanBeDistracted && ControlOrder == OrderType.Follow)
                {
                    CheckDistracted(from);
                }
            }
            else if (from is PlayerMobile)
            {
                Timer.DelayCall(TimeSpan.FromSeconds(10), ((PlayerMobile)@from).RecoverAmmo);
            }

            #region XmlSpawner
            if (!Summoned && willKill && from != null)
            {
                PlayerMobile pm = (PlayerMobile)from;
                //////CUSTOMIZATION - Alfheim Online!//////
                //Find Item on Layer and Name it
                Item bwtwohanded = from.FindItemOnLayer(Layer.TwoHanded);//two handed or shield
                Item bwonehanded = from.FindItemOnLayer(Layer.FirstValid); //One handed Sword
                Item baHelm = from.FindItemOnLayer(Layer.Helm); //helm
                Item baGloves = from.FindItemOnLayer(Layer.Gloves);//Gloves
                Item baNeck = from.FindItemOnLayer(Layer.Neck);
                Item baInntertorso = from.FindItemOnLayer(Layer.InnerTorso);
                Item bamIddletorso = from.FindItemOnLayer(Layer.MiddleTorso);
                Item baOutertorso = from.FindItemOnLayer(Layer.OuterTorso);
                Item baBracelet = from.FindItemOnLayer(Layer.Bracelet);
                Item baArms = from.FindItemOnLayer(Layer.Arms);
                Item baPants = from.FindItemOnLayer(Layer.Pants);
               
                //Find XmlLevelItem on equipment and name it
                XmlLevelItem bwtwohandedlevel = (XmlLevelItem)XmlAttach.FindAttachment(bwtwohanded, typeof(XmlLevelItem));
                XmlLevelItem bwonehandedlevel = (XmlLevelItem)XmlAttach.FindAttachment(bwonehanded, typeof(XmlLevelItem));
                XmlLevelItem baHelmLevel = (XmlLevelItem)XmlAttach.FindAttachment(baHelm, typeof(XmlLevelItem));
                XmlLevelItem baGlovesLevel = (XmlLevelItem)XmlAttach.FindAttachment(baGloves, typeof(XmlLevelItem));
                XmlLevelItem baNeckLevel = (XmlLevelItem)XmlAttach.FindAttachment(baNeck, typeof(XmlLevelItem));
                XmlLevelItem baInntertorsoLevel = (XmlLevelItem)XmlAttach.FindAttachment(baInntertorso, typeof(XmlLevelItem));
                XmlLevelItem bamIddletorsoLevel = (XmlLevelItem)XmlAttach.FindAttachment(bamIddletorso, typeof(XmlLevelItem));
                XmlLevelItem baOutertorsoLevel = (XmlLevelItem)XmlAttach.FindAttachment(baOutertorso, typeof(XmlLevelItem));
                XmlLevelItem baBraceletLevel = (XmlLevelItem)XmlAttach.FindAttachment(baBracelet, typeof(XmlLevelItem));
                XmlLevelItem baArmsLevel = (XmlLevelItem)XmlAttach.FindAttachment(baArms, typeof(XmlLevelItem));
                XmlLevelItem baPantsLevel = (XmlLevelItem)XmlAttach.FindAttachment(baPants, typeof(XmlLevelItem));
               
                //Check for Weapon and XML Level Item to apply check for EXP
                if (bwtwohanded != null )
                {
                    if (bwtwohandedlevel != null && pm.Levell > bwtwohandedlevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }
                if (bwonehanded != null )
                {
                    if (bwonehandedlevel != null && pm.Levell > bwonehandedlevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }
                if (baHelm != null )
                {
                    if (baHelmLevel != null && pm.Levell > baHelmLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }
                if (baGloves != null )
                {
                    if (baGlovesLevel != null && pm.Levell > baGlovesLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }
                if (baNeck != null )
                {
                    if (baNeckLevel != null && pm.Levell > baNeckLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }
                if (baInntertorso != null )
                {
                    if (baInntertorsoLevel != null && pm.Levell > baInntertorsoLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }
                if (bamIddletorso != null )
                {
                    if (bamIddletorsoLevel != null && pm.Levell > bamIddletorsoLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }
                if (baOutertorso != null )
                {
                    if (baOutertorsoLevel != null && pm.Levell > baOutertorsoLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }
                if (baBracelet != null )
                {
                    if (baBraceletLevel != null && pm.Levell > baBraceletLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }       
                if (baArms != null )
                {
                    if (baArmsLevel != null && pm.Levell > baArmsLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }                   
                if (baPants != null )
                {
                    if (baPantsLevel != null && pm.Levell > baPantsLevel.Level )
                    {
                        LevelItemManager.CheckItems(from, this);
                    }
                    else
                        return;
                }       

           
//                LevelItemManager.CheckItems(from, this);
               
            }
            #endregion

            base.OnDamage(amount, from, willKill);
        }
 
I see you're writing a lot of repeating code, but you could just loop through from.Items, because that list contains everything they have equipped. You can just ignore items like mount, bank and backpack.

Code:
foreach( var item in pm.Items )
{
    if( item.Layer == Layer.Bank || item.Layer == Layer.Backpack || item.Layer == Layer.Mount )
        continue;

    var xml = (XmlLevelItem)XmlAttach.FindAttachment( item, typeof(XmlLevelItem) );

    if( xml != null && pm.Levell > xml.Level )
        LevelItemManager.CheckItems( pm, this ); // this bothers me, it doesnt use item or xml references for anything?
}

The CheckItems call bothers me, because it doesn't matter what item is levelable, all of them will call the same method with the same arguments. Is 'this' as the argument not meant to be 'item'? Since 'this' is the current BaseCreature, I have to assume that a break; would be necessary after the first call to CheckItems.

Sorry, on a mobile device, can't check at this time.
 
I did consider putting this in baseweapon instead and using something like onhit, using basecreature was just something i tossed together real quick and it seemed to work out well except for that one glitch. checkitem was originated from the code required to apply the exp table and apply it to the xml item, i believed this was the original code from XML level items.
[doublepost=1496089311][/doublepost]So that code does work like the code I already have without the repetition, cleaner is better. However now the problem is, it's not checking for the max level and its always applying the exp table.

Code:
 if( xml != null && pm.Levell > xml.Level )

that isn't being used it seems.

Xml is identified as not being null and the pm.Level is higher then the xml.Level, however despite that it's still applying the
Code:
LevelItemManager.CheckItems( pm, this );


this makes no sense. To me it looks like it should work;..
[doublepost=1496097400][/doublepost]UPDATE ON THIS:....

SO 1.. THIS IS JUST STUPID, I'm sure there is a logical reason for it, however I will just agree it works and leave it at that. If someone wants to explain I would love it!

So I decided to attack this from a different approach, instead of trying to adjust what happens during the kill in basecreature, I removed that whole entry and just left the code

Code:
LevelItemManager.CheckItems(from, this);

Which works as intended by invoking the checkitems request.

So looking at what @Voxpire said about the ' this ' not making sense I decided to check into the xml Level item manager script, following the trail lead me to this code snippet in LevelItemManager.cs

Code:
        public static void CheckLevelable(XmlLevelItem item, Mobile killer, Mobile killed)
        {
            PlayerMobile pm = (PlayerMobile)killer;
          
            if ( (item.Level >= LevelItems.MaxLevelsCap) || (item.Level >= item.MaxLevel ) )
                return;

            int exp = CalcExp( killed );
            int oldLevel = item.Level;
            int expcap = CalcExpCap( oldLevel );

            if ( LevelItems.EnableExpCap && exp > expcap )
                exp = expcap;

            item.Experience += exp;

            InvalidateLevel( item );

            if ( item.Level != oldLevel )
                OnLevel( item, oldLevel, item.Level, killer );

            //if ( item is Item )
            //    ((Item)item).InvalidateProperties();
            if (item != null)
                item.InvalidateParentProperties();
        }

I added the same exception I've been pressing
Code:
(pm.Levell >= item.Level)

to get this
Code:
if ( (item.Level >= LevelItems.MaxLevelsCap) || (item.Level >= item.MaxLevel) || (pm.Levell >= item.Level) )

Issue persisted. So for some reason I got the urge to switch the statements (following the existing pattern) and got this

Code:
if ( (item.Level >= LevelItems.MaxLevelsCap) || (item.Level >= item.MaxLevel) || (item.Level >= pm.Levell) )

Went into game and THIS worked...
Level cap on item reached based on current level of PlayerMobile, and also still provided exp to other items with no issues.

So, problem resolved, NOT sure why the order mattered, I even wonder if switching the order in basecreature would have worked, but, its working.

So lessen learned... Try not to recreate the wheel, look for signs of it already existing....
 
Last edited:

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back