Ravenal
Knight
New Flipable Changes, IFlipable and FlipItem Static Method
FlipableAttribute
FlipItem.Flip() for Single Items
CLICK HERE IF YOU INSTALLED
Thanks, Rav
Works in both RunUO 1.0 Final and RunUO 2.0 RC1 and will most likely work in RunUO 2.0 RC2
You can now download the ".CS" file if you wish
Ever wondered and ever wanted to add an before and after "Methods" to your Items, basically to maybe have a neat little quest where if a player double clicks a pot or something and you want it to have it magically appear something on a flip event? where it changes by following the FlipableAttribute
Here is the script and what is edited is in green and added is blue.
To Fire the Flip method for Items...
FlipCommandHandlers.FlipItem.DoFlip( this, m );
this = the item inside the Item Script...
m -or- from = Mobile who is flipping it...
Example at Bottom...
FlipableAttribute.cs
ExampleWeapon
FlipableAttribute
FlipItem.Flip() for Single Items
CLICK HERE IF YOU INSTALLED
Thanks, Rav
Works in both RunUO 1.0 Final and RunUO 2.0 RC1 and will most likely work in RunUO 2.0 RC2
You can now download the ".CS" file if you wish
Ever wondered and ever wanted to add an before and after "Methods" to your Items, basically to maybe have a neat little quest where if a player double clicks a pot or something and you want it to have it magically appear something on a flip event? where it changes by following the FlipableAttribute
Here is the script and what is edited is in green and added is blue.
To Fire the Flip method for Items...
FlipCommandHandlers.FlipItem.DoFlip( this, m );
this = the item inside the Item Script...
m -or- from = Mobile who is flipping it...
Example at Bottom...
FlipableAttribute.cs
Code:
using System;
using Server;
using System.Reflection;
using Server.Targeting;
using Server.Commands;
namespace Server.Items
{
[COLOR=Blue]public interface IFlipable
{
bool OnBeforeFlip(Mobile m, Item item);
void OnAfterFlip(Mobile m, Item item);
} [/COLOR]
public class FlipCommandHandlers
{
public static void Initialize()
{
CommandSystem.Register( "Flip", AccessLevel.GameMaster, new CommandEventHandler( Flip_OnCommand ) );
}
[Usage( "Flip" )]
[Description( "Turns an item." )]
public static void Flip_OnCommand( CommandEventArgs e )
{
e.Mobile.Target = new FlipTarget();
}
[COLOR=Blue]public class FlipItem
{
public static void DoFlip(Item item, Mobile m)
{
if (item.Movable == false )
return;
Type type = item.GetType();
FlipableAttribute[] AttributeArray = (FlipableAttribute[])type.GetCustomAttributes(typeof(FlipableAttribute), false);
if (AttributeArray.Length == 0)
return;
FlipableAttribute fa = AttributeArray[0];
if (item is IFlipable)
if (!((IFlipable)item).OnBeforeFlip(m, item))
return;
fa.Flip(item);
if (item is IFlipable)
((IFlipable)item).OnAfterFlip(m, item);
}
}[/COLOR]
[COLOR=DarkGreen]private class FlipTarget : Target
{
public FlipTarget() : base( -1, false, TargetFlags.None )
{
}
protected override void OnTarget( Mobile from, object targeted )
{
if (targeted is Item)
{
Item item = (Item)targeted;
if ( item.Movable == false && from.AccessLevel == AccessLevel.Player )
return;
Type type = targeted.GetType();
FlipableAttribute [] AttributeArray = (FlipableAttribute []) type.GetCustomAttributes(typeof(FlipableAttribute), false);
if( AttributeArray.Length == 0 )
return;
FlipableAttribute fa = AttributeArray[0];
[COLOR=Blue]if (targeted is IFlipable)
if (!((IFlipable)targeted).OnBeforeFlip(from, item))
return;[/COLOR]
fa.Flip(item);
[COLOR=Blue]if (targeted is IFlipable)
((IFlipable)targeted).OnAfterFlip(from, item);[/COLOR]
}
}
}
}[/COLOR]
[AttributeUsage( AttributeTargets.Class )]
public class DynamicFlipingAttribute : Attribute
{
public DynamicFlipingAttribute()
{
}
}
[AttributeUsage( AttributeTargets.Class )]
public class FlipableAttribute : Attribute
{
private int[] m_ItemIDs;
public int[] ItemIDs
{
get{ return m_ItemIDs; }
}
public FlipableAttribute() : this ( null )
{
}
public FlipableAttribute( params int[] itemIDs )
{
m_ItemIDs = itemIDs;
}
public virtual void Flip( Item item)
{
if ( m_ItemIDs == null )
{
try
{
MethodInfo flipMethod = item.GetType().GetMethod( "Flip", Type.EmptyTypes );
if (flipMethod != null)
flipMethod.Invoke(item, new object[0]);
}
catch
{
}
}
else
{
int index = 0;
for ( int i = 0; i < m_ItemIDs.Length; i++ )
{
if ( item.ItemID == m_ItemIDs[i] )
{
index = i + 1;
break;
}
}
if ( index > m_ItemIDs.Length - 1)
index = 0;
item.ItemID = m_ItemIDs[index];
}
}
}
}
ExampleWeapon
Code:
using System;
using Server;
namespace Server.Items
{
[Flipable( 0xF5E, 0xF5F )]
public class ExampleWeapon : BaseWeapon, IFlipable
{
[Constructable]
public ExampleWeapon()
: base(0xF5E)
{
}
public ExampleWeapon(Serial s)
: base(s)
{
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // Version
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = (int)reader.ReadInt();
}
public override void OnDoubleClick(Mobile from)
{
FlipCommandHandlers.FlipItem.DoFlip(this, from);
}
#region IFlipable Members
/// <summary>
/// This is fired before the "Flip" Command is fired
/// </summary>
/// <param name="m">the Mobile who is targeting the item</param>
/// <param name="item">the item that is going to be fliped</param>
/// <returns>"Always return True" OnBeforeFlip otherwise it'll not do the Flip() Method</returns>
public bool OnBeforeFlip(Mobile m, Item item)
{
return true;
}
/// <summary>
/// This is fired after the "Flip" Command is fired
/// </summary>
/// <param name="m">the Mobile who targeted the item</param>
/// <param name="item">the Item that was fliped</param>
public void OnAfterFlip(Mobile m, Item item)
{
item.PublicOverheadMessage(Server.Network.MessageType.Emote, 0, false, "*flipped*");
}
#endregion
}
}