RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Xml Level Items

rtaylor1987

Sorceror
Not a bad system - would love to see some way to limit hit spells to 1.
So if the weapon has HitLightning/HitFireball/HitMagicArrow/HitHarm > 0, hide the rest of them so you can't get double hit spells.

Other than that, the system seems fairly balanced.
 

Goten34543

Sorceror
For some reason after adding in the line you specified I got these errors.

Code:
RunUO - [www.runuo.com] Version 2.0, Build 3567.2838
Core: Running on .NET Framework Version 2.0.50727
Core: Optimizing for 2 processors
Scripts: Compiling C# scripts...failed (4 errors, 0 warnings)
Errors:
+ Items/Armor/BaseArmor.cs:
    CS0246: Line 279: The type or namespace name 'ContextMenuEntry' could not be
found (are you missing a using directive or an assembly reference?)
+ Items/Clothing/BaseClothing.cs:
    CS0246: Line 60: The type or namespace name 'ContextMenuEntry' could not be
found (are you missing a using directive or an assembly reference?)
+ Items/Jewels/BaseJewel.cs:
    CS0246: Line 32: The type or namespace name 'ContextMenuEntry' could not be
found (are you missing a using directive or an assembly reference?)
    CS0246: Line 32: The type or namespace name 'List' could not be found (are y
ou missing a using directive or an assembly reference?)
+ Items/Weapons/BaseWeapon.cs:
    CS0246: Line 227: The type or namespace name 'ContextMenuEntry' could not be
found (are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
 

Goten34543

Sorceror
Never mind I found that at the top of the previously listed scripts.

Code:
using Server.ContextMenus;
using Server.Engines.XmlSpawner2;
 

Goten34543

Sorceror
I have the scripts up and running now, I really like the script. There are 2 things I would love to do if I could ask anyone for some guidance.

1.) Items not gaining exp? Not sure why, but the items aren't gaining any exp, I am positive it talks about it in LevelItemManager.cs (I posted below just incase anyone can see any issues.)
2.) I actually want to make every weapon, armor, and jewelry in the game levelable but can't concieve making all the players use the scrolls. Can anyone give me any guidance please?

Code:
using System;
using Server;
using Server.Mobiles;
using Server.Engines.XmlSpawner2;

namespace Server.Items
{
    public class LevelItemManager
    {
        /// <summary>
        /// The Number of levels our items can go to. If you
        /// change this, be sure the Exp table has the correct
        /// number of Integer values in it.
        /// </summary>

        #region Level calculation method

        private static int[] m_Table;

        public static int[] ExpTable
        {
            get{ return m_Table; }
        }

        public static void Initialize()
        {
            // The following will build the Level experence table */
            m_Table = new int[LevelItems.MaxLevelsCap];
            m_Table[0] = 0;

            for ( int i = 1; i < LevelItems.MaxLevelsCap; ++i )
            {
                m_Table[i] = ExpToLevel( i );
            }
        }

        public static int ExpToLevel( int currentlevel )
        {
            double req = ( currentlevel + 1 ) * 10;

            req = Math.Pow( req, 2 );

            req -= 100.0;

            return ( (int)Math.Round( req ) );
        }

        #endregion

        #region Exp calculation methods

        private static bool IsMageryCreature( BaseCreature bc )
        {
            return ( bc != null && bc.AI == AIType.AI_Mage && bc.Skills[SkillName.Magery].Base > 5.0 );
        }

        private static bool IsFireBreathingCreature( BaseCreature bc )
        {
            if ( bc == null )
                return false;

            return bc.HasBreath;
        }

        private static bool IsPoisonImmune( BaseCreature bc )
        {
            return ( bc != null && bc.PoisonImmune != null );
        }

        private static int GetPoisonLevel( BaseCreature bc )
        {
            if ( bc == null )
                return 0;

            Poison p = bc.HitPoison;

            if ( p == null )
                return 0;

            return p.Level + 1;
        }

        public static int CalcExp( Mobile targ )
        {
            double val = targ.Hits + targ.Stam + targ.Mana;

            for ( int i = 0; i < targ.Skills.Length; i++ )
                val += targ.Skills[i].Base;

            if ( val > 700 )
                val = 700 + ((val - 700) / 3.66667);

            BaseCreature bc = targ as BaseCreature;

            if ( IsMageryCreature( bc ) )
                val += 100;

            if ( IsFireBreathingCreature( bc ) )
                val += 100;

            if ( IsPoisonImmune( bc ) )
                val += 100;

            if ( targ is VampireBat || targ is VampireBatFamiliar )
                val += 100;

            val += GetPoisonLevel( bc ) * 20;

            val /= 10;

            return (int)val;
        }

        public static int CalcExpCap( int level )
        {
            int req = ExpToLevel( level + 1 );

            return ( req / 20 );
        }

        #endregion

        public static void CheckItems( Mobile killer, Mobile killed )
        {
            if ( killer != null )
            {
                for( int i = 0; i < 25; ++i )
                {
                    Item item = killer.FindItemOnLayer( (Layer)i );

                    XmlLevelItem levitem = XmlAttach.FindAttachment(item, typeof(XmlLevelItem)) as XmlLevelItem;

                    //if ( item != null && item is ILevelable )
                    if (item != null && levitem != null)
                        CheckLevelable(levitem, killer, killed);
                }
            }
        }

        //public static void InvalidateLevel( ILevelable item )
        public static void InvalidateLevel(XmlLevelItem item)
        {
            for( int i = 0; i < ExpTable.Length; ++i )
            {
                if ( item.Experience < ExpTable[i] )
                    return;

                item.Level = i + 1;
            }
        }

        //public static void CheckLevelable( ILevelable item, Mobile killer, Mobile killed )
        public static void CheckLevelable(XmlLevelItem item, Mobile killer, Mobile killed)
        {
            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();
        }

        //public static void OnLevel(ILevelable item, int oldLevel, int newLevel, Mobile from)
        public static void OnLevel(XmlLevelItem item, int oldLevel, int newLevel, Mobile from)
        {
            /* This is where we control all our props
            * and their maximum value. */
            int index;
            string itemdesc;

            index = newLevel % 10;
            if (index == 0)
            {
                item.Points += LevelItems.PointsPerLevel*2;
            }
            else
            {
                item.Points += LevelItems.PointsPerLevel;
            }

            from.PlaySound( 0x20F );
            from.FixedParticles( 0x376A, 1, 31, 9961, 1160, 0, EffectLayer.Waist );
            from.FixedParticles( 0x37C4, 1, 31, 9502, 43, 2, EffectLayer.Waist );

            if ( item.AttachedTo is BaseWeapon )
                itemdesc = "weapon";
            else if ( item.AttachedTo is BaseArmor )
                itemdesc = "armor";
            else if (item.AttachedTo is BaseJewel )
                itemdesc = "jewelry";
            else if (item.AttachedTo is BaseClothing )
                itemdesc = "clothing";
            else
                itemdesc = "item";

            from.SendMessage( "Your "+itemdesc+" has gained a level. It is now level {0}.", newLevel );
        }
    }
}

All help is much appreciated! Thank you!
 

Iraq-

Sorceror
You need to also make the edit in BaseCreature.cs in the OnDeath method to register the kill, read the 1st post again for that.
 

zack0428

Page
Not a bad system - would love to see some way to limit hit spells to 1.
So if the weapon has HitLightning/HitFireball/HitMagicArrow/HitHarm > 0, hide the rest of them so you can't get double hit spells.

Other than that, the system seems fairly balanced.

So would I.
I have been going through these scripts like a madman, and have yet to figure it out ..

Any help would be greatly appreciated.

Thanks
 

alchimysty

Wanderer
Thanks LordHogFred and Iraq for all your insight on this, i'm looking forward to getting it going. :)
I am currently running into the following issue when compiling.

Code:
RunUO - [www.runuo.com] Version 2.2, Build 4425.25303
Core: Running on .NET Framework Version 2.0.50727
Core: Optimizing for 8 64-bit processors
Scripts: Compiling C# scripts...failed (1 errors, 44 warnings)
 
Errors:
+ Customs/Testing/XmlLevelItems/XmlLevelItem.cs:
    CS0103: Line 26: The name 'ChangeName' does not exist in the current context
 
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

I read Iraqs post where they explained a bunch of fixes for things, but i'm not sure how much I should comment out.
Here's my XMLLevelItem.cs.

Code:
using System;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Network;
using Server.Mobiles;
using Server.Misc;
using Server.ContextMenus;
using Server.ContextMenus;
using Server.Engines.Craft;
using Server.Engines.XmlSpawner2;
 
namespace Server.Engines.XmlSpawner2
{
public class XmlLevelItem : XmlAttachment
{
private int m_Experience = 0;
private int m_Level = 0;
private int m_Points = 0;
private int m_MaxLevel = 0;
 
[CommandProperty(AccessLevel.GameMaster)]
public int Experience { get { return m_Experience; } set { m_Experience = value; } }
 
//[CommandProperty(AccessLevel.GameMaster)]
//public int Level { get { return m_Level; } set { m_Level = value; ChangeName((Item)AttachedTo); InvalidateParentProperties(); } }
 
[CommandProperty(AccessLevel.GameMaster)]
public int Points { get { return m_Points; } set { m_Points = value; } }
 
[CommandProperty(AccessLevel.GameMaster)]
public int MaxLevel { get { return m_MaxLevel; } set { m_MaxLevel = value; if (m_MaxLevel > LevelItems.MaxLevelsCap) m_MaxLevel = LevelItems.MaxLevelsCap; } }
 
public XmlLevelItem(ASerial serial)
: base(serial)
{
}
 
[Attachable]
public XmlLevelItem()
: this(200)
{
}
 
[Attachable]
public XmlLevelItem(int maxLevel)
{
Name = "LevelItem";
MaxLevel = maxLevel;
 
Experience = 0;
Level = 1;
Points = 0;
}
 
public override void OnAttach()
{
base.OnAttach();
 
if (AttachedTo is BaseWeapon || AttachedTo is BaseArmor || AttachedTo is BaseJewel)
{
InvalidateParentProperties();
}
else
{
Delete();
}
}
 
public override void OnDelete()
{
base.OnDelete();
 
InvalidateParentProperties();
}
 
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
 
writer.Write((int)0);
 
writer.Write((int)m_Experience);
writer.Write((int)m_Level);
writer.Write((int)m_MaxLevel);
writer.Write((int)m_Points);
}
 
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
 
int version = reader.ReadInt();
 
m_Experience = reader.ReadInt();
m_Level = reader.ReadInt();
m_MaxLevel = reader.ReadInt();
m_Points = reader.ReadInt();
}
}
}



Any help would be greatly appreciated. :D

-Alch
 

Iraq-

Sorceror
Code:
//[CommandProperty(AccessLevel.GameMaster)]
//public int Level { get { return m_Level; } set { m_Level = value; ChangeName((Item)AttachedTo); InvalidateParentProperties(); } }
to
Code:
[CommandProperty(AccessLevel.GameMaster)]
public int Level { get { return m_Level; } set { m_Level = value; /*ChangeName((Item)AttachedTo);*/ InvalidateParentProperties(); } }
or simply
Code:
[CommandProperty(AccessLevel.GameMaster)]
public int Level { get { return m_Level; } set { m_Level = value; InvalidateParentProperties(); } }
 

alchimysty

Wanderer
Awesome thanks so much Iraq, i got the simple change in and it's working nicely. :D

Question though...is there a way to administratively see/change the experience/points on an item?
IE if i use [addatt xmllevelitem or a deed on an item it makes it levelable, it gains exp and whatnot, however if i do a [props on it
I don't see any way to change the exp/points for testing. I know in the original release it comes up just fine. Any ideas?

-Alch
 

Attachments

  • XML Props.jpg
    XML Props.jpg
    115.7 KB · Views: 33
  • Levelable Items 3 Props.jpg
    Levelable Items 3 Props.jpg
    119.9 KB · Views: 36

Iraq-

Sorceror
Because it's XmlAttachment based system, the properties are not stored in [Props. They are stored within the XmlAttachment. Type [GetAtt or [GetAtt XmlLevelItem and target the item.
 
Top